Skip to content

Latest commit

 

History

History
77 lines (55 loc) · 27.1 KB

telegram.md

File metadata and controls

77 lines (55 loc) · 27.1 KB

Build an aviation themed Telegram chat bot.

Navigation: home

Jume 2024. Ignore this page

History

For lots of reasons, a bunch of us aviation geeks have a Telegram chat room. We got the idea to build a chat bot in Node-RED that we could ask questions of when we are on the go and just want a quick answer about some aircraft or system status.
We also use the bot chat for alerts since it shows up on our smart watches better formatted than our email does (we used to send a lot of aircraft alerts from Node-RED to our emails, but have been moving them to Telegram).

Build a chat bot

If you don't have a Telegram account, make one.
Make a room/group.
Add to the group BotFather (You can kick him out once you make your bot).
Use him to create your chat bot.

Pay attention to the bot father reply, it will include your API access token. Do not misplace this token.
In Node-RED, add the node node-red-contrib-telegrambot to your palette.
Helpful hints. Only groups can have bots/people/Node-RED. Don't forget to invite your bot to your channel after you make both. Highlight the code below and import it into your project (I would make a new flow page for it first, don't just add this to your current flow).

[{"id":"1a48a80e.7ce49","type":"http request","z":"e7e2a086.e06e3","name":"Call METAR API","method":"GET","paytoqs":"ignore","url":"http://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&stationString={{{payload}}}","tls":"","persist":false,"proxy":"","authType":"","x":840,"y":1280,"wires":[["5d0b56ca.1d20e"]]},{"id":"46ce2a87.66a264","type":"function","z":"e7e2a086.e06e3","name":"Set Metar Station","func":"//strip white space that the bot adds\nmsg.payload = msg.payload.content.trim();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":650,"y":1280,"wires":[["1a48a80e.7ce49"]]},{"id":"27963787.fbec8","type":"telegram command","z":"e7e2a086.e06e3","name":"/help","command":"/help","bot":"d1b03992.26abd8","strict":false,"hasresponse":false,"useregex":false,"removeregexcommand":false,"outputs":1,"x":266,"y":1180,"wires":[["c5d03828.be454"]]},{"id":"a62bdc7b.de8f2","type":"function","z":"e7e2a086.e06e3","name":"create help text","func":"//var helpMessage = \"/help - shows help\";\n\nvar helpMessage = \"\\r\\n/bot metar kphx - Show metar for airport code\";\nhelpMessage += \"\\r\\n/bot taf klax - Show TAF for airport code\";\nhelpMessage += \"\\r\\n/bot strikeaus - Show lightening map for AUS (wait 10 sec)\";\nhelpMessage += \"\\r\\n/bot strikeusa - Show lightening map for West-USA (wait 10 sec)\";\nhelpMessage += \"\\r\\n/bot map - Show current global ADSC aircraft\";\nhelpMessage += \"\\r\\n/bot whereis ae5bc3 - Show current location of ICAO code aircraft\";\nhelpMessage += \"\\r\\n/bot eq - Show last three earthquakes from USGS\";\nhelpMessage += \"\\r\\n/bot news - Show top three headlines from BBC\";\nhelpMessage += \"\\r\\n/bot tz - Show UTC, Aust, CA time zones\";\nhelpMessage += \"\\r\\n/bot ip - Show your IP address\";\nhelpMessage += \"\\r\\n/bot offline - Show your going to be away\";\nhelpMessage += \"\\r\\n/bot sleep - The couch got me\";\n\nhelpMessage += \"\\r\\n\";\nhelpMessage += \"\\r\\nNode-RED bot is here to serve \"+msg.originalMessage.from.first_name;\n//helpMessage += \"\\r\\nYour chat id is \" + msg.payload.chatId;\nhelpMessage += \"\\r\\n\";\n\nmsg.payload.content = helpMessage;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":1180,"wires":[["5461e215.0ca45c"]]},{"id":"c4cb1f0c.eb2078","type":"http request","z":"e7e2a086.e06e3","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://icanhazip.com","tls":"","persist":false,"proxy":"","authType":"","x":626,"y":1240,"wires":[["5f9da840.f54c48"]]},{"id":"5f9da840.f54c48","type":"function","z":"e7e2a086.e06e3","name":"build /ip","func":"//var chatId = msg.payload.chatId; //get which group the message came from so you answer back into that group.\n\nmsg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\",\"content\":\"Your IP address is: \"+msg.payload};\n\nmsg.payload.options = {disable_notification : true};//Don't wake everyone up just because someone asked for an IP address.\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":1240,"wires":[["5461e215.0ca45c"]]},{"id":"5461e215.0ca45c","type":"telegram sender","z":"e7e2a086.e06e3","name":"send response","bot":"d1b03992.26abd8","haserroroutput":false,"outputs":1,"x":1900,"y":1400,"wires":[[]]},{"id":"d64c8ecf.10b93","type":"debug","z":"e7e2a086.e06e3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1350,"y":1160,"wires":[]},{"id":"892b4a16.3727f8","type":"function","z":"e7e2a086.e06e3","name":"build /metar","func":"msg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\",\"parse_mode\": \"MarkdownV2\", \"content\":\"METAR Report: \\n Temperature: \"\n+msg.payload.temperature+\" C \\n Humidity: \" +msg.payload.humidity+ \" % \\n Visibility: \"+ msg.payload.visibility+\" km \\n Wind: \"\n+msg.payload.wind+\" Knt \\n Gusts: \"+msg.payload.gusts+\" Knt \\n Direction: \"+msg.payload.direction+ \"Deg \\n Dewpoint: \"+msg.payload.dewpoint+\" C \\n Pressure: \"\n+msg.payload.pressure+ \" mbar\"}\nmsg.payload.options = {disable_notification : true};//Don't wake everyone up for this message type.\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1390,"y":1280,"wires":[["5461e215.0ca45c"]]},{"id":"5d0b56ca.1d20e","type":"xml","z":"e7e2a086.e06e3","name":"","property":"payload","attr":"","chr":"","x":1050,"y":1280,"wires":[["df177173.20092"]]},{"id":"df177173.20092","type":"function","z":"e7e2a086.e06e3","name":"Parse METAR","func":"var METARdata = msg.payload.response.data[0].METAR[0];\nvar windkt = METARdata.wind_speed_kt[0];\nvar windkph = (windkt*1.852);\nvar winddir = METARdata.wind_dir_degrees[0]\nvar gusts = windkt; //if wind_gust_kt is not present, value defaults to wind_speed_kt\n   if (typeof METARdata.wind_gust_kt != \"undefined\") {\n\t   gusts = METARdata.wind_gust_kt[0];\n       }\nvar visibility = METARdata.visibility_statute_mi[0]*1.852;       \nvar altim = METARdata.altim_in_hg[0];\nvar pressure = Math.round(altim * 33.8637526); //convert hg to mb\nvar dew = METARdata.dewpoint_c[0];\ndew = Math.round(dew);\nvar tempC = METARdata.temp_c[0];\nvar tempF = ((tempC*1.8)+32);\n\n//tempC=5;\n//dew = 15;\n//windkt=1;\n\n//August-Roche-Magnus approximation to calculate rh_hum\nvar constA = 17.625;\nvar constB = 243.04;\nvar rh_numer = 10000.0*Math.exp((constA*eval(dew))/(eval(dew)+constB));\nvar rh_denom = Math.exp((constA*eval(tempC))/(eval(tempC)+constB));\nvar rh_hum   = (rh_numer/rh_denom);\nvar humidityemon = Math.round(rh_hum);\nvar humidity = (humidityemon/100);\n\n//Wind Chill Index Calculations using the 'Joint Action Group for Temp Indices' (JAG TI) formula\nvar chill=(13.12+0.6215*tempC-11.37*Math.pow(windkph,0.16)+0.3965*tempC*Math.pow(windkph,0.16));\n\n//Calculate Apparent Temperature\n//firstly, Calculate Vapor pressure in kPa\nvar vaporp = ((6.11*Math.pow(10,(7.5*dew/(237.3 + dew))))/10);\n//apply Steadman's Apparent Temperature formula\nvar apptemp = -2.7+(1.04*tempC)+(2*vaporp)-(windkt*0.3343886);\n        \n//Calculation of 'feels like' temperature by using the 'chill factor' if\n//the temp is below 10degC, or 'apparent temp' if over 20degC, or if between\n//10 and 20degC using a linear interpolation of both.\nvar feels;\nif (tempC < 10.0) {\n\tfeels=chill;\n\t}\n\telse if (tempC > 20.0) {\n\tfeels=apptemp;\n\t}\n\t\telse {\n\t\tvar calcA=((tempC-10)/10);\n\t\tvar calcB=1-calcA;\n\t\tfeels=((apptemp*calcA)+(chill*calcB));\n\t\t}\n\nmsg.payload = { \n    wind: windkt,\n    gusts: gusts,\n    direction: winddir,\n    humidity: humidity,\n    dewpoint: dew,\n    pressure: pressure,\n    temperature: tempC,\n    visibility: visibility,\n    feels:feels\n    };\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1200,"y":1280,"wires":[["892b4a16.3727f8"]]},{"id":"ddeacd7f.ed3c88","type":"catch","z":"e7e2a086.e06e3","name":"","scope":["27963787.fbec8"],"uncaught":false,"x":1130,"y":1160,"wires":[["d64c8ecf.10b93"]]},{"id":"c5d03828.be454","type":"switch","z":"e7e2a086.e06e3","name":"/help","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"cont","v":"/help","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":450,"y":1180,"wires":[["a62bdc7b.de8f2"],[]]},{"id":"a485972e.251cb","type":"function","z":"e7e2a086.e06e3","name":"sleep","func":"msg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\",\"content\": msg.originalMessage.from.first_name + \" is going to zzzz\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":1360,"wires":[["5461e215.0ca45c"]]},{"id":"dc1b1c47.c0a118","type":"http request","z":"e7e2a086.e06e3","name":"","method":"GET","ret":"txt","url":"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.csv","tls":"","x":630,"y":1420,"wires":[["cabee269.4c3588"]]},{"id":"cabee269.4c3588","type":"csv","z":"e7e2a086.e06e3","name":"CSV to JSON","sep":",","hdrin":true,"hdrout":"","multi":"one","ret":"\\n","temp":"\"time\", \"latitude\", \"longitude\", \"depth\", \"mag\", \"magType\", \"nst\", \"gap\", \"dmin\", \"rms\", \"net\", \"id\", \"updated\", \"place\", \"type\" ","skip":0,"x":820,"y":1420,"wires":[["d9cbfbdb.25703"]]},{"id":"d9cbfbdb.25703","type":"switch","z":"e7e2a086.e06e3","name":"hawaii","property":"payload.place","propertyType":"msg","rules":[{"t":"cont","v":"Hawaii","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":990,"y":1420,"wires":[[],["4bc99d75.841c04"]]},{"id":"4bc99d75.841c04","type":"function","z":"e7e2a086.e06e3","name":"Strip Disinteresting Data","func":"//node.warn(msg.payload);\n// \"time\", \"latitude\", \"longitude\", \"depth\", \"mag\", \"magType\", \"nst\", \"gap\", \"dmin\", \"rms\", \"net\", \"id\", \"updated\", \"place\", \"type\" \nvar out = {};\n\nif (msg.payload.longitude) delete(msg.payload.longitude);\nif (msg.payload.latitude) delete(msg.payload.latitude);\n//if (msg.payload.depth) delete(msg.payload.depth);\nif (msg.payload.nst) delete(msg.payload.nst);\nif (msg.payload.gap) delete(msg.payload.gap);\nif (msg.payload.dmin) delete(msg.payload.dmin);\nif (msg.payload.magType) delete(msg.payload.magType);\nif (msg.payload.id) delete(msg.payload.id);\nif (msg.payload.updated) delete(msg.payload.updated);\nif (msg.payload.rms) delete(msg.payload.rms);\nif (msg.payload.net) delete(msg.payload.net);\nif (msg.payload.horizontalError) delete(msg.payload.horizontalError);\nif (msg.payload.depthError) delete(msg.payload.depthError);\nif (msg.payload.magNst) delete(msg.payload.magNst);\nif (msg.payload.magError) delete(msg.payload.magError);\nif (msg.payload.status) delete(msg.payload.status);\nif (msg.payload.locationSource) delete(msg.payload.locationSource);\nif (msg.payload.magSource) delete(msg.payload.magSource);\nif (msg.payload.type) delete(msg.payload.type);\nreturn [ msg ];","outputs":"1","noerr":0,"initialize":"","finalize":"","libs":[],"x":1190,"y":1420,"wires":[["7e4704d7.9ebeb4"]]},{"id":"7e4704d7.9ebeb4","type":"join","z":"e7e2a086.e06e3","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","timeout":"2","count":"","x":1390,"y":1420,"wires":[["780c0a01.45000c"]]},{"id":"780c0a01.45000c","type":"function","z":"e7e2a086.e06e3","name":"build /quakes","func":"msg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\", \"content\":\"Earthquake Report: \\n Time: \"+msg.payload[0].time+\" \\n Depth: \" +msg.payload[0].depth+ \" \\n Mag: \"+ msg.payload[0].mag+\" \\n Location: \"+msg.payload[0].place+\" \\n \\n Time: \"\n+msg.payload[1].time+\" \\n Depth: \" +msg.payload[1].depth+ \" \\n Mag: \"+ msg.payload[1].mag+\" \\n Location: \"+msg.payload[1].place+\" \\n \\n Time: \"+msg.payload[2].time+\" \\n Depth: \" +msg.payload[2].depth+ \" \\n Mag: \"\n+ msg.payload[2].mag+\" \\n Location: \"+msg.payload[2].place+\" \\n EOF\" }\nmsg.payload.options = {disable_notification : true};//Don't wake everyone up for this message type.\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1550,"y":1420,"wires":[["5461e215.0ca45c"]]},{"id":"8c317ce6.5af828","type":"http request","z":"e7e2a086.e06e3","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"http://feeds.bbci.co.uk/news/world/rss.xml","tls":"","proxy":"","authType":"basic","x":630,"y":1540,"wires":[["122f2d24.6eb493"]]},{"id":"122f2d24.6eb493","type":"xml","z":"e7e2a086.e06e3","name":"","property":"payload","attr":"","chr":"","x":790,"y":1540,"wires":[["fa58deb7.b9932"]]},{"id":"fa58deb7.b9932","type":"function","z":"e7e2a086.e06e3","name":"build /news","func":"msg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\", link_preview : \"False\",\"content\":\"BBC World News Headlines: \\n \"+msg.payload.rss.channel[0].item[0].title[0]+\" \\n \" +msg.payload.rss.channel[0].item[0].description[0]+ \" \\n \"+ msg.payload.rss.channel[0].item[0].link[0]+\" \\n \\n \"\n+msg.payload.rss.channel[0].item[1].title[0]+\" \\n \" +msg.payload.rss.channel[0].item[1].description[0]+ \" \\n \"+ msg.payload.rss.channel[0].item[1].link[0]+\" \\n \\n \"\n+msg.payload.rss.channel[0].item[2].title[0]+\" \\n \" +msg.payload.rss.channel[0].item[2].description[0]+ \" \\n \"+ msg.payload.rss.channel[0].item[2].link[0]+\" \" }\n\n//turn of the preview, it takes up too much space.\nmsg.payload.options = {disable_web_page_preview : true, disable_notification : true};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1010,"y":1540,"wires":[["5461e215.0ca45c"]]},{"id":"3ace951a.5f5a82","type":"telegram command","z":"e7e2a086.e06e3","name":"/bot","command":"/bot","bot":"d1b03992.26abd8","strict":false,"hasresponse":false,"useregex":false,"removeregexcommand":false,"outputs":1,"x":250,"y":1400,"wires":[["2b1bda87.d2158e"]]},{"id":"2b1bda87.d2158e","type":"switch","z":"e7e2a086.e06e3","name":"select","property":"originalMessage.text","propertyType":"msg","rules":[{"t":"cont","v":"/bot ip","vt":"str"},{"t":"cont","v":"/bot metar","vt":"str"},{"t":"cont","v":"/bot offline","vt":"str"},{"t":"cont","v":"/bot sleep","vt":"str"},{"t":"cont","v":"/bot eq","vt":"str"},{"t":"cont","v":"/bot map","vt":"str"},{"t":"cont","v":"/bot news","vt":"str"},{"t":"cont","v":"/bot whereis","vt":"str"},{"t":"cont","v":"/bot taf","vt":"str"},{"t":"cont","v":"/bot strikeusa","vt":"str"},{"t":"cont","v":"/bot strikeaus","vt":"str"},{"t":"cont","v":"/bot tz","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":13,"x":390,"y":1400,"wires":[["c4cb1f0c.eb2078"],["46ce2a87.66a264"],["a9fa6dd1.268638"],["a485972e.251cb"],["dc1b1c47.c0a118"],["3c444123.50fcee"],["8c317ce6.5af828"],["7921db19.69bcac"],["791c56ce.fb0178"],["e22ba8a.6cd98d8"],["338074e8.61770c"],["a25696e.9a9b7e8"],[]]},{"id":"7921db19.69bcac","type":"function","z":"e7e2a086.e06e3","name":"make url","func":"//extract the ICAO from the bot command.\nmsg.icao = msg.payload.content.substring(msg.payload.content.length - 6);\nmsg.url = (\"https://globe.adsbexchange.com/?icao=\"+msg.icao+\"&zoom=4&hideSidebar&hidebuttons\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1600,"wires":[["63623bbc.891304"]]},{"id":"63623bbc.891304","type":"screenshot","z":"e7e2a086.e06e3","name":"","url":"http://www.example.com/","path":"","x":810,"y":1600,"wires":[["e225fcf2.a26df"]]},{"id":"65362806.b8d8f","type":"function","z":"e7e2a086.e06e3","name":"where is ac on map image","func":"var pl = {\n  content: msg.payload,\n  message: msg.url,\n  type : 'photo',\n  chatId: msg.originalMessage.chat.id,\n  from: \"ADSBEx\"\n}\nmsg.payload.options = {disable_web_page_preview : true};\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1190,"y":1600,"wires":[["5461e215.0ca45c"]]},{"id":"e225fcf2.a26df","type":"base64","z":"e7e2a086.e06e3","name":"","action":"","property":"payload","x":980,"y":1600,"wires":[["65362806.b8d8f"]]},{"id":"791c56ce.fb0178","type":"function","z":"e7e2a086.e06e3","name":"make url","func":"// extract the airport icao code from the bot command\nmsg.icao = msg.payload.content.substring(msg.payload.content.length - 4);\nmsg.url = \"https://aviationweather.gov/adds/metars/?chk_tafs=ON&hoursStr=most+recent+only&station_ids=\"+msg.icao+\"&submitmet=Get+info&std_trans=translated\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1660,"wires":[["796f36d0.7b45e"]]},{"id":"e22ba8a.6cd98d8","type":"function","z":"e7e2a086.e06e3","name":"make url","func":"msg.url = \"https://www.lightningmaps.org/blitzortung/america/index.php?lang=nl\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1720,"wires":[["fc814e6.a2f8a3"]]},{"id":"fc814e6.a2f8a3","type":"screenshot","z":"e7e2a086.e06e3","name":"","url":"http://www.example.com/","path":"","x":820,"y":1720,"wires":[["d995f207.6e0a3"]]},{"id":"d995f207.6e0a3","type":"jimp-image","z":"e7e2a086.e06e3","name":"","data":"payload","dataType":"msg","ret":"buf","parameter1":"200","parameter1Type":"num","parameter2":"460","parameter2Type":"num","parameter3":"480","parameter3Type":"num","parameter4":"412","parameter4Type":"num","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"payload","parameterCount":4,"jimpFunction":"crop","selectedJimpFunction":{"name":"crop","fn":"crop","description":"crop to the given region","parameters":[{"name":"x","type":"num","required":true,"hint":"the x coordinate to crop form"},{"name":"y","type":"num","required":true,"hint":"the y coordinate to crop form"},{"name":"w","type":"num","required":true,"hint":"the width of the crop region"},{"name":"h","type":"num","required":true,"hint":"the height of the crop region"}]},"x":1010,"y":1720,"wires":[["d96ceca0.905b2"]]},{"id":"338074e8.61770c","type":"function","z":"e7e2a086.e06e3","name":"make url","func":"msg.url = \"https://www.lightningmaps.org/blitzortung/oceania/index.php?lang=nl&bo_page=map\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1780,"wires":[["5ee5b59d.5dd0bc"]]},{"id":"5ee5b59d.5dd0bc","type":"screenshot","z":"e7e2a086.e06e3","name":"","url":"http://www.example.com/","path":"","x":820,"y":1780,"wires":[["f6a7ed83.eca05"]]},{"id":"f6a7ed83.eca05","type":"jimp-image","z":"e7e2a086.e06e3","name":"","data":"payload","dataType":"msg","ret":"buf","parameter1":"200","parameter1Type":"num","parameter2":"380","parameter2Type":"num","parameter3":"480","parameter3Type":"num","parameter4":"420","parameter4Type":"num","parameter5":"","parameter5Type":"msg","parameter6":"","parameter6Type":"msg","parameter7":"","parameter7Type":"msg","parameter8":"","parameter8Type":"msg","sendProperty":"payload","parameterCount":4,"jimpFunction":"crop","selectedJimpFunction":{"name":"crop","fn":"crop","description":"crop to the given region","parameters":[{"name":"x","type":"num","required":true,"hint":"the x coordinate to crop form"},{"name":"y","type":"num","required":true,"hint":"the y coordinate to crop form"},{"name":"w","type":"num","required":true,"hint":"the width of the crop region"},{"name":"h","type":"num","required":true,"hint":"the height of the crop region"}]},"x":1010,"y":1780,"wires":[["a2a3eac3.6679c"]]},{"id":"d96ceca0.905b2","type":"function","z":"e7e2a086.e06e3","name":"send lightening usa","func":"var pl = {\n  content: msg.payload,\n  message: `Lightening USA`,\n  type : 'photo',\n  chatId: msg.originalMessage.chat.id,\n  from: \"West Coast USA\"\n}\nmsg.payload.options = {disable_notification : true};//Don't wake everyone up for this message type.\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1230,"y":1720,"wires":[["5461e215.0ca45c"]]},{"id":"a2a3eac3.6679c","type":"function","z":"e7e2a086.e06e3","name":"send lightening aus","func":"var pl = {\n  content: msg.payload,\n  message: `Lightening AUS`,\n  type : 'photo',\n  chatId: msg.originalMessage.chat.id,\n  from: \"Aust\"\n}\nmsg.payload.options = {disable_notification : true};//Don't wake everyone up for this message type.\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1230,"y":1780,"wires":[["5461e215.0ca45c"]]},{"id":"796f36d0.7b45e","type":"http request","z":"e7e2a086.e06e3","name":"taf decode","method":"GET","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":810,"y":1660,"wires":[["762e367a.0a5f48"]]},{"id":"7691a423.8c67d4","type":"function","z":"e7e2a086.e06e3","name":"raw TAF","func":"//Clean up the message before sending to the chat.\n//todo. fix the formatting.... No really... \n\nmsg.payload = msg.payload.slice(277);\nmsg.payload = msg.payload.replace(/\\n+/g, '\\n');\n\nmsg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\",\"content\": \"TAF Report: \\n \"+msg.payload};\nmsg.payload.options = {disable_notification : true};//Don't wake everyone up for this message type.\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1460,"y":1660,"wires":[["5461e215.0ca45c"]]},{"id":"762e367a.0a5f48","type":"turndown","z":"e7e2a086.e06e3","name":"Parse HTML to markdown","x":1030,"y":1660,"wires":[["d306eeb3.bd95a"]]},{"id":"d306eeb3.bd95a","type":"change","z":"e7e2a086.e06e3","name":"Remove '**'","rules":[{"t":"change","p":"payload","pt":"msg","from":"**","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1230,"y":1660,"wires":[["7691a423.8c67d4"]]},{"id":"a25696e.9a9b7e8","type":"function","z":"e7e2a086.e06e3","name":"time zones","func":"//Tweak offsets everytime any zone goes on or off DLS.\n\nfunction twoDig(val) {return (('0'+val).slice(-2));}\nvar d = new Date();\nmsg.utc = twoDig(d.getUTCHours())+':'+twoDig(d.getUTCMinutes());\nmsg.pst = twoDig((d.getUTCHours()+17)%24) +':'+twoDig(d.getUTCMinutes());\nmsg.aest = twoDig((d.getUTCHours()+10)%24) +':'+twoDig(d.getUTCMinutes());\n\nmsg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\", \"content\":\"Time Zones: \\n UTC: \"+ msg.utc+ \"\\n PST: \"+ msg.pst + \"\\n AEST: \"+ msg.aest}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":1840,"wires":[["5461e215.0ca45c"]]},{"id":"a9fa6dd1.268638","type":"function","z":"e7e2a086.e06e3","name":"offline","func":"msg.payload = {chatId: msg.originalMessage.chat.id,\"type\":\"message\",\"content\": msg.originalMessage.from.first_name + \" is going to be offline for a bit.\"};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":1322,"wires":[["5461e215.0ca45c"]]},{"id":"3c444123.50fcee","type":"function","z":"e7e2a086.e06e3","name":"make url","func":"// Get ADSC current aircraft map\nmsg.url = (\"http://thebaldgeek.net:99/tar1090\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":1480,"wires":[["1ef87e97.81ef29"]]},{"id":"1ef87e97.81ef29","type":"screenshot","z":"e7e2a086.e06e3","name":"","url":"http://www.example.com/","path":"","x":810,"y":1480,"wires":[["107ed8fa.f22c2f"]]},{"id":"107ed8fa.f22c2f","type":"base64","z":"e7e2a086.e06e3","name":"","action":"","property":"payload","x":980,"y":1480,"wires":[["84611987.e39878"]]},{"id":"84611987.e39878","type":"function","z":"e7e2a086.e06e3","name":"ADSC aircraft","func":"var pl = {\n  content: msg.payload,\n  message: msg.url,\n  type : 'photo',\n  chatId: msg.originalMessage.chat.id,\n  from: \"ADSC\"\n}\nmsg.payload.options = {disable_web_page_preview : true};\nmsg.payload = pl;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1160,"y":1480,"wires":[["5461e215.0ca45c"]]},{"id":"d1b03992.26abd8","type":"telegram bot","botname":"NR_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}]  

This is what the flow roughly looks like:

Now double click the blue Telegram node on the left and then click the pencil icon to confiugre your bot, paste in your API token. Leave the ChatIDs and user blank.

You can change the help text and adjust the 'select' switch node as you add and remove bot commands. There are hopefully enough examples here to get you started.

A few pointers.

I use the chat bot in at least two different rooms. This is possible because most of the commands pick up the room chatID and use it to return the bot reply back to the room it was involked from.

Here is how the chatID is picked up:

var pl = {
content: msg.payload,
message: msg.url,
type : 'photo',
chatId: msg.originalMessage.chat.id,
from: "ADSBEx"
}
msg.payload.options = {disable_web_page_preview : true};
msg.payload = pl;

return msg;   

The alerts however I want to ONLY go to the aviation room, so its chat ID is fixed in the payload. Here is how it looks:

msg.payload = {"chatId":"-123456789","type":"message", "content":"Filtered Marine Satcom Message - Aircraft Related: \n \n "
+msg.payload+""}
msg.payload.options = {disable_web_page_preview : true};
return msg;  

The way I found my chat room ID is to invite the @RawDataBot to your chat room and it will show your chatID. Once you get that number, kick the bot out, its pretty anoying.
So, just to sumerize all that.... for bot commands, use the original message ID so the bot reply goes back to the room it was asked from, for alerts, hard code the room you want the alert to go to.
Of course all this only applies if you are using the bot in more than one room.

Here is an example command in action:

First, we simply invoke /help and get the bot commands. Then we ask the bot to show us the current lighting map for the USA, then we ask the bot to show us where an aircraft is. (This is one of my favorit commands as it pulls so much together).

If you add any aviation commands to your chat bot, I'd love to hear about them. Check back to this page from time to time, I will add any extra commands (I have some ideas....).
Oh, and if you clean up the TAF report formatting, I would be super appreciative if you shared that flow.

<script async src="https://www.googletagmanager.com/gtag/js?id=G-HGJWTNL65R"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-HGJWTNL65R'); </script>