Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@8bitDesigner
Last active December 15, 2015 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 8bitDesigner/5338949 to your computer and use it in GitHub Desktop.
Save 8bitDesigner/5338949 to your computer and use it in GitHub Desktop.

Sending a message with node-xmpp

Basically, you just need to create a client, and then send a formatted chunk of XML representing the message. The spec here has the details on what that XML should look like, and ltx is used to create that element.

var XMPP = require('node-xmpp')
var client = new XMPP.Client(
{ boshURL: "https://beta.buddycloud.org/http-bind/"
, jid: 'paul.sweeney@jabber.org'
, password: 'xxxxxxxxxxx'
}
);
client.on = client.addListener
function Message(to, body) {
var message = new XMPP.Element('message', {to: to, type: 'chat'})
return message.c('body').t(body)
}
client.on('online', function() {
client.send(new Message("8bitdesigner@gmail.com", "Oh hai!"))
client.end() // nodejs has nothing left to do and will exit
})
client.on('error', function(e) {
console.error(e)
})
@8bitDesigner
Copy link
Author

Notes - I'm using a BOSH transport here, ideally the next step is to shove this in browserify and supply the XMPP lib that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment