Slack DM Agent
Create a Slack AI agent that can chat with users in Slack DMs
Overview
Welcome to Magma! 🌋
This template will help you create:
- An AI agent hosted on Magma
- A Slack app connected to your agent
- Interactive chat with your agent right in your Slack workspace
Prerequisites:
- A Slack workspace where you have admin permissions
Getting Started
First, we need the Magma CLI to clone the Slack DM template, and save it to your Magma account.
Install the CLI
Login to Magma
Use the Slack DM Template
The magma init
command is how you create a new Magma agent project. If you provide the -t
flag, it will use the template you specify. Here, we’re using the slack-dm
template.
Save the Agent
After you’ve created your agent, cd
into the project directory and run:
Update the Slack manifest.json
Running magma save
will return your AGENT_ID
which you will need to update the settings.event_subscriptions.request_url
. The manifest.json
file can be found inside of your slack agent container.
Slack App Setup
Manifest Configuration
The manifest.json
file in your project root contains all the necessary Slack app configurations. You only need to update two values.
Creating Your Slack App
Create New App
- Go to https://api.slack.com/apps
- Click “Create an app”
- Select “From a manifest”
Select Workspace
Choose the workspace where you want to install the app
Upload Manifest
Replace the default manifest with the contents of your manifest.json
Review and Create
Click “Create” to finalize your app
Installing the App
Install to Workspace
- Navigate to “OAuth & Permissions”
- Click “Install to Workspace”
- Approve the requested permissions
Get Bot Token
After installation, copy the Bot User OAuth Token
Set Environment Variable
Add the token to your .env
file:
Deployment
This will:
- Deploy your agent to Magma’s infrastructure
- Set up the webhook endpoint for Slack events
- Enable real-time communication between Slack and your agent
After deployment, go to your Slack App settings > Event Subscriptions and verify that the Request URL shows as “Verified”. If it’s not verified, double-check your AGENT_ID
in the manifest.json.
Testing Your Agent
Use cmd+t
(Mac) or ctrl+t
(Windows) to quickly search for your bot in Slack!
- Open your Slack workspace
- Search for your agent by name
- Start a DM conversation
- Send a message to test the connection
If you run into any issues, use magma logs
to view your agent’s logs and debug the problem.