Skip to content

Instantly share code, notes, and snippets.

@ErikAndreas
Created March 14, 2014 14:39
Show Gist options
  • Save ErikAndreas/9548991 to your computer and use it in GitHub Desktop.
Save ErikAndreas/9548991 to your computer and use it in GitHub Desktop.
Draft to git(lab?) webhooks forwarding to xmpp (ejabberd2) muc with node.js
var Client = require('node-xmpp-client'),
ltx = require('ltx'),
express = require('express'),
app = express();
room_jid = '[email protected]',
room_nick = 'GIT';
// valid user on im server (im.domain.com)
var client = new Client({
jid: '[email protected]',
password: 'password'
});
client.addListener('online', function(data) {
console.log('online ' + data.jid.user + '@' + data.jid.domain + '/' + data.jid.resource);
stanza = new ltx.Element('presence', { to: room_jid +'/' + room_nick}).c('x', { xmlns: 'http://jabber.org/protocol/muc' });
client.send(stanza);
});
// expand this to accept webhooks
app.get('/xmpp/:msg', function (req, res) {
var msg = req.params.msg;
console.log(msg);
var stanza = new ltx.Element('message',{ to: room_jid, type: 'groupchat'}).c('body').t(msg);
client.send(stanza);
res.end('sent');
});
app.listen(3000);
console.info('Listening on port 3000');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment