Basic fetch list of users from Slack

This commit is contained in:
Rob Watson 2020-10-16 22:24:57 +02:00
parent 7e5eb098e3
commit 68200ee28a
2 changed files with 16 additions and 3 deletions

View File

@ -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()

View File

@ -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(())
}