feat(dingtalk): add QR code auth support and fix 3 critical adapter bugs#8345
feat(dingtalk): add QR code auth support and fix 3 critical adapter bugs#8345meng93 wants to merge 1 commit into
Conversation
dfe71fe to
e2ac58c
Compare
- feat: support one-click QR scan to create DingTalk bot and establish connection - fix(gateway): wrap blocking DingTalkStreamClient.start() with asyncio.to_thread() - fix(gateway): extract message fields from CallbackMessage payload instead of ChatbotMessage - fix(gateway): add oapi.dingtalk.com to allowed webhook URL domains
e2ac58c to
0aac921
Compare
|
looks good for my bug: #9752 |
|
Merged via #11574 (#11574). Your commit was cherry-picked with authorship preserved (9deeee7). Thanks for building the QR flow — it shipped essentially as you wrote it, with one small follow-up: added a user-facing disclosure that the scan page is OpenClaw-branded, since DingTalk's registration portal routes every source to What I dropped from this PR: the Also added 15 regression tests covering Follow-up: Teknium will reach out to DingTalk-Real-AI via Nous's Alibaba channel to register a sanctioned |
Summary
Fix three critical bugs in the DingTalk platform adapter that prevented the bot from receiving and replying to messages, and add QR code scanning authorization to
hermes gateway setupfor a streamlined onboarding experience.Motivation
Bug Fixes
The existing DingTalk adapter had three issues that made it non-functional in production:
DingTalkStreamClient.start()is an async coroutine, but the code wrapped it withasyncio.to_thread()as if it were blocking, causing callbacks to execute in the wrong thread and never dispatch to the main event loop.CallbackMessageobjects whose business fields (senderId,text,sessionWebhook, etc.) live insidemessage.data(camelCase keys), not as top-level Python attributes. The original code usedgetattr(message, "sender_id")which always returnedNone.api.dingtalk.com, but DingTalk actually returns session webhooks onoapi.dingtalk.com, causing all reply attempts to be rejected.New Feature — QR Code Auth
Currently, setting up DingTalk requires users to:
This is error-prone and unfriendly for new users. The DingTalk Open Platform provides a Device Flow OAuth registration API that allows CLI tools to obtain credentials via QR code scanning — no pre-existing app credentials needed.
Changes
Modified:
gateway/platforms/dingtalk.pyBug 1: Stream client async handling
Bug 2: Message field extraction from CallbackMessage
Bug 3: Webhook URL domain validation
Modified:
gateway/config.pyDINGTALK_CLIENT_ID/DINGTALK_CLIENT_SECRET/DINGTALK_HOME_CHANNELenvironment variable handling in_apply_env_overrides(), consistent with existing platform patterns (Feishu, Slack, etc.)New file:
hermes_cli/dingtalk_auth.py▀▄█)qrcodedependency on first use; falls back gracefully if unavailableModified:
hermes_cli/gateway.py_setup_dingtalk()to offer two setup methods:_setup_dingtalk()in the platform selection switch ingateway_setup()User Experience
When selecting DingTalk in
hermes gateway setup:After selecting QR scan, a QR code is rendered in the terminal. The user scans it with DingTalk, and credentials are automatically saved.
Type of Change
How to Test
QR Code Auth
hermes gateway setup, select DingTalk → QR Code Scan.envBug Fixes
DINGTALK_CLIENT_IDandDINGTALK_CLIENT_SECRETin.envhermes gatewayand confirm log output:[dingtalk] Connected via Stream Modesession_webhook=https://oapi.dingtalk.com/...(not EMPTY)Dependencies
qrcode(optional, auto-installed on first use, graceful fallback to manual input if unavailable)Screenshots / Logs
Before fix:
After fix:
Breaking Changes
None. All changes are backward-compatible:
qrcodedependency is optional with graceful fallbackChecklist
Code
fix(scope):,feat(scope):, etc.)Documentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/A