1
votes

I am facing an issue while sending context variable from Node app to Watson Conversation.

I am trying to implement the following,

  1. The user enters their phone number.
  2. Data corresponding to that phone number is fetched and displayed in next node.

For eg:

When the user enters his phone number, the next node should greet the user with their name; which is obtained from the database.

Node 1: Enter your phone number?
Node 2: <user enters the phone number>
fetches the data corresponding to the phone number from the database and passes it to Watson as context variable
Node 3: Hey, $user_name. How are you?
Node 4: <waits for user input>

The issue I am facing is,

Node app only sends the context variable back only when it wants user input, so, until that point, the Watson Conversation doesn't get the new set of the context variable. So here it sends the new set of context variable only with Node 3, but what I want is, I want the Watson Conversation to have the new set of context variable once I enter my phone number.

That is after the user enters his phone_number in Node 2, the Node app immediately fetches the user_name corresponding to it and set the value as context variable from Node app and sends it back to Watson Conversation. So before Node 3 prints Watson Conversation have the new set of context variables. But what actually happens is, when user enters the phone number, I fetch a user_name corresponding to it on my Node App, but the context variable is NOT on Watson Conversation, so now when Watson responds, the value for $user_name is still undefined, so it returns as an empty string.

Can anyone help me out in solving this? Thanks in advance.

1
You can manipulate the context object in Watson Conversation / Watson Assistant to keep the variable. This can also be done in your App. Add your code to the questiondata_henrik

1 Answers

0
votes

Node app only sends the context variable back only when it wants user input, so, until that point, the Watson Conversation doesn't get the new set of the context variable.

This is intended behaviour. Watson Assistant is stateless. It has no knowledge of context variables or where you are in the conversation until you send the context object back to it.

So you have to send the value to it. If you are, then you need to post your sample JSON request / response to get a better understanding of what is going on.


Another approach is cloud functions. You can create a cloud function within Watson Assistant which does the lookup, passes it back within the conversation, and your node app gets the values in the context response object.

Cloud functions are time sensitive though. So if there is any delay possible, than do the code within your node app.