当前位置: 首页 > news >正文

python飞书群机器人通过webhook发送消息

python飞书群机器人通过webhook发送消息

import json
import loggingimport requestslogger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)class FeishuTalk:"""飞书群机器人通过webhook发送消息"""def __init__(self, url: str = ""):test_robot_url = 'https://open.feishu.cn/open-apis/bot/v2/hook/xxx'self.url = url or test_robot_urlself.mHeader = {'Content-Type': 'application/json; charset=UTF-8'}def send(self, data):"""发送消息"""try:info = requests.post(url=self.url, data=data, headers=self.mHeader)if info.json().get("StatusCode") == 0 and info.json().get("msg") == "success":logger.info(f"飞书通知发送成功,msg={info.json()}")else:logger.warning(f"飞书通知发送异常,{info.json()=}")except Exception as e:logger.warning("飞书通知发送异常")logger.warning(e)passdef send_msg(self):"""发送消息"""field_list = [{"is_short": True,"text": {"tag": "lark_md","content": f"**姓名**:<font color=\"green\">毛豆</font>\n"}},{"is_short": True,"text": {"tag": "lark_md","content": f"**年龄**:<font color=\"green\">6</font>\n"}}]card = json.dumps({"elements": [{"tag": "div","fields": field_list},{"actions": [{"tag": "button","text": {"content": "详情","tag": "plain_text"},"type": "primary","url": 'www.baidu.com'},],"tag": "action"}],"header": {"template": "turquoise","title": {"content": "📬电通知","tag": "plain_text"}}})body = json.dumps({"msg_type": "interactive", "card": card})self.send(data=body)if __name__ == "__main__":fs = FeishuTalk()fs.send_msg()
http://www.lryc.cn/news/221702.html

相关文章:

  • 埃隆·马斯克的 AI 聊天机器人 Grok 已经上线
  • 【代码随想录】算法训练营 第十五天 第六章 二叉树 Part 2
  • 使用ssl_certificate_by_lua指令动态加载证书
  • Qt中Opencv转Qimage出现重影或者颜色不对
  • upload-labs-1
  • 【vite配置路径别名@】/启动配置
  • 3. List
  • Django初窥门径-oauth登录认证
  • 数学到底在哪里支撑着编程?
  • Python模块ADB的, 已经 pyadb
  • 猫头虎分享从Python到JavaScript传参数:多面手的数据传递术
  • 注解汇总:Spring 常用的注解
  • 合肥工业大学操作系统实验5
  • 基于SpringBoot+Vue的点餐管理系统
  • C# 继承,抽象,接口,泛型约束,扩展方法
  • mysql的备份和恢复
  • 【机器学习3】有监督学习经典分类算法
  • lv11 嵌入式开发 计算机硬件基础 1
  • 【Linux】vim
  • cstring函数
  • 【owt】p2p client mfc 工程梳理
  • pandas教程:Hierarchical Indexing 分层索引、排序和统计
  • Redis 扩展 RedisBloom 插件,解决缓存击穿、穿透
  • VBA技术资料MF80:选择文件及文件夹
  • 网络层:控制平面
  • Ubuntu 系统内核 kernel panic
  • 【flink】RowData copy/clone方式
  • 网页图标工具
  • 掌动智能:功能测试及拨测主要功能
  • 第11章 Java集合(二)