> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch14-channel-routing-and-message-dispatch/14.3-outbound-message-processing.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 14.3 Outbound Message Processing

> **Generated by**: Claude Opus 4.6 (initial draft) / Claude Opus 5 (`v2026.3.9` revision) **Token usage**: Input \~280,000 tokens, Output \~20,000 tokens (chapter total) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

After the Agent generates a reply, the message must go through an outbound processing pipeline before it can be sent to the user's channel. This process includes message chunking, confirmation reactions, typing indicators, and conversation label generation.

## 14.3.1 Message Chunking Algorithm and Channel Limits

An AI Agent's reply can be very long—a detailed code analysis or technical explanation might reach thousands or even tens of thousands of characters. However, each message channel has length limits for individual messages:

| Channel  | Single Message Limit | Chunk Limit |
| -------- | -------------------- | ----------- |
| Discord  | 2000 characters      | 2000        |
| Telegram | 4096 characters      | 4000        |
| WhatsApp | \~65536 characters   | 4000        |
| Slack    | 40000 characters     | 4000        |
| Signal   | \~6000 characters    | 4000        |

When a reply exceeds the channel limit, it needs to be **chunked** into multiple messages sent sequentially. Chunking is not simply truncating by character count—it needs to consider the integrity of Markdown formatting.

Each channel's outbound adapter defines its own chunker and chunking mode:

```typescript
// src/channels/plugins/types.adapters.ts (outbound adapter types)
export type ChannelOutboundAdapter = {
  chunker?: ((text: string, limit: number) => string[]) | null;
  chunkerMode?: "text" | "markdown";
  textChunkLimit?: number;
};
```

Most channels use plain text chunking in `"text"` mode (`chunkText`), while Telegram, due to its HTML format support, uses a dedicated chunker in `"markdown"` mode (`markdownToTelegramHtmlChunks`):

```typescript
// src/channels/plugins/outbound/telegram.ts
export const telegramOutbound: ChannelOutboundAdapter = {
  chunker: markdownToTelegramHtmlChunks,
  chunkerMode: "markdown",
  textChunkLimit: 4000,
};

// src/channels/plugins/outbound/whatsapp.ts
export const whatsappOutbound: ChannelOutboundAdapter = {
  chunker: chunkText,
  chunkerMode: "text",
  textChunkLimit: 4000,
};

// src/channels/plugins/outbound/discord.ts
export const discordOutbound: ChannelOutboundAdapter = {
  chunker: null,  // Discord has its own built-in chunking logic
  textChunkLimit: 2000,
};
```

Discord and Slack have their `chunker` set to `null`, indicating they use their own client library's built-in chunking logic rather than OpenClaw's generic chunker.

## 14.3.2 Confirmation Reactions (ACK Reactions)

Confirmation reactions are a lightweight user feedback mechanism: when the Gateway receives a message and starts processing it, it adds an emoji reaction (such as an "eyes" emoji) to the original message, letting the user know the message has been received.

`src/channels/ack-reactions.ts` implements the gating logic for confirmation reactions:

```typescript
// src/channels/ack-reactions.ts
export type AckReactionScope = "all" | "direct" | "group-all" | "group-mentions" | "off" | "none";

export function shouldAckReaction(params: AckReactionGateParams): boolean {
  const scope = params.scope ?? "group-mentions";  // Default: only confirm when mentioned in groups
  if (scope === "off" || scope === "none") return false;
  if (scope === "all") return true;
  if (scope === "direct") return params.isDirect;
  if (scope === "group-all") return params.isGroup;
  if (scope === "group-mentions") {
    // Only confirm in mentionable groups + when mentioned
    if (!params.isMentionableGroup) return false;
    if (!params.requireMention || !params.canDetectMention) return false;
    return params.effectiveWasMentioned || params.shouldBypassMention === true;
  }
  return false;
}
```

