Search code examples
node.jsibm-watsonwatsonwatson-conversation

Multiple output text value setting in watson conversation


I have following node in the conversation. I want to raise the action and based on that need to call the API. In success scenario, will show the output.text[0] and error scenario getting from output.text[1]

{
   "output": {
     "text": {
       "values": [
         "I want to get this with success scenario",
         "I want to get this with error scenario"
       ],
       "selection_policy": "sequential"
     },
     "action": "MyAction"
   }
 }

But when I am accessing this conversation node in node.js, it will always give 1st value, i.e. 'I want to get this with success scenario' It will never give output like 'I want to get this with error scenario' .

How to resolve this issue ?


Solution

  • This is really complicated to answer because depends your Business role inside your Chatbot.

    But, if you wanna answer one message according to the Condition...

    You can see in your output the selection_policy is sequential, in the other words, first will show the 1st phrase, and just if the condition access again by the user, will show the second message.

    "The order in which values in the array are returned depends on the attribute selection_policy."

    The better form to solve this is to create two conditions inside the Node flow for each phrase.

    For example first condition flow:

    if bot recognizes successScenario response "I want to get this with success scenario"
    

    In another second condition flow:

    if bot recognizes errorScenario response "I want to get this with error scenario"
    

    And your app with Nodejs will get the value according the condition.

    See the official documentation about this here, search about selection_policy.