简体   繁体   中英

Watson Assistant get message inside nested node

I want to get the response from Watson that is nested in the conversation

I can get the responses from the welcome nodes and when they don't understand the text input, because they are global

华生对话

this is my code

const AssistantV1 = require('ibm-watson/assistant/v1');
const { IamAuthenticator } = require ('ibm-watson/auth');
const { rejects } = require('assert');

const assistant = new AssistantV1({
    authenticator: new IamAuthenticator({ apikey: '<>' }),
    serviceUrl: 'https://gateway.watsonplatform.net/assistant/api/',
    version: '2020-04-01'
  });

let context = {} //I don't know what to put in context
assistant.message(
  {
    input: { text: '2' },//the answer "2" the nested node "Tramo Emision"
    workspaceId: '<>',
    context: context
  }, function (err, response) {
    if (err) {
      rejects(err)
    } else {
      context = response.context;
    }
  })
  .then(response => {
    console.log(JSON.stringify(response.result, null, 2));
  })
  .catch(err => {
    console.log(err);
  });

but this code only allows me to get global responses and not nested responses

I get as answer, this

No dialog node condition matched to true in the last dialog round - context.nodes_visited is empty. Falling back to the root node in the next round.

In your code you are resetting the context to an empty object on every cycle. This has the effect of resetting the conversation back to the beginning. The context is used to manage the conversation state. ie. where in the dialog flow your conversation is, and any variables that have been set. This allows the conversation to progress.

In the V1 API each turn on message returns the context object, which your application can peek into and modify, but it must return the full context object. So your application needs to somehow cache the context object, when it obtains it, and then return it back on the next call to message . Your app would need to initiate the cache at a file global level, outside any functions, so it would be initiated once only, and not on every conversation turn.

In the V2 API the context management is performed at a session level by the API on your behalf. To maintain context, you need to create a session and use that session id on each conversation turn. Optionally the context can be returned to your application, allowing your application to look / modify any context variables that have been set.

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