飞书机器人消息SDK
Project description
Lark Bot SDK
飞书机器人消息SDK - 一个简单易用的飞书应用机器人消息推送工具
特点
- 极简API设计,符合直觉
- 基于官方飞书SDK (lark_oapi),可靠稳定
- 支持多种消息类型:文本、富文本、卡片消息
- 自动处理认证令牌的获取和刷新
- 轻量级设计,易于集成到任何项目
安装方法
# 从源代码安装
pip install -e .
# 或者直接从PyPI安装(如果已发布)
# pip install lark_bot_sdk
快速开始
1. 初始化机器人
from lark_bot_sdk import init_bot, BotMessage
# 方式1:直接提供应用凭证
init_bot(app_id="YOUR_APP_ID", app_secret="YOUR_APP_SECRET")
# 方式2:使用配置文件
init_bot(config_file="config.json")
配置文件格式 (config.json):
{
"app_id": "YOUR_APP_ID",
"app_secret": "YOUR_APP_SECRET"
}
2. 发送消息
使用简单的BotMessage类来发送各种类型的消息:
# 发送文本消息
message = BotMessage("群组ID", {
"type": "text",
"content": "Hello World"
})
message.send()
3. 获取群组列表
from lark_bot_sdk.bot import get_group_list
groups = get_group_list()
for group in groups:
print(f"{group.name}: {group.chat_id}")
消息类型示例
文本消息
BotMessage("群组ID", {
"type": "text",
"content": "这是一条文本消息"
}).send()
富文本消息
post_content = {
"zh_cn": {
"title": "系统通知",
"content": [
[
{"tag": "text", "text": "这是一条富文本消息测试"}
],
[
{"tag": "text", "text": "支持多个段落"}
]
]
}
}
BotMessage("群组ID", {
"type": "post",
"content": post_content
}).send()
卡片消息
import time
card_content = {
"config": {
"wide_screen_mode": True
},
"header": {
"title": {
"tag": "plain_text",
"content": "系统报警"
},
"template": "red"
},
"elements": [
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": f"**服务器监控报警**\n\n时间: {time.strftime('%Y-%m-%d %H:%M:%S')}"
}
},
{
"tag": "hr"
},
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": "### 警告详情\n- CPU使用率: 92%\n- 内存使用率: 85%"
}
}
]
}
BotMessage("群组ID", {
"type": "interactive",
"content": card_content
}).send()
先决条件
- 在飞书开放平台创建一个应用
- 获取应用的App ID和App Secret
- 开启应用的机器人功能
- 开启机器人发送消息的权限
- 将机器人添加到您想要发送消息的群组中
完整示例
请参考项目中的sdk_example.py文件获取完整使用示例。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lark_bot_sdk-0.1.1.tar.gz
(5.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lark_bot_sdk-0.1.1.tar.gz.
File metadata
- Download URL: lark_bot_sdk-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebb763ddb5630ad502be520d7b6f962afc087951b464cfce2d0af0db6bf5e706
|
|
| MD5 |
d88944315901ac77dc2864f3396e58d4
|
|
| BLAKE2b-256 |
e55cfa0d08f48ba0c3a0175d66883b4a1f2f400c9f719e5d7a76ba82c7aca931
|
File details
Details for the file lark_bot_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lark_bot_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dee3f93f29d36706789116a60ba1592b2ecf805039bee1dbd16e0a5e45c6192
|
|
| MD5 |
529fdc780d904023f3ea90cec9bf6be2
|
|
| BLAKE2b-256 |
b37afea0e94d682384e23ad688805cf6be28bf93d6e8fb434c2e0b337f903aa1
|