-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodered.json
1 lines (1 loc) · 2.33 KB
/
nodered.json
1
[{"id":"7e7dc5a9.7ea4bc","type":"comment","z":"b0b355b3.ca4338","name":"Watson Assistant + Chatfuel","info":"","x":140,"y":40,"wires":[]},{"id":"322d41fc.727b1e","type":"http in","z":"b0b355b3.ca4338","name":"GET /chatfuel","url":"/chatfuel","method":"get","upload":false,"swaggerDoc":"","x":90,"y":80,"wires":[["220c92dd.9654be"]]},{"id":"220c92dd.9654be","type":"change","z":"b0b355b3.ca4338","name":"Mensagem no Payload","rules":[{"t":"set","p":"params.session_id","pt":"msg","to":"req.query.user","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"req.query.text","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":80,"wires":[["494fbc74.1c1794"]]},{"id":"c2e1ebc1.093308","type":"http response","z":"b0b355b3.ca4338","name":"Retorno HTTP","statusCode":"","headers":{},"x":1020,"y":80,"wires":[]},{"id":"368b5fea.8ce2b","type":"function","z":"b0b355b3.ca4338","name":"Parse JSON do Watson Assistant","func":"if (msg.payload) {\n let output = msg.payload.output.generic;\n msg.payload = { messages: [] };\n for (var i = 0; i < output.length; i++) {\n if (output[i].response_type === \"text\") {\n msg.payload.messages.push({ text: output[i].text }); \n } else if (output[i].response_type === \"image\") {\n msg.payload.messages.push({ attachment: { type: \"image\", payload: { url: output[i].source }}})\n } else if (output[i].response_type === \"option\") {\n var buttons = [];\n for (var b = 0; b < output[i].options.length; b++) {\n buttons.push({ type: \"show_block\", block_names: [\"Options\"], title: output[i].options[b].label });\n }\n msg.payload.messages.push({ attachment: { type: \"template\", payload: { template_type: \"button\", text: output[i].title, buttons: buttons }}});\n } else {\n msg.payload.messages.push({ text: \"Erro no retorno da API\" })\n }\n }\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":760,"y":80,"wires":[["c2e1ebc1.093308"]]},{"id":"494fbc74.1c1794","type":"watson-assistant-v2","z":"b0b355b3.ca4338","name":"Watson","service-endpoint":"","assistant_id":"","debug":false,"restart":false,"return_context":true,"alternate_intents":false,"multisession":true,"timeout":"","optout-learning":false,"persist-session-id":false,"x":520,"y":80,"wires":[["368b5fea.8ce2b"]]}]