How to get a workspace agnostic Slack bot token?

2019-07-29 06:27发布

问题:

I'm trying to create a bot that people can install in their workspaces and send/receive messages of some sort. The problem I'm running into is the documentation tells you to use the token generated for your workspace:

https://api.slack.com/bot-users#installing-bot

But this makes no sense, seeing as people would be installing the App/Bot on their workspace themselves, it's not like they would be giving me their token or anything. Surely I'm missing something. How am I meant to authenticate a bot against whatever workspace it is installed in a purely API driven way?

回答1:

There is no "workspace agnostic" Slack token. Every token is linked to a specific workspace and user.

The usual approach is that you provide an installation routine with Oauth 2.0 for your Slack app. When someone installs your app with that routine a new token is created internally that your app needs to collect and store. This is how every Slack app works.

Note that the installation has to be done once only for each workspace. The token does not expire.

Its simply when you install your Slack app on your own workspace only. That can be done directly from the Slack app management window and requires no installation routine. But then you obviously need to manually copy the generated token to your app.