Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...