Reputation: 341
I'm trying to send Direct Messages (DMs) to a user on Slack using chat.postMessage
using Bot token. But I'm only able to send messages to the users that are in my workspace.
How can I send message to any user on another workspaces?
When I try to do so, I get: "error": "channel_not_found"
I've that user's UserID
(U02....
), user's email and my Bot token.
Upvotes: 1
Views: 650
Reputation: 173
When you create a bot/app in Slack, you grant it OAuth Scopes which provide the bot access to certain information in your Slack instance. So for example, I expect you have added the users:read
Bot Token Scope to your Slack app, so that it can determine the users, and userId
's in your workspace.
However, this scope restricts the bot to only see users in your workspace.
There's a couple of ways around this though:
Now in Slack, you can message users in other workspaces with a feature called Slack Connect.
You'll first need to establish a connection with the user you want the bot to message. This can be arranged via an invite process, and once completed that userId
should become available to the bot. You can use that userId
in the channel
field of the chat.postMessage
API to direct message the user from the other workspace.
If you are on an Enterprise version of Slack, you should have multiple workspaces within a company, that are all linked by an enterpriseId
.
In this case, a possible solution might be to create what is known as an Org Level App
to have access to information across multiple workspaces. More information on Org Level apps can be found here.
Upvotes: 1