-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathchannel_history_sync.rs
33 lines (29 loc) · 1.04 KB
/
channel_history_sync.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
use slack_api::sync as slack;
use std::env;
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().map_err(|_| "Could not get default_client")?;
let response = slack::channels::history(
&client,
&token,
&slack::channels::HistoryRequest {
channel: &env::args()
.nth(1)
.ok_or("must specify channel id as argument e.g. C09123456")?,
..slack::channels::HistoryRequest::default()
},
);
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(())
}