唤醒手腕2025年最新钉钉开放平台钉钉机器人stream搭建部署详细教程(更新中)

钉钉开放平台

开放平台文档:https://open.dingtalk.com/document/resourcedownload/ding-card-interactive-card-building-platform-new

内部机器人:钉钉机器人搭建

企业内部机器人提供给开发者构建组织内部使用的机器人的能力,开发者可以通过配置企业内部机器人的配置项并调用相关接口向钉钉用户或者钉钉群内发送机器人消息,也可以接收从机器人向开发者组织的业务系统发送的消息。你可跟随本文完成企业内部机器人的配置、开发和上架。

文档地址:https://open.dingtalk.com/document/robots/custom-robot-access?spm=a213l2.30158279.0.0.56525669JvjPsu

内部机器人:创建企业内部应用

https://open-dev.dingtalk.com/fe/app?hash=%23%2Fcorp%2Fapp%3FopenCreate%3Dtrue#/corp/app?openCreate=true

内部机器人:Stream 模式

文档地址:https://open.dingtalk.com/document/resourcedownload/introduction-to-stream-mode?spm=a2q3p.21071111.0.0.31675mkf5mkf5M

Stream 模式是钉钉开放平台提供的一种集成方式,它可以监听机器人回调、事件订阅回调和注册卡片回调。使用 Stream 模式接入,钉钉开放平台将通过 Websocket 连接与应用程序通讯,Stream 模式将极大降低接入门槛和资源依赖,不需要公网服务器、IP、域名等资源,只需集成钉钉开放平台 SDK 即可。

在 Stream 模式下,开发者的应用程序通过集成 SDK 的方式与钉钉开放平台建立一条 WebSocket 连接,建立连接过程中开放平台将对连接进行鉴权。当有卡片回调发生时,开放平台将通过 WebSocket 连接将数据通知到开发者的应用程序。开发者的应用程序可以接收到这些数据并进行相应处理,从而实现与钉钉开放平台的实时通信。

安装 SDK

clike 复制代码
pip install dingtalk-stream
复制代码
# !/usr/bin/env python

import argparse
import logging
from dingtalk_stream import AckMessage
import dingtalk_stream

def setup_logger():
    logger = logging.getLogger()
    handler = logging.StreamHandler()
    handler.setFormatter(
        logging.Formatter('%(asctime)s %(name)-8s %(levelname)-8s %(message)s [%(filename)s:%(lineno)d]'))
    logger.addHandler(handler)
    logger.setLevel(logging.INFO)
    return logger


def define_options():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--client_id', dest='client_id', required=True,
        help='app_key or suite_key from https://open-dev.digntalk.com'
    )
    parser.add_argument(
        '--client_secret', dest='client_secret', required=True,
        help='app_secret or suite_secret from https://open-dev.digntalk.com'
    )
    options = parser.parse_args()
    return options


class CalcBotHandler(dingtalk_stream.ChatbotHandler):
    def __init__(self, logger: logging.Logger = None):
        super(dingtalk_stream.ChatbotHandler, self).__init__()
        if logger:
            self.logger = logger

    async def process(self, callback: dingtalk_stream.CallbackMessage):
        incoming_message = dingtalk_stream.ChatbotMessage.from_dict(callback.data)
        expression = incoming_message.text.content.strip()
        try:
            result = eval(expression)
        except Exception as e:
            result = 'Error: %s' % e
        self.logger.info('%s = %s' % (expression, result))
        response = 'Q: %s\nA: %s' % (expression, result)
        self.reply_text(response, incoming_message)

        return AckMessage.STATUS_OK, 'OK'

def main():
    logger = setup_logger()
    options = define_options()

    credential = dingtalk_stream.Credential(options.client_id, options.client_secret)
    client = dingtalk_stream.DingTalkStreamClient(credential)
    client.register_callback_handler(dingtalk_stream.chatbot.ChatbotMessage.TOPIC, CalcBotHandler(logger))
    client.start_forever()


if __name__ == '__main__':
    main()

usage: main.py [-h] --client_id CLIENT_ID --client_secret CLIENT_SECRET
main.py: error: the following arguments are required: --client_id, --client_secret

python .\main.py --client_id xxxxxx --client_secret xxxxxx
2025-10-14 04:47:03,378 dingtalk_stream.client INFO     open connection, url=https://api.dingtalk.com/v1.0/gateway/connections/open [stream.py:149]
2025-10-14 04:47:03,763 dingtalk_stream.client INFO     endpoint is {'endpoint': 'wss://wss-open-connection.dingtalk.com:443/connect', 'ticket': 'c58e29d9-a875-11f0-884b-5a20030ba585'} [stream.py:71]

互动卡片平台

文档地址:https://card.dingtalk.com/card-builder?spm=ding_open_doc.document.0.0.721e41694qaf1r&cardType=normal

自定义机器人:安全设置

为了确保自定义机器人使用过程的安全性,我们提供三种保护措施来保障你的自定义机器人安全运行。这些措施包括:设置自定义关键词、加签(使用签名加密)和 IP 地址(段)。通过这些方法,可以有效保护你的机器人不受恶意攻击

相关推荐
ModestCoder_2 小时前
ROS Bag与导航数据集技术指南
开发语言·人工智能·自然语言处理·机器人·具身智能
Mr.Winter`10 小时前
基于Proto3和单例模式的系统参数配置模块设计(附C++案例实现)
c++·人工智能·单例模式·机器人
中國龍在廣州1 天前
现在人工智能的研究路径可能走反了
人工智能·算法·搜索引擎·chatgpt·机器人
数据与后端架构提升之路1 天前
RT-2:Google DeepMind的机器人革命——如何让AI从网页知识中学会操控现实世界
机器人·视觉语言动作模型·rt-2模型·google deepmind·链式思维推理
攻城狮7号1 天前
小米具身大模型 MiMo-Embodied 发布并全面开源:统一机器人与自动驾驶
人工智能·机器人·自动驾驶·开源大模型·mimo-embodied·小米具身大模型
shayudiandian1 天前
ChatGPT风格对话机器人搭建教程
人工智能·chatgpt·机器人
robot_learner1 天前
11 月 AI 动态:多模态突破・智能体模型・开源浪潮・机器人仿真・AI 安全与主权 AI
人工智能·机器人·开源
IT观测1 天前
手部动作捕捉技术系统推荐:机器人灵巧操作的革命
机器人
m0_650108242 天前
PaLM-E:具身智能的多模态语言模型新范式
论文阅读·人工智能·机器人·具身智能·多模态大语言模型·palm-e·大模型驱动
J_Xiong01172 天前
【VLNs篇】17:NaVid:基于视频的VLM规划视觉语言导航的下一步
人工智能·机器人