You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here, you should find a green button that says Create New App. When you click this button, select the option to create your app from scratch.
Create a name for your bot, such as "My First Bot". Select the workspace you would like your bot to exist in. If your workspace has app restrictions, you will see a yellow warning message similar to the one shown below. This is okay! Click Create App.
Once you have created your bot, you should see a page like the following.
We will need to configure some settings so that the bot behaves properly. Navigate to the OAuth & Permissions tab under Features on the left panel.
Scroll down, and add the following scopes under Bot Token Scopes:
app_mentions.read: allows the bot to view messages that mention your bot.
channels:join: allows the bot to join channels.
chat:write: allows the bot to post messages in a public channel.
Next, we will enable Socket Mode. Socket Mode allows our bot to interact in our workspace without exposing a public HTTP endpoint, which might not be allowed behind a corporate firewall.
To enable Socket Mode, navigate to the “Socket Mode” tab under Settings in the left panel. Toggle the button next to Enable Socket Mode.
Create an app level token for your bot as shown below. An app level token is connected to your app universally and across each organization that your app is used in. This is different from a bot level token, which will be discussed later. The token name is bot_app_token in this example.
After clicking Generate you will receive an app level token which will be referred to as the SLACK_APP_TOKEN. Copy this token and store it somewhere safe - we will need it later. Click the Done button and make sure Socket Mode is enabled.
Once we have enabled Socket Mode, we will enable Event Subscriptions. Event subscriptions allow our bot to automatically respond to certain events, such as a mention or direct message. Navigate to “Event Subscriptions” under Features in the left panel. Enable events.
Expand the Subscribe to bot events section and click the Add Bot User Event button. Select the app_mention event to subscribe, then save your changes.
Once you have configured your bot, we can install it to a workspace. To do this, navigate to “Install App” under Settings.
If your workspace is restricted, like Twilio’s and many large organizations, you will need to request to install your app before you can view it in your workspace. This process might look different depending on your organization. At Twilio, after you request to install an app, you will be required to submit a request via the Service Now portal to approve your app.
There might be other cases where you will need to create a request when working from behind a corporate firewall. For example, you might want to use Webhooks to gather real time data for your app. Webhooks require a URL to send JSON data to. You might be able to request a unique URL from your organization for this purpose.
Once your app has been approved, revisit the Install App tab. You should now have access to a Bot User OAuth Token.
This is your SLACK_BOT_TOKEN. A Slackbot token references a bot user instance of the app you have created, and specifically sets the scopes that your bot has access to.
documentationImprovements or additions to documentation
1 participant
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Creating a Slack bot
Go to Slack Apps API
Here, you should find a green button that says Create New App. When you click this button, select the option to create your app from scratch.
Once you have created your bot, you should see a page like the following.
We will need to configure some settings so that the bot behaves properly. Navigate to the OAuth & Permissions tab under Features on the left panel.
Scroll down, and add the following scopes under Bot Token Scopes:
app_mentions.read
: allows the bot to view messages that mention your bot.channels:join
: allows the bot to join channels.chat:write
: allows the bot to post messages in a public channel.Next, we will enable Socket Mode. Socket Mode allows our bot to interact in our workspace without exposing a public HTTP endpoint, which might not be allowed behind a corporate firewall.
To enable Socket Mode, navigate to the “Socket Mode” tab under Settings in the left panel. Toggle the button next to Enable Socket Mode.
Create an app level token for your bot as shown below. An app level token is connected to your app universally and across each organization that your app is used in. This is different from a bot level token, which will be discussed later. The token name is
bot_app_token
in this example.After clicking Generate you will receive an app level token which will be referred to as the
SLACK_APP_TOKEN
. Copy this token and store it somewhere safe - we will need it later. Click the Done button and make sure Socket Mode is enabled.Once we have enabled Socket Mode, we will enable Event Subscriptions. Event subscriptions allow our bot to automatically respond to certain events, such as a mention or direct message. Navigate to “Event Subscriptions” under Features in the left panel. Enable events.
Expand the Subscribe to bot events section and click the Add Bot User Event button. Select the
app_mention
event to subscribe, then save your changes.Once you have configured your bot, we can install it to a workspace. To do this, navigate to “Install App” under Settings.
If your workspace is restricted, like Twilio’s and many large organizations, you will need to request to install your app before you can view it in your workspace. This process might look different depending on your organization. At Twilio, after you request to install an app, you will be required to submit a request via the Service Now portal to approve your app.
There might be other cases where you will need to create a request when working from behind a corporate firewall. For example, you might want to use Webhooks to gather real time data for your app. Webhooks require a URL to send JSON data to. You might be able to request a unique URL from your organization for this purpose.
Once your app has been approved, revisit the Install App tab. You should now have access to a Bot User OAuth Token.
This is your
SLACK_BOT_TOKEN
. A Slackbot token references a bot user instance of the app you have created, and specifically sets the scopes that your bot has access to.That's it, thanks for your time.
Beta Was this translation helpful? Give feedback.
All reactions