Search code examples
node.jsslackwatson-conversationwatsonbotkit

watson conversation - slack bot, textformatting


I am having trouble formatting the slackbot responses. The slactbot is connected with watson conversation through botkit (https://github.com/watson-developer-cloud/botkit-middleware). Thanks a lot

My ultimate goal is to format a JSONArray as a list in the response. But I couldn't find anything about it. I can't even output a newline with '\n' or '\\n'. On the Watson Dashboard, I would output something like this:

I notice that you shop for: $e_list.join('\n')


Solution

  • You need to set this "\n" inside your code to works. Like:

    response = "Lets see here...\n" + \
               "I've found these recipes: \n"
    

    So, inside the Watson, A subtle error that can occur here is to use single quotes instead of double. That also has the effect of rendering the newlines as \n, than, you'll need to set with " and add the \n inside your context variable, like:

    Here's a list I made just for you: <? $s_list.join('') ?>
    

    And inside your JSON Advance, see my example:

    {
      "context": {
        "s_list": [
          "onion",
          "\n",
          "olives"
        ]
      },
      "output": {
        "text": {
          "values": [
            "Here's a list I made just for you: <? $s_list.join('') ?>"
          ],
          "selection_policy": "sequential"
        }
      }
    }
    

    Obs.: The best idea is use code for did this and doesn't generate more work. Like this example from one IBM Developer using Watson conversation inside slack. Check here.

    Obs II.: I try added the \n inside each value from array and the output inside slack seems like: onion\nolives and does not recognize the \n, I'm not sure about the reason, but, probably another IBM Developer Specialist can explain more about that. But, maybe this is because is one array and not one String, check this slack question about that.

    Image inside slack:

    enter image description here