Reputation: 41
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
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