0
votes

I use https://github.com/watson-developer-cloud/botkit-middleware#implementing-app-actions as my reference. The context in my conversation does not update.

Here is my bot-facebook.js.

function checkBalance(context, callback) {
   var contextDelta = {
     user_name: 'Henrietta',
     fname: 'Pewdiepie'
  };
  callback(null, context);
}
var checkBalanceAsync = Promise.promisify(checkBalance);
var processWatsonResponse = function (bot, message) {
  if (message.watsonError) {
    console.log(message.watsonError);
    return bot.reply(message, "I'm sorry, but for technical reasons I can't respond to your message");
  }
  if (typeof message.watsonData.output !== 'undefined') {
    //send "Please wait" to users
    bot.reply(message, message.watsonData.output.text.join('\n'));  

    if (message.watsonData.output.action === 'check_balance') {
      var newMessage = clone(message);
      newMessage.text = 'check new name';  

      checkBalanceAsync(message.watsonData.context).then(function (contextDelta) {
        console.log("contextDelta: " + JSON.stringify(contextDelta));
        return watsonMiddleware.sendToWatsonAsync(bot, newMessage, contextDelta);
    }).catch(function (error) {
      newMessage.watsonError = error;
    }).then(function () {
      return processWatsonResponse(bot, newMessage);
    });
   }
  }
 };
controller.on('message_received', processWatsonResponse);  

The JSON editor of welcome node in my watson conversation.

{
  "context": {
    "fname": "",
    "user_name": ""
},
  "output": {
    "text": {
      "values": [
        "Good day :) My name is Doug and I am a chatbot."
      ],
      "selection_policy": "random"
    },
    "action": "check_balance"
  }
}  

I have tried multiple ways I could imagine.

Do I need to do something like fname: <?contextDelta.fname?> in the json editor?

1

1 Answers

0
votes

You aren't checking context in your dialog.

Context object in JSON editor is used to store captured data in context, so your node actually empties context variable. Probably you need to remove that context initialization from your dialog,

To see value of context variable, you have to use it in the output "Good day, $fname :) My name is Doug and I am a chatbot."