av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術(shù)文章
文章詳情頁

Python第三方包之DingDingBot釘釘機(jī)器人

瀏覽:2日期:2022-07-30 16:56:38

這個(gè)是作者自己封裝的一個(gè)釘釘機(jī)器人的包,目前只支持發(fā)文本格式、鏈接格式、markdown格式的消息,我們可以在很多場(chǎng)景用到這個(gè),比如告警通知等

安裝

pip install DingDingBot

使用方法

from DingDingBot.DDBOT import DingDing# 初始話DingDingBOt webhook是釘釘機(jī)器人所必須的dd = DingDing(webhook=’https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxx’)# 發(fā)送文本消息print(dd.Send_Text_Msg(Content=’test:測(cè)試數(shù)據(jù)’))# 發(fā)送鏈接消息print(dd.Send_Link_Msg(Content=’test’,Title=’測(cè)試數(shù)據(jù)’,MsgUrl=’https://www.baidu.com’,PicUrl=’https://cn.bing.com/images/search?q=outgoing%e6%9c%ba%e5%99%a8%e4%ba%ba&id=FEE700371845D9386738AAAA51DCC43DC54911AA&FORM=IQFRBA’))# 發(fā)送Markdown格式的消息print(dd.Send_MardDown_Msg(Content='# 測(cè)試數(shù)據(jù)n' + '> testone', Title=’測(cè)試數(shù)據(jù)’))

源碼

#!/usr/bin/python# -*- coding: UTF-8 -*-’’’ @@@@@@@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@@ @@@@@@@@@@@@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @@@@@@@@@ @@’’’import requests, jsonclass DingDing(): ''' # 釘釘官方文檔 Refer to official documentation: https://ding-doc.dingtalk.com/doc#/serverapi2/qf2nxq ''' # 初始化 def __init__(self, webhook): self.webhook = webhook self.session = requests.session() self.session.headers = {'Content-Type': 'application/json;charset=utf-8'} def Send_Text_Msg(self, Content: str, atMobiles: list = [], isAtAll: bool = False) -> dict: ''' :param content: 要發(fā)送的內(nèi)容 :param atMobiles: @指定的人,這里必須是列表,且參數(shù)為手機(jī)號(hào) :param isAtAll: @全體成員 :return: ''' try: data = {'msgtype': 'text','text': { 'content': Content},'at': { 'atMobiles': atMobiles, 'isAtAll': isAtAll} } response = self.session.post(self.webhook, data=json.dumps(data)) if response.status_code == ’200’:result = {'status': True, 'message': 'Message has been sent'}return result else:return response.text except Exception as error: result = {'status': False, 'message': f'Failed to send message,Error stack:{error}'} return result def Send_Link_Msg(self, Content: str, Title: str, MsgUrl: str, PicUrl: str = ’’): ''' :param Content: 鏈接的內(nèi)容 :param title: 鏈接的標(biāo)題 :param MsgUrl: 待跳轉(zhuǎn)頁面的url :param PicUrl: 消息所展示的圖片 :return: ''' try: data = {'msgtype': 'link','link': { 'text': Content, 'title': Title, 'picUrl': PicUrl, 'messageUrl': MsgUrl} } response = self.session.post(self.webhook, data=json.dumps(data)) if response.status_code == ’200’:result = {'status': True, 'message': 'Message has been sent'}return result else:return response.text except Exception as error: result = {'status': False, 'message': f'Failed to send message,Error stack:{error}'} return result def Send_MardDown_Msg(self, Content: str, Title: str, atMobiles: list = [], isAtAll: bool = False): ''' :param Content: Markdown格式的文本,僅支持下面的格式 ’’’ 標(biāo)題 # 一級(jí)標(biāo)題 ## 二級(jí)標(biāo)題 ### 三級(jí)標(biāo)題 #### 四級(jí)標(biāo)題 ##### 五級(jí)標(biāo)題 ###### 六級(jí)標(biāo)題 引用 > A man who stands for nothing will fall for anything. 文字加粗、斜體 **bold** *italic* 鏈接 [this is a link](http://name.com) 圖片 ![](http://name.com/pic.jpg) 無序列表 - item1 - item2 有序列表 1. item1 2. item2 ’’’ :param Title: 這個(gè)Markdown的標(biāo)題 :param atMobiles: @指定的人,這里必須是列表,且參數(shù)為手機(jī)號(hào) :param isAtAll: @全體成員 :return: ''' try: data = {'msgtype': 'markdown','markdown': { 'title': Title, 'text': Content},'at': { 'atMobiles': atMobiles, 'isAtAll': isAtAll} } response = self.session.post(self.webhook, data=json.dumps(data)) if response.status_code == ’200’:result = {'status': True, 'message': 'Message has been sent'}return result else:return response.text except Exception as error: result = {'status': False, 'message': f'Failed to send message,Error stack:{error}'} return result

到此這篇關(guān)于Python第三方包之DingDingBot釘釘機(jī)器人的文章就介紹到這了,更多相關(guān)Python DingDingBot內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: 釘釘 Python
相關(guān)文章:
主站蜘蛛池模板: 午夜激情在线观看 | 欧美精品二区 | 欧美专区第一页 | 久久久久免费 | 精品黑人一区二区三区国语馆 | 丁香婷婷激情 | 久久av一区二区三区亚洲 | 亚洲福利一区 | 国产亚洲久一区二区 | 国产一区二区观看 | 日韩精品一区二区三区四区 | 在线看的av| 欧美成人一级片 | 国产午夜在线 | 国产欧美精品 | 国产午夜视频 | 午夜无遮挡 | 久久久久久久久久久久久久 | 免费在线观看毛片 | www.av在线视频 | 99久久综合 | 国产精品久久久久久久久久久久午夜片 | 亚洲一区二区三区中文字幕 | 欧美日韩成人一区二区三区 | 欧美成人精品一区二区三区在线看 | 欧美日韩成人在线 | 国产午夜激情 | jizz中国女人高潮 | 国产又粗又黄又爽又硬的视频 | 九九热九九 | 日本黄色a级片 | 精品欧美在线 | 久久av影院 | 高清视频一区二区 | 日韩 欧美 亚洲 | 91福利在线视频 | aaa国产精品| 伊人久久网站 | 成人看片网 | 欧美性猛交一区二区三区精品 | 一级片av |