python调用钉钉机器人

  sre


依赖:

pip install dingtalkchatbot

调用:

from dingtalkchatbot.chatbot import DingtalkChatbot
from utils import config

def dingding_at_me(msg):
    # WebHook地址
    webhook = config.dingding_robot_url
    #dingding_user = config.dingding_user_phone
    secret = 'SEC11b9...这里填写自己的加密设置密钥'  # 可选:创建机器人勾选“加签”选项时使用
    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(webhook)  # 方式一:通常初始化方式
    #xiaoding = DingtalkChatbot(webhook, secret=secret)  # 方式二:勾选“加签”选项时使用(v1.5以上新功能)
    #xiaoding = DingtalkChatbot(webhook, pc_slide=True)  # 方式三:设置消息链接在PC端侧边栏打开(v1.5以上新功能)
    # Text消息@所有人
    #xiaoding.send_text(msg='我就是小丁,小丁就是我!', is_at_all=True)
    dingding_user = [config.dingding_user_phone]
    #xiaoding.send_text(msg=msg, at_mobiles=dingding_user)
    xiaoding.send_text(msg=msg, at_mobiles=dingding_user)

def dingding_at_all(msg):
    # WebHook地址
    webhook = config.dingding_robot_url
    #dingding_user = config.dingding_user_phone
    secret = 'SEC11b9...这里填写自己的加密设置密钥'  # 可选:创建机器人勾选“加签”选项时使用
    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(webhook)  # 方式一:通常初始化方式
    xiaoding.send_text(msg=msg, is_at_all=True)

def dingding_say(msg):
    # WebHook地址
    webhook = config.dingding_robot_url
    #dingding_user = config.dingding_user_phone
    secret = 'SEC11b9...这里填写自己的加密设置密钥'  # 可选:创建机器人勾选“加签”选项时使用
    # 初始化机器人小丁
    xiaoding = DingtalkChatbot(webhook)  # 方式一:通常初始化方式
    xiaoding.send_text(msg=msg)

if __name__ == '__main__':
    print("dingding utils")



LEAVE A COMMENT

Captcha Code