# Send a photo to Telegram

**URL:** <https://discourse.nodered.org/t/send-a-photo-to-telegram/5528>\
**Category:** General\
**Tags:** telegram\
**Created:** [6 December 2018 09:28 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528 "2018-12-06T09:28:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![talud08](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/talud08/32/3121_2.png) [@talud08](https://discourse.nodered.org/u/talud08)\
**Post date:** [6 December 2018 09:28 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/1 "2018-12-06T09:28:42Z")

</div>

I need some help in order to send a photo taken with the pi camera to Telegram.

I am using "node-red-contrib-telegrambot-home" and these are the flow and nodes:

## ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f3ee0907048d29b0f1d885e37c35716277ad6a38.png)

## ![camerapi-takephoto](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cb8908dae802debaca6caacac62e259677b76a63.png)

 ![telegram_payload](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/653c76d17f605b359d4b647270d8cf4f5b56d6de.png)

--

 ![telegram_notify](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/581049f40aa822f92a98a55cb0ea489d0afacd46.png)

With this flow the picture is taken and stored in the Pi, but I get nothing in Telegram.

I also tried with a "funtion" node instead of a "telegram payload" node:

 ![funtion](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f76e51c50aa9989b0aa53dcdad6619acd3095921.png)

In this case what I get is a text in the TelegramBot: "/home/pi/Pictures/foto". But not picture at all.

Could somebody help me?

Thank you so much.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [6 December 2018 10:18 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/2 "2018-12-06T10:18:36Z")

</div>

Have you checked to see that the photo actually exists and checked the name?

It's often easier to break a problem down.  
i.e a flow to capture a photo and store it  
a flow that gets a stored photo and sends it to telegram

That way you can see where the problem occurs

---

<div class="post-metadata">

**Author:** ![talud08](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/talud08/32/3121_2.png) [@talud08](https://discourse.nodered.org/u/talud08)\
**Post date:** [6 December 2018 10:22 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/3 "2018-12-06T10:22:45Z")

</div>

Thanks for your response.  
Yes, I have checked that the photo is in the right folder and with the right name.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [6 December 2018 12:49 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/4 "2018-12-06T12:49:07Z")

</div>

Is the send too quick... has the photo been fully written to disk and the file closed before the payload node tries to read it ?

---

<div class="post-metadata">

**Author:** ![talud08](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/talud08/32/3121_2.png) [@talud08](https://discourse.nodered.org/u/talud08)\
**Post date:** [6 December 2018 14:00 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/5 "2018-12-06T14:00:36Z")

</div>

dceejay, thank you so much for your response.

That does not seem to be the problem. I have put a delay (first of 1 and then of 5 seconds) after the "camerapi-takephoto" node and it does not work.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [8 December 2018 16:52 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/6 "2018-12-08T16:52:38Z")

</div>

You have to send the data as a multi-part form similar to any other file upload to a server. Details are here:

> **[Telegram Bot API](https://core.telegram.org/bots/api#sendphoto)**
>
> The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.
> To learn how to create…

---

<div class="post-metadata">

**Author:** ![talud08](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/talud08/32/3121_2.png) [@talud08](https://discourse.nodered.org/u/talud08)\
**Post date:** [9 December 2018 17:37 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/7 "2018-12-09T17:37:40Z")

</div>

Thank you so much for your response.

I have tried this node:

> **[node-red-contrib-send-multipart](https://flows.nodered.org/node/node-red-contrib-send-multipart)**
>
> NodeRed node for posting multipart form data to external sites

Still not working. I am afraid this multi-part form thing is far out of my current knowledge.

I copy the flow just in case somebody can detect any mistake.

Thanks again.

```
[{"id":"85be023a.0552e","type":"inject","z":"91952aac.1bd658","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":280,"y":100,"wires":[["6544f6e3.7a6388"]]},{"id":"6544f6e3.7a6388","type":"camerapi-takephoto","z":"91952aac.1bd658","filemode":"1","filename":"foto","filedefpath":"0","filepath":"/home/pi/Pictures/","fileformat":"jpeg","resolution":"1","rotation":"0","fliph":"0","flipv":"0","brightness":"50","contrast":"0","sharpness":"0","quality":"80","imageeffect":"none","exposuremode":"auto","iso":"0","agcwait":"1.0","led":"0","awb":"auto","name":"","x":360,"y":180,"wires":[["21262984.983446"]]},{"id":"21262984.983446","type":"delay","z":"91952aac.1bd658","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":240,"wires":[["c637d704.e41cd8"]]},{"id":"c637d704.e41cd8","type":"http-send-multipart","z":"91952aac.1bd658","name":"","ret":"bin","filepath":"/home/pi/Pictures/foto.JPEG","url":"my_public_IP:my_port","tls":"","x":450,"y":280,"wires":[["73793f29.5deae"]]},{"id":"73793f29.5deae","type":"telegrambot-payload","z":"91952aac.1bd658","name":"","bot":"ab134760.32e278","chatId":"My_Chat_ID","sendMethod":"sendPhoto","payload":"{\n \"photo\": \"/home/pi/Pictures/foto.JPEG\",\n \"caption\": \"Test\"\n}","x":510,"y":340,"wires":[["d68268c7.c33238"]]},{"id":"d68268c7.c33238","type":"telegrambot-notify","z":"91952aac.1bd658","name":"","bot":"ab134760.32e278","chatId":"My_chat_ID","message":"","parseMode":"HTML","x":520,"y":400,"wires":[]},{"id":"ab134760.32e278","type":"telegrambot-config","z":"","botname":"NodeRedBot","usernames":"Talud08","chatIds":"209723044","pollInterval":"300"}]
```

---

<div class="post-metadata">

**Author:** ![talud08](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/talud08/32/3121_2.png) [@talud08](https://discourse.nodered.org/u/talud08)\
**Post date:** [18 December 2018 19:06 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/8 "2018-12-18T19:06:38Z")

</div>

Hi everyone,

Just for the records, I've made a different approach to this problem and now it is solved.

I've used an Exec Node to run a system command and execute a python script, to take a picture with the raspberry pi camera and send it to a telegram bot.

I have to give the credit to Carlo Mascellani  
[http://rpihome.blogspot.com/2016/04/using-telegram-with-raspberry-pi.html](http://rpihome.blogspot.com/2016/04/using-telegram-with-raspberry-pi.html)  
Thanks Carlo

This is the code

```
import telegram
import picamera

from telegram_keys import (
    my_token,
    my_chat_id
)
    

# Connect to our bot
bot = telegram.Bot(my_token)

# Sets the id for the active chat
chat_id=my_chat_id

#Get the photo
camera=picamera.PiCamera()
camera.capture('/home/pi/Pictures/capture.jpg')
camera.close()

# Sends a message to the chat
bot.sendPhoto(chat_id=chat_id, photo=open('/home/pi/Pictures/capture.jpg', 'rb'))

```

Thank you everyone for your support.

---

<div class="post-metadata">

**Author:** ![leftShark2019](https://avatars.discourse-cdn.com/v4/letter/l/4da419/32.png) [@leftShark2019](https://discourse.nodered.org/u/leftShark2019)\
**Post date:** [16 June 2019 13:58 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/9 "2019-06-16T13:58:48Z")

</div>

```auto
import telegram import picamera from telegram_keys import ( my_token, my_chat_id ) # Connect to our bot bot = telegram.Bot(my_token) # Sets the id for the active chat chat_id=my_chat_id #Get the photo camera=picamera.PiCamera() camera.capture('/home/pi/Pictures/capture.jpg') camera.close() # Sends a message to the chat bot.sendPhoto(chat_id=chat_id, photo=open('/home/pi/Pictures/capture.jpg', 'rb'))

```

@talud08

Would this script mean the flow requires a telegram payload node or no?  
Would you mind posting your flow?

---

<div class="post-metadata">

**Author:** ![ceaswaran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceaswaran/32/28975_2.png) [@ceaswaran](https://discourse.nodered.org/u/ceaswaran)\
**Post date:** [18 April 2021 15:53 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/10 "2021-04-18T15:53:49Z")

</div>

how can we send a picture from `http://192.168.1.xx:5000/clips/frontdoorcctv-1618757066.85689-5afutf.jpg` location

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 April 2021 18:44 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/11 "2021-04-18T18:44:59Z")

</div>

Use a http request node to get the binary image, then use that in the msg property.

[This post](https://discourse.nodered.org/t/taking-a-picture-and-sending-it-via-telegram/27905/4) demonstrates requesting a picture from a http resource then sending it via telegram

---

<div class="post-metadata">

**Author:** ![ceaswaran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceaswaran/32/28975_2.png) [@ceaswaran](https://discourse.nodered.org/u/ceaswaran)\
**Post date:** [20 April 2021 08:15 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/12 "2021-04-20T08:15:27Z")

</div>

Thanks for the help i managed to send picture to telegram

Now i am in different situation

I would like to fetch the picture from my RTSP camera which stores file (Everytime a motion detected) on my secondary hard drive (Clips folder)  
I am able to get the image to my telegram using this link [http://192.168.1.66:4000/clips/cctv-XXXXXXXXXX.jpg](http://192.168.1.66:4000/clips/cctv-XXXXXXXXXX.jpg) using http get request node.

But the problem here is in the above link [http://192.168.1.66:4000/clips/cctv-XXXXXXXXXX.jpg](http://192.168.1.66:4000/clips/cctv-XXXXXXXXXX.jpg) whenever motion detected event id XXXXXXXXXX changes.

I am able to extract the event id XXXXXXXXXX using MQTT+Jason+Change payload nodes.

How do i combine the eveint id XXXXXXXXXX & create a url every time & send it thru http get requet node?

Please help

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 April 2021 08:25 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/13 "2021-04-20T08:25:48Z")

</div>

There are a few ways.

One way would be to store the XXXXXXXX value in flow context then use it to build a dynamic URL.

Use a change node to store the value from MQTT e.g. store the XXXXXXX value in flow.lastEventId using a change node.

Then add a function node before the HTTP Request node...

```javascript
var eventID = flow.get("lastEventId");
if(eventID) {
    msg.url = `http://192.168.1.66:4000/clips/cctv-${eventID}.jpg`;
    return msg;
}

```

* * *

Alternatively, if you want to initiate this flow when the MQTT value arrives, simply change your change node around to set `msg.url` to `"http://192.168.1.66:4000/clips/cctv-" & eventID & ".jpg"`  
(where eventID is the XXXXXXX value you managed to extract)

* * *

NOTE: to use a dynamic url in the request node, leave the HTTP Requests URL field empty so that it uses `msg.url`

---

<div class="post-metadata">

**Author:** ![ceaswaran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceaswaran/32/28975_2.png) [@ceaswaran](https://discourse.nodered.org/u/ceaswaran)\
**Post date:** [21 April 2021 03:17 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/14 "2021-04-21T03:17:16Z")

</div>

I managed to get the image till the HTTP node. but not able to send to telegram  
below is my flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/7/177a3a0975413f4b989cce32fa07cad3baefb1e8.png)  
Function node (send picture) after HTTP is as follows

````auto
  content: msg.payload,
  caption : 'Someone At Your Front Door',
  type : 'photo',
  chatId: 'XXXXXX',
}

msg.payload = pl;
return msg;```
````

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2021 06:58 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/15 "2021-04-21T06:58:24Z")

</div>

The obvious questions...

- Is the http request set to return a buffer?
- Is the `chatId` number you used confirmed working for regular messages?

Also, as I cannot see your full code, here is a working demo...

```auto
var pl = {
  content: msg.payload, // <-- check msg.payload is a buffer
  caption: `Someone At Your Front Door`,
  type : 'photo',
  chatId: 123456789 // <-- set chat id number
}
msg.payload = pl;
return msg;

```

---

<div class="post-metadata">

**Author:** ![ceaswaran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceaswaran/32/28975_2.png) [@ceaswaran](https://discourse.nodered.org/u/ceaswaran)\
**Post date:** [21 April 2021 12:09 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/16 "2021-04-21T12:09:37Z")

</div>

my http node details is as follows

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b5e0e1847d0f74bf6455566156cb0fd2336e726.png)

Yes my chat ID is right correct (though I have not shown it here)

I dont get it working

Not sure what's going wrong

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2021 12:19 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/17 "2021-04-21T12:19:09Z")

</div>

It is quite difficult to help further without the following...

1. a copy of your flow (export using ctrl+e)
2. an image to test with (you can temporarily connect the http node to a file node to save the buffer to file)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2021 12:53 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/18 "2021-04-21T12:53:45Z")

</div>

@ceaswaran I think this is related to using a different set of telegram nodes.

For anyone following along. @ceaswaran sent a copy of his flow privately. When i imported it, I got an warning "unknown: telegrambot-notify"

That node is not part of [node-red-contrib-telegrambot](https://flows.nodered.org/node/node-red-contrib-telegrambot) but instead appears to be a node from [node-red-contrib-telegrambot-home](https://flows.nodered.org/node/node-red-contrib-telegrambot-home).

FYI: node-red-contrib-telegrambot is by far the more popular choice and the one I use - I can't help with why the node-red-contrib-telegrambot-home nodes dont work for you. All i can say is the telegram nodes I use do work.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 April 2021 13:21 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/19 "2021-04-21T13:21:27Z")

</div>

Ah, as always, a lesson in making sure that you share all relevant information up-front when looking for help.

---

<div class="post-metadata">

**Author:** ![ceaswaran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ceaswaran/32/28975_2.png) [@ceaswaran](https://discourse.nodered.org/u/ceaswaran)\
**Post date:** [21 April 2021 18:02 UTC](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528/20 "2021-04-21T18:02:00Z")

</div>

Using `node-red-contrib-telegrambot` Worked Thanks

[Next page](https://discourse.nodered.org/t/send-a-photo-to-telegram/5528.md?page=2)
