Context in a Watson's conversation is not working in the way It supposed to work

296
June 01, 2017, at 1:52 PM

If I set the context object in a Watson's conversation I expect that it remains the nodes it previously visited I mean:

After firing an greetings' Intent, if I type 'bye' (a goodbyes Intent). It should fire a goodbyes's Intent but it just works in the test tool.

Here is the code in my Nodejs app:

let context = {}
const conversation = new ConversationV1({
    username: 'myUsername',
    password: 'myPassword',
    url: 'https://gateway.watsonplatform.net/conversation/api',
    version_date: '2017-05-26'
})
conversation.message({ workspace_id: workspaceId}, function (err, response) {
    if (err) {
        console.log(err)
    } else {
        context = response.context
    }
})
sendMessage = (message = null) => new Promise((resolve, reject) => {
        conversation.message({
            input: {text: message},
            workspace_id: workspaceId,
            context: context
        }, function (err, response) {
            if (err) {
                reject(err)
            } else {
                resolve(response.output.text)
            }
        })
    }

Although the conversation_id is always the same. I am always getting the anythingelse's Intent response instead of goodbyes' Intent.

{ intents: [ { intent: 'greetings', confidence: 1 } ],
  entities: [],
  input: { text: 'hi' },
  output: 
   { text: [ 'It is nice to talk to you, again !' ],
     nodes_visited: [ 'greetings' ],
     log_messages: [] },
  context: 
   { conversation_id: '7cc96494-d108-4dc9-95c4-63c174f20b4c',
     system: 
      { dialog_stack: [Object],
        dialog_turn_counter: 2,
        dialog_request_counter: 2,
        _node_output_map: [Object] } } }
{ intents: [ { intent: 'goodbytes', confidence: 1 } ],
  entities: [],
  input: { text: 'bye' },
  output: 
   { text: [ 'I didn\'t understand. You can try rephrasing.' ],
     nodes_visited: [ 'Anything else' ],
     log_messages: [] },
  context: 
   { conversation_id: '7cc96494-d108-4dc9-95c4-63c174f20b4c',
     system: 
      { dialog_stack: [Object],
        dialog_turn_counter: 2,
        dialog_request_counter: 2,
        _node_output_map: [Object],
        branch_exited: true,
        branch_exited_reason: 'completed' } } }
Answer 1

Dialog is stateless itself and you have to maintain this using the context var.

detailed solution here:

https://developer.ibm.com/answers/questions/287623/how-do-you-maintain-the-conversation-context-when/

let me know if this solved your problem.

Answer 2

I just discover that the important part of the context object to keep the 'context' of the conversation and work with nested intents is keep passing the new context object that you have in every http response.

let context = {}
sendMessage = (message = null) => new Promise((resolve, reject) => {
        conversation.message({
            input: {text: message},
            workspace_id: workspaceId,
            context: context
        }, function (err, response) {
            if (err) {
                reject(err)
            } else {
                context = response.context
                resolve(response.output.text)
            }
        })
    }

that means you have to update the context object in every http request:

context = response.context

as you can see in every http response you are updating the _node_output_map:

{ conversation_id: '1bb7b7e3-2bc2-4686-8f5e-8e25cdff7ff8',
  system: 
   { dialog_stack: [ [Object] ],
     dialog_turn_counter: 1,
     dialog_request_counter: 1,
     _node_output_map: { Welcome: [Object] },
     branch_exited: true,
     branch_exited_reason: 'completed' } }
{ conversation_id: '1bb7b7e3-2bc2-4686-8f5e-8e25cdff7ff8',
  system: 
   { dialog_stack: [ [Object] ],
     dialog_turn_counter: 2,
     dialog_request_counter: 2,
     _node_output_map: { Welcome: [Object], greetings: [Object] } } }
Rent Charter Buses Company
READ ALSO
Autobahn identify subscription

Autobahn identify subscription

When creating a websockets connection how can I determine the name of the subscription in the event function

373
discord.js sqlite bind or column index out of range

discord.js sqlite bind or column index out of range

So I am creating a bot for discord this code right here sends a PM to the person who joins the server:

622
What type of operations should be performed in the backend?

What type of operations should be performed in the backend?

So I understand the difference between backend and frontend, but what type of operations should I just leave for the backendFor example, if I'm using Node

201
Pushing object into globally declared array in Node.js

Pushing object into globally declared array in Node.js

I never used global variables in Nodejs so I have trouble understanding why this wont work

365