Slack App
Host agents as Slack Applications.
The Slack App is used to serve Agents or Teams via Slack, using a FastAPI server to handle Slack events and send messages.
Setup Steps
Setup and Configuration
Prerequisites
Ensure you have the following:
- A Slack workspace with admin privileges
- ngrok (for development)
- Python 3.7+
Create a Slack App
- Go to Slack App Directory
- Click "Create New App"
- Select "From scratch"
- Provide:
- App name
- Workspace to install to
- Click "Create App"
Configure OAuth & Permissions
- Navigate to "OAuth & Permissions" in your Slack App settings
- Under "Scopes", click "Add an OAuth Scope"
- Add the following Bot Token Scopes:
app_mention
chat:write
chat:write.customize
chat:write.public
im:history
im:read
im:write
- Scroll to the top and click "Install to Workspace"
- Click "Allow" to authorize the app
Setup Environment Variables
Create a .envrc
file in your project root with the following content, replacing placeholder values with your actual credentials:
Find these values in your Slack App settings:
- Bot User OAuth Token: Under "OAuth & Permissions"
- Signing Secret: Under "Basic Information" > "App Credentials"
Ensure this file is sourced by your shell (e.g., by using direnv allow
).
Setup Webhook with ngrok
- For local development, use ngrok to expose your local server to the internet:
- Copy the
https://
URL provided by ngrok - In your Slack App settings, go to "Event Subscriptions"
- Enable events by toggling the switch
- Add your Request URL:
- Format:
https://your-ngrok-url.ngrok.io/slack/events
- Format:
- Wait for Slack to verify the endpoint (your app must be running)
Configure Event Subscriptions
- Under "Subscribe to bot events" in Event Subscriptions:
- Click "Add Bot User Event" and add:
app_mention
message.im
message.channels
message.groups
- Click "Save Changes"
- Reinstall your app to apply the new permissions
Enable App Home
- Go to "App Home" in your Slack App settings
- Under "Show Tabs":
- Enable "Messages Tab"
- Check "Allow users to send Slash commands and messages from the messages tab"
- Save changes
Final Installation
- Go back to "Install App" in your Slack App settings
- Click "Reinstall to Workspace"
- Authorize the app with the new permissions
- Your app is now ready to use!
Example Usage
Create an agent, wrap it with SlackAPI
, and serve it:
Core Components
SlackAPI
: Wraps Agno agents/teams for Slack integration via FastAPI.SlackAPI.serve
: Serves the FastAPI app using Uvicorn, configured for Slack.
SlackAPI
Class
Main entry point for Agno Slack applications.
Initialization Parameters
Parameter | Type | Default | Description |
---|---|---|---|
agent | Optional[Agent] | None | Agno Agent instance. |
team | Optional[Team] | None | Agno Team instance. |
settings | Optional[APIAppSettings] | None | API configuration. Defaults if None . |
api_app | Optional[FastAPI] | None | Existing FastAPI app. New one created if None . |
router | Optional[APIRouter] | None | Existing APIRouter. New one created if None . |
app_id | Optional[str] | None | App identifier (autogenerated if not set). |
name | Optional[str] | None | Name for the App. |
description | Optional[str] | None | Description for the App. |
Provide agent
or team
, not both.
Endpoints
The main endpoint for Slack integration:
POST /slack/events
- Description: Handles all Slack events including messages and app mentions
- Security: Verifies Slack signature for each request
- Event Types:
- URL verification challenges
- Message events
- App mention events
- Features:
- Threaded conversations
- Background task processing
- Message splitting for long responses
- Support for both direct messages and channel interactions
Testing the Integration
- Start your application locally with
python <my-app>.py
(ensure ngrok is running) - Invite the bot to a channel using
/invite @YourAppName
- Try mentioning the bot in the channel:
@YourAppName hello
- Test direct messages by opening a DM with the bot
Troubleshooting
- Verify all environment variables are set correctly
- Ensure the bot has proper permissions and is invited to channels
- Check ngrok connection and URL configuration
- Verify event subscriptions are properly configured
- Monitor application logs for detailed error messages
Support
For additional help or to report issues, please refer to the documentation or open an issue in the repository.