Skip to content

feat(dingtalk): add proactive message API to send_message tool#12077

Open
shuans wants to merge 1 commit into
NousResearch:mainfrom
shuans:main
Open

feat(dingtalk): add proactive message API to send_message tool#12077
shuans wants to merge 1 commit into
NousResearch:mainfrom
shuans:main

Conversation

@shuans

@shuans shuans commented Apr 18, 2026

Copy link
Copy Markdown

send_message now supports sending to arbitrary DingTalk groups/users without requiring a webhook_url configuration. Uses the enterprise robot proactive message API (v1.0) when DINGTALK_CLIENT_ID and DINGTALK_CLIENT_SECRET are available.

Three-tier routing priority:

  1. Proactive API — calls /v1.0/robot/groupMessages/send (groups) or /v1.0/robot/oToMessages/batchSend (users) with access_token. chat_id is respected. Requires "robot proactive message" permission.
  2. Session webhook — looks up cached session webhook from recent inbound message (bot must have been @mentioned within ~5 minutes).
  3. Static webhook — falls back to DINGTALK_WEBHOOK_URL (default group only; chat_id ignored).

Also adds module-level shared session webhook cache (get_dingtalk_session_webhook) so the send_message tool can access session webhooks cached by the gateway adapter.

Changes:

  • gateway/platforms/dingtalk.py: Add shared cache + getter/storer functions; make adapter use shared cache; simplify _on_message store logic.
  • tools/send_message_tool.py: Rewrite _send_dingtalk() with proactive API support, session webhook lookup, and improved error messages.

User-facing:

  • hermes send_message dingtalk:cidXXXX "msg" # sends to specific group
  • hermes send_message dingtalk:user123 "msg" # sends to specific user
  • Requires DINGTALK_CLIENT_ID/SECRET (and optional DINGTALK_ROBOT_CODE).
  • webhook_url optional now; default-group-only fallback still supported.

What does this PR do?

Related Issue

Fixes #

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

How to Test

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform:

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

send_message now supports sending to arbitrary DingTalk groups/users
without requiring a webhook_url configuration.  Uses the enterprise
robot proactive message API (v1.0) when DINGTALK_CLIENT_ID and
DINGTALK_CLIENT_SECRET are available.

Three-tier routing priority:
1. Proactive API — calls /v1.0/robot/groupMessages/send (groups) or
   /v1.0/robot/oToMessages/batchSend (users) with access_token.
   chat_id is respected. Requires "robot proactive message" permission.
2. Session webhook — looks up cached session webhook from recent inbound
   message (bot must have been @mentioned within ~5 minutes).
3. Static webhook — falls back to DINGTALK_WEBHOOK_URL (default group
   only; chat_id ignored).

Also adds module-level shared session webhook cache
(get_dingtalk_session_webhook) so the send_message tool can access
session webhooks cached by the gateway adapter.

Changes:
- gateway/platforms/dingtalk.py: Add shared cache + getter/storer functions;
  make adapter use shared cache; simplify _on_message store logic.
- tools/send_message_tool.py: Rewrite _send_dingtalk() with proactive API
  support, session webhook lookup, and improved error messages.

User-facing:
- hermes send_message dingtalk:cidXXXX "msg"  # sends to specific group
- hermes send_message dingtalk:user123 "msg" # sends to specific user
- Requires DINGTALK_CLIENT_ID/SECRET (and optional DINGTALK_ROBOT_CODE).
- webhook_url optional now; default-group-only fallback still supported.
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists platform/dingtalk DingTalk adapter comp/gateway Gateway runner, session dispatch, delivery labels Apr 24, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Overlaps significantly with #14336 (proactive messaging via Robot OpenAPI) and #12769 (proactive messaging + media pipeline). Recommend consolidating.

@shuans

shuans commented May 28, 2026

Copy link
Copy Markdown
Author

Hi guys, I built a CLI tool that sends messages directly to DingTalk (individual or group), with a plugin system so more platforms can be added later.
npx msgcli send "hello world"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/dingtalk DingTalk adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants