CS151990
CS151990

Reputation: 41

Is there any way to get user id/conversation reference to proactively message user on teams if installation event wasnt captured

Looking for the best course of action that would have the least impact on users to be able proactively message users with teams app (bot) installed but where they have not messaged the bot and the conversation reference was not captured at time of install.

The scenario is that have an enterprise bot that has been operational for over 3 years servicing 10s of thousands of employees. The bot is auto installed for all users in the tenant, but conversation references were only being stored in the last 2/3's of the applications life, and the install event was not being captured until recently. This was not an issue in past as all proactive functionality was predicated on some interaction with the bot.

I now have a need to be able proactively messages all users within tenant regardless of if they have messaged the bot or not, or if they last messaged the bot before conversation references were being stored. There are only a small subset of users the fall into this category.

Hoping some way to generate a conversation update, be it through graph or other means. The installationUpdate event through app update seemed promising as can update the application but seems only triggered if bot is added or removed

Upvotes: 3

Views: 2699

Answers (3)

Ennova
Ennova

Reputation: 672

Review the information provided here: https://learn.microsoft.com/en-us/microsoftteams/platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages?tabs=dotnet

Here is what we do

  1. If we have the conversation ID in our cache/persistent store, we use it to send the message

  2. If we dont have, we use GET https://graph.microsoft.com/v1.0/users/{user-id}/teamwork/installedApps/{teamsAppInstallationId}/chat to get the chatid (the app id here is not the bot application ID, but the ID generated when the app is installed in the org app store and is available from the Teams Admin interface)

  3. If the user does not have our app installed, we install the app using the teamsAppInstallationId ID. This automatically generates a event without user intervention that is sent to the bot which you can then use to capture the conversation ID.
    POST /users/{user-id | user-principal-name}/teamwork/installedApps

This approach does require an Application Permission: TeamsAppInstallation.ReadWriteSelfForUser.All

Upvotes: 1

Nivedipa-MSFT
Nivedipa-MSFT

Reputation: 1460

To send a proactive message to user the bot requires the conversation reference. The conversation can be only retrieved when bot installed. Without conversation reference you cannot send a proactive message using bot.

You can use Send message in a chat API to send message to chat with delegated permissions.

Could you please raise a uservoice for your case

Upvotes: 1

AP01
AP01

Reputation: 850

You might look into using the List Teams functionality in the Graph API. You can use Graph to get teams and list their members, assuming you can grant your bot the necessary permissions. There are many features in the Graph API which might help you accomplish this.

Upvotes: 0

Related Questions