8 个版本
0.1.7 | 2023年7月20日 |
---|---|
0.1.6 | 2023年7月5日 |
0.1.5 | 2023年6月3日 |
0.1.2 | 2023年5月9日 |
#803 in 网页编程
每月 177 次下载
在 2 个包中使用(通过 botx-api-framework)
285KB
4.5K SLoC
botx-api
描述
对 eXpress api 的封装
使用
添加到 Cargo.toml
botx-api = { version = "*", features = ["anthill-di"] }
以下功能可用
botx-api-v-all
- 包含所有版本的功能(默认值)
botx-api-v2
- 包含所有 2 版本 api
botx-api-v3
- 包含所有 3 版本 api
botx-api-v4
- 包含所有 4 版本 api
anthill-di
- 添加对 anthill-di 和 async-trait-with-sync 的依赖(在 anthill-di 中添加 BotXApiContext 构造函数的注册)
token
- 启用机器人认证 api
notifications-internal
- 启用发送事件(机器人)的 api
notifications-direct
- 启用发送事件(消息)的 api
events-edit_event
- 启用编辑事件(消息)的 api
events-reply_event
- 启用对事件(消息)的响应的 api
events-status
- 启用请求事件状态的 api
events-typing
- 启用启用打印状态的 api
events-stop_typing
- 启用停止打印状态的 api
files-upload
- 启用上传文件的 api
files-download
- 启用下载文件的 api
stickers-new_sticker_pack
- 启用创建贴纸包的 api
stickers-sticker_packs_list
- 启用请求贴纸包列表的 api
stickers-add_sticker
- 启用添加贴纸包的 api
stickers-get_sticker_pack
- 启用请求贴纸包信息的 api
stickers-get_sticker
- 启用请求贴纸信息的 api
stickers-update_sticker_pack
- 启用更新贴纸包的 api
stickers-delete_sticker
- 启用删除贴纸的 api
stickers-delete_sticker_pack
- 启用删除贴纸包的 api
chats-list
- 启用请求机器人聊天列表的 api
chats-info
- 启用请求机器人聊天信息的 api
chats-add_use
- 启用将用户添加到机器人聊天的 api
chats-remove_use
- 启用从机器人聊天中删除用户的 api
chats-add_admin
- 启用将管理员添加到机器人聊天的 api
chats-set_stealth
- 启用启用隐形模式的 api
chats-disable_stealth
- 启用禁用隐身模式的API
chats-create
- 启用创建新聊天的API
chats-pin_message
- 启用在聊天中固定消息的API
chats-unpin_message
- 启用在聊天中解除消息固定的API
users-by_email
- 启用通过电子邮件地址查询用户信息的API
users-by_huid
- 启用通过huid查询用户信息的API
chats-by_login
- 启用通过ad登录和ad域名查询用户信息的API
chats-by_other_id
- 启用通过其他id查询用户信息的API
users-users_as_csv
- 启用查询用户列表的API
使用
要使用,请创建BotXApiContext对象
- 通过new方法 - 使用默认客户端设置和机器人配置
- 通过from_client方法 - 使用配置好的reqwest::async_impl::client::Client和机器人配置
- 通过from_env_with_default_client方法 - 使用默认客户端设置和从环境变量中获取的机器人配置
- 通过from_env方法 - 使用配置好的reqwest::async_impl::client::Client和从环境变量中获取的机器人配置
- 通过在anthill_di中注册 - 使用extensions::IBotXApiContextExt::register_botx_api_context方法在di上下文中注册BotXApiContext,可选地注册BotXApiContextConfiguration对象作为Singleton,reqwest::async_impl::client::Client,ApiEndpoints(否则将使用默认设置,即从环境变量中获取的机器人配置)
机器人配置来自环境变量
- BOTX_API_CTS_URL - cts服务器URL
- BOTX_API_BOT_ID - 机器人id
- BOTX_API_BOT_SECRET_KEY - 机器人密钥
所有模型都实现了builder模式。使用示例
let internal_notification_request = InternalNotificationRequestBuilder::default()
.with_group_chat_id(uuid::Uuid::from_str("de981642-5224-4e70-a8dd-9a933a8e096e"))
.with_data(PingBotsCommandData { })
.with_opts(PingBotsCommandOption { })
.build()
.expect("Не все поля запроса были указаны");
为自动更新认证添加了retry_with_auth方法
let internal_notification_request = InternalNotificationRequestBuilder::default()
.with_group_chat_id(uuid::Uuid::from_str("de981642-5224-4e70-a8dd-9a933a8e096e"))
.with_data(PingBotsCommandData { })
.with_opts(PingBotsCommandOption { })
.build()
.expect("Не все поля запроса были указаны");
let internal_notification_result = retry_with_auth(&self.api, || internal_notification(&self.api, &internal_notification_request)).await;
在anthill-di中注册时,可以注册自己的ApiEndpoints对象,这允许更改API(无意义但可能)
逻辑通过crate log写入日志。启用日志记录以更好地了解应用程序的工作方式
贡献
打开issue提出问题或建议
许可证
MIT,可用于任何目的
项目状态
状态 | 方法 | API | 描述 |
---|---|---|---|
✅ | GET | /api/v2/botx/bots/:bot_id/token | |
❌ | POST | /api/v3/botx/notification/callback/direct | 发送到聊天中的直接通知(已弃用) |
✅ | POST | /api/v4/botx/notifications/internal | 发送内部机器人通知 |
✅ | POST | /api/v4/botx/notifications/direct | 发送到聊天中的直接通知 |
✅ | POST | /api/v3/botx/events/edit_event | 编辑事件 |
✅ | POST | /api/v3/botx/events/reply_event | 对消息进行回复 |
✅ | GET | /api/v3/botx/events/:sync_id/status | 消息状态 |
✅ | POST | /api/v3/botx/events/typing | 发送typing |
✅ | POST | /api/v3/botx/events/stop_typing | 发送stop_typing |
✅ | GET | /api/v3/botx/chats/list | 获取机器人聊天列表 |
✅ | GET | /api/v3/botx/chats/info | 获取聊天信息 |
✅ | POST | /api/v3/botx/chats/add_user | 将用户添加到聊天中 |
✅ | POST | /api/v3/botx/chats/remove_user | 从聊天中删除用户 |
✅ | POST | /api/v3/botx/chats/add_admin | 将管理员添加到聊天中 |
✅ | POST | /api/v3/botx/chats/stealth_set | 在聊天中启用隐身模式 |
✅ | POST | /api/v3/botx/chats/stealth_disable | 在聊天中禁用隐身模式 |
✅ | POST | /api/v3/botx/chats/create | 创建聊天 |
✅ | POST | /api/v3/botx/chats/pin_message | 在聊天中固定消息 |
✅ | POST | /api/v3/botx/chats/unpin_message | 在聊天中解除消息固定 |
❌ | GET | /api/v3/botx/users/by_email | 通过用户的电子邮件地址查找用户数据(已弃用) |
✅ | POST | /api/v3/botx/users/by_email | 通过用户的电子邮件地址查找用户数据 |
✅ | GET | /api/v3/botx/users/by_huid | 通过用户的huid查找用户数据 |
✅ | GET | /api/v3/botx/users/by_login | 通过用户的ad登录和ad域名查找用户数据 |
✅ | GET | /api/v3/botx/users/by_other_id | 通过其他标识符查找用户数据 |
✅ | GET | /api/v3/botx/users/users_as_csv | 获取CTS上的用户列表 |
❌ | GET | /api/v3/botx/users/update_profile | 更新用户配置文件 |
❌ | GET | /api/v3/botx/smartapps/list | 在CTS上获取smartapp列表 |
❌ | POST | /api/v3/botx/smartapps/event | 发送smartapp事件 |
❌ | POST | /api/v3/botx/smartapps/notification | 发送smartapp通知 |
❌ | POST | /api/v3/botx/smartapps/upload_file | 上传smartapp文件 |
✅ | GET | /api/v3/botx/stickers/packs | 获取stickers套装列表 |
✅ | GET | /api/v3/botx/stickers/packs/:pack_id | 获取stickers套装 |
✅ | GET | /api/v3/botx/stickers/packs/:pack_id/stickers/:sticker_id | 从stickers套装中获取stickers |
✅ | POST | /api/v3/botx/stickers/packs | 创建stickers套装 |
✅ | POST | /api/v3/botx/stickers/packs/:pack_id/stickers | 将stickers添加到stickers套装 |
✅ | PUT | /api/v3/botx/stickers/packs/:pack_id | 编辑stickers套装 |
✅ | DELETE | /api/v3/botx/stickers/packs/:pack_id | 删除stickers套装 |
✅ | DELETE | /api/v3/botx/stickers/packs/:pack_id/stickers/:sticker_id | 从stickers套装中删除stickers |
✅ | GET | /api/v3/botx/files/download | 下载文件 |
✅ | POST | /api/v3/botx/files/upload | 上传文件 |
依赖项
~7–20MB
~299K SLoC