javascript - How do I add an action to watson conversation response? - Stack Overflow

I've created intent, entity and dialog without a problem. But right now I'm trying to make it

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?

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?

Share Improve this question edited Apr 3, 2019 at 17:07 Sayuri Mizuguchi 5,3303 gold badges29 silver badges57 bronze badges asked Mar 10, 2017 at 18:10 Chris WangChris Wang 3274 silver badges16 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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.

I've used the conversation simple for that.

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"
    }
  }
}

Example (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;
}

You can use the data for sending something within conversation flow.

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;
}

EDIT:

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.

You need to be careful with context variables as your next dialog node may or may not update them. Another option is to add a custom variable in the output. This is the solution used in conversation-discovery samples available in the GitHub.

  "output": {
    "text": {
      "values": [
        "Goodbye..."
      ],
      "selection_policy": "sequential"
    },
    "action": "close"
  }

Please note that this will cause a warning when closing the JSON editor.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742349546a4427234.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信