Hello everyone!
I have a question, is there any way to loop a flow that has an http node?
I'm trying to integrate a chatbot created in Watson Assistan into instagram. As I didn't find a specific node for sending messages by Direct, I decided to get the data through the http Get protocol.
[{"id":"4dda54daa8841532","type":"tab","label":"INSTAGRAM","disabled":false,"info":"","env":[]},{"id":"5546a833c1a5323e","type":"change","z":"4dda54daa8841532","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"req.query.mensage","tot":"msg"},{"t":"set","p":"resAux","pt":"flow","to":"res","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":100,"wires":[["b152bacba5dc37e1","4dcc76f29cff783e"]]},{"id":"b152bacba5dc37e1","type":"watson-assistant-v2","z":"4dda54daa8841532","name":"Albert (RADinfo-instagram)","service-endpoint":"https://api.us-south.assistant.watson.cloud.ibm.com/instances/f7d07c5e-8056-456e-99d5-ac64a4c0c2d9","assistant_id":"a28ada9a-8b42-4af5-9f57-73e99b4fb6e3","debug":true,"restart":false,"return_context":true,"alternate_intents":true,"multisession":false,"timeout":"","optout-learning":false,"persist-session-id":true,"x":160,"y":160,"wires":[["9bfd44296a217a6f","406f87d944b24edf"]]},{"id":"c1fb16f8efde2437","type":"change","z":"4dda54daa8841532","name":"","rules":[{"t":"set","p":"res","pt":"msg","to":"resAux","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":340,"wires":[["89622ac688d5d57a","da31ac5c4351818d"]]},{"id":"89622ac688d5d57a","type":"http response","z":"4dda54daa8841532","name":"","statusCode":"","headers":{},"x":230,"y":400,"wires":[]},{"id":"e8dff131ec26e51c","type":"change","z":"4dda54daa8841532","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.output.generic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":200,"y":280,"wires":[["c1fb16f8efde2437","c1ae4f4a3cb99006"]]},{"id":"9bfd44296a217a6f","type":"function","z":"4dda54daa8841532","name":"","func":"msg.payload = msg.payload.output.generic;\nvar msgMsg = msg.payload;\nvar req = msg.req;\nvar res = msg.res;\nvar size = msg.payload.length;\nnewMsg = [];\n\nfor (var index = 0; index < size; index++){\n var resType = msg.payload[index].response_type;\n \n if (resType == \"text\"){\n newMsg.push({\n payload:\n {\n content:msgMsg[index].text,\n response_type: resType,\n },\n req: req,\n res: res\n \n })\n }\n else {\n newMsg.push({\n payload:\n {\n\n content:msgMsg[index].title,\n response_type: resType,\n },\n req: req,\n res: res\n })\n }\n\n \n}\n\n\nreturn [newMsg];","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":220,"y":220,"wires":[["e8dff131ec26e51c","aeb05e536099c1a4"]]},{"id":"3d5e986c22dc8a33","type":"http in","z":"4dda54daa8841532","name":"get-radinfo-insta","url":"/instagram","method":"get","upload":false,"swaggerDoc":"","x":200,"y":40,"wires":[["5546a833c1a5323e","f07a8945b16137d3"]]},{"id":"da31ac5c4351818d","type":"debug","z":"4dda54daa8841532","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":340,"wires":[]},{"id":"c1ae4f4a3cb99006","type":"debug","z":"4dda54daa8841532","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":280,"wires":[]},{"id":"aeb05e536099c1a4","type":"debug","z":"4dda54daa8841532","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":220,"wires":[]},{"id":"406f87d944b24edf","type":"debug","z":"4dda54daa8841532","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":160,"wires":[]},{"id":"4dcc76f29cff783e","type":"debug","z":"4dda54daa8841532","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":100,"wires":[]},{"id":"f07a8945b16137d3","type":"debug","z":"4dda54daa8841532","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":40,"wires":[]}]
I'm calling JSON from node red in chaftuel, and on that platform there's no way to manipulate Objects or Arrays.
So, the way I thought was to make a loop to read each Array, but I bumped into this question, the request doesn't work and returns this error. "Error: Cannot set headers after they are sent to the client".
Is there anything that can be done?