如何通过操作将JSON对象传递给IBM Watson Assistant?

时间:2018-04-26 17:33:02

标签: json ibm-cloud chatbot watson-conversation watson-assistant

我有一个Watson Assistant实例,我想用它来为我的网站用户提供计算服务。我按照文档here进行操作,服务似乎正确地为每一位信息选择了插槽,我的客户端应用程序的方法测试也正确。我不知道为什么我无法访问我的方法发回给节点的响应。

这是我的客户端方法:



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};
}
&#13;
&#13;
&#13;

and here's my JSON editor in Watson.

我已经尝试在执行操作后立即跳转到子节点,以便在显示消息之前阻止用户输入,使用output.frais,并且没有任何效果。

访问返回对象的值并自动将其嵌入Watson响应的最佳方法是什么?

如果我有更简单的计算来做乘法,我如何在对话框节点中使用java.lang.Math类来做呢?我尝试了文档中的语法,但由于某种原因它还没有完成。

注意:我不想使用IBM Cloud Functions执行服务器操作,只需要客户端调用。

1 个答案:

答案 0 :(得分:1)

操作的结果将存储在npm install child-process-promise --save 变量context中。然后,可以通过编写frais$frais来访问对话框中的任何位置。

要在输出中显示该变量,只需在对话节点响应字段中写入:<? context.frais ?>