User conversion subflow, and issue reporter notifications

This commit is contained in:
2025-03-22 23:18:46 -04:00
parent b55715d2a9
commit b54ae70bad

View File

@ -796,6 +796,50 @@
] ]
} }
}, },
{
"id": "ea629141206d5343",
"type": "subflow",
"name": "User Conversion",
"info": "",
"category": "",
"in": [
{
"x": 60,
"y": 80,
"wires": [
{
"id": "11aabd786c07244f"
}
]
}
],
"out": [
{
"x": 380,
"y": 80,
"wires": [
{
"id": "11aabd786c07244f",
"port": 0
}
]
}
],
"env": [],
"meta": {},
"color": "#DDAA99",
"icon": "font-awesome/fa-user",
"status": {
"x": 380,
"y": 140,
"wires": [
{
"id": "11aabd786c07244f",
"port": 1
}
]
}
},
{ {
"id": "eccca853a916b662", "id": "eccca853a916b662",
"type": "group", "type": "group",
@ -1245,7 +1289,6 @@
"a9bc78f321149316", "a9bc78f321149316",
"b3bb08ff51e46985", "b3bb08ff51e46985",
"0c7ef72bd0ef47d4", "0c7ef72bd0ef47d4",
"11aabd786c07244f",
"795c53ad6642733a", "795c53ad6642733a",
"ea5306d6f92d9550", "ea5306d6f92d9550",
"4829663e9913e2aa", "4829663e9913e2aa",
@ -1257,7 +1300,8 @@
"b7022ac46a70a7d8", "b7022ac46a70a7d8",
"a64928d7a0b836cf", "a64928d7a0b836cf",
"aecc95a3db3369e2", "aecc95a3db3369e2",
"bd6bdc6ed9aded9d" "bd6bdc6ed9aded9d",
"3bd0a22c66de228a"
], ],
"x": 34, "x": 34,
"y": 579, "y": 579,
@ -1754,12 +1798,21 @@
"427cc2991454bbf0", "427cc2991454bbf0",
"7674185d1e5ee489", "7674185d1e5ee489",
"9e43408e18883dfe", "9e43408e18883dfe",
"84c8fd3cc1ab7cf1" "84c8fd3cc1ab7cf1",
"c66df253518a4507",
"2b6f06b27b6deb92",
"a64cee24cd3523c5",
"e2e2d2fb7277cde3",
"ea0bab7efe2d570d",
"f8330684e1ccac8d",
"d31d41f3e474e0c1",
"6d9c53b7dd7b0cf3",
"c5e85490ce1d4a57"
], ],
"x": 34, "x": 34,
"y": 19, "y": 19,
"w": 812, "w": 1452,
"h": 142 "h": 222
}, },
{ {
"id": "23b02b1256dfd302", "id": "23b02b1256dfd302",
@ -2236,6 +2289,23 @@
"w": 972, "w": 972,
"h": 442 "h": 442
}, },
{
"id": "fc9cdd0818afd119",
"type": "group",
"z": "3e4ba157b540d183",
"name": "User ID List",
"style": {
"label": true
},
"nodes": [
"430d9054095580f1",
"7b2670a81b8d3967"
],
"x": 34,
"y": 1099,
"w": 392,
"h": 82
},
{ {
"id": "fba69dfc80829db7", "id": "fba69dfc80829db7",
"type": "junction", "type": "junction",
@ -6028,6 +6098,26 @@
], ],
"icon": "font-awesome/fa-clock-o" "icon": "font-awesome/fa-clock-o"
}, },
{
"id": "11aabd786c07244f",
"type": "function",
"z": "ea629141206d5343",
"name": "user conversion",
"func": "// Get the user ID list from global context\n\nconst users = global.get(\"userIDList\",\"diskCon\")\n\n// Initialize variables\n\nlet userTrigger = {}\nlet userFirstName = {}\nlet userLastName = {}\nlet hassUserID = {}\nlet statusTxt = {}\n\n// Check if the user ID is in the payload or data\n\nif (msg.payload && msg.payload.context && msg.payload.context.user_id) {\n userTrigger = msg.payload.context.user_id\n} else if (msg.data && msg.data.context && msg.data.context.user_id) {\n userTrigger = msg.data.context.user_id\n} else {\n userTrigger = \"none\"\n}\n\n// Set the status message based on the user ID\n\nlet successTxt = `User: ${users[userTrigger].firstName}`\nlet errorTxt = \"User not found\"\n\nif (userTrigger === \"none\") {\n statusTxt = errorTxt\n} else {\n statusTxt = successTxt\n}\n\n// Set the user's information in the message\n\nmsg.user = users[userTrigger]\n\n// Create the status message\n\nlet statusMsg = {\n \"status\": {\n \"fill\": \"green\",\n \"shape\": \"dot\",\n \"text\": `${statusTxt} at ${new Date().toLocaleString()}`\n }\n}\n\n// Send the message and status message to the output nodes\n\nif (userTrigger === \"none\") {\n node.error(\"User not found\")\n} else {\n node.send([msg,statusMsg])\n}",
"outputs": 2,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 220,
"y": 80,
"wires": [
[],
[]
],
"icon": "font-awesome/fa-user"
},
{ {
"id": "7fc67fc156c0f4be", "id": "7fc67fc156c0f4be",
"type": "api-call-service", "type": "api-call-service",
@ -15613,10 +15703,10 @@
"y": 680, "y": 680,
"wires": [ "wires": [
[ [
"11aabd786c07244f",
"ea5306d6f92d9550", "ea5306d6f92d9550",
"d6e7197427bb4d1b", "d6e7197427bb4d1b",
"bd6bdc6ed9aded9d" "bd6bdc6ed9aded9d",
"3bd0a22c66de228a"
] ]
] ]
}, },
@ -15701,10 +15791,10 @@
"y": 860, "y": 860,
"wires": [ "wires": [
[ [
"11aabd786c07244f",
"ea5306d6f92d9550", "ea5306d6f92d9550",
"d6e7197427bb4d1b", "d6e7197427bb4d1b",
"bd6bdc6ed9aded9d" "bd6bdc6ed9aded9d",
"3bd0a22c66de228a"
] ]
] ]
}, },
@ -15769,28 +15859,6 @@
], ],
"l": false "l": false
}, },
{
"id": "11aabd786c07244f",
"type": "function",
"z": "47f17992fab9b4f5",
"g": "550e5b2d99316b12",
"name": "user conversion",
"func": "const userTrigger = msg.payload.context.user_id\n\nif (userTrigger === \"c3909d27048140729f002aaef0391775\") {\n msg.user = \"tony\"\n} else if (userTrigger === \"f387a983651a4321a7411ff8cf36f949\") {\n msg.user = \"tina\"\n} else if (userTrigger === \"879b4c04e32841b3ad1d2763a11b4e70\") {\n msg.user = \"kallen\"\n}\n\nreturn msg;",
"outputs": 1,
"timeout": "",
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 275,
"y": 860,
"wires": [
[
"73078f818abdc6c2"
]
],
"l": false
},
{ {
"id": "795c53ad6642733a", "id": "795c53ad6642733a",
"type": "api-call-service", "type": "api-call-service",
@ -17464,6 +17532,21 @@
], ],
"icon": "node-red-contrib-huemagic/hue-temperature.svg" "icon": "node-red-contrib-huemagic/hue-temperature.svg"
}, },
{
"id": "3bd0a22c66de228a",
"type": "subflow:ea629141206d5343",
"z": "47f17992fab9b4f5",
"g": "550e5b2d99316b12",
"name": "",
"x": 265,
"y": 860,
"wires": [
[
"73078f818abdc6c2"
]
],
"l": false
},
{ {
"id": "091390f43bfeddf5", "id": "091390f43bfeddf5",
"type": "api-call-service", "type": "api-call-service",
@ -28468,12 +28551,20 @@
"debugenabled": false, "debugenabled": false,
"outputs": 1, "outputs": 1,
"entityConfig": "675dd216a61c575b", "entityConfig": "675dd216a61c575b",
"outputProperties": [], "outputProperties": [
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"x": 130, "x": 130,
"y": 60, "y": 60,
"wires": [ "wires": [
[ [
"a6234b2047ba3116" "c66df253518a4507",
"6d9c53b7dd7b0cf3"
] ]
] ]
}, },
@ -28490,12 +28581,12 @@
"initialize": "const needsReponseLabel = 213\nconst typeBugLabel = 196\nconst typeEnhancementLabel = 198\nconst typeAdjustmentLabel = 208\n\nflow.set(\"needsReponseLabel\", needsReponseLabel, \"diskCon\")\nflow.set(\"typeBugLabel\", typeBugLabel, \"diskCon\")\nflow.set(\"typeEnhancementLabel\", typeEnhancementLabel, \"diskCon\")\nflow.set(\"typeAdjustmentLabel\", typeAdjustmentLabel, \"diskCon\")", "initialize": "const needsReponseLabel = 213\nconst typeBugLabel = 196\nconst typeEnhancementLabel = 198\nconst typeAdjustmentLabel = 208\n\nflow.set(\"needsReponseLabel\", needsReponseLabel, \"diskCon\")\nflow.set(\"typeBugLabel\", typeBugLabel, \"diskCon\")\nflow.set(\"typeEnhancementLabel\", typeEnhancementLabel, \"diskCon\")\nflow.set(\"typeAdjustmentLabel\", typeAdjustmentLabel, \"diskCon\")",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 310, "x": 530,
"y": 60, "y": 60,
"wires": [ "wires": [
[ [
"9e43408e18883dfe", "9e43408e18883dfe",
"7674185d1e5ee489" "d31d41f3e474e0c1"
] ]
], ],
"icon": "node-red-contrib-cpu/cpu.png" "icon": "node-red-contrib-cpu/cpu.png"
@ -28526,7 +28617,7 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "input_select", "domain": "input_select",
"service": "select_option", "service": "select_option",
"x": 670, "x": 890,
"y": 60, "y": 60,
"wires": [ "wires": [
[] []
@ -28558,7 +28649,7 @@
"blockInputOverrides": false, "blockInputOverrides": false,
"domain": "input_text", "domain": "input_text",
"service": "set_value", "service": "set_value",
"x": 490, "x": 710,
"y": 60, "y": 60,
"wires": [ "wires": [
[ [
@ -28572,17 +28663,18 @@
"z": "873eb2575d6e9014", "z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54", "g": "50e4d951ee7b3e54",
"name": "Prep API data", "name": "Prep API data",
"func": "const needsReponseLabel = flow.get(\"needsReponseLabel\", \"diskCon\")\nconst typeBugLabel = flow.get(\"typeBugLabel\", \"diskCon\")\nconst typeEnhancementLabel = flow.get(\"typeEnhancementLabel\", \"diskCon\")\nconst typeAdjustmentLabel = flow.get(\"typeAdjustmentLabel\", \"diskCon\")\nconst title = msg.text\nconst type = msg.type\n\nlet labels = [needsReponseLabel]\nlet formatType = {}\n\nif (type === 'Bug Report') {\n labels.push(typeBugLabel)\n formatType = \"[Bug]\"\n} else if (type === 'New Idea') {\n labels.push(typeEnhancementLabel)\n formatType = \"[Feature Request]\"\n} else if (type === 'Adjustment') {\n labels.push(typeAdjustmentLabel)\n formatType = \"[Adjustment Request]\"\n}\n\nlet newTitle = `${formatType}: ${title}`\n\nmsg.payload = {\n \"title\": newTitle,\n \"body\": \"This issue was submitted by the automated form on the main Home Assistant dashboard\",\n \"assignees\":[\"tm24fan8\"],\n \"labels\": labels\n}\n\nnode.status({fill:'green',shape:'dot',text:'API data prepped'})\nreturn msg", "func": "const needsReponseLabel = flow.get(\"needsReponseLabel\", \"diskCon\")\nconst typeBugLabel = flow.get(\"typeBugLabel\", \"diskCon\")\nconst typeEnhancementLabel = flow.get(\"typeEnhancementLabel\", \"diskCon\")\nconst typeAdjustmentLabel = flow.get(\"typeAdjustmentLabel\", \"diskCon\")\nconst title = msg.text\nconst type = msg.type\nconst user = msg.user\n\nlet labels = [needsReponseLabel]\nlet formatType = {}\n\nif (type === 'Bug Report') {\n labels.push(typeBugLabel)\n formatType = \"[Bug]\"\n} else if (type === 'New Idea') {\n labels.push(typeEnhancementLabel)\n formatType = \"[Feature Request]\"\n} else if (type === 'Adjustment') {\n labels.push(typeAdjustmentLabel)\n formatType = \"[Adjustment Request]\"\n}\n\nlet newTitle = `${formatType}: ${title}`\n\nmsg.payload = {\n \"title\": newTitle,\n \"body\": `This issue was submitted by ${user.firstName} ${user.lastName}, using the automated form on the main Home Assistant dashboard`,\n \"assignees\":[\"tm24fan8\"],\n \"labels\": labels\n}\n\nnode.status({fill:'green',shape:'dot',text:'API data prepped'})\nreturn msg",
"outputs": 1, "outputs": 1,
"timeout": "", "timeout": "",
"noerr": 0, "noerr": 0,
"initialize": "", "initialize": "",
"finalize": "", "finalize": "",
"libs": [], "libs": [],
"x": 500, "x": 720,
"y": 120, "y": 120,
"wires": [ "wires": [
[ [
"f8330684e1ccac8d",
"84c8fd3cc1ab7cf1" "84c8fd3cc1ab7cf1"
] ]
] ]
@ -28604,12 +28696,190 @@
"authType": "basic", "authType": "basic",
"senderr": false, "senderr": false,
"headers": [], "headers": [],
"x": 940,
"y": 120,
"wires": [
[
"ea0bab7efe2d570d",
"a64cee24cd3523c5"
]
]
},
{
"id": "c66df253518a4507",
"type": "subflow:ea629141206d5343",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "",
"x": 330,
"y": 60,
"wires": [
[
"a6234b2047ba3116",
"c5e85490ce1d4a57"
]
]
},
{
"id": "ea0bab7efe2d570d",
"type": "debug",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "HTTP Request",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1160,
"y": 200,
"wires": []
},
{
"id": "d31d41f3e474e0c1",
"type": "debug",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "Processing Data",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 720, "x": 720,
"y": 200,
"wires": []
},
{
"id": "f8330684e1ccac8d",
"type": "debug",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "API Data",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 940,
"y": 200,
"wires": []
},
{
"id": "6d9c53b7dd7b0cf3",
"type": "debug",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "Button",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 290,
"y": 200,
"wires": []
},
{
"id": "2b6f06b27b6deb92",
"type": "api-call-service",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "Text Notify",
"server": "9e87348d.9c1c48",
"version": 7,
"debugenabled": false,
"action": "script.text_notify",
"floorId": [],
"areaId": [],
"deviceId": [],
"entityId": [],
"labelId": [],
"data": "{\t \"type\": \"alert\",\t \"who\": \"tony\",\t \"title\": title,\t \"message\": message,\t \"actions\": actions\t}",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"blockInputOverrides": false,
"domain": "script",
"service": "text_notify",
"x": 1370,
"y": 120, "y": 120,
"wires": [ "wires": [
[] []
] ]
}, },
{
"id": "a64cee24cd3523c5",
"type": "function",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "Notification Setup",
"func": "const statusCode = msg.statusCode\nconst issueNumber = msg.payload.number\nconst issueTitle = msg.payload.title\nconst url = msg.payload.html_url\nconst user = msg.user\n\nlet notification = {\n \"title\": \"Issue Submitted\",\n \"message\": `${user.firstName} ${user.lastName} submitted a new issue: #${issueNumber} - ${issueTitle}`,\n \"actions\": [\n {\n \"action\": \"URI\",\n \"uri\": url,\n \"title\": \"View Issue\"\n }\n ]\n}\n\nnode.send(notification)\nnode.status({fill:'green',shape:'dot',text:`Issue #${issueNumber} notification sent`})",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1170,
"y": 120,
"wires": [
[
"2b6f06b27b6deb92",
"e2e2d2fb7277cde3"
]
]
},
{
"id": "e2e2d2fb7277cde3",
"type": "debug",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "Notification",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 1370,
"y": 200,
"wires": []
},
{
"id": "c5e85490ce1d4a57",
"type": "debug",
"z": "873eb2575d6e9014",
"g": "50e4d951ee7b3e54",
"name": "User",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 510,
"y": 200,
"wires": []
},
{ {
"id": "5d7c63526234945e", "id": "5d7c63526234945e",
"type": "api-render-template", "type": "api-render-template",
@ -33299,6 +33569,50 @@
] ]
] ]
}, },
{
"id": "430d9054095580f1",
"type": "inject",
"z": "3e4ba157b540d183",
"g": "fc9cdd0818afd119",
"name": "",
"props": [
{
"p": "tony",
"v": "c3909d27048140729f002aaef0391775",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": "30",
"topic": "",
"x": 130,
"y": 1140,
"wires": [
[
"7b2670a81b8d3967"
]
]
},
{
"id": "7b2670a81b8d3967",
"type": "function",
"z": "3e4ba157b540d183",
"g": "fc9cdd0818afd119",
"name": "User ID List",
"func": "let userIDList = {\n \"c3909d27048140729f002aaef0391775\": {\n \"shortName\": \"tony\",\n \"firstName\": \"Tony\",\n \"lastName\": \"Stork\",\n \"hassUser\": \"tonystork\"\n },\n \"f387a983651a4321a7411ff8cf36f949\": {\n \"shortName\": \"tina\",\n \"firstName\": \"Christina\",\n \"lastName\": \"Stork\",\n \"hassUser\": \"christinastork\"\n },\n \"879b4c04e32841b3ad1d2763a11b4e70\": {\n \"shortName\": \"kallen\",\n \"firstName\": \"Kallen\",\n \"lastName\": \"Stork\",\n \"hassUser\": \"kallenstork\"\n }\n}\n\nglobal.set(\"userIDList\",userIDList,\"diskCon\")",
"outputs": 0,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 330,
"y": 1140,
"wires": [],
"icon": "font-awesome/fa-user"
},
{ {
"id": "e038489eca14b1dd", "id": "e038489eca14b1dd",
"type": "discordMessage", "type": "discordMessage",