52 个版本
0.7.0 | 2023 年 7 月 19 日 |
---|---|
0.4.0 | 2023 年 3 月 31 日 |
0.3.1 | 2022 年 11 月 18 日 |
0.2.1 | 2022 年 7 月 6 日 |
0.1.4 | 2020 年 12 月 29 日 |
1538 在 Web 编程 中排名
每月 36 次下载
465KB
11K SLoC
slack-chat-api
完全自动生成且具有个人观点的 Slack API 客户端库。
API 详细信息
与 Slack 平台交互的一种方式是其基于 HTTP RPC 的 Web API,这是一组需要 OAuth 2.0 用户、机器人或工作区令牌(具有相关 OAuth 权限范围)的方法。
联系方式
姓名 | 网址 |
---|---|
Slack 开发者关系 | https://api.slack.com/support |
客户端详细信息
此客户端基于 API 规范版本 1.7.0
从 Slack OpenAPI 规范 生成。这样,当添加新功能时,它将保持最新状态。文档与代码一起生成,以便轻松使用此库。
要安装库,请将以下内容添加到您的 Cargo.toml
文件中。
[dependencies]
slack-chat-api = "0.7.0"
基本示例
典型使用将需要初始化一个 Client
。这需要一个用户代理字符串和一组凭证。
use slack_chat_api::Client;
let slack = Client::new(
String::from("client-id"),
String::from("client-secret"),
String::from("redirect-uri"),
String::from("token"),
String::from("refresh-token")
);
或者,库可以在环境中搜索客户端所需的大部分变量
SLACK_CLIENT_ID
SLACK_CLIENT_SECRET
SLACK_REDIRECT_URI
然后您可以从环境中创建一个客户端。
use slack_chat_api::Client;
let slack = Client::new_from_env(
String::from("token"),
String::from("refresh-token")
);
传递空值给 token
和 refresh_token
是可以的。在客户端的初始状态下,您将不知道这些值。
要启动一个全新的客户端并获取 token
和 refresh_token
,请使用以下操作。
use slack_chat_api::Client;
async fn do_call() {
let mut slack = Client::new_from_env("", "");
// Get the URL to request consent from the user.
// You can optionally pass in scopes. If none are provided, then the
// resulting URL will not have any scopes.
let user_consent_url = slack.user_consent_url(&["some-scope".to_string()]);
// In your redirect URL capture the code sent and our state.
// Send it along to the request for the token.
let code = "thing-from-redirect-url";
let state = "state-from-redirect-url";
let mut access_token = slack.get_access_token(code, state).await.unwrap();
// You can additionally refresh the access token with the following.
// You must have a refresh token to be able to call this function.
access_token = slack.refresh_access_token().await.unwrap();
}
依赖关系
~16–34MB
~614K SLoC