| 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().nth(1).unwrap_or_else(|| "Lunch".to_owned()); |
| 8 | let session = Session::connect(&endpoint).await.expect("browser"); |
| 9 | let url = "https://teams.cloud.microsoft/api/csa/emea/api/v1/teams/users/me?isPrefetch=false&enableMembershipSummary=true"; |
| 10 | let scope = Scope::new("https://chatsvcagg.teams.microsoft.com", "user_impersonation"); |
| 11 | let answer = session.batch(&[Request::get(url)], &scope).await.expect("csa").remove(0); |
| 12 | println!("# status {}", answer.status); |
| 13 | for team in answer.body.get("teams").and_then(Value::as_array).into_iter().flatten() { |
| 14 | for channel in team.get("channels").and_then(Value::as_array).into_iter().flatten() { |
| 15 | let name = channel.get("displayName").and_then(Value::as_str).unwrap_or_default(); |
| 16 | if !name.contains(&needle) { |
| 17 | continue; |
| 18 | } |
| 19 | println!("channel {name}"); |
| 20 | for tab in channel.get("tabs").and_then(Value::as_array).into_iter().flatten() { |
| 21 | let mut shown = tab.clone(); |
| 22 | if let Some(object) = shown.as_object_mut() { |
| 23 | object.retain(|key, _| key != "replyChainId"); |
| 24 | } |
| 25 | println!(" {}", serde_json::to_string(&shown).unwrap_or_default().chars().take(1500).collect::<String>()); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |