# Connect a Slack bot

Create a Slack application and connect a data Agent so your team can ask data questions in channels or direct messages and view message processing and delivery results.

使用指南 · 模块: integrations · 应用开发者 · 部署形态：资料未说明 · 已确认产品版本：资料未说明 · 来源：现有文档

After connecting a data Agent to Slack, your team can `@` the bot in a channel or ask directly in private messages, with answers returned to Slack. The integration uses [Socket Mode](https://docs.slack.dev/apis/events-api/using-socket-mode/) and requires no public callback URL.

## Before you begin

- Permission to create and install applications in the Slack workspace; if installation is restricted, workspace administrator approval is required.
- A [Data Agent](https://docs.asktable.com/en/agent/overview) with data sources and skills configured, and an AskTable project owner or administrator role.
- Each AskTable project should connect to only one Slack workspace to avoid person identity matching conflicts.
- Private deployments must run a [Channel gateway](https://docs.asktable.com/en/deploy/feishu-gateway) with Slack support.

An Agent can save both Feishu and Slack configurations, but only one platform is enabled at a time. Switching or selecting “Disabled” preserves configuration for switching back later.

## 1. Create a Slack application

Open [Slack apps](https://api.slack.com/apps), choose **Create New App → From an app manifest**, select a workspace, and paste this YAML:

```yaml
_metadata:
  major_version: 1
display_information:
  name: AskTable
  description: Ask questions about your data in natural language
features:
  bot_user:
    display_name: AskTable
    always_online: true
  app_home:
    home_tab_enabled: false
    messages_tab_enabled: true
    messages_tab_read_only_enabled: false
oauth_config:
  scopes:
    bot:
      - app_mentions:read
      - im:history
      - chat:write
      - reactions:write
      - users:read
      - users:read.email
settings:
  event_subscriptions:
    bot_events:
      - app_mention
      - message.im
  socket_mode_enabled: true
  org_deploy_enabled: false
  token_rotation_enabled: false
```

Review the settings and click **Create**. Change the application name and bot display name to suit your team if needed.

| Permission purpose             | Setting                                                                                                 |
| ------------------------------ | ------------------------------------------------------------------------------------------------------- |
| Receive questions              | `app_mentions:read` receives mentions; `im:history` receives direct messages                            |
| Answer and acknowledge receipt | `chat:write` sends answers; `reactions:write` adds acknowledgment reactions                             |
| Match people                   | `users:read` and `users:read.email` fetch names, avatars, email addresses, and other person information |

Keep the Messages tab enabled and allow messages in it, or users cannot directly message the bot. The manifest does not request `channels:history` or `groups:history`, so the bot does not read unrelated channel chat. Every question in channels and threads therefore requires an `@` mention.

## 2. Obtain two Tokens

In **OAuth & Permissions**, click **Install to Workspace**, approve permissions, and copy the **Bot User OAuth Token** starting with `xoxb-`.

Then open **Basic Information → App-Level Tokens**:

1. Click **Generate Token and Scopes** and enter a name.
2. Add `connections:write`.
3. Generate and copy the Token starting with `xapp-`.

| AskTable field | What to enter                                                                       |
| -------------- | ----------------------------------------------------------------------------------- |
| Bot Token      | Bot User OAuth Token starting with `xoxb-`, used to call Slack API and send answers |
| App Token      | App-Level Token starting with `xapp-`, used to establish the Socket Mode connection |

No Signing Secret is needed. Both Tokens are credentials; do not include them in screenshots or code repositories. Revoke and replace them in Slack if exposed.

## 3. Enable Slack in AskTable

Left main navigation → “More” → open the target Agent → “Channels”:

1. Select **Slack** in “Platform.”
2. For first-time configuration, enter Bot Token and App Token in the dialog and click “Save.”
3. Slack becomes active only after saving succeeds; canceling preserves the previous platform.

The form checks both Token prefixes. Selecting an already configured Slack platform enables it directly. To change credentials, use “Edit configuration” beside “Credential configuration.” Editing prefills existing credentials, so replace only values needing updates; neither Token can be cleared.

Adjust responses in “General configuration”:

| Setting             | Default                      | Purpose                                                                               |
| ------------------- | ---------------------------- | ------------------------------------------------------------------------------------- |
| Reply in threads    | On                           | Opens a thread for new channel questions to keep follow-ups together                  |
| Deep reasoning      | Off                          | Gives complex questions more reasoning time                                           |
| Channel preferences | Blank, up to 1024 characters | Adds persistent requirements to every analysis turn, such as “Give conclusions first” |

Switches save immediately; channel preferences save on blur. Deep reasoning and preferences apply from the next message. Direct messages always receive direct replies without new threads.

### Control who can ask data questions

After enabling, turn on the allowlist in “People permissions” below. Slack's allowlist is off by default, so anyone who can contact the bot can ask. When on, link Slack identities to AskTable people and authorize them for the Agent. See [Permissions and data scope](https://docs.asktable.com/en/permissions) for role-based scope restrictions. Users without bindings or authorization are rejected and enter pending approval.

Feishu and Slack allowlist switches are stored separately; check the active platform's settings after switching.

## 4. Check the connection and messages

| Connection status | Meaning                                                                |
| ----------------- | ---------------------------------------------------------------------- |
| Connected         | Current Slack Socket Mode connection is healthy                        |
| Connecting        | Establishing or restoring the connection                               |
| Disconnected      | No usable connection currently exists                                  |
| Error             | Connection or operation failed; read the explanation beside the status |

Status refreshes every 5 seconds. “Refresh” only rereads status and does not manually rebuild the connection. Connected status or a healthy gateway heartbeat does not prove a question was answered successfully.

After sending a test question, check whether “Recent messages” updates, then click “Details” to inspect **Processing status** and **Reply status**. Processing failure means an issue in analysis or another processing stage; reply failure means the result was not successfully delivered to Slack.

## 5. Invite the bot and ask questions

Enter this command in the target channel, replacing the name with your bot's name:

```text
/invite @AskTable
```

You can also add it through **Integrations → Add apps** in channel settings. Direct messages need no invitation.

| Location         | Example                                 |
| ---------------- | --------------------------------------- |
| Direct message   | `What were sales last month?`           |
| Channel          | `@AskTable What were sales last month?` |
| Thread follow-up | `@AskTable Break it down by region.`    |

Thread follow-ups also require `@`. A thread's analysis context belongs to its original questioner; others should send a separate question in the channel. Group direct messages are unsupported.

Direct messages and top-level channel questions reuse conversations for the same person, starting over after 24 consecutive hours with no new message. Thread conversations do not expire under this window. Channel and thread replies are visible to members who can view that location; use direct messages for private results.

## Troubleshooting

| Symptom                                       | Checks and resolution                                                                                                                                          |
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Shows Error                                   | Confirm correct Token prefixes, enabled Socket Mode, `connections:write` on App Token, and installation in the workspace                                       |
| Recent messages does not change               | Confirm the bot is in the channel, the question includes `@`, and `app_mention` and `message.im` are subscribed; direct messages also require the Messages tab |
| Processing failed                             | Read the reason in “Details,” check data sources and person authorizations, then retry                                                                         |
| Reply failed                                  | Confirm bot channel membership and `chat:write`; reinstall in the workspace after changing Slack permissions                                                   |
| No permission or pending approval             | Link the correct Slack person identity and authorize access to the current Agent                                                                               |
| Slack messages stop after switching platforms | Confirm “Platform” is still Slack; switching to Feishu or Disabled keeps Slack configuration but stops receiving messages                                      |

## Next steps

- Maintain the Agent's data and analysis methods: [Agent overview](https://docs.asktable.com/en/agent/overview)
- Restrict each person's data scope: [Permissions and data scope](https://docs.asktable.com/en/permissions)
- Connect the other supported platform: [Connect a Feishu bot](https://docs.asktable.com/en/integrations/feishu)
