Skip to content

Commit

Permalink
Merge pull request #148 from paulhammond/attachments
Browse files Browse the repository at this point in the history
Add back support for Slack attachments
  • Loading branch information
paulhammond committed Feb 27, 2015
2 parents 743fa06 + 471e71d commit 5eed8d6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@
"test": "mocha --compilers coffee:coffee-script/register --reporter spec"
},
"dependencies": {
"slack-client": "~1.2.0"
"slack-client": "~1.4.0"
}
}
32 changes: 32 additions & 0 deletions src/slack.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class SlackBot extends Adapter
@client.on 'userChange', @.userChange
@robot.brain.on 'loaded', @.brainLoaded

@robot.on 'slack-attachment', @.customMessage
@robot.on 'slack.attachment', @.customMessage

# Start logging in
@client.login()

Expand Down Expand Up @@ -245,4 +248,33 @@ class SlackBot extends Adapter
channel = @client.getChannelGroupOrDMByName envelope.room
channel.setTopic strings.join "\n"

customMessage: (data) =>

channelName = if data.channel
data.channel
else if data.message.envelope
data.message.envelope.room
else data.message.room

channel = @client.getChannelGroupOrDMByName channelName
return unless channel

msg = {}
msg.attachments = data.attachments || data.content
msg.attachments = [msg.attachments] unless Array.isArray msg.attachments

msg.text = data.text

if data.username && data.username != robot.name
msg.as_user = false
if data.icon_url?
msg.icon_url = data.icon_url
else if data.icon_emoji?
msg.icon_emoji = data.icon_emoji
else
msg.as_user = true

channel.postMessage msg

# Export class for unit tests
module.exports = SlackBot

0 comments on commit 5eed8d6

Please sign in to comment.