> ## 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="Start from a manifest">
    Go to [api.slack.com/apps](https://api.slack.com/apps), click **Create New App**, choose **From a manifest**, and select your workspace.
  </Step>

  <Step title="Paste the manifest">
    Paste the manifest for your mode, and replace `<your CostGraph URL>` with the address people use to open CostGraph.

    <Tabs>
      <Tab title="Socket mode">
        ```yaml theme={null}
        _metadata:
          major_version: 2
        display_information:
          name: CostGraph
          description: Ask CostGraph about your cloud and Kubernetes spend.
          background_color: "#111827"
        features:
          app_home:
            home_tab_enabled: true
            messages_tab_enabled: true
            messages_tab_read_only_enabled: false
          bot_user:
            display_name: costgraph
            always_online: true
          agent_view:
            agent_description: Answers questions about your CostGraph spend, savings and anomalies.
          slash_commands:
            - command: /costgraph
              description: Switch tenant, connect or disconnect CostGraph
              usage_hint: tenant [name] | connect | disconnect | help
              should_escape: false
        oauth_config:
          redirect_urls:
            - "https://<your CostGraph URL>/slack/callback/install"
            - "https://<your CostGraph URL>/slack/callback/link"
          scopes:
            bot:
              - app_mentions:read
              - assistant:write
              - chat:write
              - commands
              - im:history
              - users:read
            user:
              - openid
        settings:
          event_subscriptions:
            bot_events:
              - app_home_opened
              - app_mention
              - app_uninstalled
              - assistant_thread_context_changed
              - assistant_thread_started
              - message.im
              - tokens_revoked
          interactivity:
            is_enabled: true
          org_deploy_enabled: false
          socket_mode_enabled: true
          token_rotation_enabled: false
        ```
      </Tab>

      <Tab title="Webhook mode">
        ```yaml theme={null}
        _metadata:
          major_version: 2
        display_information:
          name: CostGraph
          description: Ask CostGraph about your cloud and Kubernetes spend.
          background_color: "#111827"
        features:
          app_home:
            home_tab_enabled: true
            messages_tab_enabled: true
            messages_tab_read_only_enabled: false
          bot_user:
            display_name: costgraph
            always_online: true
          agent_view:
            agent_description: Answers questions about your CostGraph spend, savings and anomalies.
          slash_commands:
            - command: /costgraph
              url: "https://<your CostGraph URL>/slack/commands"
              description: Switch tenant, connect or disconnect CostGraph
              usage_hint: tenant [name] | connect | disconnect | help
              should_escape: false
        oauth_config:
          redirect_urls:
            - "https://<your CostGraph URL>/slack/callback/install"
            - "https://<your CostGraph URL>/slack/callback/link"
          scopes:
            bot:
              - app_mentions:read
              - assistant:write
              - chat:write
              - commands
              - im:history
              - users:read
            user:
              - openid
        settings:
          event_subscriptions:
            request_url: "https://<your CostGraph URL>/slack/events"
            bot_events:
              - app_home_opened
              - app_mention
              - app_uninstalled
              - assistant_thread_context_changed
              - assistant_thread_started
              - message.im
              - tokens_revoked
          interactivity:
            is_enabled: true
            request_url: "https://<your CostGraph URL>/slack/interactivity"
          org_deploy_enabled: false
          socket_mode_enabled: false
          token_rotation_enabled: false
        ```
      </Tab>
    </Tabs>
  </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.