返回顶部
p

pywayne-lark-bot飞书机器人封装

Feishu/Lark Bot API wrapper for full-featured Feishu bot interactions. Use when users need to send messages (text, image, audio, file, post, interactive, share), especially Markdown delivery via send_markdown_to_chat with card_v2/post routing, table fallback, and auto chunking; manage files (upload/download); query user/group info; or listen for incoming messages with LarkBotListener.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
732
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

pywayne-lark-bot

Pywayne Lark Bot

飞书机器人模块,提供完整飞书 API 交互功能,包括消息发送、文件管理、用户/群组查询和消息监听。

Quick Start

python
from pywayne.lark_bot import LarkBot, TextContent

初始化

bot = LarkBot(appid=yourappid, appsecret=yourappsecret)

发送文本消息到用户

bot.sendtexttouser(useropenid=userxxx, text=Hello!)

发送文本消息到群聊

bot.sendtexttochat(chatid=oc_xxx, text=Group message)

TextContent - 文本格式化工具

创建各种文本格式,用于发送带格式的文本消息。

Mentions

python

@所有人


atall = TextContent.makeatallpattern()

@指定用户

atuser = TextContent.makeatsomeonepattern(useropenid=userxxx, username=张三, idtype=open_id)

Text Styles

python

加粗、斜体、下划线、删除线


bold = TextContent.makeboldpattern(粗体)
italic = TextContent.makeitalianpattern(斜体)
underline = TextContent.makeunderlinepattern(下划线)
strikethrough = TextContent.makedeleteline_pattern(删除线)

超链接

