Hermes DingTalk Media
Use this skill when a Hermes DingTalk bot needs to send or receive native media attachments, especially when MEDIA:/absolute/path responses do not arrive as independent DingTalk images/files.
Bundled Files
This Hermes skill includes a non-Hermes-native helper script:
scripts/fix_dingtalk_media_support.py: validates that the Hermes source tree contains the DingTalk media implementation, checks required Python modules, runs syntax checks, and can restart a Hermes profile gateway.scripts/send_dingtalk_file.py: sends a local image/file through DingTalk robot media APIs using credentials from a Hermes profile, without modifying Hermes core.
The helpers do not contain credentials. Run the validation helper from any location by passing the Hermes source repository root:
python /path/to/hermes-dingtalk-media/scripts/fix_dingtalk_media_support.py --repo-root "$HERMES_REPO"
python /path/to/hermes-dingtalk-media/scripts/fix_dingtalk_media_support.py --repo-root "$HERMES_REPO" --restart-profile <profile>
If HERMES_REPO points to the Hermes source tree, the --repo-root argument can be omitted.
To validate native DingTalk file delivery without changing Hermes source, send a local file from a configured Hermes profile:
python /path/to/hermes-dingtalk-media/scripts/send_dingtalk_file.py --profile <profile> --target-name "<group-name>" /tmp/example.txt
For one-to-one robot sends, pass a DingTalk staff/user id:
python /path/to/hermes-dingtalk-media/scripts/send_dingtalk_file.py --profile <profile> --user-id "<staff-id>" /tmp/example.txt
Core Flow
Confirm the bot receives callbacks.
- Look for
DingTalk callback receivedandinbound message: platform=dingtalk. - If no callback appears, fix Stream Mode/connectivity first.
- Look for
Confirm Hermes parsed the media tag.
- The assistant response should contain
MEDIA:/absolute/path/to/file. - Gateway logs should show
Sending DingTalk media via ... robot API.
- The assistant response should contain
Upload the local file to DingTalk.
- Endpoint:
POST https://oapi.dingtalk.com/media/upload - Params:
access_token,type=imagefor image extensions, otherwisetype=file. - Multipart field:
media. - Use returned
media_id/mediaId.
- Endpoint:
Send the uploaded
media_idwith the correct robot endpoint.- Group chat:
POST https://api.dingtalk.com/v1.0/robot/groupMessages/send - One-to-one bot chat:
POST https://api.dingtalk.com/v1.0/robot/oToMessages/batchSend
- Group chat:
Important Routing Rules
- Do not use
privateChatMessages/sendfor Hermes bot one-to-one media replies. It can returnresource.not.foundeven when upload succeeded. - For one-to-one bot media, use
oToMessages/batchSendwithuserIds: [sender_staff_id]. - For group media, use
groupMessages/sendwithopenConversationId. - Prefer
message.robot_codefrom the incoming DingTalk callback over configured app/client id. Config fallback is acceptable only when there is no callback context. - Keep the incoming callback context by
chat_id; it providesconversation_type,robot_code, andsender_staff_id.
Payloads
Group media:
payload = {
"robotCode": robot_code,
"openConversationId": chat_id,
"msgKey": msg_key,
"msgParam": json.dumps(msg_param, ensure_ascii=False),
}
One-to-one media:
payload = {
"robotCode": robot_code,
"userIds": [sender_staff_id],
"msgKey": msg_key,
"msgParam": json.dumps(msg_param, ensure_ascii=False),
}
Known media templates to try:
image_candidates = [
("sampleImageMsg", {"photoURL": media_id}),
("sampleImageMsg", {"mediaId": media_id}),
("sampleImage", {"mediaId": media_id}),
]
file_candidates = [
("sampleFile", {"mediaId": media_id, "fileName": file_name}),
("sampleFileMsg", {"mediaId": media_id, "fileName": file_name}),
]
Hermes Implementation Checklist
In gateway/platforms/dingtalk.py:
- Implement
send_image_file,send_document, andsend_video. - Resolve inbound
downloadCodeto local cache files for images/audio/video/documents. - Use a cancellable Stream loop instead of
dingtalk_stream.DingTalkStreamClient.start()if shutdown or reconnect gets stuck; the SDK can swallow cancellation. - Call
self._stream_client.pre_start()before opening the Stream connection when replacing SDKstart(). - Log media routing without exposing secrets, for example:
Sending DingTalk media via oto robot API; robot_code_source=callback recipient_source=sender_staff_id.
In tools/send_message_tool.py:
- Support DingTalk
MEDIA:extraction. - For direct sends without callback context, one-to-one media requires an explicit DingTalk user id/staff id; otherwise default to group sends.
In agent/prompt_builder.py:
- Add a DingTalk platform hint that native media can be sent with
MEDIA:/absolute/path/to/file.
Validation
Run:
cd "$HERMES_REPO"
python -m py_compile gateway/platforms/dingtalk.py tools/send_message_tool.py agent/prompt_builder.py
python /path/to/hermes-dingtalk-media/scripts/fix_dingtalk_media_support.py --repo-root "$HERMES_REPO"
git diff --check
python /path/to/hermes-dingtalk-media/scripts/fix_dingtalk_media_support.py --repo-root "$HERMES_REPO" --restart-profile <profile>
Test image and file delivery separately:
result = await adapter._send_robot_media(
chat_id=chat_id,
file_path="/tmp/example.png",
media_kind="image",
)
result = await adapter._send_robot_media(
chat_id=chat_id,
file_path="/tmp/example.txt",
media_kind="file",
file_name="example.txt",
)
Expected success shape:
{"success": True, "error": None, "message_id": "..."}
Failure Signals
resource.not.foundaftermedia/upload: upload worked, but the send endpoint orrobotCode/recipient is wrong.robot 不存在: usually wrongrobotCode; use callbackmessage.robot_code.private HTTP 400 ... resource.not.foundin one-to-one chat: switch fromprivateChatMessages/sendtooToMessages/batchSend.- No
DingTalk callback received: Stream callback delivery is not reaching Hermes; check bot/app, Stream Mode, competing gateway processes, and profile credentials.




