| 1 | use serde_json::Value; |
| 2 | use session::{DEFAULT_ENDPOINT, Request, Scope, Session}; |
| 3 | |
| 4 | #[tokio::main] |
| 5 | async fn main() { |
| 6 | let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned()); |
| 7 | let needle = std::env::args() |
| 8 | .nth(1) |
| 9 | .unwrap_or_else(|| "Lunch".to_owned()); |
| 10 | let session = Session::connect(&endpoint).await.expect("browser"); |
| 11 | let url = "https://teams.cloud.microsoft/api/csa/emea/api/v1/teams/users/me?isPrefetch=false&enableMembershipSummary=true"; |
| 12 | let scope = Scope::new( |
| 13 | "https://chatsvcagg.teams.microsoft.com", |
| 14 | "user_impersonation", |
| 15 | ); |
| 16 | let answer = session |
| 17 | .batch(&[Request::get(url)], &scope) |
| 18 | .await |
| 19 | .expect("csa") |
| 20 | .remove(0); |
| 21 | println!("# status {}", answer.status); |
| 22 | for team in answer |
| 23 | .body |
| 24 | .get("teams") |
| 25 | .and_then(Value::as_array) |
| 26 | .into_iter() |
| 27 | .flatten() |
| 28 | { |
| 29 | for channel in team |
| 30 | .get("channels") |
| 31 | .and_then(Value::as_array) |
| 32 | .into_iter() |
| 33 | .flatten() |
| 34 | { |
| 35 | let name = channel |
| 36 | .get("displayName") |
| 37 | .and_then(Value::as_str) |
| 38 | .unwrap_or_default(); |
| 39 | if !name.contains(&needle) { |
| 40 | continue; |
| 41 | } |
| 42 | println!("channel {name}"); |
| 43 | for tab in channel |
| 44 | .get("tabs") |
| 45 | .and_then(Value::as_array) |
| 46 | .into_iter() |
| 47 | .flatten() |
| 48 | { |
| 49 | let mut shown = tab.clone(); |
| 50 | if let Some(object) = shown.as_object_mut() { |
| 51 | object.retain(|key, _| key != "replyChainId"); |
| 52 | } |
| 53 | println!( |
| 54 | " {}", |
| 55 | serde_json::to_string(&shown) |
| 56 | .unwrap_or_default() |
| 57 | .chars() |
| 58 | .take(1500) |
| 59 | .collect::<String>() |
| 60 | ); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |