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

# Slack

> Connect your self-hosted CostGraph to Slack with a Slack app you create

A self-hosted deployment connects to Slack through a Slack app you create and own. Messages and credentials pass only between Slack and your deployment. People then use it as described in [Slack](/costgraph/slack/overview).

## Before you begin

* Graph AI turned on in your deployment, with `costgraphAi.enabled: true` and a model key.
* Permission to create apps in your Slack workspace.
* A CostGraph organization owner or admin in your deployment to add the app.

## Connection modes

Slack reaches your deployment in one of two ways. The following table compares them.

| Mode | How messages arrive | Network access | Choose it when |
| - | - | - | - |
| `socket` | Your deployment opens an outbound connection to Slack | Outbound HTTPS to `slack.com` and `*.slack.com`. Nothing inbound. | Your deployment is on a private network |
| `webhook` | Slack sends requests to your deployment | Slack reaches `/slack/events`, `/slack/interactivity`, and `/slack/commands` on your CostGraph URL | Your deployment has a public address |

In both modes, adding the app and connecting accounts happen in the browser. Only the people using CostGraph need to reach the dashboard.

## Create the Slack app

<Steps>
  <Step title="Copy the manifest from CostGraph">
    In your CostGraph, open **Integrations > Slack** as an organization owner or admin. The setup guide shows an app manifest generated for your deployment's URLs. Click **Copy manifest**.
  </Step>

  <Step title="Create the app from the manifest">
    Go to [api.slack.com/apps](https://api.slack.com/apps), click **Create New App**, choose **From a manifest**, select your workspace, and paste the manifest.

    In socket mode, change `socket_mode_enabled` to `true` and delete the `url` line under the slash command and the two `request_url` lines before you create the app.
  </Step>

  <Step title="Copy the app credentials">
    In **Basic Information > App Credentials**, copy the **Client ID**, **Client Secret**, and **Signing Secret**.
  </Step>

  <Step title="Create an app-level token">
    In socket mode, go to **Basic Information > App-Level Tokens**, click **Generate Token and Scopes**, add the `connections:write` scope, and copy the token. It starts with `xapp-`.
  </Step>
</Steps>

## Configure the chart

<Steps>
  <Step title="Store the credentials">
    Create a Secret whose keys are the setting names. Every deployment needs `SLACK_SIGNING_SECRET`. In webhook mode, leave out `SLACK_APP_TOKEN`.

    ```shell theme={null}
    kubectl create secret generic costgraph-slack \
      --namespace costgraph \
      --from-literal=SLACK_CLIENT_ID=<client ID> \
      --from-literal=SLACK_CLIENT_SECRET=<client secret> \
      --from-literal=SLACK_SIGNING_SECRET=<signing secret> \
      --from-literal=SLACK_APP_TOKEN=<app-level token>
    ```
  </Step>

  <Step title="Point the chart at it">
    Add the mode and the Secret to your values file.

    ```yaml theme={null}
    global:
      slack:
        mode: socket
        existingSecret: costgraph-slack
    ```
  </Step>

  <Step title="Upgrade">
    Run the upgrade. If a credential is missing, the upgrade fails and names the value to fix.

    ```shell theme={null}
    helm upgrade costgraph costgraph/costgraph-selfhosted -f my-values.yaml
    ```
  </Step>
</Steps>

In webhook mode, the chart's ingress routes the three Slack paths to Graph AI. If you run your own ingress, route `/slack/events`, `/slack/interactivity`, and `/slack/commands` as exact paths to the `costgraph-selfhosted-costgraph-ai` Service on port `4111`.

After you change the Secret, restart both components so they read it:

```shell theme={null}
kubectl rollout restart deployment -n costgraph costgraph-selfhosted costgraph-selfhosted-costgraph-ai
```

## Add the app and verify

<Steps>
  <Step title="Add the app to Slack">
    In your deployment, go to **Settings > Integrations**, open the **AI agent** category, select **Slack**, and click **Add to Slack**.
  </Step>

  <Step title="Connect your account">
    Send the app a direct message. Click **Connect CostGraph** in the reply and sign in to Slack.
  </Step>

  <Step title="Ask a question">
    Ask "What did we spend last month?" in the same direct message. The answer ends with the name of your tenant.
  </Step>
</Steps>

Every value is described in the [values reference](/costgraph/self-hosted/values#slack).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.