I created a websocket-based Slack bot (that plays chess). In order to return a graphical representation of the board (so PNG instead of simple ASCII) I must use a webhook since normal messages cannot have attachments.
The interaction with the bot is through direct messages and I have 1 webhook. If I set the channel in the wehook to '@username' the message gets posted in that user 'slackbot' DM. But I want it to be posted in my bot's DM with that user.
How do I do that?
Or is there an alternative instead of a webhook?
Thanks.
Henry
A user (or bot user) still needs to be member of a private / direct message channel in order to have access to it. It does also not matter what permission or role you have. Even the primary owner has no access to private channels he is not a member of.
Bot users can't post to a direct message conversation between two users using chat. postMessage . If your app was involved in the conversation, then it would be a multi-person direct message instead.
Open the channel or DM you'd like to send a message to. Click the message field. Type your message and add any attachments, emoji, mentions, or formatting you'd like. Press Enter to send it.
Message options Incoming webhooks allow you to add context to your messages by attaching helpful content and links. Things like images, websites, or other pieces of data make these messages more useful for your team.
Direct messages between bot and user
If you want to use a bot-specific direct message channel instead of the general slackbot channel you need to open a direct message channel just as you would between any two users.
Open the direct message channel from your bot to a user with im.open
(which will provide you with the channel ID). Then send the message to that channel ID, e.g. with chat.postMessage
.
Important: Make sure you use the bot access token and not the general access token for all API calls.
Method for sending messages
I would recommend using the API method chat.postMessage
instead of the webhook. It gives you more options than a webhook and of course also supports attachments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With