How to Create and Configure a Slack App (Bot)

This guide walks you through creating and configuring a Slack app (bot) in a Slack workspace. It covers the initial setup, permissions, event subscriptions, and authentication tokens required to connect your application to Slack.
Note: This guide covers only the Slack configuration. It does not include developing the bot's functionality, implementing its logic, or deploying it to a hosting environment.
Prerequisites
A Slack account.
Access to a Slack workspace.
Permission to create and install apps in that workspace.
You don't need a paid Slack plan or a company account to follow this guide.
1. Create a Slack App
Go to api.slack.com/apps.
Click Create New App.

Select From scratch and pick features.

Enter an app name (for example, my-slack-bot).
Select the workspace where you want to install the app.

Click Create App.
2. Configure OAuth Scopes
OAuth scopes define what your bot is allowed to access and do within a workspace.
In the left sidebar, navigate to OAuth & Permissions.
Scroll down to Scopes > Bot Token Scopes.
Click Add an OAuth Scope and add the permissions required by your bot.

For a basic bot that reads messages from public channels and sends messages, you can start with:
Scope | Description |
channels:history | View messages in public channels the bot has joined. |
channels:read | View basic information about public channels. |
chat:write | Send messages as the bot. |
Additional scopes may be required depending on your bot's functionality. For example, users:read allows access to basic user information, while groups:history allows the bot to read messages in private channels it has joined.
Note: Only request the permissions your bot needs. If you change the scopes after installation, you need to reinstall the app to authorize the updated permissions.
3. Enable Socket Mode
Socket Mode allows your app to receive events through a WebSocket connection instead of requiring a publicly accessible HTTP endpoint.
In the left sidebar, navigate to Socket Mode.
Enable the Enable Socket Mode toggle.

This is one way to connect your application to Slack and is particularly useful when you don't want to expose a public endpoint.
4. Generate the App-Level Token
The App-Level Token is used to establish the WebSocket connection when using Socket Mode.
Go to Basic Information in the left sidebar.
Scroll down to App-Level Tokens.
Click Generate Token and Scopes.
Enter a token name (for example, socket-mode).
Add the connections:write scope.
Click Generate.

Slack will generate an App-Level Token starting with xapp-.
Copy the token and store it securely. You'll need it when connecting your application to Slack.
5. Enable Event Subscriptions
Event Subscriptions allow your app to receive notifications when specific events occur in Slack.
Navigate to Event Subscriptions in the left sidebar.
Turn Enable Events on.

Under Subscribe to bot events, click Add Bot User Event.
Add the following event:
Event | Description | Required Scope |
message.channels | Notifies the bot when a message is posted in a public channel it belongs to. | channels:history |
Click Save Changes.

Depending on your requirements, you can subscribe to additional events. For example, message.groups allows the bot to receive messages from private channels it has joined, provided it has the corresponding permissions.
6. Install the App and Get the Bot Token
Navigate to OAuth & Permissions.
Click Install to Workspace.
Review the requested permissions.
Click Allow to authorize the installation.

After installation, Slack generates a Bot User OAuth Token starting with xoxb-.
Copy the token and store it securely.

7. Create the Slack Channel
Create the channel where you want the bot to work (for example, a public channel visible to everyone in your workspace). You will select this channel during installation. In this example it will be a public channel.

8. Invite the Bot to a Channel
To allow your bot to access a channel:
Open the Slack channel where you want the bot to operate.
Type /invite @my-slack-bot.
Press Enter.

The bot will now be a member of that channel and will be able to access the events and information allowed by its permissions.
9. Quick test
If you haven't developed the bot's code yet, you can run a quick test from your terminal to verify that your token and permissions are working properly by sending a message to the channel:
Export your Bot User OAuth Token as an environment variable:
export SLACK_BOT_TOKEN="xoxb-your-bot-token"
Send a test message using curl:
curl -X POST <https://slack.com/api/chat.postMessage> -H "Authorization: Bearer $SLACK_BOT_TOKEN" -H "Content-Type: application/json; charset=utf-8" --data '{"channel":"#my-slack-bot","text":"Hello World 👋"}'
If everything is configured correctly, the API will return "ok":true and you will see the message appear in the #my-slack-bot channel.

10. What's Next?
Your Slack app is now created and configured. You have the authentication tokens and permissions needed to connect an application to Slack.
The next steps depend on your project:
Develop the bot: Implement its functionality and define how it should interact with Slack.
Connect to Slack: Use the Slack API and an appropriate SDK (such as Slack Bolt for Node.js or Python).
Choose a deployment environment: Run it locally for development or deploy it to a hosting environment of your choice.
For more information, check the official Slack API documentation.



