1

I created a Slack app with a bot. I got the OAuth process working. The user completes OAuth process and I get both the regular token and bot token along with user_id.

When I try to send a api/chat.postMessage with bot token and channel = user_id that I received from OAuth, a message is created under "Slackbot".

How do I send a direct message to the user who authorized the OAuth? I want it under the (you) private/personal DM space.

Edit:

im.open creates a new channel between the bot and the authorized user. It does NOT post the message directly in the user's (you) private space.

LAX_DEV
  • 2,111
  • 3
  • 19
  • 29
  • Possible duplicate of [How to send direct messages to a user as app in app channel](https://stackoverflow.com/questions/47753834/how-to-send-direct-messages-to-a-user-as-app-in-app-channel) – Erik Kalkoken Jun 21 '19 at 11:03
  • @ErikKalkoken I have added an edit to explain the difference of you possible duplicate referenece. That post's solution is different from my requirement. – LAX_DEV Jun 21 '19 at 12:16
  • thanks for the clarification. That is indeed a different question. I''l post an answer – Erik Kalkoken Jun 21 '19 at 12:28

1 Answers1

2

Here is how you can send a message into your own personal user channel - e.g. for me it channel would be called "Erik Kalkoken (you)":

Send a message with chat.postMessage

  • Use an access token (not a bot token)
  • Set channel with the user ID. Must be the same user who authed the access token
  • Set as_user = true

Apparently this will only work if your app has an token authed by the specific user it wants to send a message to. So unless you gather tokens from all users in a workspace this will only work for the use who installed / authed your app.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114