> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2-update-deprecated-models.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Slack Bot

> Build a Slack bot that responds to messages, joins channels, and executes commands using agents.

Agno and AgentOS make it easy to deploy your agents on Slack with just 2 extra lines of code.

This example creates a simple agent for answering questions:

```python theme={null}
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.os import AgentOS
from agno.os.interfaces.slack import Slack

basic_agent = Agent(
    name="Basic Agent",
    model=OpenAIChat(id="gpt-5.2"), # Ensure OPENAI_API_KEY is set
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
)

agent_os = AgentOS(
    agents=[basic_agent],
    interfaces=[Slack(agent=basic_agent)],
)
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="slack_bot:app", port=7777, reload=True)
```

<Note>
  Install the Slack SDK: `pip install slack-sdk`
</Note>

<Note>
  Thread timestamps are automatically used as session IDs, so each Slack thread maintains its own conversation context.
</Note>

## Setup and Configuration

<Steps>
  <Step title="Prerequisites">
    Ensure you have the following:

    * A Slack workspace with admin privileges
    * ngrok (for development)
    * Python 3.7+
  </Step>

  <Step title="Create a Slack App">
    1. Go to [Slack App Directory](https://api.slack.com/apps)
    2. Click "Create New App"
    3. Select "From scratch"
    4. Provide:
       * App name
       * Workspace to install to
    5. Click "Create App"
  </Step>

  <Step title="Configure OAuth & Permissions">
    1. Navigate to "OAuth & Permissions" in your Slack App settings
    2. Under "Scopes", click "Add an OAuth Scope"
    3. Add the following Bot Token Scopes:
       * `app_mention`
       * `chat:write`
       * `chat:write.customize`
       * `chat:write.public`
       * `im:history`
       * `im:read`
       * `im:write`
    4. Scroll to the top and click "Install to Workspace"
    5. Click "Allow" to authorize the app
  </Step>

  <Step title="Setup Environment Variables">
    Create a `.env` file in your project root with the following content, replacing placeholder values with your actual credentials:

    ```bash theme={null}
    SLACK_TOKEN="xoxb-your-bot-user-token"  # Bot User OAuth Token
    SLACK_SIGNING_SECRET="your-signing-secret"  # App Signing Secret
    ```

    Find these values in your Slack App settings:

    * Bot User OAuth Token: Under "OAuth & Permissions"
    * Signing Secret: Under "Basic Information" > "App Credentials"
  </Step>

  <Step title="Setup Webhook with ngrok">
    1. Run ngrok to expose your local server, ensuring the port matches your app (7777):
       ```bash theme={null}
       ngrok http 7777
       # Or, if you have a paid ngrok plan with a static domain:
       # ngrok http --domain=your-custom-domain.ngrok-free.app 7777
       ```
    2. Copy the `https://` URL provided by ngrok
    3. In your Slack App settings, go to "Event Subscriptions"
    4. Enable events by toggling the switch
    5. Add your Request URL:
       * Format: `https://your-ngrok-url.ngrok.io/slack/events`
    6. Wait for Slack to verify the endpoint (your app must be running)
  </Step>

  <Step title="Configure Event Subscriptions">
    1. Under "Subscribe to bot events" in Event Subscriptions:
    2. Click "Add Bot User Event" and add:
       * `app_mention`
       * `message.im`
       * `message.channels`
       * `message.groups`
    3. Click "Save Changes"
    4. Reinstall your app to apply the new permissions
  </Step>

  <Step title="Enable App Home">
    1. Go to "App Home" in your Slack App settings
    2. Under "Show Tabs":
       * Enable "Messages Tab"
       * Check "Allow users to send Slash commands and messages from the messages tab"
    3. Save changes
  </Step>

  <Step title="Final Installation">
    1. Go back to "Install App" in your Slack App settings
    2. Click "Reinstall to Workspace"
    3. Authorize the app with the new permissions
    4. Your app is now ready to use!
  </Step>
</Steps>

<Note>
  ngrok is used only for local development and testing. For production deployments, see the [deployment tutorials](/production/templates/overview).
</Note>

## Developer Resources

* [Slack Interface](/agent-os/interfaces/slack/introduction)
* [Slack Events API](/reference-api/schema/slack/slack-events)
* [Deployment Templates](/production/templates/overview)
* [Discord](https://agno.link/discord)
