Skip to main content
The Channel trait defines the interface for all messaging platforms in ZeroClaw. Implement this trait to integrate new communication channels like Slack, Discord, Telegram, or custom protocols.

Trait Definition

Required Methods

name

Return the human-readable channel name.
&str
Stable lowercase identifier (e.g., β€œcli”, β€œdiscord”, β€œslack”)

send

Send a message through this channel.
&SendMessage
required
anyhow::Result<()>
Success or error

listen

Start listening for incoming messages. This is a long-running async task.
tokio::sync::mpsc::Sender<ChannelMessage>
required
Channel sender to forward received messages to the agent
anyhow::Result<()>
Returns when listener stops or encounters error
Received messages are sent as:

Optional Methods with Defaults

health_check

Check if the channel is healthy and reachable.
bool
Returns true if channel is operational
Default: Returns true.

start_typing

Signal that the bot is processing a response (typing indicator).
&str
required
User or channel to show typing indicator to
Default: No-op. Note: Implementations should repeat the indicator as needed for their platform (e.g., Slack requires renewal every 3 seconds).

stop_typing

Stop any active typing indicator.
&str
required
User or channel to stop typing indicator for
Default: No-op.

supports_draft_updates

Whether this channel supports progressive message updates via draft edits.
bool
Returns true if draft updates are supported
Default: Returns false.

send_draft

Send an initial draft message for progressive updates.
&SendMessage
required
Initial draft message content
anyhow::Result<Option<String>>
Platform-specific message ID for later edits, or None if not supported
Default: Returns Ok(None).

update_draft

Update a previously sent draft message with new accumulated content.
&str
required
Message recipient
&str
required
Platform message ID from send_draft
&str
required
Updated message content
anyhow::Result<Option<String>>
  • Ok(None) to keep current draft message ID
  • Ok(Some(new_id)) when a continuation message was created (e.g., after hitting edit-count cap)
Default: Returns Ok(None).

finalize_draft

Finalize a draft with the complete response (apply formatting).
&str
required
Message recipient
&str
required
Platform message ID
&str
required
Final message content
Default: No-op.

cancel_draft

Cancel and remove a previously sent draft message.
&str
required
Message recipient
&str
required
Platform message ID to cancel
Default: No-op.

send_approval_prompt

Send an interactive approval prompt for tool execution.
&str
required
User to prompt
&str
required
Unique request identifier
&str
required
Name of tool requiring approval
&serde_json::Value
required
Tool arguments to display
Option<String>
Thread identifier for threaded replies
Default: Sends plain-text prompt with /approve-allow and /approve-deny commands.

add_reaction

Add a reaction (emoji) to a message.
&str
required
Platform channel/conversation identifier
&str
required
Platform-scoped message identifier
&str
required
Unicode emoji (e.g., β€πŸ‘€β€, β€βœ…β€)
Default: No-op.

remove_reaction

Remove a reaction previously added by this bot.
&str
required
Platform channel identifier
&str
required
Platform message identifier
&str
required
Unicode emoji to remove
Default: No-op.

Helper Types

SendMessage

ChannelMessage

Implementation Example

Here’s a complete CLI channel implementation:

Factory Registration

Register your channel in the factory:

Best Practices

Thread Safety: The listen method runs in a long-lived async task. Ensure your implementation handles reconnection and graceful shutdown.
Message Formatting: Different platforms have different markdown/formatting support. Consider normalizing input and formatting output appropriately.
Rate Limiting: Implement appropriate rate limiting for your platform. Many messaging APIs have strict rate limits and require backoff strategies.
Draft Updates: For platforms with edit limits (e.g., Slack allows 5 edits), implement continuation messages in update_draft when limits are reached.