Topic scripting: how to get context information from the vaInputs variable

Am_d_e Potier
Giga Expert

We use the Virtual Agent using the Bot2Bot integration, leveraging the Virtual Agent API.  In this request, we send a number of parameters in the request body.

 

 

Inside a Virtual Agent Topic, how can we then get access to information of the invoking environment. 

 

For example, let's imagine we call the Virtual Agent API with a parameter "botTobot" in our JSON: 

"botToBot": True

 

How can I add a condition inside my Topic script to test this condition ? (I want to behave differently depending if I am called from "inside" (VA Widget) or "outside" (API) service now

 

From the doc, I ONLY see definitions of the "vaInputs" object, but its content is not documented except for variables.  Should I use this vaInputs object or another one? 

 
Looking forward to your great insights !

 

3 REPLIES 3

Adam Chapman
Tera Guru

@Am_d_e Potier wrote:

...How can I add a condition inside my Topic script to test this condition ? (I want to behave differently depending if I am called from "inside" (VA Widget) or "outside" (API) service now...

 


Are you looking to limit a topic to only inside or outside initiated conversations? Or are you conditionally showing topic nodes within a single topic based on this?

 

In either case, you should be able to create a new context variable and populate that context variable in the POST. Once that context variable has the value, you can use it as a condition for either the topic level condition or node level condition. 

Hi Adam, 

thank you for your input. 

I understand your point about building a new Context Variable inside the POST, but I do not understand how to check it inside a Topic workflow, in a script. Could you show me one example of how you get this variable inside the Workflow script ? 

 

For now, we found one good solution: we check the "sys_cs_channel" of the current conversation. 

Inside the workflow, we build a variable to check the source of the request.

 


@Adam Chapman wrote:

@Am_d_e Potier wrote:

...How can I add a condition inside my Topic script to test this condition ? (I want to behave differently depending if I am called from "inside" (VA Widget) or "outside" (API) service now...

 


Are you looking to limit a topic to only inside or outside initiated conversations? Or are you conditionally showing topic nodes within a single topic based on this?

 

In either case, you should be able to create a new context variable and populate that context variable in the POST. Once that context variable has the value, you can use it as a condition for either the topic level condition or node level condition. 


(function execute() {
         vaVars.isKbotRequest= false;
        var convId = vaSystem.getConversationId();
        var gr = new GlideRecord('sys_cs_conversation');
               gr.addQuery('sys_id' , convId);
               gr.query();
               if(!gr.next()){
                       gs.error("Can not find conversation: " + convId);
               }else{
                       gs.error("Got a Session of type: " + gr.device_type);
                       if (gr.device_type == 'kbot') {
                            vaVars.isKbotRequest = true;
                       } 
               }    
})()
 

The trick there is that conversation.device_type == sys_cs_channel.name

This seems a very reliable way to know what is the invoker channel inside a Topic. 

I wish all these relation were documented, that would certainly make our integration easiers

Dear @Adam Chapman ,

 

I am using Virtual Agent API to trigger a Topic in Virtual Designer. I am passing through the payload some variables like clientSessionID or contextVariables. (note that I am not using the create conversation action)

 

David129_1-1736530899520.png

 

In the the flow designer, I have created a Script variable (threadID) that I try to populate with the values sent on the payload.

 

I don't succeed in reading these values through a Script action node, I proabably don't refer to the right variable type. Could you please guide me here.

 

Can I use something like this ?

vaVars.threadID = vaContext.name
or
vaVars.threadID = vaContext.clientSessionId

 

@Am_d_e Potier, I think it is similar to what you tried to achieve initially. Have you maybe found a solution ?

 

Thanks in advance for your help.

 

David