This guide provides a step-by-step walkthrough for creating a new Slack App, generating the necessary API tokens, and inviting the bot into a channel so it can send and receive messages.
The first step is to create a "Slack App" within your workspace. This app represents your bot.
Navigate to the App Creation Page:
Go to api.slack.com/apps.
Create a New App:
For your bot to be able to post messages, you need to grant it the correct permissions. These are called "scopes".
Go to OAuth & Permissions:
In the left-hand sidebar of your app's settings, navigate to "OAuth & Permissions".
Add Bot Token Scopes:
ObjNotify module:
chat:write: Allows the bot to send messages.channels:read: Allows the bot to read basic information about public channels.groups:read: Allows the bot to read basic information about private channels.users:read: Allows the bot to look up users by their ID.Once the permissions are set, you need to "install" the app into your workspace. This action generates the API token that your application will use.
Install to Workspace:
Copy the Bot User OAuth Token:
xoxb-.Add the Token to Your Project Configuration:
Objects.global_config).slack_api_token in the [slack] section of your configuration file:[slack]
slack_api_token = "xoxb-YOUR_TOKEN_HERE"
For your bot to be able to send messages to a specific channel, it must first be a member of that channel.
Open the Channel in Slack:
Go to the channel you want the bot to post in (e.g., #alerts).
Use the /invite Command:
@YourBotName with the name you gave your app./invite @YourBotName
When you create a Slack App, you will see several different credentials on the "Basic Information" page. It's important to understand what they are for. The only one you need for the ObjNotify module is the Bot User OAuth Token (xoxb-...).
Here is a breakdown of the other credentials, using the HomeChoice Slack bot details as an illustration of the format.
App ID: A unique identifier for your app within Slack.
A09RSL40ZFAClient ID: Used as part of the OAuth 2.0 flow for authenticating users. It is not used for sending simple chat messages.
104060942197.9876684033520Client Secret: Also used for the OAuth 2.0 flow. This should be kept confidential.
0b445ee6741c5a782b194bbb9c6e838aVerification Token: A legacy method for verifying that requests are coming from Slack. This has been largely replaced by using signed secrets.
0e3a73774105360c21b70b72af79ac54Your bot is now fully commissioned and ready to send notifications to the channel you invited it to. You can now use its channel name (e.g., #alerts) in the NotifySlackConnection column of your def_notify table to direct messages to it.