How to use DingtalkChatbot - 10 common examples

To help you get started, we’ve selected a few DingtalkChatbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lazzyfu / AuditSQL / apps / project_manager / tasks.py View on Github external
def xiaoding_pull(user, id, type, addition_info=None, sleep=3):
    """
    id: 记录的id
    type: commit、close、approve、feedback、hook
    addition_info: 用户附加的消息
    """
    # 休眠3s后执行
    time.sleep(sleep)

    # 获取域名
    domain_name = DomainName.objects.get().domain_name if DomainName.objects.filter().first() else None

    if Webhook.objects.filter().first():
        webhook_addr = Webhook.objects.get().webhook_addr
        xiaoding = DingtalkChatbot(webhook_addr)

        data = AuditContents.objects.get(pk=id)
        tasks = data.tasks if data.tasks else None
        jira_url = data.url if data.url else None
        host = ':'.join((data.host, str(data.port)))
        addition_info = addition_info if addition_info else None
        if data.envi_desc == 0:
            envi_desc = '测试环境'
            if domain_name:
                jump_url = '/'.join((domain_name, 'projects/ol/test_records/'))
        elif data.envi_desc == 1:
            envi_desc = '预发布环境'
            if domain_name:
                jump_url = '/'.join((domain_name, 'projects/ol/staging_records/'))
        elif data.envi_desc == 2:
            envi_desc = '生产环境'
github pjialin / py12306 / py12306 / helpers / notification.py View on Github external
def send_dingtalk_by_webbook(self, content):
        from dingtalkchatbot.chatbot import DingtalkChatbot
        webhook = Config().DINGTALK_WEBHOOK
        dingtalk = DingtalkChatbot(webhook)
        dingtalk.send_text(msg=content, is_at_all=True)
        pass
github lazzyfu / AuditSQL / apps / orders / utils / msgNotice.py View on Github external
def dingding_push(id, user=None, type=None, msg=None, webhook=None, domain_name_tips=None):
    xiaoding = DingtalkChatbot(webhook)

    if type == 'reply':
        obj = OrderReply.objects.get(pk=id)
        reply_contents = obj.reply_contents
        data = Orders.objects.get(pk=obj.reply_id)
    else:
        # 获取数据
        data = Orders.objects.get(pk=id)
    # 如果用户手机号存在,钉钉直接@mobile
    # 如果手机号不存在,钉钉直接@all
    applicant_mobile = UserAccounts.objects.get(username=data.applicant).mobile
    auditor = ','.join([i['user'] for i in json.loads(data.auditor)])
    auditor_mobile = list(set(UserAccounts.objects.filter(username__in=auditor).values_list('mobile', flat=True)))
    reviewer = ','.join([i['user'] for i in json.loads(data.reviewer)])

    # 提交
github lazzyfu / AuditSQL / apps / project_manager / tasks.py View on Github external
def ding_notice_pull(data, weekday):
    """at未完成工单的开发,告知其尽快处理工单"""
    if Webhook.objects.filter().first():
        webhook_addr = Webhook.objects.get().webhook_addr
        xiaoding = DingtalkChatbot(webhook_addr)

        text = ''
        mobile = []
        tasks = data[0].get('tasks') + '\n'
        for i in data:
            proposer = i.get('proposer')
            title = i.get('title')
            text += f'工单负责人:{proposer}\t\t标题:{title}\n'
            mobile.append(i.get('mobile'))

        if weekday == 2:
            title = "【预发布环境未处理工单提醒】\n请下面相关工单负责人及时处理、以免影响发布,◕‿◕\n"
        if weekday == 3:
            title = "【生产环境未处理工单提醒】\n请下面相关工单负责人及时处理、以免影响发布,◕‿◕\n"

        content = ''.join((title, tasks, text))
github zhuifengshen / DingtalkChatbot / dingtalkchatbot / samples.py View on Github external
#     print(r.content)  # 输出消息发送结果


if __name__ == '__main__':
    # *************************************这里填写自己钉钉群自定义机器人的token*****************************************
    # 一、旧版的钉钉自定义机器人(无需安全设置)
    old_webhook = 'https://oapi.dingtalk.com/robot/send?access_token=77eb420ff2761ad516d974e1428c3e198b84faabc9c9ef8e86b2c71ac60bd0ea'
    # 二、新版的钉钉自定义机器人必须配置安全设置(自定义关键字、加签、IP地址/段),其中“加签”需要传入密钥才能发送成功
    new_webhook = 'https://oapi.dingtalk.com/robot/send?access_token=aa62d3aa55cd785609d1de1b8c82ebc0d5a106aa5983833ed15023cef80db7fa'
    secret = 'SEC11b94b27f5953b94deee33840d2863ebfbe7c75b68848613cdbd80228752d63b'  # 创建机器人时钉钉设置页面有提供
    # 用户手机号列表
    at_mobiles = ['18825166XXX', '这里填@的人的手机号,可自定义@的位置,默认添加在消息末尾']
    # 初始化机器人小丁
    # xiaoding = DingtalkChatbot(old_webhook)  # 旧版初始化方式
    # 新版安全设置为“加签”时,需要传入请求密钥,同时支持设置消息链接跳转方式,默认pc_slide=False为跳转到浏览器,pc_slide为在PC端侧边栏打开
    xiaoding = DingtalkChatbot(new_webhook, secret=secret, pc_slide=True)  
    # text
    xiaoding.send_text(msg='我就是小丁,小丁就是我!', is_at_all=True)
    xiaoding.send_text(msg='我就是小丁,小丁就是我!', at_mobiles=at_mobiles)

    # # image
    xiaoding.send_image(pic_url='http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg')

    # link
    xiaoding.send_link(title='万万没想到,某小璐竟然...',
                       text='故事是这样子的...',
                       message_url='http://www.kwongwah.com.my/?p=454748', 
                       pic_url='https://pbs.twimg.com/media/CEwj7EDWgAE5eIF.jpg')

    # markdown
    # 1、提醒所有人
    xiaoding.send_markdown(title='氧气文字', text='#### 广州天气\n'
github lazzyfu / AuditSQL / apps / sqlquery / tasks.py View on Github external
})

            # 发送邮件
            title = '探测到新的死锁'
            msg = EmailMessage(subject=title,
                               body=email_html_body,
                               from_email=EMAIL_FROM,
                               to=list(args)
                               )
            msg.content_subtype = "html"
            msg.send()

        # 发送钉钉通知
        if SysConfig.objects.get(key='dingding_push').is_enabled == '0':
            webhook = SysConfig.objects.get(key='dingding_push').value
            xiaoding = DingtalkChatbot(webhook)

            check_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            msg = '\n'.join((f'【警告 ◕﹏◕,探测到新的死锁记录,探测时间:{check_time}】\n', format_deadlock_data))

            xiaoding.send_text(msg=msg, is_at_all=True)
