← 返回 Skills 市场
tongshendota

dingtalk-openclaw

作者 tongyuezhou123 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
291
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install litmedia-dingtalk-openclaw
功能描述
钉钉 Stream 模式连接 OpenClaw AI 对话。通过钉钉机器人接收用户消息,调用 OpenClaw HTTP API 获取 AI 回复,再用 Webhook 发回钉钉。用于实现"钉钉 AI 助手"场景。
使用说明 (SKILL.md)

钉钉连接 OpenClaw

本 skill 指导你将钉钉机器人连接到 OpenClaw,实现通过钉钉与 AI 对话。

架构

钉钉消息 → dingtalk_stream → OpenClaw API → AI回复 → 钉钉Webhook → 用户

前置条件

  1. 钉钉企业应用(创建应用并开通 Stream 模式)
  2. OpenClaw 已运行并启用 HTTP API
  3. Python 3.8+

配置步骤

1. 安装依赖

pip install dingtalk-stream requests

2. 创建配置文件 config.py

# -*- coding: utf-8 -*-

# 钉钉应用凭证(从钉钉开放平台获取)
AGENT_ID = "你的AgentId"
APP_KEY = "你的AppKey"
APP_SECRET = "你的AppSecret"

# 机器人消息回调Topic
BOT_MESSAGE_TOPIC = "/v1.0/im/bot/messages/get"

# 日志配置
LOG_LEVEL = "INFO"
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
LOG_FILE = "logs/dingtalk_stream.log"

3. 创建主程序 main.py

# -*- coding: utf-8 -*-
"""
钉钉机器人 Stream 模式 - 连接 OpenClaw AI
"""

import sys
import logging
import requests
from pathlib import Path

try:
    import dingtalk_stream
    from dingtalk_stream import AckMessage
except ImportError:
    print("请先安装: pip install dingtalk-stream")
    sys.exit(1)

import config

# ============ 配置区域(根据你的环境修改)============
# OpenClaw API 地址
OPENCLAW_URL = "http://127.0.0.1:18789/v1/responses"
# OpenClaw Gateway Token(在 openclaw.json 中配置)
OPENCLAW_TOKEN = "你的OpenClaw_Token"

# 钉钉 Webhook(用于发送回复)
# 创建机器人后获取:群设置 → 智能群助手 → 添加机器人 → 自定义机器人
WEBHOOK_URL = "你的钉钉Webhook_URL"
# ==================================================

PROCESSED_FILE = Path("C:/Users/MyPC/.openclaw/workspace/dingtalk_processed.txt")
PROCESSED_IDS = set()

def load_processed():
    global PROCESSED_IDS
    if PROCESSED_FILE.exists():
        with open(PROCESSED_FILE, "r", encoding="utf-8") as f:
            PROCESSED_IDS = set(line.strip() for line in f if line.strip())

def save_processed(msg_id):
    with open(PROCESSED_FILE, "a", encoding="utf-8") as f:
        f.write(msg_id + "\
")
    PROCESSED_IDS.add(msg_id)

# 调用 OpenClaw AI
def get_openclaw_response(user_msg: str) -> str:
    try:
        headers = {
            "Authorization": f"Bearer {OPENCLAW_TOKEN}",
            "Content-Type": "application/json"
        }
        data = {
            "model": "openclaw",
            "input": user_msg
        }
        r = requests.post(OPENCLAW_URL, headers=headers, json=data, timeout=60)
        if r.status_code == 200:
            result = r.json()
            output = result.get("output", [])
            if output:
                content = output[0].get("content", [])
                if content:
                    return content[0].get("text", "抱歉,我无法回答这个问题。")
        logging.error(f"OpenClaw API 错误: {r.status_code} {r.text}")
        return "抱歉,我现在有点忙,请稍后再试。"
    except Exception as e:
        logging.error(f"调用 OpenClaw 失败: {e}")
        return "抱歉,连接出现问题,请稍后再试。"

# 发送回复到钉钉
def send_reply(content):
    data = {
        "msgtype": "text",
        "text": {"content": content},
        "at": {"atUserIds": [], "isAtAll": False}
    }
    try:
        r = requests.post(WEBHOOK_URL, json=data, timeout=10)
        result = r.json()
        logging.info(f"回复结果: {result}")
        return result.get("errcode", 1) == 0
    except Exception as e:
        logging.error(f"发送失败: {e}")
        return False

# 消息处理器
class Handler(dingtalk_stream.ChatbotHandler):
    def __init__(self):
        super().__init__()
    
    async def process(self, callback):
        try:
            msg = dingtalk_stream.ChatbotMessage.from_dict(callback.data)
            content = msg.text.content if msg.text else ""
            
            if not content:
                return AckMessage.STATUS_OK, 'OK'
            
            msg_id = f"{msg.conversation_id}_{msg.sender_id}_{len(content)}"
            
            if msg_id in PROCESSED_IDS:
                logging.info(f"重复消息,跳过: {content[:20]}")
                return AckMessage.STATUS_OK, 'OK'
            
            save_processed(msg_id)
            logging.info(f"收到: {content}")
            
            # 获取 AI 回复
            response = get_openclaw_response(content)
            logging.info(f"回复: {response}")
            
            # 发送到钉钉
            send_reply(response)
            
            return AckMessage.STATUS_OK, 'OK'
        except Exception as e:
            logging.error(f"处理失败: {e}")
            return AckMessage.STATUS_ERROR, str(e)

