# Slack

It's common to want your agent in your team's Slack. For instance, your support team can @mention it in a channel, and it answers in the thread.

## Answer in Slack

Use the `slack_bot` connector with the workspace the bot is installed in:

```yaml title="agents/support/agent.yaml"
name: support
mode: text
llm: llm-fast
connectors:
  - name: slack_bot
    connection: acme-workspace # the label of your Slack bot connection
```

`slack_bot` gives the agent no tools. For Slack tools, such as searching the workspace, use the [`slack` connector](https://getstream.io/agents/docs/connectors/catalog/).

The bot is a Slack app of your own, in a workspace where you can create apps. Setting it up takes six steps:

1. **Create the Slack app**

   At [api.slack.com/apps](https://api.slack.com/apps), create an app named Acme Support in your workspace. Under **OAuth & Permissions**, add the bot scopes `chat:write`, `channels:history` and `im:history`. Under **App Home**, turn on the **Messages Tab**.

2. **Save the app's client**

   Give Stream the Slack app's Client ID, App ID (such as `A012ABCD0A0`), Client Secret and Signing Secret. The two secrets go on stdin, the Client Secret first:

   ```sh
   curl -fsSL https://getstream.io/cli/beta/install.sh | bash # the agents commands are in the beta CLI
   printf '%s\n%s\n' "$SLACK_CLIENT_SECRET" "$SLACK_SIGNING_SECRET" | getstream agents connectors client set slack_bot \
     --client-id "$SLACK_CLIENT_ID" --provider-app-id A012ABCD0A0 --client-secret - --signing-secret -
   ```

   ```text
   Redirect URI (add it at the provider): https://router.example.com/v1/agents/connectors/oauth/callback
   Saved the OAuth client for slack_bot
   ```

   >
   > **Warning:** Do this before step 4: Slack checks the Request URL at once, and Stream needs the signing secret to answer.
   >

3. **Add the redirect URI**

   Copy the redirect URI the CLI printed into the Slack app's **OAuth & Permissions > Redirect URLs**.

4. **Turn on events**

   In the Slack app's **Event Subscriptions**, turn events on and set the Request URL: the redirect URI with `/v1/agents/connectors/oauth/callback` replaced by `/v1/connectors/events/slack_bot/` and your Slack App ID. For a redirect URI of `https://router.example.com/v1/agents/connectors/oauth/callback`, that is `https://router.example.com/v1/connectors/events/slack_bot/A012ABCD0A0`. Then add the bot events `message.channels`, `message.im` and `tokens_revoked`.

5. **Install the bot**

   In the [Stream Dashboard](https://getstream.io/signin/), go to **Agents > Library > Connectors**, open **Slack bot** and click **Create connection**. **Owner** starts on **Signed-in user**: pick **App**. Type `acme-workspace` in **Label**, then click **Create connection**. Slack's consent opens in a pop-up. The connection stays pending until you allow it there.

6. **Sync the agent**

   ```sh
   getstream agents sync support
   ```

Test it in Slack itself. Add the bot to a public channel and write: "@Acme Support What is our return policy?". The agent answers in that message's thread. Reply in the thread without the mention, and it answers again. The thread is one conversation, shared by everyone who writes in it.

### In the Dashboard

Steps 2 and 3 work in the Dashboard too. In the [Stream Dashboard](https://getstream.io/signin/), go to **Agents > Library > Connectors** and open **Slack bot**.

1. Click **Set OAuth client**. The dialog shows the **Redirect URI**: copy it into the Slack app's **OAuth & Permissions > Redirect URLs**.
2. Fill **Client ID**, **Client secret**, **Provider app ID** with the App ID, and **Signing secret**. Leave **Token endpoint authentication** on **Connector default**, then click **Save client**.

## With the API

Your server can save the client instead of the CLI. `$STREAM_ACCELERATION_URL` is your router's URL, and `$SERVER_TOKEN` is a [server token](https://getstream.io/agents/docs/auth/). `GET /v1/agents/connectors/slack_bot` returns the redirect URI as `redirect_uri`. Then:

```bash
curl -X PUT "$STREAM_ACCELERATION_URL/v1/agents/connectors/slack_bot/oauth-client" \
  -H "api_key: $STREAM_API_KEY" -H "stream-auth-type: jwt" \
  -H "Authorization: Bearer $SERVER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"client_id": "...", "client_secret": "...", "provider_app_id": "A012ABCD0A0", "signing_secret": "..."}'
```

Both secrets are encrypted and never returned.

## Limitations

One agent answers per connection. A second agent that uses the same connection is refused.

## Going further

- [Channels](https://getstream.io/agents/docs/connectors/channels/): Every channel, what it needs, and which one to start with.
- [iMessage](https://getstream.io/agents/docs/connectors/imessage/): Answer over iMessage on your own Linq line.
- [SMS](https://getstream.io/agents/docs/connectors/sms/): Answer over SMS on your own Telnyx number.
- [Troubleshooting](https://getstream.io/agents/docs/connectors/troubleshooting/): Errors you may see, why, and what to do.
- [Creating an agent](https://getstream.io/agents/docs/creating-an-agent/): The agent folder, and every key of agent.yaml.

---

For the most recent version of this documentation, visit [https://getstream.io/agents/docs/connectors/slack/](https://getstream.io/agents/docs/connectors/slack/).