Skip to content

步骤

添加机器人

1. 群设置中添加自定义机器人

1832670413046415360.png

2. 机器人设置

注意拿到两个值,一时拿不到也没事,添加成功之后,仍然可以点击设置找到机器人,点击一下就能找到这些信息了。

bash
# 密钥
# SECbc1bd91d9ffd0943b4302811bfef5d48e459e6b8f625727cca09295a237f1d5a
# Wbhook
# https://oapi.dingtalk.com/robot/send?access_token=21bf5e47c25b42829760b50dbab658e5bd3f30b99360c65482023cb90e35f4c0

1832670413851721728.png

Python脚本编写

模块下载

bash
pip install DingtalkChatbot

上脚本

python
from dingtalkchatbot.chatbot import DingtalkChatbot


class DingtalkRobot(object):
    def __init__(self, webhook, secret=None):
        self.webhook = webhook
        self.secret = secret
        self.chatbot = DingtalkChatbot(self.webhook, self.secret)

    def send_text(self, content):
        """ 发送普通文本消息 """
        self.chatbot.send_text(msg=content, is_at_all=False)


if __name__ == '__main__':
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=21bf5e47c25b42829760b50dbab658e5bd3f30b99360c65482023cb90e35f4c0"
    secret = "SECbc1bd91d9ffd0943b4302811bfef5d48e459e6b8f625727cca09295a237f1d5a"
    robot = DingtalkRobot(webhook, secret)
    robot.send_text('Hello, Dingtalk!')