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

# Slack Ingestion

> Sync one Slack channel into Cognee memory incrementally, with forget-on-delete

A minimal guide to turning a Slack channel into Cognee memory. `slack_source()` returns a dlt resource you pass straight to `remember()`: a thread becomes one document, the messages without replies of one UTC day become one document for that day, and later syncs render again only the threads and days that changed.

> [!WARNING]
>
> This reads the messages of the channel, the names of their authors, and the names of attached files (never their content). Nothing is fetched until you run the script. Keep the channel in its own dataset so you can wipe it with a single `cognee.forget`.

## Before You Start

* Complete [Quickstart](https://docs.cognee.ai/getting-started/quickstart.md) to understand basic operations
* Ensure you have [LLM Providers](https://docs.cognee.ai/setup-configuration/llm-providers.md) configured (`LLM_API_KEY` in `.env`)
* Read [dlt Integration](https://docs.cognee.ai/integrations/dlt-integration.md) for how structured sources flow through `remember()`
* Create a Slack app at [api.slack.com/apps](https://api.slack.com/apps) with the bot scopes `channels:history`, `channels:read` and `users:read` (`groups:history` and `groups:read` for a private channel), install it into your workspace, and copy the bot token (`xoxb-...`)
* Invite the app to the channel (`/invite @YourApp`)
* Export `SLACK_BOT_TOKEN`, `SLACK_TEAM_ID` (`T...`) and `SLACK_CHANNEL_ID` (`C...`)

## Code in Action

```python theme={null}
import asyncio
import os

import cognee
from cognee.tasks.ingestion.connectors import slack_source

# Keep the channel in its own dataset so it is easy to inspect and forget.
DATASET_NAME = "slack_channel"

# Routing kwargs for remember(). Pass the same ones on every later sync.
#   write_disposition="merge" is REQUIRED: the add pipeline defaults to "replace",
#     which would wipe the synced channel on the next sync.
#   max_rows_per_table=0 keeps every staged row in view, so forget-on-delete compares
#     against the whole channel.
SLACK_REMEMBER_KWARGS = {
    "primary_key": "id",
    "write_disposition": "merge",
    "max_rows_per_table": 0,
    "self_improvement": False,
}


async def main():
    token = os.environ.get("SLACK_BOT_TOKEN")
    team_id = os.environ.get("SLACK_TEAM_ID")
    channel_id = os.environ.get("SLACK_CHANNEL_ID")
    if not (token and team_id and channel_id):
        print(
            "Set SLACK_BOT_TOKEN, SLACK_TEAM_ID and SLACK_CHANNEL_ID.\n"
            "See the setup steps in this file's docstring, then re-run."
        )
        return

    # Start from a clean slate so the demo is reproducible.
    await cognee.prune.prune_data()
    await cognee.prune.prune_system(metadata=True)

    # The resource name keys the staging table and the sync state: one per channel.
    source = slack_source(
        access_token=token,
        team_id=team_id,
        channel_id=channel_id,
        resource_name=f"slack_channel_{channel_id.lower()}",
    )

    print("\n=== Slack sync ===")
    result = await cognee.remember(source, dataset_name=DATASET_NAME, **SLACK_REMEMBER_KWARGS)
    print(result)
    # A run cut short by the request budget or a rate limit reports failed_budget or
    # failed_rate_limit here; run the script again (without the prune) to continue.
    print("Sync stats:", source.cognee_sync_stats)

    answer = await cognee.recall(
        query_text="What did the channel decide recently, and who decided it?",
        datasets=[DATASET_NAME],
        node_name=[f"slack:channel:{channel_id}"],
    )
    print(answer[0].text if answer else "No answer.")


if __name__ == "__main__":
    asyncio.run(main())
```

## What Just Happened

### Step 1: Configure the Sync

```python theme={null}
SLACK_REMEMBER_KWARGS = {
    "primary_key": "id",
    "write_disposition": "merge",
    "max_rows_per_table": 0,
    "self_improvement": False,
}
```

These are the routing options for `remember()`; pass the same ones on every later sync. `write_disposition="merge"` upserts documents by their `id` instead of replacing the synced channel on the next sync, and `max_rows_per_table=0` keeps every staged row in view so forget-on-delete compares against the whole channel.

### Step 2: Build the Slack Source

```python theme={null}
    source = slack_source(
        access_token=token,
        team_id=team_id,
        channel_id=channel_id,
        resource_name=f"slack_channel_{channel_id.lower()}",
    )
```

`slack_source()` reads one channel of one workspace with your bot token. The `resource_name` keys the staging table and the sync state, so use one per channel. If any of the three environment variables is missing, the script prints a message and returns before fetching anything; the setup steps it points to are the ones in [Before You Start](#before-you-start).

### Step 3: Sync and Ask the Channel

```python theme={null}
    result = await cognee.remember(source, dataset_name=DATASET_NAME, **SLACK_REMEMBER_KWARGS)
    print(result)
    # A run cut short by the request budget or a rate limit reports failed_budget or
    # failed_rate_limit here; run the script again (without the prune) to continue.
    print("Sync stats:", source.cognee_sync_stats)

    answer = await cognee.recall(
        query_text="What did the channel decide recently, and who decided it?",
        datasets=[DATASET_NAME],
        node_name=[f"slack:channel:{channel_id}"],
    )
    print(answer[0].text if answer else "No answer.")
```

The sync pulls the channel into the `slack_channel` dataset and builds the graph. A large channel finishes its first sync over several runs: each run stops after `max_requests` Slack API requests (1500 by default, a `slack_source()` argument) or 600 seconds, and the next one resumes where it stopped. Remove the two `prune` calls before you run the script again: they wipe the memory earlier runs built but not dlt's staged copy of the channel, so every document synced so far would go through graph extraction again. `recall()` then answers from that dataset, scoped to the channel's node set.

> [card] [Slack](https://docs.cognee.ai/integrations/slack-integration.md)
>
> Ask, save, and recall Cognee memory from Slack itself

> [card] [dlt (Data Load Tool)](https://docs.cognee.ai/integrations/dlt-integration.md)
>
> How dlt sources, merge syncs, and orphan cleanup work

> [card] [Remember](https://docs.cognee.ai/core-concepts/main-operations/remember.md)
>
> All `remember()` parameters, including the dlt options

> [card] [Forget](https://docs.cognee.ai/core-concepts/main-operations/forget.md)
>
> Wipe the Slack dataset when you are done


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