Configure message with User Context

I have created a bot with Anonymous as a target audience.
and the requirement is to use the botOptions.userIdentity = 'damaresh.n@gmail.com'; in the message node like “your email id is {{context.session.UserContext.emailId}}” .

Assertion is set as
var jsonData = {
“clientId”: options.clientId,
“clientSecret”: options.clientSecret,
“identity”: options.userIdentity,
“aud”: “”,
“isAnonymous”: false
};

As a Developer when I change the response and chat in the test window it’s working as expected

we do not want to create a bot with the target audience as Enterprise users because we don’t want to manage the access.
as this bot is used in the webchat channel which sits on the salesforce site of our ORG.

@damaresh.n
Did you want to ask a question or shared what you have done? If it was a question, could you please specify it?
How you pass on user identity is unique to your use case. It can be an alphanumeric string also (not just email). It just has to be. unique for each user. If you want to maintain history, you will need to maintain the logic of providing user identity uniquely.

@swagata.sengupta question is how to send unique identity in anonymous bot?

Currently i am passing unique user id in botoptions.useridentity

@damaresh.n
Be it anonymous or not, user identity has to be passed the same way.

botoptions.useridentity
In the same, you pass any unique identifier like time-stamp/ some unique string. If you send some value which was previously sent, platform will assume it is the old user trying to communicate and may show chat history etc.

Can you please give me an example on how to use this botoptions.useridentity in the response similar to “This is your email {{context.session.UserContext.emailId}}” and how to send the same identity to botkit on any event?

Let me suggest you to do this…
Please check the context object to see where your sent value is present. This way you will know a lot of information about what is being passed on to the bot and how bot is capturing and dealing with information.

On a message node, only have this.

print(JSON.stringify(context.session));

Copy the output and use a JSON parser to check the content.

After following your instructions,

image

This was the only useful part that I found from the complete JSON, this has the value which i passed in useridentity but it’s in an array.

how to access this data?
Ex: context.session.UserContext.identities[0].val

Looks right. Please try.

The Response Contains Hi! cs-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/damaresh.n@xyz.com

along with email id it contains client id aswell.

The use case is to have a bot without maintaining User Details in User Management section of admin console as client is not ready to maintain similar details which they have been maintains in Active directory.

@damaresh.n
Based on whatever data is passed on to the bot, you can get it from context (the way you did). You can further slice it and use the relevant part. When you integrate
Check out the post on custom data. It may help you.


Or else you may consider hitting a service with some unique identifier to get the email user name and display it.