-
-
Save KyMidd/e04799b7262366229e57a7dad32dafbe 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 resolve_team_id_from_team_id(headers, target_channel_id): | |
| # Get all teams the user is a member of | |
| # Only supports up to 100 teams for now, should add pagination if needed at some point | |
| teams_response = requests.get( | |
| "https://graph.microsoft.com/v1.0/me/joinedTeams", headers=headers) | |
| teams_response.raise_for_status() | |
| teams = teams_response.json() | |
| # For each team, check each channel to find the one with the target_channel_id | |
| for team in teams.get("value", []): | |
| team_id = team["id"] | |
| team_name = team.get("displayName", "") | |
| channels_response = requests.get( | |
| f"https://graph.microsoft.com/v1.0/teams/{team_id}/channels", | |
| headers=headers | |
| ) | |
| channels_response.raise_for_status() | |
| channels = channels_response.json() | |
| # Iterate through channels to find the one with the target_channel_id | |
| for channel in channels.get("value", []): | |
| if channel["id"] == target_channel_id: | |
| channel_name = channel.get("displayName", "") | |
| return { | |
| "team_id": team_id, | |
| "channel_id": target_channel_id, | |
| "team_name": team_name, | |
| "channel_name": channel_name | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment