How can my teams app get Teams Id and Its Email informations

himawan 0 Reputation points
2023-11-08T02:52:22.8766667+00:00

I'm creating a Microsoft Teams App, which is a bot to send proactive message.
The app is done and i upload it into my organization, created the azure ad for the bot within my tenant.

This is how the bot register the user's teams id and email info into our db

  1. When user add the app/bot into their teams acc, then our bot will register/save data like ms teams id, conversation id, tenant id, etc (except for the user email, since it is not found from within the information available on that event)
  2. The bot then provide welcome message with button to login message, where they will be asked consent and login sso to use ms graph to fetch their email.
    the email then synced with the teams id data within our db

The problem with this approach is that, we havent publish our app to store yet, but when i tried to upload the app into other tenant, the user is able to add it but when click login it seems the ms graph couldn't get the user info since its not exist on the creator tenant.

How are we supposed to get the ms teams id, conversation id, tenant id, and email info from the user? Are my approach wrong? How can i fix it?

This is the error message when tried to log in :

Screen Shot 2023-11-08 at 10.40.02

Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
10,335 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
3,349 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Prasad-MSFT 6,891 Reputation points Microsoft Vendor
    2023-11-08T06:11:31.7766667+00:00

    The error message you're seeing is likely due to the fact that your app is not multi-tenant. When you register an app in Azure AD, it is, by default, single-tenant, meaning it can only authenticate users in the tenant it was registered in. If you want to authenticate users from other tenants, you need to make your app multi-tenant. After making your app multi-tenant, users from other tenants should be able to authenticate with your app.

    However, when you use SSO, Teams provides a token that your app can use to call Microsoft Graph and fetch the user's email address. This token is scoped to the user's profile information and email, and it can only be used to call Microsoft Graph. If you need to call other APIs or fetch other information, you'll need to implement a consent flow to get the necessary permissions from the user. In your case, you're trying to fetch the user's Teams ID, conversation ID, and tenant ID. These are not available through Microsoft Graph, so you'll need to fetch them from the context of your app. The Teams ID and tenant ID are available in the team object in the context, and the conversation ID is available in the channel object.

    const teamId = context.activity.channelData.team.id;
    const tenantId = context.activity.channelData.tenant.id;
    const conversationId = context.activity.conversation.id;
    

    Remember, these values are only available in team or channel context. If your app is installed in a personal scope, you won't be able to fetch the team ID or tenant ID.

    Thanks, 

    Prasad Das

    ************************************************************************* 

    If the response is helpful, please click "Accept Answer" and upvote it. You can share your feedback via Microsoft Teams Developer Feedback link.

    0 comments No comments

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.