-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelegramTAK.json
1 lines (1 loc) · 15.5 KB
/
telegramTAK.json
1
[{"id":"65930269.15cc9c","type":"tab","label":"TelegramTAK 2.0","disabled":false,"info":"Connects to FTS emergency and send a Telegram location and a message to a specific Telegram group chat. From a same chat, you ca create an emergency OR send a regular chat to all in FTS."},{"id":"527a0337.e9e60c","type":"telegram sender","z":"65930269.15cc9c","name":"Send emergency","bot":"ce1eb260.b0f65","haserroroutput":true,"outputs":2,"x":1450,"y":160,"wires":[[],["4ba9fda5.a6c0a4"]]},{"id":"94eac137.12f37","type":"function","z":"65930269.15cc9c","name":"send location","func":"let longitude;\n let latitude;\nlet item = msg.payload;\nglobal.set(\"BOT_TOKEN\")\nmsg.payload = [];\n\n longitude =item[\"lon\"];\n latitude= item[\"lat\"];\n \nmsg.payload = {}\n\n\n\n msg.payload.chatId = global.get('ChatId');\nmsg.payload.type = 'location';\nmsg.payload.content={\n 'longitude': longitude,\n 'latitude': latitude\n };\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1230,"y":140,"wires":[["527a0337.e9e60c"]]},{"id":"a8841cc3.b2a3","type":"http request","z":"65930269.15cc9c","name":"Get emergencies","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"bearer","x":470,"y":140,"wires":[["54bac6d2.534fa8","d8312c48.46df7"]]},{"id":"54bac6d2.534fa8","type":"json","z":"65930269.15cc9c","name":"transform to Json","property":"payload","action":"","pretty":false,"x":650,"y":180,"wires":[["d8312c48.46df7","c45a3e91.decab"]]},{"id":"d8312c48.46df7","type":"debug","z":"65930269.15cc9c","name":"Json Payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":640,"y":60,"wires":[]},{"id":"c45a3e91.decab","type":"split","z":"65930269.15cc9c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":810,"y":140,"wires":[["2ad6b66e.507eaa","10854496.29664b"]]},{"id":"2ad6b66e.507eaa","type":"debug","z":"65930269.15cc9c","name":"","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":940,"y":40,"wires":[]},{"id":"4ba9fda5.a6c0a4","type":"debug","z":"65930269.15cc9c","name":"after function","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1670,"y":200,"wires":[]},{"id":"c50a8457.29c528","type":"split","z":"65930269.15cc9c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1090,"y":140,"wires":[["94eac137.12f37","9f131823.c13a48"]]},{"id":"9f131823.c13a48","type":"function","z":"65930269.15cc9c","name":"send text","func":"let longitude;\n let latitude;\n let name;\n let type;\n let message1 = 'you have an emergency!\\n';\n let message2 = ' is ';\n let message3 = '\\n Latitude: ';\n let message4 = '\\n longitude: ';\n \nlet item = msg.payload;\nmsg.payload = [];\n\n var i;\n\n name = item[\"name\"];\n type = item[\"type\"];\n longitude =item[\"lon\"];\n latitude= item[\"lat\"];\n \nmsg.payload = {}\n\n\nmsg.payload.chatId = global.get('ChatId');\nmsg.payload.type = 'message';\nmsg.payload.content = message1 + name + message2 + type + message3 + latitude + message4 + longitude;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1240,"y":180,"wires":[["527a0337.e9e60c"]]},{"id":"10854496.29664b","type":"switch","z":"65930269.15cc9c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"empty"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":950,"y":140,"wires":[["e9d37ecc.a0f7e"],["c50a8457.29c528","52558b56.b545a4"]]},{"id":"e9d37ecc.a0f7e","type":"debug","z":"65930269.15cc9c","name":"empty!","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":80,"wires":[]},{"id":"52558b56.b545a4","type":"debug","z":"65930269.15cc9c","name":"Full!","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":200,"wires":[]},{"id":"944c2260.00c8","type":"telegram receiver","z":"65930269.15cc9c","name":"FTHPub","bot":"ce1eb260.b0f65","saveDataDir":"","filterCommands":false,"x":160,"y":400,"wires":[["dff2b0fd.79b22","b49c9910.d6e7d8"],["395d01ff.503aae"]]},{"id":"395d01ff.503aae","type":"debug","z":"65930269.15cc9c","name":"no way!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":360,"y":480,"wires":[]},{"id":"39315d29.071eb2","type":"debug","z":"65930269.15cc9c","name":"REST emergency","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":240,"wires":[]},{"id":"986f6f30.6df84","type":"function","z":"65930269.15cc9c","name":"Emergency message","func":"msg.url = global.get(\"FTH_FTS_URL\");\nmsg.port = global.get('FTH_FTS_API_Port');\nvar ChatEndpoint = global.get(\"ChatId\");\nmsg.url= \"http://\"+msg.url +\":\"+msg.port.toString() +\"/ManageEmergency/postEmergency\";\n\n\n\n\nvar latitude = msg.payload.content.latitude;\nvar longitude = msg.payload.content.longitude;\n// var name = msg.payload.from.username;\nvar name=msg.originalMessage.from.first_name;\nvar emergencyType= \"In Contact\";\nmsg.payload={name, emergencyType, latitude, longitude };\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":320,"wires":[["39315d29.071eb2","84068f.3371697"]]},{"id":"dff2b0fd.79b22","type":"debug","z":"65930269.15cc9c","name":"original","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":380,"y":280,"wires":[]},{"id":"84068f.3371697","type":"http request","z":"65930269.15cc9c","name":"Post emergency to FTS","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"bearer","x":890,"y":340,"wires":[["3c5d43c7.1ad6cc"]]},{"id":"3c5d43c7.1ad6cc","type":"debug","z":"65930269.15cc9c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1090,"y":300,"wires":[]},{"id":"b49c9910.d6e7d8","type":"switch","z":"65930269.15cc9c","name":"switch message types","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"location","vt":"str"},{"t":"eq","v":"message","vt":"str"},{"t":"eq","v":"document","vt":"str"},{"t":"eq","v":"photo","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":5,"x":420,"y":400,"wires":[["986f6f30.6df84","39315d29.071eb2"],["571fd398.5c4f7c"],["4f045dbf.8418c4"],["7ee7ca83.178104"],["f1f2a71d.7dfe48"]]},{"id":"285ab342.0e00fc","type":"http request","z":"65930269.15cc9c","name":"Post Chat to FTS","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://{{{url}}}:{{{port}}}/ManageChat/postChatToAll","tls":"","persist":false,"proxy":"","authType":"bearer","x":870,"y":460,"wires":[["11fee39b.ff9c9c"]]},{"id":"571fd398.5c4f7c","type":"function","z":"65930269.15cc9c","name":"Chat Message","func":"msg.url = global.get(\"FTH_FTS_URL\");\n msg.port = global.get('FTH_FTS_API_Port');\n\nif(msg.payload.type='message') \n{\n\n // var name = msg.payload.from.username;\n var sender=msg.originalMessage.from.username;\n //var message= msg.payload.text;\n var message= msg.originalMessage.text\n msg.payload={sender, message};\n return msg;\n}\nelse \n{\n return null;\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":440,"wires":[["285ab342.0e00fc","d88c8cfc.eac9e"]]},{"id":"f1f2a71d.7dfe48","type":"debug","z":"65930269.15cc9c","name":"otherwise","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":620,"y":580,"wires":[]},{"id":"d88c8cfc.eac9e","type":"debug","z":"65930269.15cc9c","name":"REST chat","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":400,"wires":[]},{"id":"e0c52793.956cc8","type":"catch","z":"65930269.15cc9c","name":"","scope":null,"uncaught":false,"x":120,"y":660,"wires":[["70a8bc92.516f04"]]},{"id":"70a8bc92.516f04","type":"debug","z":"65930269.15cc9c","name":"TelegramTAK exception","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":350,"y":660,"wires":[]},{"id":"4f045dbf.8418c4","type":"debug","z":"65930269.15cc9c","name":"Document","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":380,"wires":[]},{"id":"7ee7ca83.178104","type":"function","z":"65930269.15cc9c","name":"Prepare Get Photo URL","func":"var photo = msg.originalMessage.photo;\nmsg.file_id = photo[photo.length-1].file_id; // get the largest photo\nmsg.token = '1494779202:AAE1Sb0RRfrBjnevVVgqh4f-0zSadsZoCQQ';\nmsg.sender=msg.originalMessage.from.username;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":500,"wires":[["48f478f2.e6f9c8","e0b77dda.8ba2d"]]},{"id":"48f478f2.e6f9c8","type":"http request","z":"65930269.15cc9c","name":"Get Photo URL","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.telegram.org/bot{{{token}}}/getFile?file_id={{{file_id}}}","tls":"","persist":false,"proxy":"","authType":"","x":880,"y":520,"wires":[["40380834.cfcc58","c28a3fe9.70a2c"]]},{"id":"c28a3fe9.70a2c","type":"function","z":"65930269.15cc9c","name":"Set to payload","func":"msg.filename = msg.payload.result.file_path.split('/')[1]\nmsg.url = 'https://api.telegram.org/file/bot' + msg.token + '/' + msg.payload.result.file_path;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1080,"y":520,"wires":[["3861a165.06e53e","c79bf75d.e540d8"]]},{"id":"3861a165.06e53e","type":"http request","z":"65930269.15cc9c","name":"request telegram pic","method":"GET","ret":"bin","paytoqs":"ignore","url":"{{{url}}}","tls":"6ab2056f.fa1a6c","persist":false,"proxy":"","authType":"","x":1300,"y":520,"wires":[["32145f92.cd646","cb5f2d26.e3e9f"]]},{"id":"32145f92.cd646","type":"zip","z":"65930269.15cc9c","name":"Zip content","mode":"compress","filename":"","compressionlevel":6,"outasstring":false,"x":1510,"y":520,"wires":[["c9475ca5.9007","8352b69a.412d78"]]},{"id":"ee621fc8.4165f","type":"http request","z":"65930269.15cc9c","name":"Post 2 FTS","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"bearer","x":1890,"y":340,"wires":[["11fee39b.ff9c9c"]]},{"id":"11fee39b.ff9c9c","type":"switch","z":"65930269.15cc9c","name":"check return","property":"payload.statusCode","propertyType":"msg","rules":[{"t":"eq","v":"200","vt":"str"},{"t":"eq","v":"500","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":1850,"y":460,"wires":[["ce459063.e3e26"],["193a758d.e998ba"],["739d6f4a.5224c"]]},{"id":"ce459063.e3e26","type":"debug","z":"65930269.15cc9c","name":"Success!","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":2060,"y":400,"wires":[]},{"id":"193a758d.e998ba","type":"debug","z":"65930269.15cc9c","name":" INTERNAL SERVER ERROR","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2110,"y":460,"wires":[]},{"id":"739d6f4a.5224c","type":"debug","z":"65930269.15cc9c","name":"Issue","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2070,"y":520,"wires":[]},{"id":"8352b69a.412d78","type":"function","z":"65930269.15cc9c","name":"DP postdata gen","func":"const request = global.get('request');\nconst fs = global.get('fs');\n\nlet serverip = global.get('FTH_FTS_URL');\nlet serverport = global.get('FTH_FTS_API_Port');\nconsole.log(\"running\")\ntry{\n var name = msg.filename.split('.')\n name.pop()\n name = name.join('.')+'.zip'\n //console.log(name)\n node.warn(\"name is: =\" + name);\nvar options = {\n 'method': 'POST',\n 'url': \"http://\"+serverip +\":\"+serverport +\"/DataPackageTable?filename=\"+ name,\n 'headers': {\n 'Authorization': 'Bearer token'\n },\n formData: {\n 'assetfile': {\n 'value': msg.payload,\n 'options': {\n 'filename': name,\n 'contentType': \"application/x-zip-compressed\"\n }\n }\n }\n};\nconsole.log(\"making request\")\nawait request(options, function (error, response) {\n if (error) throw new Error(error);\n //console.log(response)\n msg.payload = response\n node.send(msg)\n node.done()\n node.log(\"done\")\n});\nreturn;\n}\ncatch(err){\n console.log('error encountered')\n console.log(err)\n msg.payload = err\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1710,"y":520,"wires":[["11fee39b.ff9c9c"]]},{"id":"40380834.cfcc58","type":"debug","z":"65930269.15cc9c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1070,"y":560,"wires":[]},{"id":"c9475ca5.9007","type":"debug","z":"65930269.15cc9c","name":"zip payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1710,"y":580,"wires":[]},{"id":"c79bf75d.e540d8","type":"debug","z":"65930269.15cc9c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"url","targetType":"msg","statusVal":"","statusType":"auto","x":1260,"y":560,"wires":[]},{"id":"e0b77dda.8ba2d","type":"debug","z":"65930269.15cc9c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":580,"wires":[]},{"id":"cb5f2d26.e3e9f","type":"debug","z":"65930269.15cc9c","name":"Telegram pic","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1510,"y":580,"wires":[]},{"id":"47da3bfe.5d12e4","type":"function","z":"65930269.15cc9c","name":"Configuration","func":"msg.url = `http://${global.get(\"FTH_FTS_URL\")}:${global.get('FTH_FTS_API_Port')}/ManageEmergency/getEmergency`;\nmsg.port = global.get('FTH_FTS_API_Port');\nmsg.payload.chatId = -1001297275903;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":140,"wires":[["a8841cc3.b2a3"]]},{"id":"26bcfb9e.619f64","type":"inject","z":"65930269.15cc9c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"900","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":140,"wires":[["47da3bfe.5d12e4"]]},{"id":"ce1eb260.b0f65","type":"telegram bot","botname":"FreeTAKServerNotification","usernames":"","chatids":"-1001297275903","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":true},{"id":"6ab2056f.fa1a6c","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]