1
votes

i'm trying to send a user name to my WCS but i not sure how can i do that using a request. My consersation ask for the user email and use a js script to return a json from my sql server...

I'm doing something like that:

What's your email? // WCS
[email protected] //USER
Just a minute.<script>getUserInformation('[email protected]');</script> // WCS
nodeTrue //USER (I sent this after confirmated if the user exist and got the user name.)
Hi <span id='myText'></span><script>document.getElementById('myText').innerHTML = userName;</script>! //WCS

I know this is not the best way to do that but it is working. I'm trying to call my js functions using something like "output:{'action':}" (And handle it in my node.js like the 'car dashboard sample'), but, it's possible send a varible from my .js to a conversation context?

1

1 Answers

0
votes

I had the same problem a few months ago. In this case, I used functions for access the context variables on the client side (Using this example from Ashley and accessing the context), but, for security issues of some company data, I did need to use custom code in the server-side... And, for this case, you can use the method call for Watson Conversation, and access the context variables and creates values with custom code in your favor.

Something like this:

conversation.message(payload, function (err, data) {
    data.context.yourValue = returnFromYourDatabase;
    if (err) {
      return res.status(err.code || 500).json(err);
    }
    updateMessage(payload, data, req, res);

  });
}); 

You can see the function updateMessage, this call is one example from IBM Developers, and this function is used to update the message in every request. You can use this function to set too, because this function get the parameters from the call.

For example:

function updateMessage(input, response) {
  response.context.yourValue = returnFromYourDatabase;
  var responseText = null;
  if (!response.output) {
    response.output = {};
  } 
}

See API Reference for Watson Conversation Service using Node.js.

See the Project with Node.js by IBM Developers.