1

When creating a slack app, it creates a "channel" under the Apps header on the left hand menu. I want to be able to private message users within this from my bot / app rather than creating a new channel or messaging the user via slack bot.

The following direct messages the user via slack bot

curl -X POST "https://slack.com/api/chat.postMessage" -H  "accept: application/json" -d token=TOKEN -d channel=abc123 - d text=Hello

Or this messages all users in the workspace who have enabled the App via the apps own channel

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' https://hooks.slack.com/services/ABXXX/CDXXX/EFXXXX

I want a combo of these where I message 1 user via the apps own channel

An example of this is how Pull Reminders app works. All users in a workspace can use the app but when a pull request gets assigned to a user, only the user in question gets notified via the apps channel.

Stretch0
  • 8,362
  • 13
  • 71
  • 133
  • @Strecho0 Thank you for your question. I linked you the accepted answer that shows how to send a message to a user in the app channel. – Erik Kalkoken Feb 14 '19 at 18:05
  • I think in general its better to update the original question instead of posting a new one. Would appreciate if you could delete the original question, since it does not seam to serve any further purpose. Much appreciated! https://stackoverflow.com/questions/54659096/how-to-message-a-user-in-a-slack-app-via-api/54675828#54675828 – Erik Kalkoken Feb 14 '19 at 18:08
  • 1
    Thanks @ErikKalkoken, that solved my problem. I have tried to delete the original post but unable to now due to it already receiving comments / answers. I will keep that in mind in the future. – Stretch0 Feb 14 '19 at 20:16

1 Answers1

-1

I believe in this answer and thread it's covered.

By sending this :

curl -X POST "https://slack.com/api/chat.postMessage" -H  "accept: application/json" -d token=BOT_ACCESS_TOKEN -d channel=U0G9QF3C6 - d text=Hello

So as you see, the user ID is a channel name. This is specified here. What user access by clicking your App in the sidebar it's like IM between bot and user.

Ruslan Isay
  • 933
  • 7
  • 10
  • Hi @Ruslan Isay. Thanks for your contribution. I think the question your answer shows how to send a direct message to a user. But as I understand the question its asking about how to send a message in the app channel to a user, not a direct message. – Erik Kalkoken Feb 14 '19 at 18:03
  • Hi @ErikKalkoken! Maybe I'm not aware, but there is no such thing like "app channel". The only way to set up direct communication between a single user and application is via direct message from the bot to the user. And because this bot is listed like a separate channel in the sidebar of Slack, consufion with channels happens (in other words, what Slack users see in the sidebar is the IM with bot or app if non-bot token is used). – Ruslan Isay Feb 16 '19 at 04:47
  • I think that is not correct. There are two ways how an app can message a user privately. Either by sending a direct message to the user ID (then the message shows up in the slackbot channel). Or by posting a message in the app channel. Please check the answer accepted duplicate answer for details on how sending in the app channel works. – Erik Kalkoken Feb 16 '19 at 10:42
  • @ErikKalkoken Thanks for your clarification. I really was not aware of the option you described. However, the original question was about "When creating a slack app, it creates a "channel" under the Apps header". That's why I think more logical is to post by user ID instead of creating new channel and then post there. Additionally, it's more complicated to store and keep track of additional ID for new channel rather simply operate with user iD. – Ruslan Isay Feb 22 '19 at 16:40
  • I agree its a bit more complicated, but it looks nicer since all messages will appear under the app specific channel as opposed to being mixed up with other messages in the slackbot channel. – Erik Kalkoken Feb 22 '19 at 16:53
  • Seems there is a confusion. If you follow my approach, users will receive direct messages **not** from universal Slackbot, but from App-specific bot (or in other words in the App channel, e.g. MySlackApp). Note, it's important to set `as_user` option to true when posting a message and using bot token. So actually the result will be exactly the same as in the question. – Ruslan Isay Feb 22 '19 at 17:08
  • @ErikKalkoken I just wanted point your attention to my last comment if you have a moment to look. – Ruslan Isay Feb 27 '19 at 16:12
  • Your approach works. Thanks for sharing it. Would be great if you could add your alternative solution to the original question, which this is a duplicate of, so others can benefit from it. (btw. your answer here is currently missing the as_user property so this would not work) https://stackoverflow.com/questions/47753834/how-to-send-direct-messages-to-a-user-as-app-in-app-channel – Erik Kalkoken Feb 28 '19 at 12:38
  • 1
    That's good idea. Done. – Ruslan Isay Feb 28 '19 at 16:22