Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

[Slack] 👻 Add Ephemeral Message Support #958

Merged
merged 2 commits into from
Aug 29, 2017

Conversation

jonchurch
Copy link
Contributor

@jonchurch jonchurch commented Aug 15, 2017

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 setting user: 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

@@ -338,6 +337,10 @@ module.exports = function(botkit, config) {
};

bot.send = function(message, cb) {
if (message.ephemeral) {
Copy link
Contributor Author

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})
Copy link

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 ?

Copy link
Contributor Author

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})
Copy link

@k001 k001 Aug 16, 2017

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

@jonchurch jonchurch changed the title [Slack] 👻 Add Ephemeral Message Support [Slack] 👻 Add Ephemeral Message Support Aug 27, 2017
Copy link
Contributor

@benbrown benbrown left a 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.

@benbrown benbrown merged commit 0af2df7 into howdyai:master Aug 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants