Skip to content

Instantly share code, notes, and snippets.

@cheadrian
Last active March 27, 2023 18:24
Show Gist options
  • Save cheadrian/bc01eecfb80bf5dc702b3f41668553a0 to your computer and use it in GitHub Desktop.
Save cheadrian/bc01eecfb80bf5dc702b3f41668553a0 to your computer and use it in GitHub Desktop.
Node-RED chatbots using RedBot, WhatsApp Link, ChatGPT, Dall-e 2, Email

These are the flows witch you can import into your Node-RED.

Contains OpenAI API examples for ChatGPT and Dall-e 2 combined with chat platforms, like Messenger, Whatsapp Business, Whatsapp Personal and Telegram.

There's also an example with email conversation.

You can find the list of articles which you can use with these files on Medium, here.

[
{
"id": "e6da46131ceed4fb",
"type": "tab",
"label": "OpenAI API",
"disabled": false,
"info": "",
"env": []
},
{
"id": "bf51565be34158ba",
"type": "http request",
"z": "e6da46131ceed4fb",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.openai.com/v1/chat/completions",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "bearer",
"senderr": false,
"headers": [],
"x": 430,
"y": 240,
"wires": [
[
"7627281c058b8a40"
]
]
},
{
"id": "7efe3e431a7e6d00",
"type": "template",
"z": "e6da46131ceed4fb",
"name": "Message",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Hello bot!",
"output": "str",
"x": 200,
"y": 120,
"wires": [
[
"a86e4dd004486738"
]
]
},
{
"id": "c31cc49404b315e8",
"type": "inject",
"z": "e6da46131ceed4fb",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
},
{
"p": "chatID",
"v": "123456789",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 160,
"y": 80,
"wires": [
[
"7efe3e431a7e6d00"
]
]
},
{
"id": "0a2a8c300fbe892c",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "chatgpt_in",
"links": [],
"x": 55,
"y": 160,
"wires": [
[
"a86e4dd004486738"
]
]
},
{
"id": "ee232ed4b483a468",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "chatgpt_out",
"mode": "return",
"links": [],
"x": 715,
"y": 260,
"wires": []
},
{
"id": "7627281c058b8a40",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.choices[0].message.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 470,
"y": 280,
"wires": [
[
"d821f5e73ad30717"
]
]
},
{
"id": "a86e4dd004486738",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "Change model config",
"rules": [
{
"t": "set",
"p": "gpt_config.model",
"pt": "msg",
"to": "gpt-3.5-turbo",
"tot": "str"
},
{
"t": "set",
"p": "gpt_config.system",
"pt": "msg",
"to": "You reply to the emails as a customer support employee for IT support. Maximum 50 words.",
"tot": "str"
},
{
"t": "set",
"p": "gpt_config.temperature",
"pt": "msg",
"to": "1",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.top_p",
"pt": "msg",
"to": "1",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.presence_penalty",
"pt": "msg",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.frequency_penalty",
"pt": "msg",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.max_tokens",
"pt": "msg",
"to": "2048",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 260,
"y": 160,
"wires": [
[
"4d9239f766dd1ee5"
]
]
},
{
"id": "9b5be63de486af3c",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "[Link]Chat API Reference ",
"info": "https://platform.openai.com/docs/api-reference/chat/create\n\nhttps://platform.openai.com/docs/guides/chat/introduction",
"x": 590,
"y": 160,
"wires": []
},
{
"id": "15c9b2befc9785da",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Save conversation history",
"info": "This will save the conversation\nhistory, input and response,\nfor the last 6 messages for\neach platform to a file.\nYou can use a database, like Postgress or\nNoSQL variants. ",
"x": 590,
"y": 580,
"wires": []
},
{
"id": "ee86db05dc050f8e",
"type": "function",
"z": "e6da46131ceed4fb",
"name": "Config chat model",
"func": "/* \n * E.g. input for history\n * msg.gpt_history = [{ \"role\": \"assistant\", \"content\": \"The Los Angeles Dodgers won the World Series in 2020.\" },\n * { \"role\": \"user\", \"content\": \"Where was it played?\" } ]\n */\n\nmsg.gpt_messages = [ { \"role\": \"system\", \"content\": msg.gpt_config.system } ];\n\nif (msg.gpt_history){\n msg.gpt_messages = msg.gpt_messages.concat(msg.gpt_history);\n}\n\nmsg.gpt_messages = msg.gpt_messages.concat({ \"role\": \"user\", \"content\": msg.payload });\n\nmsg.payload =\n{\n \"model\": msg.gpt_config.model,\n \"messages\": msg.gpt_messages,\n \"temperature\": msg.gpt_config.temperature,\n \"top_p\": msg.gpt_config.top_p,\n \"presence_penalty\": msg.gpt_config.presence_penalty,\n \"frequency_penalty\": msg.gpt_config.frequency_penalty,\n \"max_tokens\": msg.gpt_config.max_tokens\n}\n\ndelete (msg.gpt_config);\ndelete (msg.gpt_history);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 200,
"wires": [
[
"bf51565be34158ba"
]
]
},
{
"id": "eb00035c36ac739f",
"type": "switch",
"z": "e6da46131ceed4fb",
"name": "Check if RedBot or WhatsApp personal",
"property": "originalMessage",
"propertyType": "msg",
"rules": [
{
"t": "hask",
"v": "chatId",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 260,
"y": 520,
"wires": [
[
"e7f70d3b76fd56f9"
],
[
"4fa4c728be999a0f"
]
]
},
{
"id": "e7f70d3b76fd56f9",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "saveID",
"pt": "msg",
"to": "originalMessage.chatId",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 500,
"wires": [
[
"1fb6c955238349a9"
]
]
},
{
"id": "4fa4c728be999a0f",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "saveID",
"pt": "msg",
"to": "chatID",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 540,
"wires": [
[
"1fb6c955238349a9"
]
]
},
{
"id": "1fb6c955238349a9",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "filename",
"pt": "msg",
"to": "\"/data/chat_save/\" & saveID & \".json\"",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 750,
"y": 480,
"wires": [
[
"5c1c0ced602a4506"
]
]
},
{
"id": "d821f5e73ad30717",
"type": "switch",
"z": "e6da46131ceed4fb",
"name": "Status code 200",
"property": "statusCode",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "200",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 500,
"y": 320,
"wires": [
[
"ee232ed4b483a468",
"ea69b2ae2fb4ecc0"
],
[
"f05579cea6eddee7"
]
]
},
{
"id": "f05579cea6eddee7",
"type": "debug",
"z": "e6da46131ceed4fb",
"name": "API Error",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 760,
"y": 340,
"wires": []
},
{
"id": "dd3306028f512ae0",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "gpt_history_in",
"links": [
"4d9239f766dd1ee5"
],
"x": 55,
"y": 440,
"wires": [
[
"57cbe5d7e145265a"
]
]
},
{
"id": "05ea0c20ec7661be",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Check if history exist",
"info": "Verify if a file with the specific saveID exist.",
"x": 570,
"y": 380,
"wires": []
},
{
"id": "5c1c0ced602a4506",
"type": "file in",
"z": "e6da46131ceed4fb",
"name": "Get conversation",
"filename": "filename",
"filenameType": "msg",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 770,
"y": 520,
"wires": [
[
"f9fbd684daf9ee90"
]
]
},
{
"id": "f9fbd684daf9ee90",
"type": "json",
"z": "e6da46131ceed4fb",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 830,
"y": 560,
"wires": [
[
"37211b0a377a4b0e"
]
]
},
{
"id": "08d23a700481c2d0",
"type": "function",
"z": "e6da46131ceed4fb",
"name": "Save current and last N",
"func": "/* \n * Save the current response and delete older than N limit\n */\n//Remove first array element, \"role\":\"system\"\nmsg.gpt_messages.shift();\nvar gpt_response = [{ \"role\": \"assistant\", \"content\": msg.payload }]; \nvar current_conversation = msg.gpt_messages.concat(gpt_response);\n//Get the last N from history\ncurrent_conversation = current_conversation.slice(-(msg.maximum_histroy * 2));\nmsg.payload = current_conversation;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 660,
"wires": [
[
"10b56afb812da49f"
]
]
},
{
"id": "57cbe5d7e145265a",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "gpt_asked",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 440,
"wires": [
[
"962dd3ca8a41dbfc"
]
]
},
{
"id": "10b56afb812da49f",
"type": "file",
"z": "e6da46131ceed4fb",
"name": "Save conversation",
"filename": "filename",
"filenameType": "msg",
"appendNewline": false,
"createDir": true,
"overwriteFile": "true",
"encoding": "none",
"x": 710,
"y": 660,
"wires": [
[]
]
},
{
"id": "8048cf0539ac4f55",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "gpt_history_out",
"mode": "link",
"links": [
"81c7c2f4545507e7"
],
"x": 1105,
"y": 600,
"wires": []
},
{
"id": "4d9239f766dd1ee5",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "chatgpt_out",
"mode": "link",
"links": [
"dd3306028f512ae0"
],
"x": 405,
"y": 160,
"wires": []
},
{
"id": "81c7c2f4545507e7",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "link in 1",
"links": [
"8048cf0539ac4f55"
],
"x": 235,
"y": 200,
"wires": [
[
"ee86db05dc050f8e"
]
]
},
{
"id": "37211b0a377a4b0e",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "gpt_history",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "gpt_asked",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 600,
"wires": [
[
"8048cf0539ac4f55"
]
]
},
{
"id": "00b3fd403c2f6aac",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Call the ChatGPT API",
"info": "",
"x": 580,
"y": 40,
"wires": []
},
{
"id": "e0e0c2930abdfb07",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "gpt_history_save_in",
"links": [
"ea69b2ae2fb4ecc0"
],
"x": 55,
"y": 660,
"wires": [
[
"f3b2ddeeb67dcdc6"
]
]
},
{
"id": "ea69b2ae2fb4ecc0",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "chatgpt_out",
"mode": "link",
"links": [
"e0e0c2930abdfb07"
],
"x": 715,
"y": 300,
"wires": []
},
{
"id": "fa2a85103c4924fb",
"type": "catch",
"z": "e6da46131ceed4fb",
"name": "If file not found",
"scope": [
"5c1c0ced602a4506"
],
"uncaught": false,
"x": 980,
"y": 520,
"wires": [
[
"8048cf0539ac4f55"
]
]
},
{
"id": "f3b2ddeeb67dcdc6",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "maximum_histroy",
"pt": "msg",
"to": "6",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 210,
"y": 660,
"wires": [
[
"08d23a700481c2d0"
]
]
},
{
"id": "88698f105ae398f1",
"type": "http request",
"z": "e6da46131ceed4fb",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.openai.com/v1/images/generations",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "bearer",
"senderr": false,
"headers": [],
"x": 290,
"y": 900,
"wires": [
[
"4fd1ba17724cc32f"
]
]
},
{
"id": "24112cb41f1f983f",
"type": "template",
"z": "e6da46131ceed4fb",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "json",
"syntax": "mustache",
"template": "{\n \"prompt\": \"{{payload.img_prompt}}\",\n \"n\": 1,\n \"size\": \"{{payload.resolution}}\"\n}",
"output": "json",
"x": 260,
"y": 860,
"wires": [
[
"88698f105ae398f1"
]
]
},
{
"id": "da0254b711276bdc",
"type": "image",
"z": "e6da46131ceed4fb",
"name": "",
"width": 160,
"data": "payload",
"dataType": "msg",
"thumbnail": false,
"active": true,
"pass": false,
"outputs": 0,
"x": 360,
"y": 980,
"wires": []
},
{
"id": "2cfdfff15961b9d6",
"type": "inject",
"z": "e6da46131ceed4fb",
"name": "",
"props": [
{
"p": "payload.img_prompt",
"v": "A cute cat.",
"vt": "str"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 150,
"y": 780,
"wires": [
[
"1e8787cff0ccfe81"
]
]
},
{
"id": "4fd1ba17724cc32f",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.data[0].url",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 940,
"wires": [
[
"da0254b711276bdc",
"5268a38e5582c90e"
]
]
},
{
"id": "982664b0a0fd715a",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Bonus: create image with \"dall-e-2\" and send it",
"info": "",
"x": 650,
"y": 720,
"wires": []
},
{
"id": "cc9b2b14ee514bbe",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "openai_dalle_in",
"links": [],
"x": 55,
"y": 820,
"wires": [
[
"1e8787cff0ccfe81"
]
]
},
{
"id": "1e8787cff0ccfe81",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "Set resolution",
"rules": [
{
"t": "set",
"p": "payload.resolution",
"pt": "msg",
"to": "256x256",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 220,
"y": 820,
"wires": [
[
"24112cb41f1f983f"
]
]
},
{
"id": "5268a38e5582c90e",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "openai_dalle_out",
"mode": "return",
"links": [],
"x": 495,
"y": 940,
"wires": []
},
{
"id": "962dd3ca8a41dbfc",
"type": "switch",
"z": "e6da46131ceed4fb",
"name": "Check if is email",
"property": "from",
"propertyType": "msg",
"rules": [
{
"t": "nnull"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 320,
"y": 480,
"wires": [
[
"893f58f851b0fb7d"
],
[
"eb00035c36ac739f"
]
]
},
{
"id": "893f58f851b0fb7d",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "saveID",
"pt": "msg",
"to": "from",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 460,
"wires": [
[
"1fb6c955238349a9"
]
]
},
{
"id": "bdc1531b0db774c0",
"type": "tab",
"label": "ChatGPT - Email response",
"disabled": false,
"info": "",
"env": []
},
{
"id": "1fbbc2fd3c5aef46",
"type": "e-mail in",
"z": "bdc1531b0db774c0",
"name": "Email in",
"protocol": "IMAP",
"server": "outlook.office365.com",
"useSSL": true,
"autotls": "always",
"port": "993",
"box": "INBOX",
"disposition": "Read",
"criteria": "UNSEEN",
"repeat": "10",
"fetch": "auto",
"inputs": 0,
"x": 170,
"y": 320,
"wires": [
[
"0845f55f72a53031"
]
]
},
{
"id": "4e2b1d95b0730506",
"type": "e-mail",
"z": "bdc1531b0db774c0",
"server": "smtp-mail.outlook.com",
"port": "587",
"secure": false,
"tls": true,
"name": "",
"dname": "Email output",
"x": 610,
"y": 160,
"wires": []
},
{
"id": "77aef4c29312a425",
"type": "inject",
"z": "bdc1531b0db774c0",
"name": "Inject email body & subject",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "This is a test Email from Node-RED",
"payload": "Test email from Node-RED ChatGPT.",
"payloadType": "str",
"x": 210,
"y": 160,
"wires": [
[
"4e2b1d95b0730506"
]
]
},
{
"id": "46bb8f78aa171d14",
"type": "inject",
"z": "bdc1531b0db774c0",
"name": "Inject to HTML",
"props": [
{
"p": "payload.generated_text",
"v": "Test email from Node-RED ChatGPT.",
"vt": "str"
},
{
"p": "payload.img_url",
"v": "https://picsum.photos/seed/picsum/256/256",
"vt": "str"
},
{
"p": "payload.img_prompt",
"v": "a cute cat with green eyes",
"vt": "str"
},
{
"p": "topic",
"vt": "str"
},
{
"p": "to",
"v": "[email protected]",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "This is a test Email from Node-RED",
"x": 180,
"y": 200,
"wires": [
[
"22e035cb5a9832f5"
]
]
},
{
"id": "504a92166128ce1b",
"type": "link call",
"z": "bdc1531b0db774c0",
"name": "",
"links": [
"0a2a8c300fbe892c"
],
"linkType": "static",
"timeout": "60",
"x": 450,
"y": 440,
"wires": [
[
"18782e8eec2d74fa"
]
]
},
{
"id": "d789180f7c2c5fd1",
"type": "template",
"z": "bdc1531b0db774c0",
"name": "Ask GPT to respond",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Respond to email with subject {{topic}} this content:\n{{payload}}",
"output": "str",
"x": 400,
"y": 400,
"wires": [
[
"504a92166128ce1b"
]
]
},
{
"id": "f6b820180918c26a",
"type": "template",
"z": "bdc1531b0db774c0",
"name": "Ask GPT to create prompt for Dall-e 2",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Generate 10 one word tags, comma delimited, for this subject: {{topic}}",
"output": "str",
"x": 410,
"y": 520,
"wires": [
[
"087560c898efb069"
]
]
},
{
"id": "087560c898efb069",
"type": "link call",
"z": "bdc1531b0db774c0",
"name": "",
"links": [
"0a2a8c300fbe892c"
],
"linkType": "static",
"timeout": "60",
"x": 510,
"y": 560,
"wires": [
[
"d8cc4079d1b2a9f8"
]
]
},
{
"id": "48de465c1bc11465",
"type": "link call",
"z": "bdc1531b0db774c0",
"name": "",
"links": [
"cc9b2b14ee514bbe"
],
"linkType": "static",
"timeout": "30",
"x": 540,
"y": 640,
"wires": [
[
"05bcb447bf58143a",
"fe665ab327d104d3"
]
]
},
{
"id": "d8cc4079d1b2a9f8",
"type": "change",
"z": "bdc1531b0db774c0",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "payload.img_prompt",
"tot": "msg"
},
{
"t": "set",
"p": "img_prompt",
"pt": "msg",
"to": "payload.img_prompt",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 520,
"y": 600,
"wires": [
[
"48de465c1bc11465"
]
]
},
{
"id": "05bcb447bf58143a",
"type": "change",
"z": "bdc1531b0db774c0",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "payload.img_url",
"tot": "msg"
},
{
"t": "move",
"p": "generated_text",
"pt": "msg",
"to": "payload.generated_text",
"tot": "msg"
},
{
"t": "move",
"p": "img_prompt",
"pt": "msg",
"to": "payload.img_prompt",
"tot": "msg"
},
{
"t": "move",
"p": "from",
"pt": "msg",
"to": "to",
"tot": "msg"
},
{
"t": "delete",
"p": "html",
"pt": "msg"
},
{
"t": "delete",
"p": "headers",
"pt": "msg"
},
{
"t": "delete",
"p": "attachments",
"pt": "msg"
},
{
"t": "delete",
"p": "header",
"pt": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 740,
"y": 640,
"wires": [
[
"4af63bd7921275fd"
]
]
},
{
"id": "18782e8eec2d74fa",
"type": "change",
"z": "bdc1531b0db774c0",
"name": "",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "generated_text",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 450,
"y": 480,
"wires": [
[
"f6b820180918c26a"
]
]
},
{
"id": "caedb828f4c91a03",
"type": "link in",
"z": "bdc1531b0db774c0",
"name": "email_response_in",
"links": [
"4af63bd7921275fd"
],
"x": 235,
"y": 240,
"wires": [
[
"22e035cb5a9832f5"
]
]
},
{
"id": "4af63bd7921275fd",
"type": "link out",
"z": "bdc1531b0db774c0",
"name": "email_response_out",
"mode": "link",
"links": [
"caedb828f4c91a03"
],
"x": 865,
"y": 640,
"wires": []
},
{
"id": "0845f55f72a53031",
"type": "function",
"z": "bdc1531b0db774c0",
"name": "Till the replay",
"func": "//If this is a replay message, only pick the part till the replay, e.g. \"On Friday ..\"\nlet text = msg.payload;\nlet pattern = /[\\S\\s*]*(?=(\\u21b5|....|)On\\s+([^,])+.([^,])+.([^@])+)/g;\nlet match = text.match(pattern); \n\nif (match) {\n let extractedText = match[0].trim();\n msg.payload = extractedText;\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 170,
"y": 360,
"wires": [
[
"5b80422576d9d1a4"
]
]
},
{
"id": "5b80422576d9d1a4",
"type": "change",
"z": "bdc1531b0db774c0",
"name": "",
"rules": [
{
"t": "set",
"p": "originalMail",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 160,
"y": 400,
"wires": [
[
"d789180f7c2c5fd1"
]
]
},
{
"id": "22e035cb5a9832f5",
"type": "template",
"z": "bdc1531b0db774c0",
"name": "HTML Template",
"field": "payload",
"fieldType": "msg",
"format": "html",
"syntax": "mustache",
"template": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional //EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\">\n<head>\n<!--[if gte mso 9]>\n<xml>\n <o:OfficeDocumentSettings>\n <o:AllowPNG/>\n <o:PixelsPerInch>96</o:PixelsPerInch>\n </o:OfficeDocumentSettings>\n</xml>\n<![endif]-->\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <meta name=\"x-apple-disable-message-reformatting\">\n <!--[if !mso]><!--><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><!--<![endif]-->\n <title></title>\n \n <style type=\"text/css\">\n @media only screen and (min-width: 520px) {\n .u-row {\n width: 500px !important;\n }\n .u-row .u-col {\n vertical-align: top;\n }\n\n .u-row .u-col-100 {\n width: 500px !important;\n }\n\n}\n\n@media (max-width: 520px) {\n .u-row-container {\n max-width: 100% !important;\n padding-left: 0px !important;\n padding-right: 0px !important;\n }\n .u-row .u-col {\n min-width: 320px !important;\n max-width: 100% !important;\n display: block !important;\n }\n .u-row {\n width: 100% !important;\n }\n .u-col {\n width: 100% !important;\n }\n .u-col > div {\n margin: 0 auto;\n }\n}\nbody {\n margin: 0;\n padding: 0;\n}\n\ntable,\ntr,\ntd {\n vertical-align: top;\n border-collapse: collapse;\n}\n\np {\n margin: 0;\n}\n\n.ie-container table,\n.mso-container table {\n table-layout: fixed;\n}\n\n* {\n line-height: inherit;\n}\n\na[x-apple-data-detectors='true'] {\n color: inherit !important;\n text-decoration: none !important;\n}\n\n@media (max-width: 480px) {\n .hide-mobile {\n max-height: 0px;\n overflow: hidden;\n display: none !important;\n }\n}\n\ntable, td { color: #000000; } #u_body a { color: #0000ee; text-decoration: underline; }\n </style>\n \n \n\n</head>\n\n<body class=\"clean-body u_body\" style=\"margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #ffffff;color: #000000\">\n <!--[if IE]><div class=\"ie-container\"><![endif]-->\n <!--[if mso]><div class=\"mso-container\"><![endif]-->\n <table id=\"u_body\" style=\"border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;min-width: 320px;Margin: 0 auto;background-color: #ffffff;width:100%\" cellpadding=\"0\" cellspacing=\"0\">\n <tbody>\n <tr style=\"vertical-align: top\">\n <td style=\"word-break: break-word;border-collapse: collapse !important;vertical-align: top\">\n <!--[if (mso)|(IE)]><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td align=\"center\" style=\"background-color: #ffffff;\"><![endif]-->\n \n\n<div class=\"u-row-container\" style=\"padding: 20px;background-color: transparent\">\n <div class=\"u-row\" style=\"Margin: 0 auto;min-width: 320px;max-width: 500px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: #b9b9b9;\">\n <div style=\"border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;\">\n <!--[if (mso)|(IE)]><table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td style=\"padding: 20px;background-color: transparent;\" align=\"center\"><table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:500px;\"><tr style=\"background-color: #b9b9b9;\"><![endif]-->\n \n<!--[if (mso)|(IE)]><td align=\"center\" width=\"500\" style=\"width: 500px;padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;\" valign=\"top\"><![endif]-->\n<div class=\"u-col u-col-100\" style=\"max-width: 320px;min-width: 500px;display: table-cell;vertical-align: top;\">\n <div style=\"height: 100%;width: 100% !important;\">\n <!--[if (!mso)&(!IE)]><!--><div style=\"box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;\"><!--<![endif]-->\n \n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n <tr>\n <td style=\"padding-right: 0px;padding-left: 0px;\" align=\"center\">\n \n <img align=\"center\" border=\"0\" src=\"{{payload.img_url}}\" alt=\"{{payload.img_prompt}}\" title=\"{{payload.img_prompt}}\" style=\"outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 100%;max-width: 100%;\" width=\"100\"/>\n \n </td>\n </tr>\n</table>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <h1 style=\"margin: 0px; line-height: 140%; text-align: left; word-wrap: break-word; font-size: 22px; \">Image description</h1>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <div style=\"line-height: 140%; text-align: left; word-wrap: break-word;\">\n <p style=\"line-height: 140%;\">This is an image description: {{payload.img_prompt}}</p>\n </div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <h1 style=\"margin: 0px; line-height: 140%; text-align: left; word-wrap: break-word; font-size: 22px; \">ChatGPT generated content</h1>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <div style=\"line-height: 140%; text-align: left; word-wrap: break-word;\">\n <p style=\"line-height: 140%;\">ChatGPT generated content: {{payload.generated_text}}</p>\n </div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:12px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n<div class=\"menu\" style=\"text-align:center\">\n<!--[if (mso)|(IE)]><table role=\"presentation\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><![endif]-->\n\n <!--[if (mso)|(IE)]><td style=\"padding:5px 15px\"><![endif]-->\n \n <a href=\"https://che-adrian.medium.com/\" target=\"_blank\" style=\"padding:5px 15px;display:inline-block;color:#0068A5;font-size:14px;text-decoration:none\" >\n Open Website\n </a>\n \n <!--[if (mso)|(IE)]></td><![endif]-->\n \n <!--[if (mso)|(IE)]><td style=\"padding:5px 15px\"><![endif]-->\n <span style=\"padding:5px 15px;display:inline-block;color:#444444;font-size:14px;\" class=\"hide-mobile\">\n -\n </span>\n <!--[if (mso)|(IE)]></td><![endif]-->\n \n\n <!--[if (mso)|(IE)]><td style=\"padding:5px 15px\"><![endif]-->\n \n <a href=\"https://che-adrian.medium.com/\" target=\"_blank\" style=\"padding:5px 15px;display:inline-block;color:#0068A5;font-size:14px;text-decoration:none\" >\n About us\n </a>\n \n <!--[if (mso)|(IE)]></td><![endif]-->\n \n\n<!--[if (mso)|(IE)]></tr></table><![endif]-->\n</div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <table height=\"0px\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" style=\"border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;border-top: 1px solid #BBBBBB;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%\">\n <tbody>\n <tr style=\"vertical-align: top\">\n <td style=\"word-break: break-word;border-collapse: collapse !important;vertical-align: top;font-size: 0px;line-height: 0px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%\">\n <span>&#160;</span>\n </td>\n </tr>\n </tbody>\n </table>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <h1 style=\"margin: 0px; line-height: 140%; text-align: left; word-wrap: break-word; font-size: 22px; \">Footer</h1>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n<table style=\"font-family:arial,helvetica,sans-serif;\" role=\"presentation\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" border=\"0\">\n <tbody>\n <tr>\n <td style=\"overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:arial,helvetica,sans-serif;\" align=\"left\">\n \n <div style=\"line-height: 140%; text-align: left; word-wrap: break-word;\">\n <p style=\"line-height: 140%;\">This email was generated with the help of Dall-e 2 and ChatGPT</p>\n </div>\n\n </td>\n </tr>\n </tbody>\n</table>\n\n <!--[if (!mso)&(!IE)]><!--></div><!--<![endif]-->\n </div>\n</div>\n<!--[if (mso)|(IE)]></td><![endif]-->\n <!--[if (mso)|(IE)]></tr></table></td></tr></table><![endif]-->\n </div>\n </div>\n</div>\n\n\n <!--[if (mso)|(IE)]></td></tr></table><![endif]-->\n </td>\n </tr>\n </tbody>\n </table>\n <!--[if mso]></div><![endif]-->\n <!--[if IE]></div><![endif]-->\n</body>\n\n</html>",
"output": "str",
"x": 420,
"y": 200,
"wires": [
[
"4e2b1d95b0730506"
]
]
},
{
"id": "3f00ca79b193a2b7",
"type": "change",
"z": "bdc1531b0db774c0",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 300,
"wires": [
[]
]
},
{
"id": "fe665ab327d104d3",
"type": "image",
"z": "bdc1531b0db774c0",
"name": "",
"width": 160,
"data": "payload",
"dataType": "msg",
"thumbnail": false,
"active": true,
"pass": false,
"outputs": 0,
"x": 560,
"y": 680,
"wires": []
}
]
[
{
"id": "e6da46131ceed4fb",
"type": "tab",
"label": "OpenAI API",
"disabled": false,
"info": "",
"env": []
},
{
"id": "bf51565be34158ba",
"type": "http request",
"z": "e6da46131ceed4fb",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.openai.com/v1/chat/completions",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "bearer",
"senderr": false,
"headers": [],
"x": 430,
"y": 240,
"wires": [
[
"7627281c058b8a40"
]
]
},
{
"id": "7efe3e431a7e6d00",
"type": "template",
"z": "e6da46131ceed4fb",
"name": "Message",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Hello bot!",
"output": "str",
"x": 200,
"y": 120,
"wires": [
[
"a86e4dd004486738"
]
]
},
{
"id": "c31cc49404b315e8",
"type": "inject",
"z": "e6da46131ceed4fb",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
},
{
"p": "chatID",
"v": "123456789",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 160,
"y": 80,
"wires": [
[
"7efe3e431a7e6d00"
]
]
},
{
"id": "0a2a8c300fbe892c",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "chatgpt_in",
"links": [],
"x": 55,
"y": 160,
"wires": [
[
"a86e4dd004486738"
]
]
},
{
"id": "ee232ed4b483a468",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "chatgpt_out",
"mode": "return",
"links": [],
"x": 715,
"y": 260,
"wires": []
},
{
"id": "7627281c058b8a40",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.choices[0].message.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 470,
"y": 280,
"wires": [
[
"d821f5e73ad30717"
]
]
},
{
"id": "a86e4dd004486738",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "Change model config",
"rules": [
{
"t": "set",
"p": "gpt_config.model",
"pt": "msg",
"to": "gpt-3.5-turbo",
"tot": "str"
},
{
"t": "set",
"p": "gpt_config.system",
"pt": "msg",
"to": "You are the perfect chatbot for the shop customer. Respond in maximum 25 words in english.",
"tot": "str"
},
{
"t": "set",
"p": "gpt_config.temperature",
"pt": "msg",
"to": "1",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.top_p",
"pt": "msg",
"to": "1",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.presence_penalty",
"pt": "msg",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.frequency_penalty",
"pt": "msg",
"to": "0",
"tot": "num"
},
{
"t": "set",
"p": "gpt_config.max_tokens",
"pt": "msg",
"to": "2048",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 260,
"y": 160,
"wires": [
[
"4d9239f766dd1ee5"
]
]
},
{
"id": "9b5be63de486af3c",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "[Link]Chat API Reference ",
"info": "https://platform.openai.com/docs/api-reference/chat/create\n\nhttps://platform.openai.com/docs/guides/chat/introduction",
"x": 590,
"y": 160,
"wires": []
},
{
"id": "15c9b2befc9785da",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Save conversation history",
"info": "This will save the conversation\nhistory, input and response,\nfor the last 6 messages for\neach platform to a file.\nYou can use a database, like Postgress or\nNoSQL variants. ",
"x": 590,
"y": 580,
"wires": []
},
{
"id": "ee86db05dc050f8e",
"type": "function",
"z": "e6da46131ceed4fb",
"name": "Config chat model",
"func": "/* \n * E.g. input for history\n * msg.gpt_history = [{ \"role\": \"assistant\", \"content\": \"The Los Angeles Dodgers won the World Series in 2020.\" },\n * { \"role\": \"user\", \"content\": \"Where was it played?\" } ]\n */\n\nmsg.gpt_messages = [ { \"role\": \"system\", \"content\": msg.gpt_config.system } ];\n\nif (msg.gpt_history){\n msg.gpt_messages = msg.gpt_messages.concat(msg.gpt_history);\n}\n\nmsg.gpt_messages = msg.gpt_messages.concat({ \"role\": \"user\", \"content\": msg.payload });\n\nmsg.payload =\n{\n \"model\": msg.gpt_config.model,\n \"messages\": msg.gpt_messages,\n \"temperature\": msg.gpt_config.temperature,\n \"top_p\": msg.gpt_config.top_p,\n \"presence_penalty\": msg.gpt_config.presence_penalty,\n \"frequency_penalty\": msg.gpt_config.frequency_penalty,\n \"max_tokens\": msg.gpt_config.max_tokens\n}\n\ndelete (msg.gpt_config);\ndelete (msg.gpt_history);\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 200,
"wires": [
[
"bf51565be34158ba"
]
]
},
{
"id": "eb00035c36ac739f",
"type": "switch",
"z": "e6da46131ceed4fb",
"name": "Check if RedBot or WhatsApp personal",
"property": "originalMessage",
"propertyType": "msg",
"rules": [
{
"t": "hask",
"v": "chatId",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 260,
"y": 480,
"wires": [
[
"e7f70d3b76fd56f9"
],
[
"4fa4c728be999a0f"
]
]
},
{
"id": "e7f70d3b76fd56f9",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "saveID",
"pt": "msg",
"to": "originalMessage.chatId",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 460,
"wires": [
[
"1fb6c955238349a9"
]
]
},
{
"id": "4fa4c728be999a0f",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "saveID",
"pt": "msg",
"to": "chatID",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 500,
"wires": [
[
"1fb6c955238349a9"
]
]
},
{
"id": "1fb6c955238349a9",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "filename",
"pt": "msg",
"to": "\"/data/chat_save/\" & saveID & \".json\"",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 750,
"y": 480,
"wires": [
[
"5c1c0ced602a4506"
]
]
},
{
"id": "d821f5e73ad30717",
"type": "switch",
"z": "e6da46131ceed4fb",
"name": "Status code 200",
"property": "statusCode",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "200",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 500,
"y": 320,
"wires": [
[
"ee232ed4b483a468",
"ea69b2ae2fb4ecc0"
],
[
"f05579cea6eddee7"
]
]
},
{
"id": "f05579cea6eddee7",
"type": "debug",
"z": "e6da46131ceed4fb",
"name": "API Error",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 760,
"y": 340,
"wires": []
},
{
"id": "dd3306028f512ae0",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "gpt_history_in",
"links": [
"4d9239f766dd1ee5"
],
"x": 55,
"y": 440,
"wires": [
[
"57cbe5d7e145265a"
]
]
},
{
"id": "05ea0c20ec7661be",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Check if history exist",
"info": "Verify if a file with the specific saveID exist.",
"x": 570,
"y": 380,
"wires": []
},
{
"id": "5c1c0ced602a4506",
"type": "file in",
"z": "e6da46131ceed4fb",
"name": "Get conversation",
"filename": "filename",
"filenameType": "msg",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 770,
"y": 520,
"wires": [
[
"f9fbd684daf9ee90"
]
]
},
{
"id": "f9fbd684daf9ee90",
"type": "json",
"z": "e6da46131ceed4fb",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 830,
"y": 560,
"wires": [
[
"37211b0a377a4b0e"
]
]
},
{
"id": "08d23a700481c2d0",
"type": "function",
"z": "e6da46131ceed4fb",
"name": "Save current and last N",
"func": "/* \n * Save the current response and delete older than N limit\n */\n//Remove first array element, \"role\":\"system\"\nmsg.gpt_messages.shift();\nvar gpt_response = [{ \"role\": \"assistant\", \"content\": msg.payload }]; \nvar current_conversation = msg.gpt_messages.concat(gpt_response);\n//Get the last N from history\ncurrent_conversation = current_conversation.slice(-(msg.maximum_histroy * 2));\nmsg.payload = current_conversation;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 660,
"wires": [
[
"10b56afb812da49f"
]
]
},
{
"id": "57cbe5d7e145265a",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "gpt_asked",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 330,
"y": 440,
"wires": [
[
"eb00035c36ac739f"
]
]
},
{
"id": "10b56afb812da49f",
"type": "file",
"z": "e6da46131ceed4fb",
"name": "Save conversation",
"filename": "filename",
"filenameType": "msg",
"appendNewline": false,
"createDir": true,
"overwriteFile": "true",
"encoding": "none",
"x": 710,
"y": 660,
"wires": [
[]
]
},
{
"id": "8048cf0539ac4f55",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "gpt_history_out",
"mode": "link",
"links": [
"81c7c2f4545507e7"
],
"x": 1105,
"y": 600,
"wires": []
},
{
"id": "4d9239f766dd1ee5",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "chatgpt_out",
"mode": "link",
"links": [
"dd3306028f512ae0"
],
"x": 405,
"y": 160,
"wires": []
},
{
"id": "81c7c2f4545507e7",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "link in 1",
"links": [
"8048cf0539ac4f55"
],
"x": 235,
"y": 200,
"wires": [
[
"ee86db05dc050f8e"
]
]
},
{
"id": "37211b0a377a4b0e",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "gpt_history",
"pt": "msg",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "gpt_asked",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 820,
"y": 600,
"wires": [
[
"8048cf0539ac4f55"
]
]
},
{
"id": "00b3fd403c2f6aac",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Call the ChatGPT API",
"info": "",
"x": 580,
"y": 40,
"wires": []
},
{
"id": "e0e0c2930abdfb07",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "gpt_history_save_in",
"links": [
"ea69b2ae2fb4ecc0"
],
"x": 55,
"y": 660,
"wires": [
[
"f3b2ddeeb67dcdc6"
]
]
},
{
"id": "ea69b2ae2fb4ecc0",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "chatgpt_out",
"mode": "link",
"links": [
"e0e0c2930abdfb07"
],
"x": 715,
"y": 300,
"wires": []
},
{
"id": "fa2a85103c4924fb",
"type": "catch",
"z": "e6da46131ceed4fb",
"name": "If file not found",
"scope": [
"5c1c0ced602a4506"
],
"uncaught": false,
"x": 980,
"y": 520,
"wires": [
[
"8048cf0539ac4f55"
]
]
},
{
"id": "f3b2ddeeb67dcdc6",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "maximum_histroy",
"pt": "msg",
"to": "6",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 210,
"y": 660,
"wires": [
[
"08d23a700481c2d0"
]
]
},
{
"id": "88698f105ae398f1",
"type": "http request",
"z": "e6da46131ceed4fb",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.openai.com/v1/images/generations",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "bearer",
"senderr": false,
"headers": [],
"x": 290,
"y": 900,
"wires": [
[
"4fd1ba17724cc32f"
]
]
},
{
"id": "24112cb41f1f983f",
"type": "template",
"z": "e6da46131ceed4fb",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "json",
"syntax": "mustache",
"template": "{\n \"prompt\": \"{{payload.img_prompt}}\",\n \"n\": 1,\n \"size\": \"{{payload.resolution}}\"\n}",
"output": "json",
"x": 260,
"y": 860,
"wires": [
[
"88698f105ae398f1"
]
]
},
{
"id": "da0254b711276bdc",
"type": "image",
"z": "e6da46131ceed4fb",
"name": "",
"width": 160,
"data": "payload",
"dataType": "msg",
"thumbnail": false,
"active": true,
"pass": false,
"outputs": 0,
"x": 360,
"y": 980,
"wires": []
},
{
"id": "2cfdfff15961b9d6",
"type": "inject",
"z": "e6da46131ceed4fb",
"name": "",
"props": [
{
"p": "payload.img_prompt",
"v": "A cute cat.",
"vt": "str"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 150,
"y": 780,
"wires": [
[
"1e8787cff0ccfe81"
]
]
},
{
"id": "4fd1ba17724cc32f",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.data[0].url",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 320,
"y": 940,
"wires": [
[
"da0254b711276bdc",
"5268a38e5582c90e"
]
]
},
{
"id": "982664b0a0fd715a",
"type": "comment",
"z": "e6da46131ceed4fb",
"name": "Bonus: create image with \"dall-e-2\" and send it",
"info": "",
"x": 650,
"y": 720,
"wires": []
},
{
"id": "cc9b2b14ee514bbe",
"type": "link in",
"z": "e6da46131ceed4fb",
"name": "openai_dalle_in",
"links": [],
"x": 55,
"y": 820,
"wires": [
[
"1e8787cff0ccfe81"
]
]
},
{
"id": "1e8787cff0ccfe81",
"type": "change",
"z": "e6da46131ceed4fb",
"name": "Set resolution",
"rules": [
{
"t": "set",
"p": "payload.resolution",
"pt": "msg",
"to": "256x256",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 220,
"y": 820,
"wires": [
[
"24112cb41f1f983f"
]
]
},
{
"id": "5268a38e5582c90e",
"type": "link out",
"z": "e6da46131ceed4fb",
"name": "openai_dalle_out",
"mode": "return",
"links": [],
"x": 495,
"y": 940,
"wires": []
}
]
[
{
"id": "9991a72588754b12",
"type": "tab",
"label": "OpenAI Chatbot",
"disabled": false,
"info": "",
"env": []
},
{
"id": "3a263fec8ca467c6",
"type": "chatbot-telegram-receive",
"z": "9991a72588754b12",
"bot": "2c5102c4bbe71250",
"botProduction": "",
"x": 130,
"y": 60,
"wires": [
[
"60e7f8731afb5f80"
]
]
},
{
"id": "632d01914b2d6ba7",
"type": "chatbot-telegram-send",
"z": "9991a72588754b12",
"bot": "2c5102c4bbe71250",
"botProduction": "",
"track": false,
"passThrough": false,
"errorOutput": false,
"outputs": 0,
"x": 690,
"y": 160,
"wires": []
},
{
"id": "81727d65b1fdecba",
"type": "chatbot-conversation",
"z": "9991a72588754b12",
"name": "",
"botDevelopment": "2c5102c4bbe71250",
"botProduction": "",
"chatId": "",
"userId": "",
"transport": "telegram",
"x": 470,
"y": 160,
"wires": [
[
"632d01914b2d6ba7"
]
]
},
{
"id": "35a3ffb5c4e67730",
"type": "chatbot-facebook-receive",
"z": "9991a72588754b12",
"bot": "560632cf62e82692",
"botProduction": "",
"x": 130,
"y": 260,
"wires": [
[
"679888811fca2f99"
]
]
},
{
"id": "e37fb62d8f204d23",
"type": "chatbot-facebook-send",
"z": "9991a72588754b12",
"bot": "560632cf62e82692",
"botProduction": "",
"track": false,
"passThrough": false,
"errorOutput": false,
"outputs": 0,
"x": 700,
"y": 320,
"wires": []
},
{
"id": "6451b6778b87d0da",
"type": "chatbot-conversation",
"z": "9991a72588754b12",
"name": "",
"botDevelopment": "560632cf62e82692",
"botProduction": "",
"chatId": "",
"userId": "",
"transport": "facebook",
"x": 470,
"y": 320,
"wires": [
[
"e37fb62d8f204d23"
]
]
},
{
"id": "7901e1b568ba8bb5",
"type": "chatbot-whatsapp-receive",
"z": "9991a72588754b12",
"bot": "",
"botProduction": "",
"x": 130,
"y": 400,
"wires": [
[
"dd99fc5ecb7dc003"
]
]
},
{
"id": "9d074b19352c1e58",
"type": "chatbot-whatsapp-send",
"z": "9991a72588754b12",
"bot": "",
"botProduction": "",
"track": false,
"passThrough": false,
"errorOutput": false,
"outputs": 0,
"x": 690,
"y": 460,
"wires": []
},
{
"id": "d81f94b4472d5357",
"type": "chatbot-conversation",
"z": "9991a72588754b12",
"name": "",
"botDevelopment": "",
"botProduction": "",
"chatId": "",
"userId": "",
"transport": "",
"x": 470,
"y": 460,
"wires": [
[
"9d074b19352c1e58"
]
]
},
{
"id": "2a74378f887fb3ad",
"type": "change",
"z": "9991a72588754b12",
"name": "str(chatId)",
"rules": [
{
"t": "set",
"p": "payload.chatId",
"pt": "msg",
"to": "$string(msg.payload.chatId)",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 240,
"y": 160,
"wires": [
[
"81727d65b1fdecba"
]
]
},
{
"id": "ac59238d2028057e",
"type": "admin",
"z": "9991a72588754b12",
"name": "WA Admin",
"whatsappLink": "dcaa1c3a26ef76d4",
"x": 590,
"y": 680,
"wires": [
[]
]
},
{
"id": "89d412a030fc482f",
"type": "chats-in",
"z": "9991a72588754b12",
"name": "Chats In",
"whatsappLink": "dcaa1c3a26ef76d4",
"whatsappLiteevent": "messages.upsert",
"whatsappWebevent": "message",
"x": 160,
"y": 540,
"wires": [
[
"cf13ae5fd2302550"
]
]
},
{
"id": "d219a54611710c6d",
"type": "chats-out",
"z": "9991a72588754b12",
"name": "Chats Out",
"whatsappLink": "dcaa1c3a26ef76d4",
"number": "",
"x": 600,
"y": 600,
"wires": []
},
{
"id": "cf13ae5fd2302550",
"type": "change",
"z": "9991a72588754b12",
"name": "Set replay number",
"rules": [
{
"t": "set",
"p": "toNumber",
"pt": "msg",
"to": "from",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 150,
"y": 600,
"wires": [
[
"0fd9e106fb644271"
]
]
},
{
"id": "4b93149e8af14ee5",
"type": "chatbot-message",
"z": "9991a72588754b12",
"name": "",
"message": [],
"language": "none",
"x": 190,
"y": 120,
"wires": [
[
"2a74378f887fb3ad"
]
]
},
{
"id": "752c76214e00a83e",
"type": "chatbot-message",
"z": "9991a72588754b12",
"name": "",
"message": [],
"language": "none",
"x": 190,
"y": 320,
"wires": [
[
"6451b6778b87d0da"
]
]
},
{
"id": "670d33f5fcdfe29e",
"type": "chatbot-message",
"z": "9991a72588754b12",
"name": "",
"message": [],
"language": "none",
"x": 190,
"y": 460,
"wires": [
[
"d81f94b4472d5357"
]
]
},
{
"id": "bf51565be34158ba",
"type": "http request",
"z": "9991a72588754b12",
"name": "",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.openai.com/v1/chat/completions",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "bearer",
"senderr": false,
"headers": [],
"x": 330,
"y": 800,
"wires": [
[
"7627281c058b8a40"
]
]
},
{
"id": "50c6e0acc962b414",
"type": "template",
"z": "9991a72588754b12",
"name": "Config chat model",
"field": "payload",
"fieldType": "msg",
"format": "json",
"syntax": "mustache",
"template": "{\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [{\"role\": \"user\", \"content\": \"{{payload}}\"}],\n \"temperature\": 1,\n \"top_p\": 1,\n \"presence_penalty\": 0,\n \"frequency_penalty\": 0,\n \"max_tokens\": 2048\n}",
"output": "json",
"x": 270,
"y": 760,
"wires": [
[
"bf51565be34158ba"
]
]
},
{
"id": "7efe3e431a7e6d00",
"type": "template",
"z": "9991a72588754b12",
"name": "Message",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "Hello bot!",
"output": "str",
"x": 180,
"y": 720,
"wires": [
[
"50c6e0acc962b414"
]
]
},
{
"id": "c31cc49404b315e8",
"type": "inject",
"z": "9991a72588754b12",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 680,
"wires": [
[
"7efe3e431a7e6d00"
]
]
},
{
"id": "0a2a8c300fbe892c",
"type": "link in",
"z": "9991a72588754b12",
"name": "chatgpt_in",
"links": [
"0fd9e106fb644271",
"95f61719997b5aba",
"b283846d28a4775d",
"cc826a8c39ce99e5"
],
"x": 95,
"y": 760,
"wires": [
[
"50c6e0acc962b414"
]
]
},
{
"id": "ee232ed4b483a468",
"type": "link out",
"z": "9991a72588754b12",
"name": "chatgpt_out",
"mode": "link",
"links": [
"87a8331d0156dada",
"e3a8054e02357181",
"d3b4a99d902d040d",
"c2c2bff57c07a168"
],
"x": 525,
"y": 840,
"wires": []
},
{
"id": "87a8331d0156dada",
"type": "link in",
"z": "9991a72588754b12",
"name": "link in 1",
"links": [
"ee232ed4b483a468"
],
"x": 485,
"y": 600,
"wires": [
[
"d219a54611710c6d"
]
]
},
{
"id": "0fd9e106fb644271",
"type": "link out",
"z": "9991a72588754b12",
"name": "link out 1",
"mode": "link",
"links": [
"0a2a8c300fbe892c"
],
"x": 305,
"y": 600,
"wires": []
},
{
"id": "7627281c058b8a40",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.choices[0].message.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 380,
"y": 840,
"wires": [
[
"ee232ed4b483a468"
]
]
},
{
"id": "95f61719997b5aba",
"type": "link out",
"z": "9991a72588754b12",
"name": "link out 2",
"mode": "link",
"links": [
"0a2a8c300fbe892c"
],
"x": 465,
"y": 60,
"wires": []
},
{
"id": "60e7f8731afb5f80",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 60,
"wires": [
[
"95f61719997b5aba"
]
]
},
{
"id": "e3a8054e02357181",
"type": "link in",
"z": "9991a72588754b12",
"name": "link in 2",
"links": [
"ee232ed4b483a468"
],
"x": 545,
"y": 60,
"wires": [
[
"48e25994614950f6"
]
]
},
{
"id": "48e25994614950f6",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "message",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 670,
"y": 60,
"wires": [
[
"4b93149e8af14ee5"
]
]
},
{
"id": "cc826a8c39ce99e5",
"type": "link out",
"z": "9991a72588754b12",
"name": "link out 3",
"mode": "link",
"links": [
"0a2a8c300fbe892c"
],
"x": 465,
"y": 260,
"wires": []
},
{
"id": "679888811fca2f99",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 260,
"wires": [
[
"cc826a8c39ce99e5"
]
]
},
{
"id": "d3b4a99d902d040d",
"type": "link in",
"z": "9991a72588754b12",
"name": "link in 3",
"links": [
"ee232ed4b483a468"
],
"x": 545,
"y": 260,
"wires": [
[
"088da4ef4acc3dd1"
]
]
},
{
"id": "088da4ef4acc3dd1",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "message",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 670,
"y": 260,
"wires": [
[
"752c76214e00a83e"
]
]
},
{
"id": "b283846d28a4775d",
"type": "link out",
"z": "9991a72588754b12",
"name": "link out 4",
"mode": "link",
"links": [
"0a2a8c300fbe892c"
],
"x": 465,
"y": 400,
"wires": []
},
{
"id": "dd99fc5ecb7dc003",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "payload.content",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 340,
"y": 400,
"wires": [
[
"b283846d28a4775d"
]
]
},
{
"id": "c2c2bff57c07a168",
"type": "link in",
"z": "9991a72588754b12",
"name": "link in 4",
"links": [
"ee232ed4b483a468"
],
"x": 545,
"y": 400,
"wires": [
[
"0f2c236107109931"
]
]
},
{
"id": "0f2c236107109931",
"type": "change",
"z": "9991a72588754b12",
"name": "",
"rules": [
{
"t": "set",
"p": "message",
"pt": "msg",
"to": "payload",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 670,
"y": 400,
"wires": [
[
"670d33f5fcdfe29e"
]
]
},
{
"id": "2c5102c4bbe71250",
"type": "chatbot-telegram-node",
"botname": "TahityBot",
"usernames": "",
"polling": "1000",
"store": "",
"log": "",
"debug": false,
"skipMediaFiles": false,
"webHook": "",
"connectMode": "polling",
"storeMessages": true,
"enableMissionControl": false,
"inspectMessages": true,
"chatbotId": ""
},
{
"id": "560632cf62e82692",
"type": "chatbot-facebook-node",
"botname": "Messenger",
"usernames": "",
"store": "",
"log": "",
"debug": false,
"multiWebHook": false,
"profileFields": "first_name,last_name",
"storeMessages": true,
"enableMissionControl": false,
"inspectMessages": true,
"chatbotId": ""
},
{
"id": "dcaa1c3a26ef76d4",
"type": "whatsappLink",
"cName": "whatsapp-web",
"name": "Web",
"clientType": "waSocketClient",
"onlineStatus": true,
"loopTime": "5"
}
]
[
{
"id": "4370517eccea40e5",
"type": "tab",
"label": "WhatsApp bot",
"disabled": false,
"info": "",
"env": []
},
{
"id": "fb4a62aa73a3363c",
"type": "admin",
"z": "4370517eccea40e5",
"name": "WA Admin",
"whatsappLink": "dcaa1c3a26ef76d4",
"x": 170,
"y": 1120,
"wires": [
[]
]
},
{
"id": "a695d61574a6f685",
"type": "chats-in",
"z": "4370517eccea40e5",
"name": "Chats In",
"whatsappLink": "dcaa1c3a26ef76d4",
"whatsappLiteevent": "messages.upsert",
"whatsappWebevent": "message",
"x": 180,
"y": 920,
"wires": [
[
"fab9d579c6b1af68"
]
]
},
{
"id": "4f7e2730673aa3ca",
"type": "chats-out",
"z": "4370517eccea40e5",
"name": "Chats Out",
"whatsappLink": "dcaa1c3a26ef76d4",
"number": "",
"x": 900,
"y": 920,
"wires": []
},
{
"id": "fab9d579c6b1af68",
"type": "change",
"z": "4370517eccea40e5",
"name": "Set replay number",
"rules": [
{
"t": "set",
"p": "toNumber",
"pt": "msg",
"to": "from",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 370,
"y": 920,
"wires": [
[
"83f0e75e78a8013e",
"7d69d5ce7850ed4c"
]
]
},
{
"id": "9017a32f07c16736",
"type": "template",
"z": "4370517eccea40e5",
"name": "Default",
"field": "payload",
"fieldType": "msg",
"format": "text",
"syntax": "plain",
"template": "Type \"Help!\" if you want to see buttons. ",
"output": "str",
"x": 700,
"y": 960,
"wires": [
[
"4f7e2730673aa3ca"
]
]
},
{
"id": "7d69d5ce7850ed4c",
"type": "switch",
"z": "4370517eccea40e5",
"name": "Buttons",
"property": "message.buttonsResponseMessage.selectedButtonId",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "products",
"vt": "str"
},
{
"t": "eq",
"v": "options",
"vt": "str"
},
{
"t": "eq",
"v": "anything",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 3,
"x": 560,
"y": 1040,
"wires": [
[
"310b15ef23752a4b"
],
[
"acbb73fea978000a"
],
[
"ad2313727e436c53"
]
]
},
{
"id": "6060858df42c6580",
"type": "template",
"z": "4370517eccea40e5",
"name": "Help!",
"field": "payload",
"fieldType": "msg",
"format": "json",
"syntax": "plain",
"template": "{\n \"text\": \"This is a menu.\",\n \"footer\": \"Nice menu!\",\n \"headerType\": 1,\n \"buttons\": [\n {\"buttonId\": \"products\", \"buttonText\": {\"displayText\": \"Products\"}, \"type\": 1},\n {\"buttonId\": \"options\", \"buttonText\": {\"displayText\": \"Options\"}, \"type\": 1},\n {\"buttonId\": \"anything\", \"buttonText\": {\"displayText\": \"Anything\"}, \"type\": 1}\n ]\n}",
"output": "json",
"x": 710,
"y": 920,
"wires": [
[
"4f7e2730673aa3ca"
]
]
},
{
"id": "310b15ef23752a4b",
"type": "template",
"z": "4370517eccea40e5",
"name": "Products",
"field": "payload",
"fieldType": "msg",
"format": "text",
"syntax": "plain",
"template": "Here's a list of products:\n- Jacket\n- Phone\n- Flying duck 🦆",
"output": "str",
"x": 700,
"y": 1000,
"wires": [
[
"4f7e2730673aa3ca"
]
]
},
{
"id": "acbb73fea978000a",
"type": "template",
"z": "4370517eccea40e5",
"name": "Options",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "plain",
"template": "You have many options, but not anything more here.",
"output": "str",
"x": 700,
"y": 1040,
"wires": [
[
"4f7e2730673aa3ca"
]
]
},
{
"id": "ad2313727e436c53",
"type": "template",
"z": "4370517eccea40e5",
"name": "Anything",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "plain",
"template": "Anything, just can be really anything.",
"output": "str",
"x": 700,
"y": 1080,
"wires": [
[
"4f7e2730673aa3ca"
]
]
},
{
"id": "83f0e75e78a8013e",
"type": "switch",
"z": "4370517eccea40e5",
"name": "Want help",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "cont",
"v": "Help",
"vt": "str"
},
{
"t": "nempty"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 560,
"y": 920,
"wires": [
[
"6060858df42c6580"
],
[
"9017a32f07c16736"
]
]
},
{
"id": "dcaa1c3a26ef76d4",
"type": "whatsappLink",
"cName": "whatsapp-web",
"name": "Web",
"clientType": "waSocketClient",
"onlineStatus": true,
"loopTime": "5"
}
]
@cheadrian
Copy link
Author

Check out this repository: https://github.com/cheadrian/node-red-flows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment