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

Add callback support to SlackBot::{send,reply} #540

Merged
merged 12 commits into from
Apr 24, 2020
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"dependencies": {
"@slack/client": "3.16.1-sec.2",
"bluebird": "^3.5.1",
"lodash": "^4.17.10",
"es6-promise": "~4.2.5"
"lodash": "^4.17.10"
},
"peerDependencies": {
"hubot": ">= 2.0.0"
Expand Down
12 changes: 7 additions & 5 deletions src/bot.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{SlackTextMessage, ReactionMessage, PresenceMessage} = require "./message"
SlackClient = require "./client"
pkg = require "../package"
Promise = global.Promise || require('es6-promise')
Promise = require("bluebird");

class SlackBot extends Adapter

Expand Down Expand Up @@ -84,10 +84,11 @@ class SlackBot extends Adapter
callback = ->
if typeof(messages[messages.length - 1]) == 'function'
callback = messages.pop()
for message in messages
messagePromises = messages.map (message) =>
return Promise.resolve() if typeof(message) is 'function'
rtlechow marked this conversation as resolved.
Show resolved Hide resolved
# NOTE: perhaps do envelope manipulation here instead of in the client (separation of concerns)
@client.send(envelope, message) unless message is ""
Promise.all(messages).then(callback.bind(null, null), callback)
Promise.all(messagePromises).then(callback.bind(null, null), callback)

###*
# Hubot is replying to a Slack message
Expand All @@ -99,12 +100,13 @@ class SlackBot extends Adapter
callback = ->
if typeof(messages[messages.length - 1]) == 'function'
callback = messages.pop()
for message in messages
messagePromises = messages.map (message) =>
return Promise.resolve() if typeof(message) is 'function'
rtlechow marked this conversation as resolved.
Show resolved Hide resolved
if message isnt ""
# TODO: channel prefix matching should be removed
message = "<@#{envelope.user.id}>: #{message}" unless envelope.room[0] is "D"
@client.send envelope, message
Promise.all(messages).then(callback.bind(null, null), callback)
Promise.all(messagePromises).then(callback.bind(null, null), callback)

###*
# Hubot is setting the Slack conversation topic
Expand Down