github zhuifengshen / DingtalkChatbot / dingtalkchatbot / samples.py View on Github external
'> ![美景](http://www.sinaimg.cn/dy/slidenews/5_img/2013_28/453_28488_469248.jpg)\n'
                           '> ###### 10点20分发布 [天气信息](https://www.seniverse.com/)\n',
                           at_mobiles=at_mobiles, is_auto_at=False)

    # 整体跳转ActionCard
    btns1 = [CardItem(title="查看详情", url="https://www.dingtalk.com/")]
    actioncard1 = ActionCard(title='万万没想到,竟然...',
                             text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns1,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard1)

    # 单独跳转ActionCard
    # 1、两个按钮选择
    btns2 = [CardItem(title="支持", url="https://www.dingtalk.com/"), CardItem(title="反对", url="https://www.dingtalk.com/")]
    actioncard2 = ActionCard(title='万万没想到,竟然...',
                             text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns2,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard2)
    # 2、三个按钮选择
    btns3 = [CardItem(title="支持", url="https://www.dingtalk.com/"), CardItem(title="中立", url="https://www.dingtalk.com/"), CardItem(title="反对", url="https://www.dingtalk.com/")]
    actioncard3 = ActionCard(title='万万没想到,竟然...',
                             text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns3,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard3)

    # FeedCard类型
github zhuifengshen / DingtalkChatbot / dingtalkchatbot / samples.py View on Github external
btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard2)
    # 2、三个按钮选择
    btns3 = [CardItem(title="支持", url="https://www.dingtalk.com/"), CardItem(title="中立", url="https://www.dingtalk.com/"), CardItem(title="反对", url="https://www.dingtalk.com/")]
    actioncard3 = ActionCard(title='万万没想到,竟然...',
                             text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns3,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard3)

    # FeedCard类型
    card1 = CardItem(title="氧气美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    card2 = CardItem(title="氧眼美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    card3 = CardItem(title="氧神美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    cards = [card1, card2, card3]
    xiaoding.send_feed_card(cards)
github zhuifengshen / DingtalkChatbot / dingtalkchatbot / samples.py View on Github external
btns=btns2,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard2)
    # 2、三个按钮选择
    btns3 = [CardItem(title="支持", url="https://www.dingtalk.com/"), CardItem(title="中立", url="https://www.dingtalk.com/"), CardItem(title="反对", url="https://www.dingtalk.com/")]
    actioncard3 = ActionCard(title='万万没想到,竟然...',
                             text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns3,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard3)

    # FeedCard类型
    card1 = CardItem(title="氧气美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    card2 = CardItem(title="氧眼美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    card3 = CardItem(title="氧神美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    cards = [card1, card2, card3]
    xiaoding.send_feed_card(cards)
github zhuifengshen / DingtalkChatbot / dingtalkchatbot / samples.py View on Github external
text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns2,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard2)
    # 2、三个按钮选择
    btns3 = [CardItem(title="支持", url="https://www.dingtalk.com/"), CardItem(title="中立", url="https://www.dingtalk.com/"), CardItem(title="反对", url="https://www.dingtalk.com/")]
    actioncard3 = ActionCard(title='万万没想到,竟然...',
                             text='![markdown](http://www.songshan.es/wp-content/uploads/2016/01/Yin-Yang.png) \n### 故事是这样子的...',
                             btns=btns3,
                             btn_orientation=1,
                             hide_avatar=1)
    xiaoding.send_action_card(actioncard3)

    # FeedCard类型
    card1 = CardItem(title="氧气美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    card2 = CardItem(title="氧眼美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    card3 = CardItem(title="氧神美女", url="https://www.baidu.com/", pic_url="http://pic1.win4000.com/wallpaper/2020-03-11/5e68b0557f3a6.jpg")
    cards = [card1, card2, card3]
    xiaoding.send_feed_card(cards)

DingtalkChatbot

一个钉钉自定义机器人消息的Python封装库

MIT
Latest version published 1 year ago

Package Health Score

56 / 100
Full package analysis

Similar packages