BlueGit

ict rusty-teams

Files

rusty-teams / scripts / cleanup-test-chats.py

cleanup-test-chats.py

cleanup-test-chats.py 1.2 KiB Download Raw
1"""Hide the "Native client test" meeting chats that live call tests leave behind.
2
3Runs through the signed-in M365 web session (skill running-m365-web-session).
4"""
5import os
6import sys
7import urllib.parse
8
9sys.path.insert(0, os.path.expanduser("~/.claude/skills/running-m365-web-session"))
10from m365web.client import Client
11
12SUBJECT = "Native client test"
13GRAPH = "https://graph.microsoft.com/v1.0"
14SCOPE = "Chat.ReadWrite"
15
16with Client() as client:
17 me = client.request("GET", f"{GRAPH}/me?$select=id", SCOPE)
18 organization = client.request("GET", f"{GRAPH}/organization?$select=id", SCOPE)
19 user = {"id": me["id"], "tenantId": organization["value"][0]["id"]}
20 url = f"{GRAPH}/me/chats?$select=id,topic&$filter=topic eq '{SUBJECT}'&$top=50"
21 chat_ids = []
22 while url:
23 page = client.request("GET", url, SCOPE)
24 chat_ids += [chat["id"] for chat in page["value"] if chat.get("topic") == SUBJECT]
25 url = page.get("@odata.nextLink")
26 for chat_id in chat_ids:
27 path = urllib.parse.quote(chat_id, safe="")
28 client.request("POST", f"{GRAPH}/chats/{path}/hideForUser", SCOPE, body={"user": user})
29 print(f"hid {len(chat_ids)} test meeting chat(s)")