-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[Slack] 👻 Add Ephemeral Message Support #958
Conversation
@@ -338,6 +337,10 @@ module.exports = function(botkit, config) { | |||
}; | |||
|
|||
bot.send = function(message, cb) { | |||
if (message.ephemeral) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to retain a single send function, and just check if the message should be ephemeral or not
Using send like this also preserves access to these messages from send middlewares!
attachments: message.attachments ? | ||
JSON.stringify(message.attachments) : null, | ||
}; | ||
console.log({message}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use botkit.debug
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No good reason, ty for catching it
JSON.stringify(message.attachments) : null, | ||
}; | ||
console.log({message}) | ||
console.log({slack_message}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, is better use botkit.debug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thanks for updating the docs.
First pass at this for everyone hungry to jump on the new features!
TLDR; We have bot.whisper now!!
This adds two new functions to Botkit to make use of the new
chat.postEphemeral
Web API method.bot.whisper():
Works just like bot.reply, takes a source message and clones the channel and user (user is required for this api method) and sends it. We also set
as_user
to true to show the messages are coming from the bot user (or whoevers token you're making calls with). This can be overridden by settinguser: false
on the outgoing message body, or using the second new method:bot.sendEphemeral():
Works like bot.send, takes a botkit message with a channel and user (again, user is required for this method by slack) and sends a message, unprompted by the user.
Ephemeral in Conversations
Currently there is shakey support of interactive messages, slack is not sending the original message in the trigger payload, which is normally sent along with interactive message payloads.replyInteractive to ephemeral interactive messages doesnt update them either. I asked in the slack api channel but havent heard anything about this yet.That unfortunately makes ephemeral messages, at this time, not as feature rich as their standard counterparts, and doing complex user flows with updating their choices isnt possible currently in the ephemeral realm 👻Got a response from @episod! Interactive messages do work with ephem. However, slack is not passing the original message object along with the payload. To respond, you must construct a new message. I've experienced issues where my updated message is attributed to the App and not the bot. Not sure what I'm doing wrong still, passing
as_user: true
doesnt seem to work.To send an ephemeral message as part of a normal conversation, add
ephemeral: true
to the message body. See the updated docs for an example