<!-- source: https://deepwiki.com/qhkm/zeptoclaw/7.3-slack-integration -->

# Slack Integration

- src/channels/discord.rs
- src/channels/lark.rs
- src/channels/slack.rs
- src/channels/webhook.rs
- src/channels/whatsapp_cloud.rs
- src/providers/gemini.rs

This page documents ZeptoClaw's Slack channel implementation, covering Socket Mode inbound messaging, Web API outbound messaging, message threading, and file attachment handling. For general channel architecture concepts (Channel trait, BaseChannelConfig, allowlists, reconnection strategies), see [Channel Architecture](https://github.com/qhkm/zeptoclaw/blob/2c743d31/Channel Architecture) For other platform integrations, see [Telegram Integration](https://github.com/qhkm/zeptoclaw/blob/2c743d31/Telegram Integration) [Discord Integration](https://github.com/qhkm/zeptoclaw/blob/2c743d31/Discord Integration) and [WhatsApp Integration](https://github.com/qhkm/zeptoclaw/blob/2c743d31/WhatsApp Integration)

## Architecture Overview

The Slack integration uses a **dual-protocol architecture**: Socket Mode WebSocket for receiving inbound messages, and the REST-based Web API for sending outbound messages. This approach avoids webhook complexity while enabling real-time bidirectional communication.

**High-Level Architecture**

```

```

Sources: [src/channels/slack.rs1-107](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L1-L107) [src/channels/slack.rs326-444](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L326-L444) [src/channels/slack.rs506-558](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L506-L558)

## Configuration

The `SlackChannel` is configured via `SlackConfig`, which contains credentials and access control settings. Configuration can be loaded from `config.json` or overridden via environment variables.

**SlackConfig Fields**

*If `app_token` is not provided, the channel operates in **outbound-only mode** (Web API only, no Socket Mode inbound).

**Environment Variable Overrides**

- ZEPTOCLAW_CHANNELS_SLACK_BOT_TOKEN - Override bot token
- ZEPTOCLAW_CHANNELS_SLACK_APP_TOKEN - Override app token
- ZEPTOCLAW_CHANNELS_SLACK_ENABLED - Enable/disable channel

Sources: [src/channels/slack.rs100-137](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L100-L137)

## Inbound Message Flow (Socket Mode)

Socket Mode eliminates the need for public webhook URLs. ZeptoClaw opens a WebSocket connection to Slack's Socket Mode API, which pushes events in real-time.

**Socket Mode Connection Sequence**

```

```

**Key Code Entities**

**Message Filtering Rules**

Messages are **ignored** if:

1. event.type is not "message" ( src/channels/slack.rs 275 )
2. event.subtype is present (e.g. message_changed ) ( src/channels/slack.rs 277 )
3. event.bot_id is present (bot message) ( src/channels/slack.rs 277 )
4. sender_id , chat_id , or content is empty ( src/channels/slack.rs 281-286 )
5. Sender not in allowlist (when allowlist is non-empty) ( src/channels/slack.rs 288-299 )

Sources: [src/channels/slack.rs201-314](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L201-L314) [src/channels/slack.rs326-444](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L326-L444)

## Media and File Handling

ZeptoClaw supports receiving images via Slack. When a message contains files, the integration filters for image types and downloads them using the bot token.

**File Extraction Logic**

1. parse_socket_message iterates through envelope.payload.event.files ( src/channels/slack.rs 215-226 ).
2. It filters for files where mimetype starts with "image/" ( src/channels/slack.rs 224-225 ).
3. download_slack_files is called for each identified file ( src/channels/slack.rs 446-484 ).
4. Downloads use the bot_token via bearer_auth to access private Slack URLs ( src/channels/slack.rs 460-461 ).
5. Files are converted to MediaAttachment and added to the InboundMessage ( src/channels/slack.rs 308-311 ).

Sources: [src/channels/slack.rs215-231](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L215-L231) [src/channels/slack.rs446-484](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L446-L484)

## Outbound Message Flow (Web API)

Outbound messages are sent via Slack's `chat.postMessage` REST API endpoint using the `bot_token` for authentication.

**Outbound Send Sequence**

```

```

**Payload Structure**

**Key Code Entities**

Sources: [src/channels/slack.rs138-158](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L138-L158) [src/channels/slack.rs506-558](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L506-L558)

## Reconnection and Error Handling

Socket Mode connections implement **automatic reconnection with a fixed delay**.

**Reconnection Strategy**

The `run_socket_mode_loop` uses a `loop` block that wraps the entire connection and event processing logic ([src/channels/slack.rs326-444](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L326-L444)). If the WebSocket stream ends or an error occurs, the loop waits for `SLACK_RECONNECT_DELAY_SECS` and attempts to fetch a new WebSocket URL ([src/channels/slack.rs434-443](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L434-L443)).

Sources: [src/channels/slack.rs27](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L27-L27) [src/channels/slack.rs434-443](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L434-L443)

## Thread Support

Slack organizes conversations into **threads** using the `thread_ts` field. ZeptoClaw preserves thread context for both inbound and outbound messages.

**Inbound Thread Metadata**

When a message is part of a thread, `SlackEvent` contains:

- ts - The message's own timestamp
- thread_ts - The parent thread timestamp

These are attached as metadata to `InboundMessage` ([src/channels/slack.rs302-306](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L302-L306)):

```

```

**Outbound Thread Replies**

To reply in a thread, set `OutboundMessage.reply_to` to the parent `thread_ts`. The `build_payload` function adds this as the `thread_ts` field in the API request ([src/channels/slack.rs151-155](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L151-L155)):

```

```

Sources: [src/channels/slack.rs151-155](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L151-L155) [src/channels/slack.rs302-306](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L302-L306)

## Code Entity Reference

**Core Types**

**Key Functions**

Sources: [src/channels/slack.rs1-568](https://github.com/qhkm/zeptoclaw/blob/2c743d31/src/channels/slack.rs#L1-L568)
