Closed soovui closed 2 years ago
Do you have a specific error? Could you share some logs?
Hi @scraton,
want to ask also,... I'm following your Steps. At my system it is working with photos. But only if the photo is on a pulic website.
Is it also possible to send local photos from node-red or from local network? And if so, How? Can you write an example/documentation? Or maybe a short explanaion here will also help.
If not, is it possible to write that feature? --> Maybe sending buffer via notify-node ore something like that?
Thank you.
Is it also possible to send local photos from node-red or from local network? And if so, How? Can you write an example/documentation? Or maybe a short explanaion here will also help.
I did some quick testing and it seems to work without any need for modification. Check out this flow:
[{"id":"bcdd9edf.cad39","type":"inject","z":"bf09bafc.f9a1b8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":160,"wires":[["4e1a229c.4df4cc"]]},{"id":"4e1a229c.4df4cc","type":"file in","z":"bf09bafc.f9a1b8","name":"TelegramCommandBotMessage.png","filename":"/data/node_modules/node-red-contrib-telegrambot-home/images/TelegramCommandBotMessage.png","format":"","chunk":false,"sendError":false,"encoding":"none","x":370,"y":160,"wires":[["1acab4d0.ddbcbb"]]},{"id":"4130da67.1873e4","type":"telegrambot-payload","z":"bf09bafc.f9a1b8","name":"sendPhoto","bot":"a57fbdd0.29aa1","chatId":"570634206","sendMethod":"sendPhoto","payload":"","x":750,"y":160,"wires":[[]]},{"id":"1acab4d0.ddbcbb","type":"function","z":"bf09bafc.f9a1b8","name":"","func":"msg.method = \"sendPhoto\"\nmsg.payload = {\n photo: msg.payload,\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":160,"wires":[["4130da67.1873e4"]]},{"id":"a57fbdd0.29aa1","type":"telegrambot-config","botname":"TubigNaDevBot","usernames":"","chatIds":"","pollInterval":"300"}]
Here's how it works:
file in
node to load the contents of a file as a "single Buffer object". This can be replaced with anything that loads a file as a Buffer object.function
node to generate the message payload:
msg.method = "sendPhoto"
msg.payload = {
photo: msg.payload, // msg.payload is the Buffer object from `file in`
};
return msg;
telegram payload
node to send the generated payload. You can either set method to sendPhoto
or - set by msg.method -
.Theoretically you could replace these steps with any binary content such as videos, documents, etc. Whatever Telegram supports. You can refer to the official documentation for what all can be done. Wherever they say to provide an InputFile
, you can just pass a Buffer
object and it seems to handle the uploading automatically. :+1:
Hope that helps!
I try many times and I failed to send photo. Follow exactly your code.