Search code examples
slackslack-api

Slack bot - Sending messages to different users in multiple Workspaces


I want to deliver direct messages to different users by using Slack bot. I'll send them based on events of my web app.

But different companies will install my bot in different Workspaces. That also means an user X of company A is in workspace A, and user Y of company B is in Workspace B

My doubts are:

  1. If I call API method users.list will it include all users from all workspaces that installed the bot?

  2. The bot user access token is the same for all workspaces?


Solution

  • 1 - No. users.list will only contain the users for one workspace. The one that is linked to the token you are using in the API call.

    2 - No. There is a different bot token for every workspace

    Here is how it works.

    • A user that wants to use your bot in his workspace needs to first install it. During the installation process (via Oauth 2.0) a new token for that workspace will be generated and you app will need to store it. Note that installation has to be once only. The token does not expire.
    • When your app receives an event it will contain the team ID (that references the workspace). You app then needs to use the token for that workspace to make any API calls.