Fetch UserContext details through channel


(nisa) #1

Hi,
As i am using MS teams as my channel,I have a message node that welcomes user -“Hi {{context.session.UserContext.emailId}}”
But in teams it does not print the user email id followed by “Hi” instead it only prints just “Hi”.Same behaviour even if I use a entity node and within the bot responses I provide the same text.


(Swagat) #2

MS Teams may not be sending emailId under UserContext and that is the reason it is unable to resolve it.

Can you please try this - For a message node, go to advanced settings and add a channel specific message in Java Script mode.

print(JSON.stringify(context)); //it will print a big JSON object

You may also try
print(JSON.stringify(context.session.UserContext));
Or
print(JSON.stringify(context.session.BotUserSession));

Ensure the bot is published.

You will know where the email Id etc. are coming from. It will be a big JSON but it will reveal much information. Hope this helps.


(rajat jain) #3

I have tried above but i m getting
either nothing in the msteams or [object Object]

Is there any other way to do it


(Swagat) #4

@rajatjain4
This is what we go tot know from MS Teams support. They do not send email id hence it is out of Kore.ai’s control.

unfortunately, there is no straight forward way to extract the Email ID value from the activity object due to security reasons.

In from.aadObjectId of the Activity object there’s the AAD Object ID of the sender; from that you can look up the email address using MS Graph provided your appId has at least User.ReadBasic permissions . The email address is not included for privacy reasons, by design.


(Vijay Thakkar) #5

If your channel is MS Teams, then I guess, you’re using OAuth 2.0 using Microsoft Identity framework.

If yes, then below applies

I have successfully integrated MS Teams and solved this particular tasks by calling Graph API through a Service Node in Dialog tasks.

Endpoint URL: https://graph.microsoft.com/v1.0/me/

No parameters needed to be passed

This API returns JSON object with many user details with column “userPrincipalName” with email ID.

That way you know who is the user logged on and using chatbot. You can store this information and other details like displayName and etc in {{context.session.UserContext.firstName}}”, {{context.session.UserContext.emailId}}”, etc.

Use this context info later in other dialog tasks without needing to call MS graph API.


(Vijay Cinn) #6

@vijay.thakkar I am trying to follow your post to check if I can do the same, I am stuck on creating an Auth Profile for oAuth2 that return “AzureOAuthStrategy requires a tenant id.” Please advise on your setup which may help me past this issue. Thanks in advance! koreai_oauth_issue2 koreai_oauth_issue1