scraton / node-red-contrib-telegrambot-home

Useful Node RED nodes for connecting your home to Telegram.
MIT License
28 stars 11 forks source link

Unable to send photo for both static or msg.method #26

Closed soovui closed 2 years ago

soovui commented 4 years ago

I try many times and I failed to send photo. Follow exactly your code.

scraton commented 3 years ago

Do you have a specific error? Could you share some logs?

Speeedy0815 commented 2 years ago

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.

scraton commented 2 years ago

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"}]
Screen Shot 2021-10-10 at 10 49 39

Here's how it works:

  1. Inject can be replaced with any node that triggers an input.
  2. Use the 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.
  3. Use a 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;
  4. Use a 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!