raj
raj

Reputation: 41

how to get user/sender email id in Microsoft bot-framework activity?

Is there any way to get sender/user email id in bot-framework request?

I'm able to get sender name in activity but any other way to get email id along with name and conversion id?

Upvotes: 0

Views: 1876

Answers (2)

user3855877
user3855877

Reputation: 99

Actually, I can see that Bot Framework makes it possible to get information from Teams channel quite easily. First, in your code add the following using statement:

using Microsoft.Bot.Builder.Teams;

Then use the following lines inside the code where you want to get sender's data:

var members = await TeamsInfo.GetMembersAsync(turnContext, cancellationToken);
var userData = "";
foreach (var teamMember in members)
{
    if (teamMember.Id != turnContext.Activity.Recipient.Id)
    {
        userData = $"AadObjectId: {teamMember.AadObjectId}, Email: {teamMember.Email}, GivenName: {teamMember.GivenName}, Name: {teamMember.Name}, Role: {teamMember.Role}, Surname: {teamMember.Surname}, TenantId: {teamMember.TenantId}, UserPrincipalName: {teamMember.UserPrincipalName}, UserRole: {teamMember.UserRole}";
    }
}

The members variable will contain 2 elements: one represents the bot, and the other one represents the sender (human user). This snippet build the userData string variable which contains values of all properties available in the teamMember object.

EDIT: if you can't access the turnContext object and instead you can access the stepContext object (they're present in Bot Framework's EchoBot and CoreBot, respectively), just replace turnContext in the code snippet I attached with stepContext.Context.

Upvotes: 0

Dana V
Dana V

Reputation: 1347

As @md-farid-uddin-kiron said, you can use Graph. There is a sample that pretty much has this already setup. Please check here (I linked to a specific line for an example).

The conversation ID can be retrieved by: stepContext.Context.Activity.Conversation.Id

Upvotes: 1

Related Questions