How to get an event for any new chat message in groupchats using microsoft graph subscription api?

Tanuj Doye 0 Reputation points
2025-01-07T04:51:01.07+00:00

Objective: To enable a Teams application to read messages from chats where the bot is not mentioned, using the chatMessages:readWriteWhereInstalled permission.

Efforts Undertaken:

  1. Initial Implementation Using chatMessages:read-write Permission: Successfully implemented message reading functionality using the chatMessages:read-write permission. Utilized the Microsoft Graph API subscription endpoint https://graph.microsoft.com/beta/subscriptions/. The resource used for testing: "resource": "/chats//messages". Verified that messages could be read from the specified chat under this permission.
  2. Client Requirement to Use chatMessages:readWriteWhereInstalled Permission: The client requested that the implementation be modified to use chatMessages:readWriteWhereInstalled permission.
  3. Investigation of App Manifest: Analyzed the attached app manifest file. Observed discrepancies: The bot ID and app ID in the manifest were different. The bearer token was being generated using the bot ID’s client ID and client secret but not for the app ID. 4. App Presence in Chats: Identified that the application needs to be present in chats for chatMessages:readWriteWhereInstalled to function. Explored and implemented app installation into chats using the TeamsAppInstallation.ReadWriteForChat.All permission via REST template. Confirmed that app installation to chats was successful.
  4. Adjustments to the Subscription Resource: Updated the subscription resource to "/appCatalogs/teamsApps//installedToChats/getAllMessages" as per the requirements. Tested the modified subscription post API. 6. Token Generation Challenges: Encountered failure in functionality due to token-related issues: The bearer token being used was generated for the bot ID. Unable to generate a token for the app ID since no corresponding application existed in the Azure Entra account for the app ID. Observed inconsistency where the bot ID and app ID were reported as the same in the Azure portal, but installation operations did not work when using the same bot ID/app ID.
  5. Reference Documentation: Referred to the Microsoft Graph API documentation: Microsoft Graph API Subscription Documentation Investigated the prerequisites and limitations of the API for the specified resource.

Current Status: Despite successful app installation in chats, the message reading functionality using the chatMessages:readWriteWhereInstalled permission is not working. The root cause appears to be related to token generation and app ID discrepancies. Roadblocks Identified: No separate application in Azure Entra corresponding to the app ID for token generation. The bot ID and app ID mismatch in the context of app installation and functionality. Lack of clarity on using the chatMessages:readWriteWhereInstalled permission effectively with the current app setup.

Next Steps and Support Required: Guidance on resolving app ID and bot ID discrepancies. Confirmation on the correct process for token generation for the app ID. Validation of the resource path "/appCatalogs/teamsApps//installedToChats/getAllMessages" for subscriptions. Assistance in identifying any missing configurations or permissions.

Conclusion: Extensive research and implementation efforts have been made to enable the Teams app to read messages from chats where it is installed. However, token generation and configuration issues are blocking progress. Support from the relevant technical team is required to resolve these issues and move forward.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,798 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.