-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathchatgpt_email_summary.json
1 lines (1 loc) · 14.2 KB
/
chatgpt_email_summary.json
1
[{"id":"2e2f7abe9bc61a02","type":"e-mail in","z":"6014cd4353950ab1","name":"Emails from Gmail","protocol":"IMAP","server":"imap.gmail.com","useSSL":true,"autotls":"never","port":"993","box":"INBOX","disposition":"None","criteria":"_msg_","repeat":"300","fetch":"trigger","inputs":1,"x":790,"y":740,"wires":[["6f497811882b2bc7","18dac22a3f790f32"]]},{"id":"69a629be06df0cbf","type":"inject","z":"6014cd4353950ab1","name":"Daily","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 03 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":740,"wires":[["09e844f96834b623"]]},{"id":"6f497811882b2bc7","type":"debug","z":"6014cd4353950ab1","name":"debug 382","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":740,"wires":[]},{"id":"06af171dce28de59","type":"change","z":"6014cd4353950ab1","name":"Filter","rules":[{"t":"set","p":"criteria","pt":"msg","to":"[\"UNSEEN\",[\"FROM\",\"[email protected]\"],[\"!SUBJECT\",\"[eWeLink Forum] Summary\"]]","tot":"json"},{"t":"set","p":"source","pt":"msg","to":"ewelink","tot":"str"},{"t":"set","p":"start","pt":"msg","to":"","tot":"date"},{"t":"set","p":"payload","pt":"msg","to":"start","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":740,"wires":[["4f218054e809bf42","18dac22a3f790f32","5d1d9620577a26c1"]]},{"id":"4f218054e809bf42","type":"function","z":"6014cd4353950ab1","name":"Last 30d","func":"let now = new Date();\n\n\nlet datefilter = [];\ndatefilter.push(\"SINCE\");\n\nlet newdate = new Date();\nnewdate.setTime(now.getTime()-1000*60*60*24*30);\ndatefilter.push(newdate.toLocaleString(\"en-US\"));\n\nmsg.criteria.push(datefilter);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":740,"wires":[["2e2f7abe9bc61a02"]]},{"id":"636a02053f4fce23","type":"html","z":"6014cd4353950ab1","name":"","property":"html","outproperty":"payload","tag":"div","ret":"text","as":"single","x":1250,"y":800,"wires":[["c66022083bfb0a5c"]]},{"id":"844d04bbcbea7ac0","type":"html","z":"6014cd4353950ab1","name":"","property":"html","outproperty":"payload","tag":"a","ret":"text","as":"single","x":1250,"y":840,"wires":[["4f21adfc01ec3c40"]]},{"id":"18dac22a3f790f32","type":"function","z":"6014cd4353950ab1","name":"Tag emails","func":"let data = context.get(\"data\") ?? {};\n\nlet id = msg.start;\n\n// this is the start trigger, we will soon be getting emails\nif (msg.payload === \"start\") {\n \n data[id] = {};\n data[id].counter = 0;\n data[id].source = msg.source;\n data[id].criteria = msg.criteria;\n data[id].start = msg.start;\n context.set(\"data\",data);\n node.status({fill:\"yellow\",shape:\"ring\",text:\"New download: \"+id});\n\n return [null,msg];\n}\n\n// delayed end message to clean up the context\nif (msg.payload === \"end\") {\n node.status({ fill: \"grey\", shape: \"ring\", text: \"Ended ID: \" + id + \", count: \" + data[id].counter });\n delete data[id];\n context.set(\"data\", data);\n return;\n}\n\n// add a counter tag to the email to identify them\nmsg.counter = data[id].counter;\ndata[id].counter++;\ncontext.set(\"data\", data);\nnode.status({ fill: \"green\", shape: \"ring\", text: \"ID: \" + id + \", count: \" + data[id].counter });\n\nreturn [msg,null];\n","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":800,"wires":[["636a02053f4fce23","844d04bbcbea7ac0","330943e6573eeb8d"],["6ac2e3c0100ac831"]]},{"id":"ea1825ae481418c6","type":"delay","z":"6014cd4353950ab1","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":560,"y":920,"wires":[["123fd9c3f7a4b84c"]]},{"id":"123fd9c3f7a4b84c","type":"change","z":"6014cd4353950ab1","name":"End","rules":[{"t":"set","p":"payload","pt":"msg","to":"end","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":920,"wires":[["18dac22a3f790f32","ad95a430f93c3c9f"]]},{"id":"c66022083bfb0a5c","type":"change","z":"6014cd4353950ab1","name":"Content","rules":[{"t":"set","p":"content","pt":"msg","to":"body","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":800,"wires":[["3b16f8c6439b8ca0"]]},{"id":"4f21adfc01ec3c40","type":"change","z":"6014cd4353950ab1","name":"Content","rules":[{"t":"set","p":"content","pt":"msg","to":"user","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":840,"wires":[["3b16f8c6439b8ca0"]]},{"id":"3b16f8c6439b8ca0","type":"function","z":"6014cd4353950ab1","name":"Combine data","func":"let data = context.get(\"data\") ?? [];\n\nlet id = msg.counter;\n\n// Start message recevied, clear the earlier data\nif (msg.payload === \"start\") {\n data = [];\n context.set(\"data\", data);\n return;\n}\n\n// End message received, return the results\nif (msg.payload === \"end\") {\n msg.payload = data;\n node.status({ fill: \"green\", shape: \"ring\", text: \"Sending results\" });\n return msg;\n}\n\n// if the data does not exists yet, create it\nif (id === data.length) {\n data.push({user:\"\",subject:msg.topic,body:\"\",url:\"\"})\n}\n// Extract the body\nif (msg.content === \"body\") {\n data[id].body = msg.payload[3].replace(/(\\r\\n|\\n|\\r)/gm, \" \");;\n}\n// Extract the user\nif (msg.content === \"user\") {\n data[id].user = msg.payload[0];\n}\n// Extract the url\nif (msg.content === \"link\") {\n data[id].url = msg.payload[msg.payload.length-1].href;\n}\nnode.status({ fill: \"green\", shape: \"ring\", text: \"Adding... id:\" + id });\n\ncontext.set(\"data\",data);\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1600,"y":820,"wires":[["1516ba02d93d17fa","3273f54ef6b30ed8"]]},{"id":"1516ba02d93d17fa","type":"debug","z":"6014cd4353950ab1","name":"Compiled messages","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1840,"y":780,"wires":[]},{"id":"330943e6573eeb8d","type":"html","z":"6014cd4353950ab1","name":"","property":"html","outproperty":"payload","tag":"a ","ret":"attr","as":"single","x":1250,"y":880,"wires":[["4c8cedb5b084f90d"]]},{"id":"4c8cedb5b084f90d","type":"change","z":"6014cd4353950ab1","name":"Content","rules":[{"t":"set","p":"content","pt":"msg","to":"link","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1400,"y":880,"wires":[["3b16f8c6439b8ca0"]]},{"id":"3273f54ef6b30ed8","type":"json","z":"6014cd4353950ab1","name":"","property":"payload","action":"","pretty":false,"x":1790,"y":820,"wires":[["382e7bcdaf870e07"]]},{"id":"382e7bcdaf870e07","type":"function","z":"6014cd4353950ab1","name":"GPT Completions prompt","func":"\nlet request = {};\nrequest.api = 'chat/completions';\nrequest.params = {\n \"model\": \"gpt-3.5-turbo\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a smart home expert and you are provided a list of forum topics in this area. These topics are provided in a JSON format, in an array. Each element has a user attribute which contains the userid, a subject attribute which is the topic's subject, url attribute which contains a link to the webpage and a body attribute which contains the actual message. First create a summary of all these topics and summarize the nature of them in a few sentences. Then list out each of the topic that are about new functionality, or home automation ideas. In this list call out the subject, the url and a short summary of the body text. Format your response in HTML so it can be sent as a formatted email.\"\n },\n {\n \"role\": \"user\",\n \"content\": msg.payload\n }\n ]\n}\nreturn request;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":2010,"y":820,"wires":[["e32f6509bd2ae68e","d0b3f5bb3e42dcef"]]},{"id":"d0b3f5bb3e42dcef","type":"openai","z":"6014cd4353950ab1","name":"","api":"","creds":"cc2050a953749795","x":2220,"y":820,"wires":[["0b40da4a8337f09a","3772a47d96792e63"]]},{"id":"0b40da4a8337f09a","type":"debug","z":"6014cd4353950ab1","name":"OpenAI Response","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2410,"y":820,"wires":[]},{"id":"8167bd55e7f6b655","type":"inject","z":"6014cd4353950ab1","name":"Example","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"api\":\"chat/completions\",\"params\":{\"model\":\"gpt-3.5-turbo\",\"messages\":[{\"role\":\"system\",\"content\":\"You are a smart home expert and you are provided a list of forum topics in this area. These topics are provided in a JSON format, in an array. Each element has a user attribute which contains the userid, a subject attribute which is the topic's subject, url attribute which contains a link to the webpage and a body attribute which contains the actual message. First create a summary of all these topics and summarize the nature of them in a few sentences. Then list out each of the topic that are about new functionality, or home automation ideas. In this list call out the subject, the url and a short summary of the body text. Format your response in HTML so it can be sent as a formatted email.\"},{\"role\":\"user\",\"content\":\"[{\\\"user\\\":\\\"emechantaf\\\",\\\"subject\\\":\\\"[eWeLink Forum] [eWeLink CUBE] Ihost problem to connect the devices\\\",\\\"body\\\":\\\"Hello im installer for sonoff brand. I have problem with i host i link a account, I cant find the devices on i host why? And wifi door sensor can be syncing with i host ? Thank you\\\",\\\"url\\\":\\\"https://forum.ewelink.cc/email/unsubscribe/371d867d485ae2a7817a86c2c65b59f4eb40ff282bce0c03203481f450cd5d04\\\"},{\\\"user\\\":\\\"john.e.dixon\\\",\\\"subject\\\":\\\"[eWeLink Forum] [eWeLink CUBE] iHost Node-Red 4 update\\\",\\\"body\\\":\\\"Hi iHost - NodeRed instalation failure What’s the version of your iHost? eWelink CUBE 2.0.0 Chrome 126.0.6478.127 Screenshot won’t show much, the Web UI tab is in blank, same if I open in another tab with 192.xx xx xx :1880. In Edge browser it runs normally. \\\",\\\"url\\\":\\\"https://forum.ewelink.cc/email/unsubscribe/7b9e5e2c9b50ec8d1ad6a6a4059ec0a93f3bf5e4ce0d3243611f70b6cf80f98b\\\"},{\\\"user\\\":\\\"el404\\\",\\\"subject\\\":\\\"[eWeLink Forum] [eWeLink CUBE] SNZB-04P vs homebridge\\\",\\\"body\\\":\\\"I bought SNZB-04P a...\"}]},\"_msgid\":\"b1a03702b1a0790f\",\"payload\":{\"id\":\"chatcmpl-9wV10kE6Yy8Hx9XVOuYQcKZYkoRiX\",\"object\":\"chat.completion\",\"created\":1723729274,\"model\":\"gpt-3.5-turbo-0125\",\"choices\":[{\"index\":0,\"message\":{\"role\":\"assistant\",\"content\":\"<html>\\n<head>\\n <title>Summary of eWeLink Forum Topics</title>\\n</head>\\n<body>\\n <h2>Summary of eWeLink Forum Topics:</h2>\\n <p>The forum topics mainly focus on discussions related to eWeLink CUBE, iHost, home automation, new functionality, device support, connectivity, and smart home integration.</p>\\n\\n <h2>List of Topics Related to New Functionality or Home Automation Ideas:</h2>\\n <ol>\\n <li>\\n <h3><a href=\\\"https://forum.ewelink.cc/email/unsubscribe/392fcf33689e861610b872688ca4c8e35ab8883814e46cd2ceaae8d5be5ee390\\\">SNZB-04P vs homebridge</a></h3>\\n <p>I bought SNZB-04P and added it to IHost. Works with iHost but not changing status in Homebridge. Looking to add support.</p>\\n </li>\\n <li>\\n <h3><a href=\\\"https://forum.ewelink.cc/email/unsubscribe/ae5f53b4cbcd1e99d93a186d9e563a92fe8c292b5afe810c852f1b53a12da915\\\">Does iHost Matter Bridge Support Water Leakage Sensors?</a></h3>\\n <p>Question regarding adding SNZB-05P flood sensors to the Matter bridge.</p>\\n </li>\\n...\",\"refusal\":null},\"logprobs\":null,\"finish_reason\":\"stop\"}],\"usage\":{\"prompt_tokens\":7428,\"completion_tokens\":542,\"total_tokens\":7970},\"system_fingerprint\":null}}","payloadType":"json","x":2020,"y":920,"wires":[["3772a47d96792e63"]]},{"id":"8ec07d9f8a3c7094","type":"e-mail","z":"6014cd4353950ab1","server":"smtp.gmail.com","port":"465","secure":true,"tls":true,"name":"[email protected]","dname":"Gmail","x":2390,"y":920,"wires":[]},{"id":"3772a47d96792e63","type":"function","z":"6014cd4353950ab1","name":"Format email","func":"let email = { topic: \"eWeLink AI Summary\", payload: msg.payload.choices[0].message.content };\nreturn email;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2210,"y":920,"wires":[["8ec07d9f8a3c7094"]]},{"id":"e32f6509bd2ae68e","type":"debug","z":"6014cd4353950ab1","name":"OpenAI request","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2240,"y":780,"wires":[]},{"id":"09e844f96834b623","type":"function","z":"6014cd4353950ab1","name":"10th?","func":"let now = new Date();\n\nif (now.getDate() === 10) {\n node.status({fill:\"green\",shape:\"ring\",text:\"Triggering\"});\n return msg;\n}\n\nnode.status({ fill: \"grey\", shape: \"ring\", text: \"Not triggering: \" + now.getDate() });","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":740,"wires":[["06af171dce28de59"]]},{"id":"a88a579eb86d683d","type":"comment","z":"6014cd4353950ab1","name":"eWeLink forum AI summary","info":"","x":150,"y":680,"wires":[]},{"id":"ab94be2854104c0e","type":"inject","z":"6014cd4353950ab1","name":"Test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":820,"wires":[["06af171dce28de59"]]},{"id":"ad95a430f93c3c9f","type":"junction","z":"6014cd4353950ab1","x":1460,"y":920,"wires":[["3b16f8c6439b8ca0"]]},{"id":"6ac2e3c0100ac831","type":"junction","z":"6014cd4353950ab1","x":440,"y":920,"wires":[["ea1825ae481418c6"]]},{"id":"5d1d9620577a26c1","type":"junction","z":"6014cd4353950ab1","x":540,"y":700,"wires":[["09321e8d33166ce8"]]},{"id":"09321e8d33166ce8","type":"junction","z":"6014cd4353950ab1","x":1460,"y":700,"wires":[["3b16f8c6439b8ca0"]]},{"id":"cc2050a953749795","type":"openaiApiKey","name":""}]