Yuanbao is an enterprise messaging platform primarily used within Tencent and enterprise environments. It uses WebSocket for real-time communication, HMAC-based authentication, and supports rich media including images, files, and voice messages.
Prerequisites
- A Yuanbao account with bot creation permissions
- Yuanbao APP_ID and APP_SECRET (from platform admin)
- Python packages:
websocketsandhttpx, both core Mibyan dependencies
Setup
1. Create a Bot in Yuanbao
- Download the Yuanbao app from https://yuanbao.tencent.com/
- In the app, go to PAI → My Bot and create a new bot
- After the bot is created, copy the APP_ID and APP_SECRET
2. Run the Setup Wizard
The easiest way to configure Yuanbao is through the interactive setup:- Ask for your APP_ID
- Ask for your APP_SECRET
- Save the configuration automatically
3. Configure Environment Variables
After initial setup, verify these variables in~/.mibyan/.env:
4. Start the Gateway
Features
- WebSocket gateway — real-time bidirectional communication
- HMAC authentication — secure request signing with APP_ID/APP_SECRET
- C2C messaging — direct user-to-bot conversations
- Group messaging — conversations in group chats
- Media support — images, files, and voice messages via COS (Cloud Object Storage)
- Markdown formatting — messages are automatically chunked for Yuanbao’s size limits
- Message deduplication — prevents duplicate processing of the same message
- Heartbeat/keep-alive — maintains WebSocket connection stability
- Typing indicators — shows “typing…” status while the agent processes
- Automatic reconnection — handles WebSocket disconnections with exponential backoff
- Group information queries — retrieve group details and member lists
- Sticker/Emoji support — send TIMFaceElem stickers and emoji in conversations
- WeChat forwarded chat-history support — when a user forwards a WeChat chat-history bundle into Yuanbao, the adapter decodes the forwarded records (sender nicknames, text, and multimedia entries, including nested forwards) and injects them into the conversation so the agent can read the full forwarded thread
- Auto-sethome — first user to message the bot is automatically set as the home channel owner
- Slow-response notification — sends a waiting message when the agent takes longer than expected
Configuration Options
Chat ID Formats
Yuanbao uses prefixed identifiers depending on conversation type:Media Uploads
The Yuanbao adapter automatically handles media uploads via COS (Tencent Cloud Object Storage):- Images: Supports JPEG, PNG, GIF, WebP
- Files: Supports all common document types
- Voice: Supports WAV, MP3, OGG
Home Channel
Use the/sethome command in any Yuanbao chat (DM or group) to designate it as the home channel. Scheduled tasks (cron jobs) deliver their results to this channel.
You can also set it manually in ~/.mibyan/.env:
Example: Set Home Channel
- Start a conversation with the bot in Yuanbao
- Send the command:
/sethome - The bot responds: “Home channel set to [chat_name] with ID [chat_id]. Cron jobs will deliver to this location.”
- Future cron jobs and notifications will be sent to this channel
Example: Cron Job Delivery
Create a cron job:Usage Tips
Starting a Conversation
Send any message to the bot in Yuanbao:Available Commands
All standard Mibyan commands work on Yuanbao:Sending Files
To send a file to the bot, simply attach it directly in the Yuanbao chat. The bot will automatically download and process the file attachment. You can also include a message with the attachment:Receiving Files
When you ask the bot to create or export a file, it sends the file directly to your Yuanbao chat.Troubleshooting
Bot is online but not responding to messages
Cause: Authentication failed during WebSocket handshake. Fix:- Verify APP_ID and APP_SECRET are correct
- Check that the WebSocket URL is accessible
- Ensure the bot account has proper permissions
- Review gateway logs:
tail -f ~/.mibyan/logs/gateway.log
”Connection refused” error
Cause: WebSocket URL is unreachable or incorrect. Fix:- Verify the WebSocket URL format (should start with
wss://) - Check network connectivity to the Yuanbao API domain
- Confirm firewall allows WebSocket connections
- Test URL with:
curl -I https://[YUANBAO_API_DOMAIN]
Media uploads fail
Cause: COS credentials are invalid or media server is unreachable. Fix:- Verify API_DOMAIN is correct
- Check that media upload permissions are enabled for your bot
- Ensure the media file is accessible and not corrupted
- Check COS bucket configuration with platform admin
Messages not delivered to home channel
Cause: Home channel ID format is incorrect or cron job hasn’t triggered. Fix:- Verify YUANBAO_HOME_CHANNEL is in correct format
- Test with
/sethomecommand to auto-detect correct format - Check cron job schedule with
/status - Verify bot has send permissions in the target chat
Frequent disconnections
Cause: WebSocket connection is unstable or network is unreliable. Fix:- Check gateway logs for error patterns
- Increase heartbeat timeout in connection settings
- Ensure stable network connection to Yuanbao API
- Consider enabling verbose logging:
mibyan gateway run -vv
Access Control
Yuanbao supports fine-grained access control for both DM and group conversations:config.yaml:
Advanced Configuration
Message Chunking
Yuanbao has a maximum message size. Mibyan automatically chunks large responses with Markdown-aware splitting (respects code fences, tables, and paragraph boundaries).Connection Parameters
The following connection parameters are built into the adapter with sensible defaults:These values are currently not configurable via environment variables. They are optimized for typical Yuanbao deployments.

