Skip to content

Commit

Permalink
Support for channel/group join/leave notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
grantmd authored and paulhammond committed Dec 8, 2014
1 parent 7095a76 commit 02b45b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ This is a modified set of instructions based on the [instructions on the Hubot w

% heroku config:add HEROKU_URL=http://soothing-mists-4567.herokuapp.com
% heroku config:add HUBOT_SLACK_TOKEN=xoxp-1234-5678-91011-00e4dd
% heroku config:add HUBOT_SLACK_BOTNAME=slack-hubot

- Deploy and start the bot:

Expand Down
26 changes: 17 additions & 9 deletions src/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class SlackBot extends Adapter
@client = new SlackClient options.token, options.autoReconnect, options.autoMark

# Setup event handlers
# TODO: I think hubot would like to know when people come online and enter/leave channels
# TODO: Handle eventual events at (re-)connection time for unreads and provide a config for whether we want to process them
@client.on 'error', @.error
@client.on 'loggedIn', @.loggedIn
Expand Down Expand Up @@ -63,17 +62,26 @@ class SlackBot extends Adapter
# Ignore our own messages
return if user.name == @robot.name

# Build message text to respond to, including all attachments
txt = msg.getBody()
# Test for enter/leave messages
if msg.type is 'channel_join' or 'group_join'
@robot.logger.debug "#{user.name} has joined #{channel.name}"
@receive new EnterMessage user

# Process the user into a full hubot user
user = @robot.brain.userForId user.name
user.room = channel.name
user.type = 'groupchat'
else if msg.type is 'channel_leave' or 'group_leave'
@robot.logger.debug "#{user.name} has left #{channel.name}"
@receive new LeaveMessage user

@robot.logger.debug "Received message: '#{txt}' in channel: #{channel.name}, from: #{user.name}"
else
# Build message text to respond to, including all attachments
txt = msg.getBody()

@receive new TextMessage user, txt, msg.ts
# Process the user into a full hubot user
user = @robot.brain.userForId user.name
user.room = channel.name

@robot.logger.debug "Received message: '#{txt}' in channel: #{channel.name}, from: #{user.name}"

@receive new TextMessage user, txt, msg.ts

send: (envelope, messages...) ->
channel = @client.getChannelGroupOrDMByName envelope.room
Expand Down

0 comments on commit 02b45b8

Please sign in to comment.