简体   繁体   中英

How to pass JSON object to IBM Watson Assistant through an action?

I have an instance of Watson Assistant that I want to use to provide calculation services for my site's users. I followed the doc here and the service seems to correctly pick up the slots for each bit of information and my client app's method tests properly as well. I'm not sure why I can't access the response sent back by my method to the node.

Here's my client method:

 function fraisCar(action){ if (action.puissance <= 3) { if(action.kilometres <= 5000){ var bareme = action.kilometres * 0.41; } if(action.kilometres > 5000 && action.kilometres <= 20000){ var bareme = (action.kilometres * 0.245) + 824 } if(action.kilometres > 20000){ var bareme = (action.kilometres * 0.286) } } if (action.puissance == 4) { if(action.kilometres <= 5000){ var bareme = action.kilometres * 0.493; } if(action.kilometres > 5000 && action.kilometres <= 20000){ var bareme = (action.kilometres * 0.277) + 1082 } if(action.kilometres > 20000){ var bareme = (action.kilometres * 0.332) } } if (action.puissance == 5) { if(action.kilometres <= 5000){ var bareme = action.kilometres * 0.543; } if(action.kilometres > 5000 && action.kilometres <= 20000){ var bareme = (action.kilometres * 0.305) + 1188 } if(action.kilometres > 20000){ var bareme = (action.kilometres * 0.364) } } if (action.puissance == 5) { if(action.kilometres <= 5000){ var bareme = action.kilometres * 0.543; } if(action.kilometres > 5000 && action.kilometres <= 20000){ var bareme = (action.kilometres * 0.305) + 1188 } if(action.kilometres > 20000){ var bareme = (action.kilometres * 0.364) } } if (action.puissance == 6) { if(action.kilometres <= 5000){ var bareme = action.kilometres * 0.568; } if(action.kilometres > 5000 && action.kilometres <= 20000){ var bareme = (action.kilometres * 0.32) + 1244 } if(action.kilometres > 20000){ var bareme = (action.kilometres * 0.382) } } if (action.puissance > 6) { if(action.kilometres <= 5000){ var bareme = action.kilometres * 0.595; } if(action.kilometres > 5000 && action.kilometres <= 20000){ var bareme = (action.kilometres * 0.337) + 1288 } if(action.kilometres > 20000){ var bareme = (action.kilometres * 0.401) } } var frais = bareme + action.fraisGarage + action.fraisPeage + action.fraisEmprunt; return {frais: frais}; } 

and here's my JSON editor in Watson.

I have tried jumping to a child node immediately after the action is carried out in order to prevent user input from being expected before showing the message, using output.frais and as well and nothing works.

What's the best way to access the value of the return object and automatically embed it in a Watson response?

And if I have simpler calculations to do like multiplication, how do I go about using the java.lang.Math class within the dialog nodes to do it? I tried the syntax in the docs and it's just not complete for some reason.

Note: I don't want to perform a server action with IBM Cloud Functions, just a client call.

The result of the action will be stored in a context variable frais . It can be then access anywhere from dialog by writing $frais or <? context.frais ?> <? context.frais ?> .

To display that variable in an output simply write in your dialog node response field: "This is the value of context.frais: $frais ." .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM