feat(dingtalk): proactive messaging via Robot OpenAPI + send_message_tool media support#14336
Open
meng93 wants to merge 1 commit into
Open
feat(dingtalk): proactive messaging via Robot OpenAPI + send_message_tool media support#14336meng93 wants to merge 1 commit into
meng93 wants to merge 1 commit into
Conversation
Collaborator
This was referenced Apr 23, 2026
5f4ce7d to
f454ddd
Compare
…tool media - Add DingTalk access-token management (_dingtalk_fetch_access_token, _dingtalk_fetch_oapi_token) with process-wide cache, 5 min safety margin, and asyncio.Lock for concurrent safety. - Add _dingtalk_upload_media() — upload local files to /media/upload (legacy OAPI token) with mime auto-detection and 20 MB guard. - Add _dingtalk_classify_chat_id() — route on chat_id shape: 'cidXXX==' → group /groupMessages/send, plain staffId or 'user:<staffId>' → 1:1 /oToMessages/batchSend. - Add dingtalk_send_proactive() orchestrator — text + media delivery. - In send(), fall back to dingtalk_send_proactive() when no session webhook is cached (proactive/cron/cross-platform delivery). - Fix /sethome DM chat_id: persist 'user:<staffId>' instead of DM conversation_id so proactive DM delivery works (gateway/run.py). - Enhance send_message_tool.py: MEDIA:<path> tag extraction, native DingTalk/Feishu routing with media_files support. - Update test assertions for proactive-send error path.
f454ddd to
8221966
Compare
Open
5 tasks
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable proactive (non-session-webhook) message delivery for DingTalk via the Robot OpenAPI, and extend
send_message_toolto support native media attachments on DingTalk and Feishu.Motivation
The DingTalk adapter previously could only reply within a session webhook window. Cron jobs, cross-platform
send_message, and delayed deliveries all failed withNo valid session_webhook. This PR adds the same proactive-send capability that the Feishu adapter already has — using AppKey/AppSecret to call the Robot OpenAPI directly.Additionally,
send_message_toolwas text-only for DingTalk/Feishu. Users asking the agent to "send this image to DingTalk" got an error.Changes
gateway/platforms/dingtalk.py_dingtalk_fetch_access_token,_dingtalk_fetch_oapi_tokenwith process-wide cache + Lockgateway/platforms/dingtalk.py_dingtalk_upload_media()— upload to/media/upload(legacy OAPI token) with mime auto-detectiongateway/platforms/dingtalk.py_dingtalk_classify_chat_id()— routecidXXX==→ group,user:<staffId>→ 1:1gateway/platforms/dingtalk.py_dingtalk_build_msg_param()— pick sampleMarkdown/sampleText/sampleImageMsg etc.gateway/platforms/dingtalk.pydingtalk_send_proactive()— orchestrator: text + per-file media deliverygateway/platforms/dingtalk.pysend()falls back to proactive when no session webhook cachedgateway/run.py/sethomeDM fix: persistuser:<staffId>instead of DM conversation_idtools/send_message_tool.pyMEDIA:<path>tag + bare-path extraction; native DingTalk/Feishu routing; updated capability descriptiontests/gateway/test_dingtalk.pyTest Plan
tests/gateway/test_dingtalk.pytests pass.cidXXX==), proactive send to DM (user:<staffId>), media upload (image, PDF, audio).send_message_toolMEDIA tag extraction and native routing.Risk Assessment
Medium. The proactive-send path is new and touches production DingTalk API endpoints. Token caching + Locks mitigate thundering-herd issues. The
send()fallback is conservative — it only activates when no session webhook exists (i.e., would have failed before anyway).send_message_toolchanges are backward-compatible (media tags are opt-in).