Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send direct messages to a user as app in app channel

Tags:

How is it possible to send message in slack directly to the user, by user.id as application. enter image description here

this application has scope: bot,channels:write,emoji:read,users:read,users:read.email

I find how to send message only as DM or by webhooks, but there is no scope for that. Any one has idea?

like image 301
Koloritnij Avatar asked Dec 11 '17 13:12

Koloritnij


People also ask

Can Slack bot send direct message to user?

You may see Slackbot in channels throughout your workspace, delivering reminders and automated messages for you and your teammates. When there's a reminder or a message just for you, Slackbot will send you a DM. You can access your DM with Slackbot the same way you would find a DM with anyone else in your workspace.

How do I send a message to a Slack channel in Java?

I want to send DM to the User and would need to follow the below steps: Lookup user ID from email: https://api.slack.com/methods/users.lookupByEmail. Open DM with user: https://api.slack.com/methods/conversations.open. Send a message to the DM: https://api.slack.com/methods/chat.postMessage.


1 Answers

If I understand your question correctly, you want to send direct messages to users in the app channel instead of the standard slackbot channel.

In order to do that you need to

  1. Your app needs the bot scope and a bot user
  2. Open a direct message channel from your app with the user with conversations.open. You get back a direct message ID.
  3. Send a message with chat.postMessage to the the direct message channel ID

Make sure to use your bot access token (not the user access token) from your Slack app.

The bot scope gives you all permissions needed to open and send DMs to users from your bot channel. No other scopes are required.

You can also use the new conversations methods, which work for all kind of channel types to do the same.

See also this question on the same topic.

like image 150
Erik Kalkoken Avatar answered Nov 02 '22 07:11

Erik Kalkoken