Search code examples
node.jsbotframeworkmicrosoft-teams

Is there an API to retrieve all alias emails of a user?


I have a use case where i would like to retrieve all the email aliases of a particular user in the Microsoft bot. Is there an API to retrieve all the alias emails of a user?

Backstory:

We're mapping users from Microsoft Teams with users of our product. When a user interacts with the bot, Microsoft Teams sends those messages from a different user id(which is an alias email for the same user). I would like a way to retrieve all the email aliases of a particular user so that I can map all of the id's in the beginning.


Solution

  • So I'm no expert on the email side of things, but hopefully I can at least give you some useful direction.

    1. The "Alias" you're talking about is actually the user's main UPN for their Office 365 account. The other address(es) you might know about would most likely in fact be "aliases", just for information
    2. From your Bot, you need to be able to call back to Office 365, either using the Graph API, or (I guess) the Exchange API to get actual email aliases. To do this, your user will need to give your Bot rights to do so. If you want to do this from within the bot itself, you'll most likely need to use a Signin Card so that the user can give your bot the rights it needs
    3. Another possible option is to rather request the UPN from Office 365 when the user signs up to your service (however you got the email in the first place - I'm guessing perhaps from a website of some sort)

    Hope that helps

    Update: The other answer on this thread is about using the Graph API - that's what I was referring to above in point 2. In order to do that, you'll need to:

    1. Get an id for the user, to be able to look up their email address, which you'll have from the Bot conversation (from the "From" property)

    2. Authenticate somehow to the Graph API, in order to make a call like the other person is suggesting on this thread. If you make the call -on behalf of the user- (called a "delegated" call), you'd call the "/me/" endpoint that is being suggested in the other answer. If you instead try as an "application" id, you'd rather call /users/, as described here. But either way I think you'll need to register an Azure AD Application, so that you have the ability to call the Graph API. To do that, if you've not used Graph before, you'll need to do a bit of "getting started" reading - I'd suggest starting here.