Overview
Once your bot has joined groups or channels, it can send messages with various content types, reply in threads, and edit existing messages.Your bot must be a member of a group or channel before sending messages. See Joining Communities first.
Message Content Types
OpenChat supports multiple message content types:Text Messages
The most common message type:Governance Proposals
For posting NNS or SNS governance proposals:Sending Group Messages
Send messages to standalone groups using the group’s canister ID.Basic Text Message
DFX Example
Sending Channel Messages
Send messages to channels within communities.Basic Channel Message
DFX Example
Message ID Management
The SDK generates unique message IDs and allows you to save them for later reference.Generating Message IDs
Saving Message IDs
Practical Usage
Thread Support
Reply to messages in threads by providing thethreadRootMessageIndex.
Sending Thread Replies
Example from ProposalBot
Editing Messages
Modify existing messages using their message ID.Edit Group Messages
Edit Channel Messages
Complete Edit Example
Error Handling
Common Response Codes
| Response | Description | Solution |
|---|---|---|
#Success | Message sent successfully | - |
#ChannelNotFound | Channel doesn’t exist | Verify channel ID |
#ThreadMessageNotFound | Thread root not found | Verify thread index |
#MessageEmpty | Content is empty | Provide message content |
#TextTooLong | Message exceeds limit | Shorten message |
#NotAuthorized | Bot lacks permissions | Check bot role |
#UserNotInChannel | Bot not a member | Join channel first |
#UserSuspended | Bot is suspended | Contact admins |
#RulesNotAccepted | Must accept rules | Accept group rules |
Robust Error Handling
TallyBot Example
Here’s how TallyBot sends and edits messages for tally updates:Best Practices
- Save Message IDs - Always save message IDs when you’ll need to edit messages later
- Handle Errors Gracefully - Check all response variants and handle appropriately
- Use Thread Support - Keep conversations organized by replying in threads
- Respect Rate Limits - Don’t send too many messages too quickly
- Clean Up - Delete saved message IDs when messages are finalized
Next Steps
Manage Subscriptions
Set up subscription systems for your bot
API Reference
Explore the complete API