link = TextContent.makeurlpattern(https://example.com, 点击访问)

LarkBot - 消息发送与查询

推荐路径:发送 Markdown(优先使用)

优先使用 sendmarkdownto_chat,它会自动处理大文本分包,并支持两种路由:

  • - prefer=cardv2(默认):发送 schema 2.0 interactive 卡片,适合绝大多数 Markdown 场景
  • prefer=post:发送 post 富文本;可设置 tablefallback=code_block 将 Markdown 表格稳定降级

python
md =

发布说明

  • - 新增对账接口
  • 修复支付重试逻辑
模块状态
API完成
FE
测试中 |

默认走 card_v2(推荐)

bot.sendmarkdownto_chat( chatid=ocxxx, md_text=md, title=版本进度, prefer=card_v2 )

需要 post 时切换路由

bot.sendmarkdownto_chat( chatid=ocxxx, md_text=md, title=版本进度, prefer=post, tablefallback=codeblock )

发送消息

Text Message

python
bot.sendtexttouser(useropen_id, 私聊消息)
bot.sendtexttochat(chatid, 群聊消息)

Image Message

python

上传图片


imagekey = bot.uploadimage(/path/to/image.jpg)

发送图片

bot.sendimagetouser(useropenid, imagekey) bot.sendimagetochat(chatid, image_key)

Audio / Media / File Message

python

上传文件


filekey = bot.uploadfile(/path/to/file.pdf, file_type=pdf)

发送音频

bot.sendaudiotouser(useropenid, filekey)

发送多媒体

bot.sendmediatochat(chatid, file_key)

发送文件

bot.sendfiletouser(useropenid, filekey)

Post (Rich Text) Message

python
from pywayne.lark_bot import PostContent

post = PostContent(title=富文本标题)

添加内容

line = post.maketextcontent(这是粗体文本, styles=[bold]) post.addcontentinnewline(line)

发送

bot.sendposttouser(useropenid, post.getcontent()) bot.sendposttochat(chatid, post.get_content())

Interactive Card Message

python

直接传原始 interactive 卡片


card = {
header: {title: {content: 卡片标题, tag: plain_text}},
elements: [...]
}
bot.sendinteractivetouser(useropen_id, card)
bot.sendinteractivetochat(chatid, card)

CardContentV2(schema 2.0 卡片构造器)

python
from pywayne.lark_bot import CardContentV2

card = CardContentV2(title=日报, template=blue)
card.add_markdown(# 今日进展\n\n- 完成接口联调\n- 修复2个问题)
card.add_hr()
card.addimage(imgkey=img_xxx)

bot.sendinteractivetochat(chatid, card.get_card())

Share Message

python

分享群聊


bot.sendsharedchattouser(useropenid, sharedchatid)
bot.sendsharedchattochat(chatid, sharedchat_id)

分享用户

bot.sendsharedusertouser(useropenid, shareduserid) bot.sendsharedusertochat(chatid, shareduser_id)

PostContent - 富文本构建器

python
post = PostContent(title=标题)

可用内容类型

text = post.maketextcontent(文本, styles=[bold, underline]) link = post.makelinkcontent(链接文字, https://example.com) at = post.makeatcontent(useropenid) img = post.makeimagecontent(imagekey=imgxxx) media = post.makemediacontent(filekey=filexxx, imagekey=thumbxxx) emoji = post.makeemojicontent(emoji_type=OK) hr = post.makehrcontent() codeblock = post.makecodeblockcontent(language=python, text=print(hello)) markdown = post.makemarkdowncontent(Markdown)

添加内容

post.addcontentinnewline(text) post.addcontentsin_line([link, at]) # 同一行添加多个元素

python

推荐:直接添加 markdown,支持分块与表格降级


md =

迭代计划
任务状态
Adone
B
doing |

post.addmarkdown(md, tableas=codeblock, maxchunk_bytes=8000)

文件操作

python

上传


imagekey = bot.uploadimage(/path/to/image.jpg)
filekey = bot.uploadfile(/path/to/file.pdf, file_type=pdf)

下载

bot.downloadimage(imagekey, /save/path/image.jpg) bot.downloadfile(filekey, /save/path/file.pdf)

下载消息中的所有资源

resources = bot.downloadmessageresources( messageid=msgxxx, messagecontent={imagekey:img_xxx}, save_dir=/save/dir )

用户与群组查询

python

获取用户信息


users = bot.getuserinfo(emails=[test@example.com], mobiles=[13800138000])

获取群组列表

groups = bot.getgrouplist()

通过群名获取群ID

chatids = bot.getgroupchatidbyname(项目讨论组)

获取群成员

members = bot.getmembersingroupbygroupchatid(chatid)

通过群成员名获取 open_id

memberids = bot.getmemberopenidbyname(chat_id, 张三)

获取群名和用户名

chatname, username = bot.getchatandusername(chatid, userid)

LarkBotListener - 消息监听

飞书消息监听器,用于实时接收和处理消息。

python
from pywayne.larkbotlistener import LarkBotListener
from pathlib import Path

listener = LarkBotListener(
appid=yourapp_id,
appsecret=yourapp_secret
)

文本消息处理

python
@listener.texthandler(grouponly=False, user_only=False)
async def handletext(text: str, chatid: str, isgroup: bool, groupname: str, user_name: str):
print(f收到来自 {user_name} 的消息: {text})
# 回复
listener.sendmessage(chatid, f已收到:{text})

图片消息处理

python
@listener.imagehandler(grouponly=True)
async def handleimage(imagepath: Path, chatid: str, username: str):
print(f收到图片: {image_path})
# 处理图片...

文件消息处理

python
@listener.file_handler()
async def handlefile(filepath: Path, chatid: str, username: str):
print(f收到文件: {file_path})
# 处理文件...

通用消息监听

python
@listener.listen(message_type=post)
async def handle_post(ctx):
print(f收到富文本消息: {ctx.content})

启动监听

python
listener.run()

监听器参数说明

Handler

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 lark-bot-1776108576 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 lark-bot-1776108576 技能

通过命令行安装

skillhub install lark-bot-1776108576

下载

⬇ 下载 pywayne-lark-bot v0.1.0(免费)

文件大小: 3.97 KB | 发布时间: 2026-4-15 13:12

v0.1.0 最新 2026-4-15 13:12
- Initial public release of pywayne-lark-bot.
- Provides comprehensive Feishu/Lark bot API wrapper for sending messages (including Markdown, image, audio, file, post, interactive cards, and share), with advanced Markdown handling and auto chunking.
- Supports file upload/download and robust user/group info querying.
- Includes LarkBotListener for asynchronous message listening with flexible handler decorators and built-in de-duplication.
- Offers extensive message formatting utilities (mention, text styles, rich post/card builders) and fallback strategies for Markdown tables.
- Complete usage examples and reference included in documentation.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部