feat(gateway): Add WeChat platform adapter with long-poll architecture - #5230
feat(gateway): Add WeChat platform adapter with long-poll architecture#5230Alex4Xu wants to merge 3 commits into
Conversation
|
Substantial. 3080 lines of new code for a complete platform adapter is one of the biggest single PRs on this repo. Architectural choices look sound: long-poll matching the official Tencent plugin (vs. reinventing with webhooks), transport/adapter/state separation, isolated media logic with AES decryption, session-expiry account pause instead of retry hammering. 73 tests is solid coverage. Two questions worth flagging for long-running infra: how does the |
|
Thanks for the thorough review — both questions pointed at real issues. Ran verification tests against both before patching (using GLM-5.1 + Claude Code), and confirmed:
Polling backoff on 429/503: The loop was using Both fixes are covered by new regression tests added to |
1abaae8 to
0fd249a
Compare
Add full WeChat (personal) messaging platform adapter following the official Tencent openclaw-weixin plugin architecture: - WeChatAdapter: lifecycle management, QR login, poll loop, inbound/outbound message handling for text, image, file, voice, and video - WeChatTransport: raw HTTP wrappers, header building, base_info injection, long-poll API, CDN upload pipeline, media send/receive - WeChatStateStore: account store, sync cursor store, context-token cache - 73 tests covering login state transitions, polling, message conversion, media routing, session-expired pause behavior, typing tickets, and payload shapes Key design choices: - Long-poll based (not webhook) matching official plugin - context_token continuity for session management - Media logic isolated in transport layer - AES decryption support for inbound images - errcode=-14 session expiry handling with account pause Closes: WeChat integration for Hermes gateway
… rate-limit backoff Two issues confirmed by regression tests before patching: 1. WeChatSessionExpiredError did not clear the context_token cache, leaving stale tokens that would be reused after an account reconnects mid-session. Fix: call clear_context_tokens(account_id) before pausing the account. 2. The poll loop used min(consecutive_failures, 5) for all errors with no distinction for 429/503, sustaining up to 1 req/3s under rate limiting. Fix: introduce WeChatRateLimitError in the transport layer (_api_get / _api_post raise it on 429/503); caught separately in _poll_account_loop with exponential backoff min(2**n, 60). Both fixes covered by new tests in TestIssueVerification. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…orm registration Progress messages: - Remove WeChat from _no_edit_platforms — enable tool-call progress for WeChat - WeChat uses "new-tool-only" dedup (no spam when same tool repeats) - Cap at 3 progress messages then silently drop; typing indicator covers the rest - Progress interval set to 5s (matches openclaw-weixin reference, reduces API pressure) Typing indicator: - Override _keep_typing in WeChatAdapter with 5s keepalive interval (base default is 2s, tuned for Telegram/Discord; WeChat reference uses 5s) Platform registration: - Register WeChatAdapter in gateway router - Add WECHAT_ALLOWED_USERS / WECHAT_ALLOW_ALL_USERS access control - Disable streaming and tool-progress editing for WeChat (no edit_message support) - Add hermes-wechat toolset; include in hermes-gateway union CLI: - Add `hermes wechat login / status / accounts` subcommands - Add WeChat to skills platform list Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
0fd249a to
dfd8d37
Compare
Summary
Add a complete WeChat (personal) messaging platform adapter following the official Tencent
openclaw-weixinplugin architecture.What this adds
gateway/platforms/wechat.py) - Full adapter lifecycle: QR login, continuous polling, inbound/outbound message handling for text, images, files, voice, and videogateway/platforms/wechat_transport.py) - Raw HTTP wrappers, header building, base_info injection, long-poll API, CDN upload pipeline, media send/receive with AES decryptiongateway/platforms/wechat_state.py) - Account store, sync cursor persistence, context-token cachingtests/gateway/test_wechat.py) - Covering login state transitions, polling, message conversion, media routing, session-expired pause behavior, typing tickets, and payload shapesKey design decisions
context_tokencontinuity for session management, cached per account+usererrcode=-14session expiry handled with account pause (not hammering retries)base_info.channel_versioninjected on all API requestsFiles changed
gateway/platforms/wechat.pygateway/platforms/wechat_transport.pygateway/platforms/wechat_state.pytests/gateway/test_wechat.pyRegistration points (already present in upstream)
gateway/config.py:Platform.WECHATenum memberhermes_cli/tools_config.py: WeChat entry inPLATFORMSdicthermes_cli/skills_config.py: WeChat entry inPLATFORMSdicttoolsets.py:hermes-wechattoolset definitionhermes_cli/main.py:hermes wechatCLI commandsTesting
Motivation
WeChat is the dominant messaging platform in China. This adapter enables Hermes users to interact with the agent via WeChat personal accounts using the official Tencent iLink bot protocol, expanding Hermes's multi-platform gateway to cover this critical market.
Notes
This PR mirrors the official Tencent
openclaw-weixinplugin architecture rather than inventing a webhook/proxy design. The code has been tested with two live WeChat bot accounts.