Getting User ID of the Teams Channel, Outside of the request processing by the Bot.

Andrei Verner 96 Reputation points
2021-11-19T13:27:34.947+00:00

Hello!

It is possible to get the User ID of the Teams channel by the AadObjectId or Email?

I need to notify the user when triggered some external event, by using a bot (send the proactive message) with nothing knowledge about Conversation between user and bot (Maybe it even not created).

I know that to create or continue conversation between user and bot - necessary ConversationID between bot and user (if it already created), or member ID (User ID of the teams channel) and recipient ID (BotID), something like this:

var channelData = new TeamsChannelData { Tenant = new TenantInfo("My org tenant ID") };
var member = new TeamsChannelAccount { Id = "User ID of the teams channel" };
var recipient = new TeamsChannelAccount { Id = "Bot application client ID" };

var conversationParameters = new ConversationParameters
{
    Members = new List<ChannelAccount> { member },
    Bot = recipient,
    ChannelData = channelData,
    IsGroup = false
};

await _botAdapter.CreateConversationAsync(
    null,
    ServiceUrl,
    _microsoftAppCredentials,
    conversationParameters,
    async (turnContext, cancellationToken) =>
    {
        await turnContext.SendActivityAsync("Some notification message").ConfigureAwait(false);
        await Task.CompletedTask;
    },
    default(CancellationToken));

And if BotID is something kind of constants and I can store it in the app settings, then UserId of Teams channel I need to define by the Email or AadObjetId.

So, it's possible?

Anyway - thank you.

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
742 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 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.
2,823 questions
{count} votes

Accepted answer
  1. Andrei Verner 96 Reputation points
    2021-11-24T17:28:33.527+00:00

    According to the answers, I realized that if it is possible, then by using MS Graph API.

    As a last resort, I will try to find a necessary user among members of some team, something like this:

    using (var connectorClient = new ConnectorClient(new Uri("https://smba.trafficmanager.net/emea/"), _microsoftAppCredentials))
    {
        var members = await connectorClient.Conversations.GetConversationMembersAsync("ID of team where installed bot and where may be a user");
        ...
    

    Еhough this option is not entirely suitable for me, because:

    • Bot should be installed into this team
    • User may be not a member of this team
    • User can leave this team

    So I can't say, that my issue was resolved, but, I guess, this thread may be closed.

    Thank you!

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ChetanSharmamsft 1,026 Reputation points Microsoft Vendor
    2021-12-02T07:35:48.893+00:00

    @Andrei Verner - To get User ID of the Teams Channel, You need to install the bot in this channel and can get the ID using turnContext.
    Looks like there is no direct way to get the User ID of the Teams channel by the AadObjectId or Email.

    Thanks,
    Chetan Sharma


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

    0 comments No comments