def main():
    print("=" * 50)
    print("  钉钉 + OpenClaw AI 对话机器人")
    print("=" * 50)
    
    load_processed()
    logging.info(f"已加载 {len(PROCESSED_IDS)} 条已处理消息")
    
    credential = dingtalk_stream.Credential(config.APP_KEY, config.APP_SECRET)
    client = dingtalk_stream.DingTalkStreamClient(credential)
    client.register_callback_handler(dingtalk_stream.ChatbotMessage.TOPIC, Handler())
    
    logging.info("正在连接钉钉...")
    client.start_forever()

if __name__ == "__main__":
    main()

4. 启用 OpenClaw HTTP API

编辑 C:\Users\MyPC\.openclaw\openclaw.json,添加:

{
  "gateway": {
    "http": {
      "endpoints": {
        "responses": {
          "enabled": true
        }
      }
    }
  }
}

重启 OpenClaw Gateway 后生效。

5. 运行

python main.py

注意事项

  1. APP_KEY 和 APP_SECRET 在钉钉开放平台的企业应用详情页获取
  2. WEBHOOK_URL 创建自定义机器人后获取,注意安全设置(加签)
  3. OPENCLAW_TOKEN 在 openclaw.json 的 gateway.auth.token 中查看
  4. 确保 OpenClaw Gateway 运行在 127.0.0.1:18789

调试

查看日志文件 logs/dingtalk_stream.log 排查问题。

安全使用建议
This skill implements a legitimate DingTalk → OpenClaw chat bridge, but the metadata fails to declare required credentials and the instructions encourage storing secrets in plaintext and writing to a hardcoded user path. Before installing or running it: (1) obtain and store APP_KEY/APP_SECRET, WEBHOOK_URL, and OPENCLAW_TOKEN securely (prefer environment variables or a secrets manager rather than config.py); (2) avoid hardcoded paths — change PROCESSED_FILE to a directory you control and ensure file permissions restrict access; (3) verify the dingtalk-stream package source (PyPI project page) to ensure it's legitimate; (4) ensure the DingTalk webhook is restricted (use signature/secret if available) and that OpenClaw runs on a trusted host (127.0.0.1 is safer than a public endpoint); (5) because the skill metadata omits required secrets and has no source/homepage, exercise extra caution — ask the publisher for source code or a repository and for declared required env vars before trusting this skill. If you cannot verify the package origin or publisher, treat the skill as untrusted.
功能分析
Type: OpenClaw Skill Name: litmedia-dingtalk-openclaw Version: 1.0.0 The skill bundle provides a legitimate integration for connecting a DingTalk bot to the OpenClaw AI gateway using the official `dingtalk-stream` library. The Python scripts (`main.py`, `config.py`) and instructions in `SKILL.md` implement message handling, deduplication, and API communication consistent with the stated purpose. While the code contains hardcoded absolute paths (e.g., `C:/Users/MyPC/...` in `main.py`) and lacks credential encryption, these appear to be artifacts of a local development environment rather than indicators of malicious intent or data exfiltration.
能力评估
Purpose & Capability
The skill is a DingTalk Stream → OpenClaw connector and the code and instructions implement that. Required secrets (DingTalk APP_KEY/APP_SECRET, OpenClaw token, DingTalk webhook) are consistent with the stated purpose — but the skill metadata claims 'no required env vars' and provides no primary credential, which is inconsistent with the runtime instructions that require multiple credentials.
Instruction Scope
SKILL.md gives precise runtime code that reads/writes local files, registers a callback handler, posts requests to an internal OpenClaw HTTP API and to an external DingTalk webhook. It also instructs creating a plaintext config.py containing secrets and writes a processed-message file to a hardcoded user path. The instructions grant the skill broad discretion to send chat content externally (to OpenClaw) and to store identifiers locally — this is expected for the connector but the plaintext credential handling and hardcoded paths are insecure and not declared in metadata.
Install Mechanism
Instruction-only skill with no install spec or downloadable code; runtime requires pip packages (dingtalk-stream, requests). No installers or external archives are fetched by the skill itself, minimizing install-time risk.
Credentials
The code requires several secrets (APP_KEY, APP_SECRET, WEBHOOK_URL, OPENCLAW_TOKEN) but the registry metadata lists none. Requiring multiple tokens is proportionate to the purpose, but not declaring them is a transparency problem. Additionally, the guidance tells users to store these secrets in a plaintext config.py, which is insecure. The skill also writes to a hardcoded path (C:/Users/.../.openclaw/...), which implies filesystem access that should be disclosed.
Persistence & Privilege
The skill is not always-enabled and does not request elevated platform privileges. It does persist state by appending processed message IDs to a local file and instructs editing the user's OpenClaw gateway config; those are reasonable for a long-running bot but should be called out. Autonomous invocation (default) is allowed — expected for connector skills.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install litmedia-dingtalk-openclaw
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /litmedia-dingtalk-openclaw 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
钉钉 Stream 模式连接 OpenClaw AI 对话。通过钉钉机器人接收用户消息,调用 OpenClaw HTTP API 获取 AI 回复,再用 Webhook 发回钉钉。用于实现"钉钉 AI 助手"场景。
元数据
Slug litmedia-dingtalk-openclaw
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

dingtalk-openclaw 是什么?

钉钉 Stream 模式连接 OpenClaw AI 对话。通过钉钉机器人接收用户消息,调用 OpenClaw HTTP API 获取 AI 回复,再用 Webhook 发回钉钉。用于实现"钉钉 AI 助手"场景。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 291 次。

如何安装 dingtalk-openclaw?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install litmedia-dingtalk-openclaw」即可一键安装,无需额外配置。

dingtalk-openclaw 是免费的吗?

是的,dingtalk-openclaw 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

dingtalk-openclaw 支持哪些平台?

dingtalk-openclaw 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 dingtalk-openclaw?

由 tongyuezhou123(@tongshendota)开发并维护,当前版本 v1.0.0。

💬 留言讨论