> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magmadeploy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Slack DM Agent

> Create a Slack AI agent that can chat with users in Slack DMs

<Check icon="clock">Estimated time to complete: 5 minutes</Check>

<img className="block rounded-xl" src="https://mintcdn.com/pompeiilabsinc/INRokfUt_EitWThD/assets/templates/slack-dm/slack-agent-header.jpg?fit=max&auto=format&n=INRokfUt_EitWThD&q=85&s=719738eb7b90cc2cdd1418e20585d4c7" alt="Slack Agent Demo Light" width="2368" height="1195" data-path="assets/templates/slack-dm/slack-agent-header.jpg" />

## 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

<Info>
  **Prerequisites**:

  * A Slack workspace where you have admin permissions
</Info>

## Getting Started

First, we need the Magma CLI to clone the Slack DM template, and save it to your Magma account.

<Steps>
  <Step title="Install the CLI">
    ```bash theme={null}
    npm install -g @pompeii-labs/cli
    ```
  </Step>

  <Step title="Login to Magma">
    ```bash theme={null}
    magma login
    ```
  </Step>

  <Step title="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.

    ```bash theme={null}
    magma init -t slack-dm <agent-name>
    ```
  </Step>

  <Step title="Save the Agent">
    After you've created your agent, `cd` into the project directory and run:

    ```bash theme={null}
    magma save
    ```
  </Step>

  <Step title="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.
  </Step>
</Steps>

## Slack App Setup

### Manifest Configuration

<Info>
  The `manifest.json` file in your project root contains all the necessary Slack app configurations. You only need to update two values.
</Info>

<AccordionGroup>
  <Accordion title="Required Changes">
    1. `AGENT_NAME` in the `display_information` section
    2. `AGENT_ID` in the `settings.event_subscriptions.request_url` section
  </Accordion>

  <Accordion title="What these values mean">
    * `AGENT_NAME` is what users will see when they interact with your bot
    * `AGENT_ID` is used to route Slack events to your specific Magma agent
  </Accordion>
</AccordionGroup>

### Creating Your Slack App

<Steps>
  <Step title="Create New App">
    1. Go to [https://api.slack.com/apps](https://api.slack.com/apps)
    2. Click "Create an app"
    3. Select "From a manifest"
  </Step>

  <Step title="Select Workspace">
    Choose the workspace where you want to install the app
  </Step>

  <Step title="Upload Manifest">
    Replace the default manifest with the contents of your `manifest.json`
  </Step>

  <Step title="Review and Create">
    Click "Create" to finalize your app
  </Step>
</Steps>

### Installing the App

<Steps>
  <Step title="Install to Workspace">
    1. Navigate to "OAuth & Permissions"
    2. Click "Install to Workspace"
    3. Approve the requested permissions
  </Step>

  <Step title="Get Bot Token">
    After installation, copy the `Bot User OAuth Token`
  </Step>

  <Step title="Set Environment Variable">
    Add the token to your `.env` file:

    ```bash theme={null}
    SLACK_BOT_TOKEN=xoxb-your-token-here
    ```
  </Step>
</Steps>

## Deployment

<CodeGroup>
  ```bash npm theme={null}
  magma deploy
  ```
</CodeGroup>

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

<Info>
  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.
</Info>

## Testing Your Agent

<Tip>
  Use `cmd+t` (Mac) or `ctrl+t` (Windows) to quickly search for your bot in Slack!
</Tip>

1. Open your Slack workspace
2. Search for your agent by name
3. Start a DM conversation
4. Send a message to test the connection

<Warning>
  If you run into any issues, use `magma logs` to view your agent's logs and debug the problem.
</Warning>

<CardGroup cols={2}>
  <Card title="Need Help?" icon="question" href="mailto:founders@pompeiilabs.com">
    Contact our support team for assistance
  </Card>

  <Card title="Join Community" icon="slack" href="https://magmacommunity.slack.com">
    Connect with other Magma developers
  </Card>
</CardGroup>
