Retrieve Teams User ID based on AAD ID
Asked Answered
K

2

6

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?

Killie answered 6/5, 2020 at 9:55 Comment(0)
B
0

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.

Bergstrom answered 6/5, 2020 at 10:8 Comment(4)
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?Killie
No, 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 learn.microsoft.com/en-us/graph/api/…), but not install it to a user programmaticallyBergstrom
@HiltonGiesenow, you can install an app to an user programmatically as you can read here.Barvick
ah, silly, I -thought- I'd seen such an op, but forgot to check the "beta" endpoint - thanks Mick!Bergstrom
B
1

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.

Barvick answered 6/5, 2020 at 11:22 Comment(0)
B
0

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.

Bergstrom answered 6/5, 2020 at 10:8 Comment(4)
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?Killie
No, 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 learn.microsoft.com/en-us/graph/api/…), but not install it to a user programmaticallyBergstrom
@HiltonGiesenow, you can install an app to an user programmatically as you can read here.Barvick
ah, silly, I -thought- I'd seen such an op, but forgot to check the "beta" endpoint - thanks Mick!Bergstrom

© 2022 - 2024 — McMap. All rights reserved.