Skip to main content

飞书机器人消息SDK

Project description

Feishu SDK

飞书机器人消息SDK - 一个简单易用的飞书应用机器人消息推送工具

特点

  • 极简API设计,符合直觉
  • 基于官方飞书SDK (lark_oapi),可靠稳定
  • 支持多种消息类型:文本、富文本、卡片消息
  • 自动处理认证令牌的获取和刷新
  • 轻量级设计,易于集成到任何项目

安装方法

# 从源代码安装
pip install -e .

# 或者直接从PyPI安装(如果已发布)
# pip install feishusdk

快速开始

1. 初始化机器人

from feishusdk 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 feishusdk.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()

先决条件

  1. 飞书开放平台创建一个应用
  2. 获取应用的App ID和App Secret
  3. 开启应用的机器人功能
  4. 开启机器人发送消息的权限
  5. 将机器人添加到您想要发送消息的群组中

完整示例

请参考项目中的sdk_example.py文件获取完整使用示例。

Project details


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.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lark_bot_sdk-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file lark_bot_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: lark_bot_sdk-0.1.0.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

Hashes for lark_bot_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 441512bfedd3a26975349a14b47d82e7948cbd4e76bd4afd2e7db9028c6afd17
MD5 577012a8c3f42d8d084d071bce0319d6
BLAKE2b-256 1a29da5e46bd93a7dce3a3c0c342f4957f7836f1fcf19ce58ca2641cd649dbec

See more details on using hashes here.

File details

Details for the file lark_bot_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lark_bot_sdk-0.1.0-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

Hashes for lark_bot_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a09739370684107254d3f9fc9d911b70cd828eef9d453f8746d5d57b3e09a5e3
MD5 1b04f275def29aa9675184bb1b6e1c11
BLAKE2b-256 3835559883ec94b23b9e1c9074a4d194b53603b868c33bcb5e026c5d8f444403

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page