Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for XMPP rosters on connect #65

Closed
wants to merge 13 commits into from
13 changes: 13 additions & 0 deletions src/xmpp.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class XmppBot extends Adapter
@connected = false
@configClient(options)

# Expose the XMPP client through the robot to allow third-party scripts
# to send messages directly
@robot.xmppClient = @client
@robot.xmppRoster = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the robot had a reference to the adapter it was using. I could be wrong though.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently there is a robot.adapter. I will make sure it works the same as what I'm doing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need robot.adapter.client.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that robot.adapter.client works


configClient: (options) ->
@client.connection.socket.setTimeout 0
@client.connection.socket.setKeepAlive true, options.keepaliveInterval
Expand Down Expand Up @@ -152,6 +157,14 @@ 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 (stanza.attrs.id == 'roster_1' && stanza.children[0]['children'])
roster_items = stanza.children[0]['children']

for item in roster_items
jid = new Xmpp.JID(item.attrs.jid)
@robot.xmppRoster.push(jid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this result in duplicates if the bot sat in multiple rooms with the same people?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I don't use rooms. Could certainly add some checking to ensure there are no dupes.


readMessage: (stanza) =>
# ignore non-messages
Expand Down