Private Message to User via Web API, not RTM API on Slack

317 views Asked by At

Is there a way to post a message via the web API as a bot user? Right now it seems the flow is to use as_user=False and set channel to @username that you want to send it to.

However, if I'm not using RTM, is there a nice way to send a direct message as the bot itself? https://api.slack.com/methods/chat.postMessage

1

There are 1 answers

2
Erik Kalkoken On

Yes. If you use the bot_access_token that you receive after installing your Slack app to the team with the bot scope when invoking the API method chat.postMessage, the direct message will come from your bot user. as_user has to be false, which is the default.

See Using Oauth 2.0 section "Bot user access tokens" for an example of how to get the bot_access_token.