collector-etc/NodeRed-API.json

683 lines
21 KiB
JSON

[
{
"id": "5f82d0265a7780fe",
"type": "tab",
"label": "Plurality Reality",
"disabled": false,
"info": ""
},
{
"id": "a4f9a1d4dc0bed16",
"type": "junction",
"z": "5f82d0265a7780fe",
"x": 600,
"y": 360,
"wires": [
[
"485fbb51070dc89d",
"097b153e6e371842",
"36cdf90159b3cdb3",
"5e41df8e716cb6e7",
"26c5134882c95d99",
"be99c4b93f8b31ca",
"db81d439bf71bd2e"
]
]
},
{
"id": "f8677e4020d3227c",
"type": "junction",
"z": "5f82d0265a7780fe",
"x": 220,
"y": 160,
"wires": [
[
"4e1d9fc4f01dcd0a",
"bd1a9ca4c8a3be31"
]
]
},
{
"id": "b65c5c782a7c405d",
"type": "http in",
"z": "5f82d0265a7780fe",
"name": "Switch endpoint",
"url": "/switch",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 120,
"y": 100,
"wires": [
[
"f8677e4020d3227c",
"2b39c6f59be83971"
]
]
},
{
"id": "4e1d9fc4f01dcd0a",
"type": "http response",
"z": "5f82d0265a7780fe",
"name": "",
"statusCode": "",
"headers": {},
"x": 310,
"y": 180,
"wires": []
},
{
"id": "bd1a9ca4c8a3be31",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Pluralkit",
"func": "\nconst AllowedTokens = [\n \"CUSTOM_API_KEY\",\n \"CUSTOM_API_KEY\"\n];\n\nif (typeof msg.payload.token !== \"string\"){\n return [null, null];\n}\nif (!AllowedTokens.includes(msg.payload.token)){\n return [null, null];\n}\n\nlet debugRun = false;\nif (typeof msg.payload.debug !== 'undefined'){\n debugRun = (msg.payload.debug);\n}\n\nmsg.payload.token = undefined;\n\nlet PK = global.get('pk').default;\nlet p = new PK({\n base_url: \"https://api.pluralkit.me\",\n version: 2,\n token: \"PLURALKIT_API_KEY\"\n});\nlet cray = await p.getSystem({\n system: \"zyucn\"\n})\nlet fronters = [];\nlet newFronter = false;\nif (typeof msg.payload.members != 'undefined'){\n fronters = msg.payload.members;\n let currentFronters = await cray.getFronters();\n if (currentFronters.members.size != fronters.length){\n newFronter = true; // Additional/Removed Fronter\n }else{\n currentFronters.members.forEach(mem => {\n if (!fronters.includes(mem.id)){\n newFronter = true; //New Fronter\n }\n });\n if (Array.from(currentFronters.members)[0].id != fronters[0]){\n newFronter = true; //New fronter order\n }\n }\n if (newFronter){\n await cray.createSwitch({\n members: fronters\n });\n }\n}\n\nmsg.payload = fronters;\nmsg.debugRun = debugRun;\nreturn [msg, (newFronter?msg:null)];",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 320,
"y": 140,
"wires": [
[
"4bfc82c4b478ca10"
],
[
"66b4b7d2b57038f0"
]
]
},
{
"id": "4bfc82c4b478ca10",
"type": "debug",
"z": "5f82d0265a7780fe",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 490,
"y": 140,
"wires": []
},
{
"id": "290374deba671a83",
"type": "http request",
"z": "5f82d0265a7780fe",
"name": "Pusher",
"method": "POST",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://PUSHER_API_KEY.pushnotifications.pusher.com/publish_api/v1/instances/PUSHER_API_KEY/publishes",
"tls": "",
"persist": false,
"proxy": "",
"authType": "bearer",
"x": 940,
"y": 160,
"wires": [
[]
],
"icon": "node-red/inject.svg"
},
{
"id": "66b4b7d2b57038f0",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Switch Alert",
"func": "//TODO: Handle null\n\nlet PK = global.get('pk').default;\nlet p = new PK({\n base_url: \"https://api.pluralkit.me\",\n version: 2,\n token: \"PLUEALKIT_API_KEY\"\n});\nlet cray = await p.getSystem({\n system: \"zyucn\"\n})\nlet fronters = await cray.getFronters();\n\nflow.set(\"members\", JSON.stringify(Array.from(fronters.members, (member) => {\n return member[1];\n})))\n\nlet bodyMsg = \"\";\nif (fronters.members.size == 0){\n fronters.members = [\n {\n id: \"\",\n name: \"No one\"\n }\n ];\n}\nmsg.pkit = fronters.members;\nfronters.members.forEach(member => {\n bodyMsg += \" & \" + member.name;\n});\nbodyMsg = bodyMsg.slice(3);\nbodyMsg += \" \" + (bodyMsg.includes(\"&\")?\"are\":\"is\") + \" now fronting.\";\nmsg.payload = bodyMsg;\n\nlet fronterList = \"\";\nfronters.members.forEach(member => {\n fronterList += member.name + \", \";\n});\nfronterList = fronterList.slice(0, -2);\nmsg.fronter = fronterList;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 510,
"y": 180,
"wires": [
[
"a4f9a1d4dc0bed16"
]
]
},
{
"id": "432e1801bd8996b7",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Pluralkit Template",
"func": "let PK = global.get('pk').default;\nlet p = new PK({\n base_url: \"https://api.pluralkit.me\",\n version: 2,\n token: \"PLURALKIT_API_KEY\"\n});\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 350,
"y": 100,
"wires": [
[]
]
},
{
"id": "ab8165c02bbaf688",
"type": "telegram sender",
"z": "5f82d0265a7780fe",
"name": "",
"bot": "e9716457749e0eb5",
"haserroroutput": false,
"outputs": 1,
"x": 1130,
"y": 260,
"wires": [
[]
]
},
{
"id": "ef69abf209f5bc4a",
"type": "telegram command",
"z": "5f82d0265a7780fe",
"name": "/sub",
"command": "/subscribe",
"description": "Subscribe to Cray's system notifications",
"registercommand": true,
"language": "en",
"scope": "all_private_chats",
"bot": "e9716457749e0eb5",
"strict": false,
"hasresponse": false,
"useregex": false,
"removeregexcommand": false,
"outputs": 1,
"x": 110,
"y": 220,
"wires": [
[
"cda5079172bbf006"
]
]
},
{
"id": "4ad3123e9c534458",
"type": "mongodb4",
"z": "5f82d0265a7780fe",
"clientNode": "e26a1e35ae350282",
"collection": "subscribers",
"operation": "find",
"output": "toArray",
"name": "Find Subs",
"x": 920,
"y": 260,
"wires": [
[
"ea94c5e41f4d82c6"
]
]
},
{
"id": "3fcb838dfeaed9fe",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Assemble Tele",
"func": "\nmsg.payload = {\n chatId: msg.payload.telegramId,\n type: \"message\",\n content: msg.content\n};\n//DEBUGGING\nif (msg.debugRun){\n msg.payload.chatId = DEVID; \n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1140,
"y": 220,
"wires": [
[
"ab8165c02bbaf688"
]
]
},
{
"id": "ea94c5e41f4d82c6",
"type": "split",
"z": "5f82d0265a7780fe",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 990,
"y": 220,
"wires": [
[
"3fcb838dfeaed9fe"
]
]
},
{
"id": "cda5079172bbf006",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Process Current DB",
"func": "let telegramId = msg.originalMessage.chat.id;\n\n// Add to subscriptions\nmsg.payload = [{\n telegramId: telegramId\n}];\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 260,
"y": 260,
"wires": [
[
"155db78cc9ff74ba"
]
]
},
{
"id": "155db78cc9ff74ba",
"type": "mongodb4",
"z": "5f82d0265a7780fe",
"clientNode": "e26a1e35ae350282",
"collection": "subscribers",
"operation": "insertOne",
"output": "toArray",
"name": "Subscribe",
"x": 240,
"y": 300,
"wires": [
[
"db62b4e61870f27f"
]
]
},
{
"id": "db62b4e61870f27f",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Generate Response Message",
"func": "\nlet telegramId = msg.originalMessage.chat.id;\n\n// Add to subscriptions\nmsg.payload = {\n chatId: telegramId,\n type: \"message\",\n content: \"Subscribed to the Cray system\"\n};\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 290,
"y": 340,
"wires": [
[
"f71b982f74da5540"
]
]
},
{
"id": "f71b982f74da5540",
"type": "telegram sender",
"z": "5f82d0265a7780fe",
"name": "",
"bot": "e9716457749e0eb5",
"haserroroutput": false,
"outputs": 1,
"x": 250,
"y": 380,
"wires": [
[]
]
},
{
"id": "a75ca0dc2d7aac4c",
"type": "websocket out",
"z": "5f82d0265a7780fe",
"name": "Fronter Socket",
"server": "edb292d97a0b097a",
"client": "",
"x": 1000,
"y": 420,
"wires": []
},
{
"id": "2636a3a89b7f5519",
"type": "websocket in",
"z": "5f82d0265a7780fe",
"name": "",
"server": "edb292d97a0b097a",
"client": "",
"x": 790,
"y": 420,
"wires": [
[
"a75ca0dc2d7aac4c"
]
]
},
{
"id": "36cdf90159b3cdb3",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Assemble Web",
"func": "// Assemble for web notifications\nmsg.payload = JSON.stringify({\n interests: [\n \"cray_system\"\n ],\n web: {\n notification: {\n title: \"Cray System\",\n body: msg.payload\n }\n }\n});\nmsg.headers = {\n 'Content-Type': 'application/json'\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 780,
"y": 160,
"wires": [
[
"290374deba671a83"
]
]
},
{
"id": "485fbb51070dc89d",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Assemble Telegram",
"func": "// Assemble for Telegram Notifications\nmsg.content = msg.payload;\nmsg.payload = [{\n}];\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 220,
"wires": [
[
"4ad3123e9c534458"
]
]
},
{
"id": "26c5134882c95d99",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Assemble Socket",
"func": "// Assemble Socket Data\nlet fronters = JSON.parse(flow.get(\"members\"))\nif (fronters.length > 0){\n msg.payload = fronters[0].id\n}else{\n msg.payload = \"null\"\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 380,
"wires": [
[
"a75ca0dc2d7aac4c"
]
]
},
{
"id": "5e41df8e716cb6e7",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Discord Profile",
"func": "\nmsg.text = msg.fronter;\nmsg.status = msg.fronter;\n// TODO: Set emoji based on fronter\nmsg.icon = \"🏳️‍🌈\";\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 780,
"y": 100,
"wires": [
[
"4a5bf45282ba0390"
]
]
},
{
"id": "097b153e6e371842",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "TODO: Discord Bot",
"func": "\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 790,
"y": 320,
"wires": [
[
"05d1850f5b804e20"
]
]
},
{
"id": "4a5bf45282ba0390",
"type": "discordStatus",
"z": "5f82d0265a7780fe",
"token": "",
"statusType": "msg",
"customContent": "text",
"icon": "msg.icon",
"stt": "online",
"x": 960,
"y": 100,
"wires": [
[]
]
},
{
"id": "be99c4b93f8b31ca",
"type": "hb-status",
"z": "5f82d0265a7780fe",
"name": "Door",
"Homebridge": "homebridge",
"Manufacturer": "MagicHome",
"Service": "Lightbulb",
"device": "homebridgeEA:HOMERGB",
"conf": "588152ebedcf9ddf",
"x": 750,
"y": 480,
"wires": [
[
"997a912f8abfe9f4"
]
]
},
{
"id": "05d1850f5b804e20",
"type": "debug",
"z": "5f82d0265a7780fe",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 970,
"y": 320,
"wires": []
},
{
"id": "997a912f8abfe9f4",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Smart Home Lookup",
"func": "// Shift current light config into msg object\nmsg.light = msg.payload\n\nconst RGBToHSB = (r, g, b) => {\n r /= 255;\n g /= 255;\n b /= 255;\n const v = Math.max(r, g, b),\n n = v - Math.min(r, g, b);\n const h =\n n === 0 ? 0 : n && v === r ? (g - b) / n : v === g ? 2 + (b - r) / n : 4 + (r - g) / n;\n return [60 * (h < 0 ? h + 6 : h), v && (n / v) * 100, v * 100];\n};\n\nlet fronters = JSON.parse(flow.get(\"members\"))\n\n\nif (typeof fronters == 'object'){\n if (fronters[0].color != null){\n let memberColor = {\n r: Number(`0x${fronters[0].color.slice(0, -4)}`),\n g: Number(`0x${fronters[0].color.slice(2, -2)}`),\n b: Number(`0x${fronters[0].color.slice(4)}`)\n }\n memberColor = RGBToHSB(memberColor.r, memberColor.g, memberColor.b)\n memberColor = {\n Saturation: memberColor[1],\n On: 1,\n // Brightness: memberColor[2],\n Brightness: msg.light.Brightness,\n Hue: memberColor[0]\n }\n let doorColor = null\n if (msg.light.On == 1){\n doorColor = msg\n doorColor.payload = memberColor\n }\n let gemColor = msg\n gemColor.payload = memberColor\n msg = [doorColor, gemColor]\n }else{\n msg = null\n }\n}else{\n msg = null\n}\nreturn msg",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 920,
"y": 480,
"wires": [
[
"3af0892eda3373b1"
],
[
"fad5f43e466bdb2c"
]
]
},
{
"id": "3af0892eda3373b1",
"type": "hb-control",
"z": "5f82d0265a7780fe",
"name": "Door",
"Homebridge": "homebridge",
"Manufacturer": "MagicHome",
"Service": "Lightbulb",
"device": "homebridgeEA:HOMERGB",
"conf": "588152ebedcf9ddf",
"outputs": 1,
"x": 1210,
"y": 460,
"wires": [
[]
]
},
{
"id": "fad5f43e466bdb2c",
"type": "hb-control",
"z": "5f82d0265a7780fe",
"name": "Gem",
"Homebridge": "homebridge",
"Manufacturer": "Corrupt Link",
"Service": "Lightbulb",
"device": "homebridgeEA:RGBLIGHT",
"conf": "588152ebedcf9ddf",
"outputs": 1,
"x": 1090,
"y": 480,
"wires": [
[]
]
},
{
"id": "4d2da22298fe3d41",
"type": "sms",
"z": "5f82d0265a7780fe",
"d": true,
"name": "Phone Trigger",
"message": "",
"numbers": "[\"+15550201234\"]",
"throttle": 1000,
"twilio": "021ccf289ebca7ec",
"x": 1020,
"y": 540,
"wires": [
[]
]
},
{
"id": "db81d439bf71bd2e",
"type": "function",
"z": "5f82d0265a7780fe",
"name": "Phone Shortcut Triger",
"func": "let fronters = JSON.parse(flow.get(\"members\"))\nif (typeof fronters == 'object'){\n if (fronters.length > 0){\n msg.payload = fronters[0].id\n msg.topic = \"SWITCH\"\n node.send(msg)\n }\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 800,
"y": 540,
"wires": [
[
"4d2da22298fe3d41",
"dbe287bc2eb9f964"
]
]
},
{
"id": "dbe287bc2eb9f964",
"type": "e-mail",
"z": "5f82d0265a7780fe",
"d": true,
"server": "smtp.example.com",
"port": "465",
"authtype": "BASIC",
"saslformat": true,
"token": "oauth2Response.access_token",
"secure": true,
"tls": true,
"name": "test@mail.com",
"dname": "Email Trigger",
"x": 1010,
"y": 600,
"wires": []
},
{
"id": "2b39c6f59be83971",
"type": "debug",
"z": "5f82d0265a7780fe",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 310,
"y": 40,
"wires": []
},
{
"id": "e9716457749e0eb5",
"type": "telegram bot",
"botname": "plural_bot",
"usernames": "",
"chatids": "",
"baseapiurl": "",
"updatemode": "polling",
"pollinterval": "300",
"usesocks": false,
"sockshost": "",
"socksport": "6667",
"socksusername": "anonymous",
"sockspassword": "",
"bothost": "",
"botpath": "",
"localbotport": "8443",
"publicbotport": "8443",
"privatekey": "",
"certificate": "",
"useselfsignedcertificate": false,
"sslterminated": false,
"verboselogging": false
},
{
"id": "e26a1e35ae350282",
"type": "mongodb4-client",
"name": "Plurality",
"protocol": "mongodb",
"hostname": "192.0.0.10",
"port": "27017",
"dbName": "plurality",
"authSource": "",
"authMechanism": "DEFAULT",
"tls": false,
"tlsCAFile": "",
"tlsInsecure": false,
"uri": "",
"advanced": "",
"uriTabActive": "tab-uri-simple"
},
{
"id": "edb292d97a0b097a",
"type": "websocket-listener",
"path": "/switch/fronter",
"wholemsg": "false"
},
{
"id": "588152ebedcf9ddf",
"type": "hb-conf",
"username": "999-69-666",
"macAddress": ""
},
{
"id": "021ccf289ebca7ec",
"type": "twilioConfig",
"name": "twilioConfig"
}
]