How to Build an AI Agent in Slack [DIY Guide]
4 min read
Step by step instructions on creating an AI agent in Slack using Open Source Slack AI Bot Builder
![Cover Image for How to Build an AI Agent in Slack [DIY Guide]](https://cdn.hashnode.com/res/hashnode/image/upload/v1753596357650/0913d77d-d6ca-470f-b188-ea89eab1bd5b.png?w=1600&h=840&fit=crop&crop=entropy&auto=compress,format&format=webp)
Objective
By the end of this DIY guide, you’ll have:
A Slack Bot
A backend that can
Listen to user messages or alerts in a channel and take agentic action based on prompts or steps that you might have in mind.
Query your Grafana instance, analyse logs/dashboards and send info about anomaly in reply to an alert/message in your Slack channel
Pre-requisites
Ngrok to expose the slackbot server. Setup instructions
Grafana (Optional)
Step 0: Clone the repo:
Repository Link - https://github.com/DrDroidLab/slack-ai-bot-builder
Step 1: Building the Slack Bot with an integrated backend
The backend repo setup here, behaves in multiple ways:
Acts as an MCP Client for any AI calls you might want to make
Acts as a server to accept webhooks from Slack and manage configurations
Setting up the Ngrok Tunnel
Expose port 5000 of your localhost, using the command:
ngrok http 5000
You will receive a HTTPS URL of the form https://abc123.ngrok.io
Which is pointing to port 5000 of your system.
Note: We have not setup a server running on port 5000 yet, but that is fine since ngrok is independent of that, and exposes the port regardless.
Creating the Slack Application
Go to Slack API Apps – https://api.slack.com/apps
Click on Create App, and select the option ‘From a manifest’
Copy the manifest json from the repository and replace the placeholder ‘<hostname>’ with the HTTPS URL you got from ngrok. Include the “https://” part as well.
Install the app in your workspace.
Copy the credentials for the slack application into credentials.yaml
app_id, app_name and signing secret can be found in the basic information tab.
Bot-auth-token can be found in the Oauth & Permissions tab.
openai_key from openai - if you plan to use AI based workflows.
Create a channel called #drdroid-slack-bot-tester in your slack workspace & add the bot to the channel.
Setting up the bot server
Run the following commands to set up your virtual environment and activate it.
uv env venv
source .venv/bin/activate
Install dependencies using:
uv sync
Now we can finally run the bot server using:
uv run python app.py
The server is now running on port 5000, and exposed to the outside world via your ngrok tunnel.
Testing the bot
Add the bot to the drdroid-slack-bot-tester workspace that you had previously created.
And just type in a ‘hi’. The bot should send you a sample response.
Step 2: Integrating AI
There is already an example workflow for AI (name: "chatbot") in the workflows.yaml. It is just boilerplate code, you can modify it as required. For now, you can tag your bot in the drdroid-slack-bot-tester, and chat with it.
- Add your OpenAI/LLM key
For example:
Message in Slack: chatbot How to debug Kubernetes CrashLoopBackOff error? @bot
Message in Slack: chatbot I'm getting this alert. What does it mean? @bot
Step 3: Making the bot an Agent by giving AI access to different tools (Grafana for demo)
MCP Servers help abstract out any API and making them accessible to AI.
Setting up Grafana MCP Server
Clone the following repository:
Repository URL - https://github.com/DrDroidLab/grafana-mcp-server
Navigate into the root directory of the repository.
Populate the src/grafana_mcp_server/config.yaml
with your grafana credentials.
Install and setup the dependencies using:
uv venv .venv
source .venv/bin/activate
uv sync
Run the MCP server:
uv run -m src.grafana_mcp_server.mcp_server
Your MCP server is now running on port 8000.
Creating an AI Grafana workflow in slack-bot-builder
There is already an example workflow for grafana ai in the workflows.yaml.
We will be running the script scripts/grafana_ai_tool.py in this workflow, it is just boilerplate code, you can modify it as required.
Now you can tag your bot in the drdroid-slack-bot-tester, and ask it to do various things from grafana.
For example:
Message in Slack: Fetch me logs from the currencyservice in grafana ai.
Message in Slack: Fetch and analyse the Go Microservices dashboard from grafana ai
Next Steps:
Now that you’ve been able to setup a bot, here are a few things you can do:
Productionise it from your current ngrok setup to a static endpoint
Integrate with Grafana or open source MCP servers of your favourite tool that you want to leverage for automation
Add custom prompts and scripts
Stuck anywhere? Ask on our Discord