Extract Public URL for Photo Received in Telegram Node

Using node-red-contrib-telegrambot to retrieve the public URL (non-authenticated access) of the photo sent to the telegram. The photo url is set to the msg.payload.

[{"id":"cf98104c.8eec8","type":"telegram receiver","z":"e2571389.a6d7d","name":"","bot":"","x":110,"y":80,"wires":[["15ac1917.457f27"],[]]},{"id":"15ac1917.457f27","type":"switch","z":"e2571389.a6d7d","name":"isPhoto?","property":"payload.type","propertyType":"msg","rules":[{"t":"eq","v":"photo","vt":"str"}],"checkall":"true","outputs":1,"x":280,"y":80,"wires":[["44422340.704ddc"]]},{"id":"44422340.704ddc","type":"function","z":"e2571389.a6d7d","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 = '<TELEGRAMBOT_TOKEN>';\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":80,"wires":[["4c8cfaea.63cd74"]]},{"id":"cc34a11a.44a4e","type":"telegram sender","z":"e2571389.a6d7d","name":"","bot":"","x":1070,"y":80,"wires":[[]]},{"id":"4c8cfaea.63cd74","type":"http request","z":"e2571389.a6d7d","name":"Get Photo URL","method":"GET","ret":"obj","url":"https://api.telegram.org/bot{{{token}}}/getFile?file_id={{{file_id}}}","tls":"","x":680,"y":80,"wires":[["236de1f.243cb1e"]]},{"id":"236de1f.243cb1e","type":"function","z":"e2571389.a6d7d","name":"Set to payload","func":"msg.payload = 'https://api.telegram.org/file/bot' + msg.token + '/' + msg.payload.result.file_path;\nreturn msg;","outputs":1,"noerr":0,"x":860,"y":80,"wires":[["26ddf126.579bbe","cc34a11a.44a4e"]]},{"id":"26ddf126.579bbe","type":"debug","z":"e2571389.a6d7d","name":"","active":false,"console":"false","complete":"payload","x":1060,"y":120,"wires":[]}]

Flow Info

Created 6 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x2)
  • http request (x1)
  • switch (x1)
Other

Tags

  • telegram
  • bot
  • photo
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option