Basic fetch list of users from Slack
This commit is contained in:
parent
7e5eb098e3
commit
68200ee28a
|
@ -30,7 +30,7 @@ async fn index() -> Template {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rocket::launch]
|
#[rocket::launch]
|
||||||
fn rocket() -> rocket::Rocket {
|
async fn rocket() -> rocket::Rocket {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
|
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
|
|
17
src/slack.rs
17
src/slack.rs
|
@ -13,8 +13,7 @@ struct SlackProfile<'a> {
|
||||||
|
|
||||||
pub async fn set_status(msg: &str) -> Result<(), String> {
|
pub async fn set_status(msg: &str) -> Result<(), String> {
|
||||||
let client = slack_api::default_client().map_err(|e| e.to_string())?;
|
let client = slack_api::default_client().map_err(|e| e.to_string())?;
|
||||||
let api_key =
|
let api_key = env::var("SLACK_OAUTH_ACCESS_TOKEN").expect("SLACK_OAUTH_ACCESS_TOKEN");
|
||||||
env::var("SLACK_OAUTH_ACCESS_TOKEN").expect("could not load SLACK_OAUTH_ACCESS_TOKEN");
|
|
||||||
let profile = SlackProfile {
|
let profile = SlackProfile {
|
||||||
status_text: msg,
|
status_text: msg,
|
||||||
status_emoji: ":mountain:",
|
status_emoji: ":mountain:",
|
||||||
|
@ -34,3 +33,17 @@ pub async fn set_status(msg: &str) -> Result<(), String> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_all() -> Result<(), String> {
|
||||||
|
let client = slack_api::default_client().map_err(|e| e.to_string())?;
|
||||||
|
let api_key = env::var("SLACK_OAUTH_ACCESS_TOKEN").expect("SLACK_OAUTH_ACCESS_TOKEN");
|
||||||
|
let list_req = slack_api::users::ListRequest::default();
|
||||||
|
let resp = slack_api::users::list(&client, &api_key, &list_req)
|
||||||
|
.map_err(|e| e.to_string())
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let members = resp.members.unwrap();
|
||||||
|
println!("Got vec with {} members", members.len());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue