Last active
July 24, 2025 16:10
-
-
Save KyMidd/aaa0b0a5922fea3d969c180ab1a0cd84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_teams_conversation_history(user_graph_auth_token, event_body): | |
| #... | |
| if conversation_type == "channel": | |
| # ... | |
| elif conversation_type == "personal": | |
| user_aad_id = event_body["from"]["aadObjectId"] | |
| # If replying to message | |
| if reply_to_id: | |
| chat_id = event_body["conversation"]["id"] | |
| else: | |
| # Find graph API compatible chat_id from conversation_id (Teams APIs are weird) | |
| chat_id = resolve_chat_id_from_installed_apps(user_graph_auth_token, user_aad_id) | |
| # Read back the most recent messages in the personal chat | |
| url = f"https://graph.microsoft.com/v1.0/chats/{chat_id}/messages?$top={teams_dm_conversation_read_msg_count}" | |
| # Get previous messages | |
| response = requests.get(url, headers=headers) | |
| if response.status_code != 200: | |
| raise Exception(f"Graph API error {response.status_code}: {response.text}") | |
| data = response.json() | |
| messages = data.get("value", []) | |
| # Sort so we get the oldest first | |
| messages = list(reversed(messages)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment