forked from slack-rs/slack-rs-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_history.rs
34 lines (30 loc) · 1.06 KB
/
channel_history.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use slack_api as slack;
use std::env;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// You can generate a legacy token to quickly test these apis
// https://api.slack.com/custom-integrations/legacy-tokens
let token = env::var("SLACK_API_TOKEN").map_err(|_| "SLACK_API_TOKEN env var must be set")?;
let client = slack::default_client(&token).map_err(|_| "Could not get default_client")?;
let response = slack::channels::history(
&client,
&slack::channels::HistoryRequest {
channel: &env::args()
.nth(1)
.ok_or("must specify channel id as argument e.g. C09123456")?,
..slack::channels::HistoryRequest::default()
},
)
.await;
if let Ok(response) = response {
if let Some(messages) = response.messages {
for message in &messages {
println!("{:?}", message);
}
println!("Got {} messages:", messages.len());
}
} else {
println!("{:?}", response);
}
Ok(())
}