diff --git a/src/api/mod.rs b/src/api/mod.rs index 2f8d4e2..ce154b1 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -21,10 +21,9 @@ pub struct SlackChannel { * Get slack channels. */ pub async fn get_channels(config: &Config) -> Result> { - let params = vec![("token", &config.token)]; - let url = Url::parse_with_params("https://slack.com/api/conversations.list", params).unwrap(); + let url = Url::parse("https://slack.com/api/conversations.list").unwrap(); - let client = Client::new().get(url); + let client = Client::new().get(url).bearer_auth(&config.token); let res: SlackResponse = client.send().await?.json().await?; @@ -39,14 +38,13 @@ pub async fn get_channels(config: &Config) -> Result> { * Post slack message. */ pub async fn post_message(config: &Config, channel: &str, text: &str) -> Result { - let body = vec![ - ("channel", channel), - ("text", text), - ("token", &config.token), - ]; + let body = vec![("channel", channel), ("text", text)]; let url = Url::parse("https://slack.com/api/chat.postMessage").unwrap(); - let client = Client::new().post(url).form(&body); + let client = Client::new() + .post(url) + .bearer_auth(&config.token) + .form(&body); let res: SlackResponse = client.send().await?.json().await?;