Standard Responses - Can I use context variables in standard response?


(Neha Sheikh) #1

Can I use context variables in standard response?


(Subrahmanyam Donepudi) #2

@nehamsheikh Yes, you can use context variables in the standard responses. Please follow the below syntax:
UserContext.get("<key>")


(Neha Sheikh) #3

Hi @Subrahmanyam ,

We have tried the configuration of the standard response with the ‘UserContext’ and it worked fine.

We want to configure the standard response to show custom context value to the user.
e.g.: if a value is set in’ UserContext’ or ‘context’ then how can we configure the custom value in standard response. For now it showing the custom value set as undefined.

Regards,
Neha Sheikh


(Subrahmanyam Donepudi) #4

@nehamsheikh, If the channel you use for the bot is web/mobile client, then you can set the customData from the SDK itself by passing it in the botinfo and the same will be available in the BotUserSession data of context. The syntax to retrieve the data at standard response is same as mentioned previously. Please refer to the below posts for more details.

Alternatively, you could even configure the events like Onconnect or Welcome Event available under Apps and Agents to invoke a dialog or run a script at connection of web socket or on first message from the user and then store the needed information into BotUserSession , for instance. This way, the data is available for use and can be accessed from standard responses as well.


(Neha Sheikh) #5

For standard response for Hi -
In advanced mode, tried accessing bot session values as:

print(BotUserSession.get(“standardResponseForHi”) + " " + UserSession.get(“standardResponseForHi”) );

This doesn’t seem to work.
Can you please let me know how will it work?

Thanks,
Neha Sheikh


(Subrahmanyam Donepudi) #6

Hi @nehamsheikh ,
Did you apply the message at all channels or apply a channel specific override? For channel override, we will need to use the template as supported by the channel.

I have configured the below sample code for all channels at the standard response “Hi” and the message rendered for me.

  BotUserSession.put("standardResponseForHi","standardResponseForHi from BUS");
UserSession.put("standardResponseForHi","standardResponseForHi from US");
print(BotUserSession.get("standardResponseForHi") + " " + UserSession.get("standardResponseForHi") );  

image

image


(Neha Sheikh) #7

Hi,

Thanks for the reply. It is working now for all channels.
I had configured for Web channel so it wasn’t working before.

What is the best place to initialize what needs to be shown in greetings/welcome message?
We have user details in custom data and few of the information comes from service node call. Not sure about the place where I should put setting this data in Usersession.

Thanks in advance. :slight_smile:


(Neha Sheikh) #8

I am using bot builder 6.2.3 right now.
I cannot use on connect and welcome event as of now as it is not part of bot builder 6.2.3.

Anything else you could suggest of?


(Subrahmanyam Donepudi) #9

@nehamsheikh If you were to show custom messages at standard responses based on the information present in context/ session data, the best place to store the needed info is under the BotUserSession. This context type holds the information of customData as passed from the webSDK and developer could add more data onto it by writing script at onconnect event.


(Subrahmanyam Donepudi) #10

Hi @nehamsheikh, if the onconnect and welcome events are not available as part of the current version of bot builder and if you are using webSDK as the channel, configure the message to be sent to bot at the event “onOpenWSConnection” which serves as the message sent to bot when the WS connection is opened. You could configure this change at kore-bot-sdk-client.js file in the webSDK.

Please refer to the below topic for more details: