> ## Documentation Index
> Fetch the complete documentation index at: https://docs.definable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Slack Bot

> Deploy an agent as a Slack bot with slash commands.

Build a Slack bot with tools, memory, and slash commands.

<Steps>
  <Step title="Create the Slack app">
    1. Go to [api.slack.com/apps](https://api.slack.com/apps) and click **Create New App**
    2. Enable **Socket Mode** and generate an App-Level Token (`xapp-`)
    3. Add bot scopes: `chat:write`, `app_mentions:read`, `channels:history`, `im:history`
    4. Subscribe to events: `message.im`, `app_mention`
    5. Install the app and copy the Bot Token (`xoxb-`)
  </Step>

  <Step title="Create the agent">
    ```python slack_bot.py theme={null}
    import asyncio
    import os
    from definable.agent import Agent
    from definable.agent.interface import SlackInterface
    from definable.memory import Memory, SQLiteStore
    from definable.tool.decorator import tool

    @tool
    def search_docs(query: str) -> str:
        """Search documentation for an answer."""
        return f"Found results for: {query}"

    agent = Agent(
        model="gpt-4o",
        instructions="You are a helpful Slack assistant.",
        tools=[search_docs],
        memory=Memory(store=SQLiteStore("./slack_memory.db")),
    )

    interface = SlackInterface(
        agent=agent,
        bot_token=os.environ["SLACK_BOT_TOKEN"],
        app_token=os.environ["SLACK_APP_TOKEN"],
        slash_commands={
            "/ask": "Ask the AI assistant a question",
        },
        done_reaction="white_check_mark",
    )

    asyncio.run(interface.serve_forever())
    ```
  </Step>

  <Step title="Install dependencies">
    ```bash theme={null}
    pip install 'definable[slack]'
    ```
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export SLACK_BOT_TOKEN="xoxb-..."
    export SLACK_APP_TOKEN="xapp-..."
    export OPENAI_API_KEY="sk-..."
    ```
  </Step>

  <Step title="Run">
    ```bash theme={null}
    python slack_bot.py
    ```

    Mention the bot in a channel or send a DM. Use `/ask` for slash commands.
  </Step>
</Steps>

## Production Deployment

Switch to HTTP Events API mode for production:

```python theme={null}
interface = SlackInterface(
    agent=agent,
    bot_token=os.environ["SLACK_BOT_TOKEN"],
    signing_secret=os.environ["SLACK_SIGNING_SECRET"],
    mode="http",
)
```

See [Slack reference](/interfaces/slack) for all configuration options including Block Kit interactions, modals, and shortcuts.
