# Slack

Slack is a communication platform for teams and organizations. The Sling Slack connector extracts data from the Slack Web API, supporting workspace info, users, channels, channel members, messages, and thread replies.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](https://docs.slingdata.io/sling-cli/cli-pro) or [Platform Plan](https://docs.slingdata.io/sling-platform/platform).
{% endhint %}

## Setup

The following credentials are accepted:

**Secrets:**

* `bot_token` **(required)** -> Your Slack Bot User OAuth Token (starts with `xoxb-`)

**Inputs:**

* `anchor_date` *(optional)* -> Starting date for the first sync of incremental endpoints (ISO 8601 format, e.g., `2024-01-01T00:00:00Z`). Defaults to 1 year ago.

### Creating a Slack App and Getting a Bot Token

1. Go to the [Slack API Apps page](https://api.slack.com/apps)
2. Click **Create New App** → **From scratch**
3. Enter an app name (e.g., "Sling Data Extractor") and select your workspace
4. Navigate to **OAuth & Permissions** in the sidebar
5. Under **Bot Token Scopes**, add the following scopes:
   * `channels:read` — View basic information about public channels
   * `channels:history` — View messages and other content in public channels
   * `channels:join` — Join public channels (needed to read message history)
   * `groups:read` — View basic information about private channels
   * `groups:history` — View messages in private channels the bot is in
   * `users:read` — View people in the workspace
   * `users:read.email` — View email addresses of people in the workspace
   * `team:read` — View the workspace name, email domain, and icon
6. Click **Install to Workspace** and authorize the app
7. Copy the **Bot User OAuth Token** (starts with `xoxb-`)

{% hint style="warning" %}
**Important:** The bot must be a member of channels to read their message history. The bot will automatically join public channels when using the `channels:join` scope. For private channels, you must manually invite the bot.
{% endhint %}

### Using `sling conns`

Here are examples of setting a connection named `SLACK`. We must provide the `type=api` property:

{% code overflow="wrap" %}

```bash
sling conns set SLACK type=api spec=slack secrets='{ bot_token: xoxb-your-bot-token }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/sling-cli/environment#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export SLACK='{ type: api, spec: slack, secrets: { bot_token: "xoxb-your-bot-token" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/sling-cli/environment#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  SLACK:
    type: api
    spec: slack
    secrets:
      bot_token: "xoxb-your-bot-token"
```

## Replication

Here's an example replication configuration to sync Slack data to a PostgreSQL database:

```yaml
source: SLACK
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: slack.{stream_name}

streams:
  # sync all endpoints
  '*':
```

**Incremental sync for messages:**

```yaml
source: SLACK
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: slack.{stream_name}

streams:
  team_info:
  users:
  channels:
  channel_members:
  messages:
    mode: incremental
  threads:
```

## Endpoints

| Endpoint          | Description                              | Incremental | Depends On |
| ----------------- | ---------------------------------------- | ----------- | ---------- |
| `team_info`       | Workspace/team information               | No          | —          |
| `users`           | All users in the workspace               | No          | —          |
| `channels`        | All public channels in the workspace     | No          | —          |
| `channel_members` | Members of each channel                  | No          | `channels` |
| `messages`        | Message history for each channel         | Yes         | `channels` |
| `threads`         | Thread replies for messages with threads | No          | `messages` |

The connector uses a **queue-based architecture** to handle parent-child relationships. The `channels` endpoint runs first and populates channel IDs, which are used by `channel_members` and `messages`. The `messages` endpoint identifies threaded messages and queues thread references for the `threads` endpoint.

To discover available endpoints:

```bash
sling conns discover SLACK
```

### Endpoint Details

**`team_info`** — Returns information about the workspace/team, including name, domain, email domain, and icon.

**`users`** — Returns all users in the workspace, including profile information, timezone, admin status, and bot status. Runs in full-refresh mode.

**`channels`** — Returns all public channels in the workspace, including archived channels. Contains channel metadata such as name, topic, purpose, creator, and member count. Channel IDs are queued for child endpoints.

**`channel_members`** — Returns the member list for each channel. Iterates over all channel IDs from the `channels` endpoint.

**`messages`** — Returns the message history for each channel. Supports incremental sync using the `oldest` timestamp parameter. Messages with threads are identified and their references are queued for the `threads` endpoint. Each message includes text content, author, timestamps, reactions, and attachment information.

**`threads`** — Returns all replies within threaded conversations. Iterates over thread references queued by the `messages` endpoint. Includes the parent message and all replies.

## Incremental Sync

The `messages` endpoint supports incremental sync using the `oldest` timestamp parameter:

* **First run:** Fetches all messages from the `anchor_date` (defaults to 1 year ago)
* **Subsequent runs:** Only fetches messages posted after the last sync timestamp

You can customize the starting date with the `anchor_date` input:

```yaml
connections:
  SLACK:
    type: api
    spec: slack
    secrets:
      bot_token: "xoxb-your-bot-token"
    inputs:
      anchor_date: "2024-01-01T00:00:00Z"
```

All other endpoints run in full-refresh mode since they represent current state rather than time-series data.

## Rate Limiting

The Slack Web API enforces rate limits per method tier:

* **Tier 1:** 1 request per minute
* **Tier 2:** 20 requests per minute
* **Tier 3:** 50 requests per minute
* **Tier 4:** 100 requests per minute

The connector automatically:

* Limits to 4 requests per second with concurrency of 3
* Retries with exponential backoff on 429 (rate limit) responses
* Allows up to 5 retry attempts
* Gracefully skips channels the bot is not a member of

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/connections/api-connections/slack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
