Telling the server we're online
Once the client is connected, we'll need to tell the server that we're online so that it knows to route any stanzas sent to the bare JID (bot@localhost
) through to our script. To do this, we'll need to build a stanza using the library that comes as part of node-xmpp-client
called Less than XML or ltx.
We can access ltx
via the client object we loaded earlier. To send the presence data, we must first be online, so we'll add a function call in that event to send a presence stanza. Our code now becomes:
const Client = require('node-xmpp-client') , ltx = Client.ltx const options = { jid: 'bot@localhost', password: 'tellnoone' } const client = new Client(options) client.on('online', (connectionDetails) => { console.log('We are connected!') console.log(connectionDetails) sendPresence() }) const sendPresence = () => { var stanza = new ltx.Element('presence...