Setup Steps
Setup and Configuration
1
Prerequisites
Ensure you have the following:
- A Slack workspace with admin privileges
- ngrok (for development)
- Python 3.7+
2
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"
3
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_mentionchat:writechat:write.customizechat:write.publicim:historyim:readim:write
- Scroll to the top and click "Install to Workspace"
- Click "Allow" to authorize the app
4
Setup Environment Variables
Create a Find these values in your Slack App settings:
.envrc file in your project root with the following content, replacing placeholder values with your actual credentials:- Bot User OAuth Token: Under "OAuth & Permissions"
- Signing Secret: Under "Basic Information" > "App Credentials"
direnv allow).5
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)
6
Configure Event Subscriptions
- Under "Subscribe to bot events" in Event Subscriptions:
- Click "Add Bot User Event" and add:
app_mentionmessage.immessage.channelsmessage.groups
- Click "Save Changes"
- Reinstall your app to apply the new permissions
7
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
8
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 withSlackAPI, 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
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