Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs
Hi @Gabriel-N
can you please share me the python version of powershell script you shared,I tried converting it using an AI tool, but it didn't work as expected. Having a Python version would be very helpful.
Also, I attempted using the interactive token-based approach with the following function:
def get_access_token_interactive(client_id, tenant_id, scopes):
"""
Get an access token using delegated permissions (interactive user login) via MSAL.
"""
authority = f"https://login.microsoftonline.com/{tenant_id}"
app = msal.PublicClientApplication(client_id, authority=authority)
accounts = app.get_accounts()
if accounts:
result = app.acquire_token_silent(scopes, account=accounts[0])
if result and 'access_token' in result:
return result['access_token']
# Interactive login
result = app.acquire_token_interactive(scopes)
if 'access_token' in result:
return result['access_token']
else:
print("Failed to obtain access token interactively.")
print(result.get('error_description'))
return None
def find_group_chat_by_name(access_token, group_chat_name):
"""
Find a group chat by its name from the signed-in user's chats and return its chat ID.
"""
url = "https://graph.microsoft.com/v1.0/me/chats?$filter=chatType eq 'group'"
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}
response = requests.get(url, headers=headers)
if response.status_code != 200:
print(f"Error fetching group chats: {response.status_code}")
print(response.text)
return None
chats = response.json().get('value', [])
for chat in chats:
if chat.get('topic', '').lower() == group_chat_name.lower():
return chat['id']
This approach works perfectly fine in a local environment. Initially, it opens a browser window and displays the message 'Authenticated successfully, you can close this window now,' after which it successfully retrieves the messages from the group chat. However, in GitHub Actions, GUI-based (interactive) authentication is not supported, so this method cannot be used in that environment.