The default behavior is `"group-mentions"`—only send confirmation reactions when @mentioned in groups. This avoids producing redundant reactions in private chats (private chats don't need confirmation since the reply itself is confirmation), while providing clear feedback to users in groups.

Confirmation reactions also support **removal after reply**—when the Agent sends a reply, the previously added confirmation reaction is automatically removed:

```typescript
// src/channels/ack-reactions.ts
export function removeAckReactionAfterReply(params: {
  removeAfterReply: boolean;
  ackReactionPromise: Promise<boolean> | null;
  ackReactionValue: string | null;
  remove: () => Promise<void>;
}) {
  if (!params.removeAfterReply) return;
  if (!params.ackReactionPromise || !params.ackReactionValue) return;
  // Remove after confirmation reaction is actually sent
  void params.ackReactionPromise.then((didAck) => {
    if (!didAck) return;
    params.remove().catch((err) => params.onError?.(err));
  });
}
```

## 14.3.3 Typing Indicators

Many channels support "the other party is typing" indicators. OpenClaw continuously sends typing indicators while the Agent is processing a message, letting users know the AI is thinking.

`src/channels/typing.ts` provides a factory function for typing callbacks:

```typescript
// src/channels/typing.ts
export type TypingCallbacks = {
  onReplyStart: () => Promise<void>;  // Called when reply starts
  onIdle?: () => void;                // Called when idle (stop typing indicator)
};

export function createTypingCallbacks(params: {
  start: () => Promise<void>;         // Start typing indicator
  stop?: () => Promise<void>;         // Stop typing indicator
  onStartError: (err: unknown) => void;
  onStopError?: (err: unknown) => void;
}): TypingCallbacks {
  const onReplyStart = async () => {
    try {
      await params.start();
    } catch (err) {
      params.onStartError(err);
    }
  };

  const onIdle = params.stop
    ? () => {
        void params.stop().catch((err) =>
          (params.onStopError ?? params.onStartError)(err)
        );
      }
    : undefined;

  return { onReplyStart, onIdle };
}
```

A design detail: the `onIdle` callback is **optional**. This is because some channels (like Telegram) have typing indicators that automatically expire after a certain time and don't need to be explicitly stopped. Other channels (like Discord) require manually stopping the typing state.

Typing indicator errors do not interrupt the message processing flow—it's just an auxiliary user experience feature, and even if it fails, it should not affect the Agent's normal reply.

## 14.3.4 Conversation Labels and Reply Prefixes

### Conversation Labels

`src/channels/conversation-label.ts` generates a human-readable label for each session, used to identify sessions in the UI and logs:

```typescript
// src/channels/conversation-label.ts
export function resolveConversationLabel(ctx: MsgContext): string | undefined {
  // Prefer explicitly set labels
  const explicit = ctx.ConversationLabel?.trim();
  if (explicit) return explicit;

  // Threads use thread labels
  const threadLabel = ctx.ThreadLabel?.trim();
  if (threadLabel) return threadLabel;

  // Direct messages use sender name
  const chatType = normalizeChatType(ctx.ChatType);
  if (chatType === "direct") {
    return ctx.SenderName?.trim() || ctx.From?.trim() || undefined;
  }

  // Groups use channel name / group subject / space name
  const base = ctx.GroupChannel?.trim() || ctx.GroupSubject?.trim()
    || ctx.GroupSpace?.trim() || ctx.From?.trim() || "";
  if (!base) return undefined;

  // Append id: suffix for pure numeric IDs or WhatsApp group IDs
  const id = extractConversationId(ctx.From);
  if (id && shouldAppendId(id) && base !== id && !base.includes(id)) {
    return `${base} id:${id}`;
  }
  return base;
}
```

Label generation follows the principle of "being as meaningful as possible": direct messages show the other party's name (e.g., "Alice"), groups show the group name (e.g., "#general"), and if only numeric IDs exist, an `id:` prefix is appended for identification (e.g., "Engineering Group id:12345").

### Reply Prefixes

`src/channels/reply-prefix.ts` can add a prefix to each of the Agent's replies, typically used to annotate the model being used or identity information:

```typescript
// src/channels/reply-prefix.ts
export function createReplyPrefixContext(params: {
  cfg: OpenClawConfig;
  agentId: string;
  channel?: string;
  accountId?: string;
}): ReplyPrefixContextBundle {
  const prefixContext: ResponsePrefixContext = {
    identityName: resolveIdentityName(cfg, agentId),
  };

  const onModelSelected = (ctx: ModelSelectionContext) => {
    // Update prefix context after model selection
    prefixContext.provider = ctx.provider;
    prefixContext.model = extractShortModelName(ctx.model);
    prefixContext.modelFull = `${ctx.provider}/${ctx.model}`;
    prefixContext.thinkingLevel = ctx.thinkLevel ?? "off";
  };

  return {
    prefixContext,
    responsePrefix: resolveEffectiveMessagesConfig(cfg, agentId, {
      channel: params.channel, accountId: params.accountId,
    }).responsePrefix,
    responsePrefixContextProvider: () => prefixContext,
    onModelSelected,
  };
}
```

Reply prefixes are **configurable templates** that can include variables like `{{model}}`, `{{provider}}`, `{{identityName}}`, etc. For example, configuring `responsePrefix: "[{{model}}] "` will add a model identifier like `[claude-4-opus]` before each reply.

***

## Section Summary

The outbound message processing pipeline transforms the Agent's raw reply into the final message users see in each channel:

1. **Intelligent chunking**: Automatically splits long messages based on channel limits, supporting both plain text and Markdown chunking modes
2. **Confirmation reactions**: Adds emoji reactions when messages are received, automatically removes after reply, enabled by default only when mentioned in groups
3. **Typing indicators**: Continuously sends typing status while Agent is processing, errors don't affect the main flow
4. **Conversation labels**: Generates human-readable labels for each session, convenient for identification in UI and logs
5. **Reply prefixes**: Configurable template system that adds model, identity, and other annotation information before replies
