如何在Watson对话响应中添加操作? [英] How do I add an action to watson conversation response?

查看:79
本文介绍了如何在Watson对话响应中添加操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了意图,实体和对话框,没有任何问题.但是现在我正在尝试做到这一点,以便当用户发送再见"时,应用程序将关闭.根据文档,我将不得不命名一个与意图一起执行的动作.我怎么做?是通过代码还是通过对话工作区平台?

I've created intent, entity and dialog without a problem. But right now I'm trying to make it so when the user send "goodbye", the application would close. According to the doc, I'll have to name an action that goes along with an intent. How do I do that? Is it through code or through the conversation workspace platform?

推荐答案

您可以为此使用context variablesaction variables. 如何使用上下文变量?在高级"响应中添加上下文"和值,请检查我的示例.

You can use context variables or action variables for that. How to use context variables? Add in your Advance response the "context" and the values, check my example.

为此,我使用了对话简单.

在您的Watson开发人员云-IBM Bluemix-Watson对话中,在高级响应中添加此JSON示例,假设您的应用程序将在此对话节点中执行以下操作:

In your Watson Developer Cloud - IBM Bluemix - Watson Conversation, add in the Advanced response this JSON example, Assuming it is in this conversation node that your application will do something:

{
  "context": {
    "verified": true;
  },
  "output": {
    "text": {
      "values": [
        "Please wait and I'll verified your request."
      ],
      "selection_policy": "sequential"
    }
  }
}

示例(app.js):

function updateMessage(input, data, req, res) {
  if (data.context.verified === true){
    searchRequest(data, req, res);
    } else if (data.output && data.output.text) {
    return res.json(data);
    }
    return data;
}

您可以使用数据在对话流中发送内容.

function searchRequest(data, req, res){
    // something to do and return value
    var sendRequest = "Thanks for wait, the request is" + valueRequest;
    data.output.text[0] = sendRequest;
    return data;
}

您可以添加一个JSON对象(例如"action"),您的代码将识别该变量,其示例与@Mikko所说的相同.您可以使用以下方法进行检查:

You can add one JSON object like "action", and your code will recognize this variable, with the same example that @Mikko said. And you can check this with:

data.output.action === 'close'

  • 详细了解上下文变量.
  • 详细了解构建对话框.
    • See more about Context variables.
    • See more about Building a dialog.
    • 这篇关于如何在Watson对话响应中添加操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