Combine multiple payloads from Conversation Workspace Manager

#1

Hi!
Im experimenting a bit with Watson Conversation and Node-Red. What Im trying to do at the moment is to display a list from Intents, Entities and dialog nodes on a simple html site.

I can display the payloads separately, but I would like to join them into a single payload.
Now, If I use the Join Node. It displays correctly in the Debug node, but on HTML side it just say [object Object].
I also tried to combine the payloads with context.data function but this did not send send the payload to html side.
Another error I receive is "Error: Can't set headers after they are sent."
So it seems that even If i join the payloads, its triggering the header 3 times.

Any suggestion on what I should think of?
Thanks in advance

( send the conversation workspace with workspace ID, but this one will be deleted later :slight_smile: )

[{"id":"307e061c.1db29a","type":"function","z":"bc99043b.af8d78","name":"msg.payload = msg.intents","func":"msg.topic=\"intents\";\nmsg.payload = msg.intents\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":560,"wires":[["c829437f.c946b"]]},{"id":"ea91b5d3.9a57a8","type":"http in","z":"bc99043b.af8d78","name":"","url":"/intent_temp2","method":"get","upload":false,"swaggerDoc":"","x":90,"y":580,"wires":[["a03f9592.1aade8","ee338634.7c6d18","110b618b.46539e"]]},{"id":"1ee42d63.ff8873","type":"template","z":"bc99043b.af8d78","name":"HTML","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n  <head>\n    <title>My Site</title>\n</head>    \n    <div>intent: {{payload.intents}}</div>\n    </br>\n     <div>entities: {{payload.entities}}</div>\n     </br>\n     <div>dialog nodes: {{payload.dialog_nodes}}</div>\n     </br>\n</html>","x":910,"y":600,"wires":[["63acbc87.39cbb4"]]},{"id":"63acbc87.39cbb4","type":"http response","z":"bc99043b.af8d78","name":"","statusCode":"","headers":{},"x":1050,"y":600,"wires":[]},{"id":"8d979e7e.79f8d","type":"debug","z":"bc99043b.af8d78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":930,"y":540,"wires":[]},{"id":"bcc74919.a13df8","type":"function","z":"bc99043b.af8d78","name":"msg.payload = msg.entities","func":"msg.topic=\"entities\";\nmsg.payload = msg.entities\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":600,"wires":[["c829437f.c946b"]]},{"id":"5cb982ec.ae9ddc","type":"function","z":"bc99043b.af8d78","name":"msg.payload = msg.dialog_nodes","func":"msg.topic=\"dialog_nodes\";\nmsg.payload = msg.dialog_nodes\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":640,"wires":[["c829437f.c946b"]]},{"id":"c829437f.c946b","type":"join","z":"bc99043b.af8d78","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":730,"y":580,"wires":[["8d979e7e.79f8d","1ee42d63.ff8873"]]},{"id":"a03f9592.1aade8","type":"watson-conversation-v1-workspace-manager","z":"bc99043b.af8d78","name":"List Intents","cwm-custom-mode":"listIntents","cwm-workspace-id":"aee96b05-8e3f-4afa-b72a-0375932d0902","cwm-intent":"","cwm-example":"","cwm-entity":"","cwm-entity-value":"","cwm-dialog-node":"","cwm-export-content":true,"cwm-default-endpoint":true,"cwm-service-endpoint":"https://gateway.watsonplatform.net/assistant/api","x":270,"y":560,"wires":[["307e061c.1db29a"]]},{"id":"ee338634.7c6d18","type":"watson-conversation-v1-workspace-manager","z":"bc99043b.af8d78","name":"List Entities","cwm-custom-mode":"listEntities","cwm-workspace-id":"aee96b05-8e3f-4afa-b72a-0375932d0902","cwm-intent":"","cwm-example":"","cwm-entity":"","cwm-entity-value":"","cwm-dialog-node":"","cwm-export-content":true,"cwm-default-endpoint":true,"cwm-service-endpoint":"https://gateway.watsonplatform.net/assistant/api","x":270,"y":600,"wires":[["bcc74919.a13df8"]]},{"id":"110b618b.46539e","type":"watson-conversation-v1-workspace-manager","z":"bc99043b.af8d78","name":"List Dialog Nodes","cwm-custom-mode":"listDialogNodes","cwm-workspace-id":"aee96b05-8e3f-4afa-b72a-0375932d0902","cwm-intent":"","cwm-example":"","cwm-entity":"","cwm-entity-value":"","cwm-dialog-node":"","cwm-export-content":true,"cwm-default-endpoint":true,"cwm-service-endpoint":"https://gateway.watsonplatform.net/assistant/api","x":270,"y":640,"wires":[["5cb982ec.ae9ddc"]]},{"id":"2bf30914.649cf6","type":"function","z":"bc99043b.af8d78","name":"Join Context","func":"context.data = context.data || new Object();\n\nswitch (msg.topic) {\n    case \"task1\":\n       context.data.task1 = msg.intents;\n        msg = null;\n        break;\n    case \"task2\":\n        context.data.task2 = msg.entities;\n        msg = null;\n        break;\n    case \"task3\":\n        context.data.task3 = msg.dialog_nodes;\n        msg = null;\n        break;\n        \n    default:\n        msg = null;\n    \tbreak;\n\n}\n\nif(context.data.task1 != null && context.data.task2 != null && context.data.task3 != null) {\n\tmsg2 = new Object();\n    msg2 = context.data;\n    context.data=null;\n\treturn msg2;\n} else return msg;","outputs":1,"noerr":0,"x":750,"y":660,"wires":[[]]}]
0 Likes

#2

It’s probably worth reading up on javascript objects if you want to get the most out of Node-RED.
But you should be able to use the debug output to understand the structure of you merged message.

1 Like