Channel interface defines the contract that all NanoClaw channels must implement. Channels handle communication with external platforms like WhatsApp, Telegram, Slack, Discord, and Gmail.
Interface Definition
Location:src/types.ts:82-93
Required Properties
Unique identifier for the channel (e.g.,
"whatsapp", "telegram", "slack").This name is used:- In the channel registry
- For logging and debugging
- As a prefix for folder names (
{channel}_{group-name})
Required Methods
Initialize and establish connection to the external platform.Called: Once at startup by the orchestrator.Responsibilities:
- Authenticate with the platform
- Set up event listeners for incoming messages
- Restore any persisted session state
- Call
onMessagecallback when messages are received - Call
onChatMetadatacallback when discovering new chats
Send a text message to the specified chat or group.Parameters:
jid- Platform-specific chat identifier (e.g.,"[email protected]"for WhatsApp)text- Message text to send
Check if the channel is currently connected to the platform.Returns:
true if connected and ready to send/receive messages, false otherwise.Example:Determine if this channel handles messages for the given JID.Called: By the router to determine which channel should send a message.Returns:
true if this channel owns the JID, false otherwise.Example:Gracefully disconnect from the platform.Called: During shutdown to clean up resources.Example:
Optional Methods
Show or hide typing indicator in the specified chat.Implementation is optional. Channels that support typing indicators (WhatsApp, Telegram) can implement this for better UX.Parameters:
jid- Chat identifierisTyping-trueto show typing indicator,falseto hide
Sync chat/group names and metadata from the platform.Implementation is optional. Useful for channels where chat metadata is not delivered inline with messages.Parameters:
force- Iftrue, force a full sync even if recently synced
- Fetch list of chats/groups from the platform
- Call
onChatMetadatafor each chat with name and metadata
Callback Types
Channels receive callback functions viaChannelOpts to communicate with the orchestrator.
OnInboundMessage
Location:src/types.ts:96
chatJid- Platform-specific chat identifiermessage- Message object with the following structure:
OnChatMetadata
Location:src/types.ts:98-105
- Inline delivery: Some channels (Telegram) deliver chat names with every message - call this from
connect()or message handlers - Separate sync: Other channels (WhatsApp) need explicit syncing - call this from
syncGroups()
chatJid- Platform-specific chat identifiertimestamp- ISO timestamp of discoveryname- (Optional) Display name of the chat/groupchannel- (Optional) Channel nameisGroup- (Optional) True if this is a group chat
Implementation Example
Here’s a complete minimal channel implementation:JID Format Guidelines
Each channel should use platform-specific JID formats that are:- Unique: No collisions between channels
- Stable: Same chat always has same JID
- Reversible: Can be used to send messages back
| Channel | JID Format | Example |
|---|---|---|
{number}@{suffix} | [email protected] | |
| Telegram | tg:{chat_id} | tg:-1001234567890 |
| Slack | slack:{team}:{channel} | slack:T1234:C5678 |
| Discord | dc:{guild}:{channel} | dc:123456789:987654321 |
| Gmail | gmail:{email} | gmail:[email protected] |
Related Documentation
- Channel Registry - How channels self-register
- Channel System Architecture - Overview of the channel system