a Feishu Third-party libraries
Project description
飞书 sdk
第三方Feishu库,目前只实现了使用的机器人
部分功能,后续会看精力继续完善
导入
from feishu.Application import Bot
bot = Bot(app_id='xxxxxxxxxxxxxxx', app_secret="xxxxxxxxxxxxxxx")
事前准备
测试的话需要给自己发送消息,我们需要一个飞书的登录预授权码 注意失效,仅为5分钟
你需要在飞书开放平台 所测试的机器人 -> 安全设置中 添加一个重定向URL,内容为https://example.com
然后下面方法或手动拼接,获取一个地址,类似于 https://open.feishu.cn/open-apis/authen/v1/index?app_id=xxxxxxxxx&redirect_uri=https://example.com&state= `,在浏览器中打开,登录后,从地址栏中拿到预授权码
print(bot.get_authorization_code_by_browser_url())
然后获取你自己的 open_id
print(bot.get_user_info(code='上面获取的预授权码'))
部分功能实例
获取Token
# 租户Token
print(bot.get_tenant_access_token())
# app Token
print(bot.get_app_access_token())
创建群组
bot.create_group(name="测试测试", open_ids=['xxxxxxx'])
发送文字消息
bot.send_user_message(user_open_id="xxxxxxxxxxxxx", text='测试消息')
发送卡片消息
bot.send_user_card_message(user_open_id="ou_b7fd6a20da4e3903bc2324b71232c5ac", title="测试标题", text="测试内容")
发送复杂卡片消息
message_config = {
'title': '上线任务审批通知',
'action': '上线审批',
'system': ','.join(['a', 'b', 'c']),
'reason': '因为地球毁灭',
'detail': '用户:xxxx 申请发布服务,您可以确认。',
'button': [
{
'title': '同意',
'type': 'primary',
'value': {
'action': 'approval_online_order',
'order_id': '12345',
'option': 'agree'
},
},
{
'title': '拒绝',
'type': 'danger',
'value': {
'action': 'approval_online_order',
'order_id': '12345',
'user_id': '123',
'option': 'disagree'
}
},
]
}
bot.send_user_card_message(user_open_id="ou_b7fd6a20da4e3903bc2324b71232c5ac", **message_config)
卡片消息格式自定义
bot.configuration_card_message(image_key="img_5abe5193-14df-4b7d-af6f-15fac38c485g",
button_confirm=False,
name='123',
auto_add_time=True
)
bot.send_user_card_message(user_open_id="ou_b7fd6a20da4e3903bc2324b71232c5ac", **message_config)
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
feishu-sdk-1.0.0.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for feishu_sdk-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 989e66f6d20c6b0155b768dc5736dca2871dd8251a4ea748e5fc4c9aa3f1d78a |
|
MD5 | 0afdb41b9fd247b26ad20f1e157eb00a |
|
BLAKE2b-256 | 6b700b0675e8b28f06c9c5d3b53082ea1b3550a0d7dcc48ad6cf68bc5a89e86d |