I am trying to start a scheduled proactive conversation (the bot initiates the conversation on scheduled time). I managed to get the User's AAD ID based on Graph API, but it doesn't match the Teams user ID. Tried for over 2 hours to obtain the right id, but I can't figure it out how. What would be the best approach I should take?
2 Answers
Have a look at the Microsoft Graph api to get the chat thread ID.
When the app is installed for the user, the bot will get receive a conversationUpdate event that will contain the necessary information for it to send the proactive message. For more information, see Bot events.
If you lose the chatThreadId, you can find it again by calling:
GET /users/{user-id}/chats?$filter=installedApps/any(a:a/teamsApp/id eq '{teamsAppid}')
However, this will only for for the personal scope! My advice would be to make sure you catch the conversationUpdate
which is triggered after an install and persist the user details in a database.
I'm curious how you tried to "match" these? In any case, I don't think they're intended to match up in any way (the aadObjectId Guid and the "29:..." user id). As a result, you should store a mapping on your side (database or similar). You need to store ServiceUrl and ConversationId anyway to do proactive messaging, so just tack userid on as well.

- 9,809
- 2
- 10
- 24
-
So you mean that there is no possible way to start the conversation without the ConversationId being stored... Let's say, by example. only by email? – AlinP25 May 06 '20 at 10:12
-
1No, you definitely can't 100% initiate in that way. It's a bit of a pain, but an understandable decision because otherwise you could create "Spam" bots, so to speak. The user has to physically connect with (i.e. install) the bot at least one time. In addition, note that you can install an app into a team using Graph (see https://learn.microsoft.com/en-us/graph/api/teamsappinstallation-add?view=graph-rest-1.0&tabs=http), but not install it to a user programmatically – Hilton Giesenow May 06 '20 at 13:09
-
1@HiltonGiesenow, you can install an app to an user programmatically as you can read [here](https://learn.microsoft.com/en-us/graph/teams-proactive-messaging#install-the-app). – Mick May 06 '20 at 15:37
-
1ah, silly, I -thought- I'd seen such an op, but forgot to check the "beta" endpoint - thanks Mick! – Hilton Giesenow May 06 '20 at 16:47