Skip to main content
slack_bot.py
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
from agno.os.app import AgentOS
from agno.os.interfaces.slack import Slack

agent_db = SqliteDb(session_table="agent_sessions", db_file="tmp/persistent_memory.db")

basic_agent = Agent(
    name="Basic Agent",
    model=OpenAIChat(id="gpt-4o"),
    db=agent_db,
    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)
Install the dependency: uv pip install 'agno[slack]'

Setup

1

Create a Slack App

  1. Go to api.slack.com/apps and click Create New App
  2. Choose From scratch, give it a name, and select your workspace
  3. On the Basic Information page, copy the Signing Secret
2

Enable Agents & AI Apps

This is required for streaming task cards and suggested prompts.
  1. In the sidebar, click Agents & AI Apps
  2. Toggle Agent or Assistant to On
  3. Under Suggested Prompts, select Dynamic
  4. Click Save
Enabling this automatically adds the assistant:write scope.
3

Add OAuth Scopes

  1. In the sidebar, click OAuth & Permissions
  2. Under Scopes > Bot Token Scopes, add:
ScopePurpose
app_mentions:readReceive @mention events
assistant:writeStreaming (task cards, suggested prompts)
chat:writeSend messages and stream responses
im:historyRead DM history for thread context
files:readDownload files users send to the bot
files:writeUpload response files (images, docs)
These are the minimum scopes for streaming. Add channels:history, groups:history, users:read, or search:read if your agent uses SlackTools for channel history, user lookup, or message search.
  1. Click Install to Workspace and authorize the app
  2. Copy the Bot User OAuth Token (xoxb-...)
4

Set Environment Variables

export SLACK_TOKEN="xoxb-your-bot-user-token"
export SLACK_SIGNING_SECRET="your-signing-secret"
Find these in your Slack App settings:
  • Bot User OAuth Token: OAuth & Permissions
  • Signing Secret: Basic Information > App Credentials
5

Subscribe to Events

  1. In the sidebar, click Event Subscriptions
  2. Toggle Enable Events to On
  3. Set Request URL to your tunnel URL:
    https://<your-tunnel>/slack/events
    
    Your app must be running for Slack to verify the URL.
  4. Under Subscribe to bot events, add:
EventPurpose
app_mentionRespond to @mentions in channels
message.imRespond to direct messages
assistant_thread_startedSet suggested prompts on new threads
Add message.channels and message.groups if you set reply_to_mentions_only=False and want the bot to respond to all channel messages.
  1. Click Save Changes
  2. Go to Install App and click Reinstall to Workspace
6

Enable App Home

  1. In the sidebar, click App Home
  2. Under Show Tabs, enable Messages Tab
  3. Check Allow users to send Slash commands and messages from the messages tab
7

Start a Tunnel

Slack needs a public HTTPS URL to deliver events:
ngrok http 7777
Copy the https:// forwarding URL and paste it into the Event Subscriptions Request URL (Step 5). The free ngrok tier gives you a random subdomain that changes on restart.
8

Run the App

python slack_bot.py
DM the bot or @mention it in a channel to test.
ngrok is for local development only. For production, see the deployment templates.

Scopes Reference

Add scopes based on the features your bot uses.

Minimum (streaming bot that responds to mentions and DMs)

ScopeRequired For
app_mentions:readReceive @mention events in channels
assistant:writeStreaming task cards, suggested prompts, thread titles
channels:readResolve channel names (called on every inbound event)
chat:writeSend messages and stream responses
im:historyRead DM history for thread context

File handling

ScopeRequired For
files:readDownload files users attach to messages
files:writeUpload images, audio, video, and files generated by agent tools

SlackTools methods

ScopeRequired For
channels:readlist_channels(), get_channel_info()
channels:historyget_channel_history(), get_thread() in public channels
groups:readlist_channels() for private channels
groups:historyget_channel_history(), get_thread() in private channels
search:readsearch_messages() (requires user token)
search:read.publicsearch_workspace() messages and channels
search:read.filessearch_workspace() files
search:read.userssearch_workspace() users
users:readlist_users(), get_user_info()
users:read.emailget_user_info() with email field

Other features

ScopeRequired For
users:readresolve_user_identity=True on the Slack interface
users:read.emailresolve_user_identity=True with email lookup
channels:historyreply_to_mentions_only=False in public channels
groups:historyreply_to_mentions_only=False in private channels

Event subscriptions

EventRequired For
app_mentionRespond to @mentions in channels
message.imRespond to direct messages
assistant_thread_startedSet suggested prompts on new threads
message.channelsRespond to all public channel messages (reply_to_mentions_only=False)
message.groupsRespond to all private channel messages (reply_to_mentions_only=False)

Developer Resources

Slack Interface

Streaming, sessions, file handling, and behavior details.

Interface Reference

All parameters, endpoints, and event handling.

SlackTools

Give agents outbound Slack actions: messaging, search, files.

Deployment Templates

Production deployment guides for AWS, GCP, and Docker.