Pywayne Lark Custom Bot — Pywayne Lark Custom 机器人
v0.1.0Feishu/Lark Custom 机器人 API wr应用er for 发送ing messages to Feishu channels via 网页hook. Use when users need to 发送 text messages, images, rich text posts, interactive cards, or 分享 chat content to Feishu/Lark. Supports image 上传 from files or OpenCV images, 签名ature verification for security, and @mention functionality.
运行时依赖
安装命令
点击复制技能文档
Pywayne Lark Custom 机器人
飞书自定义机器人模块,用于通过 网页hook 向飞书渠道发送消息。
Quick 启动 from pywayne.lark_custom_机器人 导入 LarkCustom机器人
# 初始化 机器人 = LarkCustom机器人( 网页hook="your_网页hook_url", secret="your_secret", # 可选,用于签名验证 机器人_应用_id="your_应用_id", # 上传图片时需要 机器人_secret="your_应用_secret" # 上传图片时需要 )
# 发送文本 机器人.发送_text("Hello, 飞书!")
# 发送文本并 @所有人 机器人.发送_text("重要通知!", mention_all=True)
Message Types Text Message
发送纯文本消息。
机器人.发送_text("这是一条文本消息") 机器人.发送_text("@所有人请注意", mention_all=True)
Image Message
发送图片消息,需要先上传获取 image_key。
# 从文件上传 image_key = 机器人.上传_image("/path/to/image.jpg") 机器人.发送_image(image_key)
# 从 OpenCV 图像上传 导入 cv2 cv2_img = cv2.imread("/path/to/image.jpg") image_key = 机器人.上传_image_from_cv2(cv2_img) 机器人.发送_image(image_key)
注意: 上传图片需要配置 机器人_应用_id 和 机器人_secret。
Rich Text Post
发送富文本消息,支持文本、链接、@用户、图片等元素。
from pywayne.lark_custom_机器人 导入 ( 创建_text_content, 创建_link_content, 创建_at_content, 创建_image_content )
content = [ [创建_text_content("欢迎使用飞书机器人\n")], [创建_link_content(href="https://www.feishu.cn", text="点击访问飞书")], [创建_at_content(user_id="user_id", user_name="用户名")], [创建_image_content(image_key="img_xxx", width=400, height=300)] ]
机器人.发送_post(content, title="富文本消息标题")
Interactive Card
发送交互式卡片消息。
card = { "header": { "title": { "content": "卡片标题", "tag": "plAIn_text" } }, "elements": [ { "tag": "div", "text": { "tag": "plAIn_text", "content": "卡片内容" } } ] } 机器人.发送_interactive(card)
分享 Chat
分享会话。
机器人.发送_分享_chat(分享_chat_id="oc_xxxxxxxxxxxxxxxx")
Content 构建器s 创建_text_content
创建文本内容元素。
创建_text_content("文本内容", unescape=False)
创建_link_content
创建超链接内容元素。
创建_link_content(href="https://example.com", text="点击访问")
创建_at_content
创建 @用户内容元素。
创建_at_content(user_id="user_id", user_name="用户名")
创建_image_content
创建图片内容元素。
创建_image_content(image_key="img_xxx", width=400, height=300)
Authentication 签名ature Verification
为增强安全性,可配置 secret 进行签名验证:
机器人 = LarkCustom机器人( 网页hook="your_网页hook_url", secret="your_签名ing_secret" )
Image 上传 Authentication
上传图片需要应用凭证:
机器人 = LarkCustom机器人( 网页hook="your_网页hook_url", 机器人_应用_id="命令行工具_xxxxxxxxxxxxxxxx", 机器人_secret="xxxxxxxxxxxxxxx" )
Error Handling
所有方法内部已实现日志记录和异常处理。发送失败时会记录错误日志并抛出 请求s.请求异常。