diff --git a/README.mdown b/README.mdown index 951be5c..302cbef 100644 --- a/README.mdown +++ b/README.mdown @@ -1,6 +1,6 @@ # Hubot XMPP -Connects Hubot to your XMPP network +Connects Hubot to your XMPP network [![Build Status](https://secure.travis-ci.org/markstory/hubot-xmpp.png?branch=master)](http://travis-ci.org/markstory/hubot-xmpp) @@ -29,10 +29,11 @@ Optional: the host to be defined. * `HUBOT_XMPP_PREFERRED_SASL_MECHANISM` Used to change the encoding used for SASL. * `HUBOT_XMPP_DISALLOW_TLS` Prevent upgrading the connection to a secure one via TLS. +* `HUBOT_XMPP_CLIENT_ROSTER` Will request and cache the client's roster after connecting `HUBOT_XMPP_ROOMS` can be a comma separated list of rooms to join. If your rooms require passwords you should use the `jid:password` syntax. -Room passwords cannot contain `,`. Room names must be the full jid of the +Room passwords cannot contain `,`. Room names must be the full jid of the room for example `dev@conference.jabber.example.org`. ## Installation diff --git a/src/xmpp.coffee b/src/xmpp.coffee index c0fdb44..d8b1d8d 100644 --- a/src/xmpp.coffee +++ b/src/xmpp.coffee @@ -27,6 +27,7 @@ class XmppBot extends Adapter legacySSL: process.env.HUBOT_XMPP_LEGACYSSL preferredSaslMechanism: process.env.HUBOT_XMPP_PREFERRED_SASL_MECHANISM disallowTLS: process.env.HUBOT_XMPP_DISALLOW_TLS + roster: process.env.HUBOT_XMPP_CLIENT_ROSTER @robot.logger.info util.inspect(options) options.password = process.env.HUBOT_XMPP_PASSWORD @@ -81,6 +82,12 @@ class XmppBot extends Adapter @client.send presence @robot.logger.info 'Hubot XMPP sent initial presence' + # Request client roster if enabled + if @options.roster + @client.send do => + el = new Xmpp.Element('iq', from: @options.username, type: 'get', id: 'roster_1') + q = el.c('query', xmlns: 'jabber:iq:roster') + @joinRoom room for room in @options.rooms @emit if @connected then 'reconnected' else 'connected' @@ -152,6 +159,18 @@ class XmppBot extends Adapter @robot.logger.debug "[sending pong] #{pong}" @client.send pong + # Keep a record of the client's primarty roster after connecting, so that + # scripts have the option of sending messages to all of the clients contacts + else if (stanza.attrs.id == 'roster_1' && stanza.children[0]['children']) + roster_items = stanza.children[0]['children'] + + @client.roster = [] + + for item in roster_items + jid = new Xmpp.JID(item.attrs.jid) + @client.roster.push(jid) + + @robot.logger.debug "[setting roster] #{@client.roster}" readMessage: (stanza) => # ignore non-messages