# Help with generating a jpg from raw mqtt data and sending via telegam

**URL:** <https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333>\
**Category:** General\
**Created:** [26 November 2021 12:58 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333 "2021-11-26T12:58:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yonny24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yonny24/32/49675_2.png) [@Yonny24](https://discourse.nodered.org/u/Yonny24)\
**Post date:** [26 November 2021 12:58 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/1 "2021-11-26T12:58:19Z")

</div>

I really hope someone can help me here as I'm stuck..(before I pull more hair out).

Got mqtt snapshot data coming in and I can preview the image with the view node.  
But how do I render those raw data bytes to send as an image? I see the view node does this magically so you can preview the images, but this is the image I want to send along to my telegram. (From Frigate)  
Many thanks!

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87e13a525b941ef379e6752ec1c541363b64115f.png)

---

<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:** [26 November 2021 14:48 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/2 "2021-11-26T14:48:19Z")

</div>

You set the buffer as `msg.payload.content`

Here are 3 working examples...

> [@Unable to send text\_link from telegram bot](https://discourse.nodered.org/t/unable-to-send-text-link-from-telegram-bot/45615/4):
>
> Try using markdown... msg.payload = { content: msg.payload, //the image buffer caption: `There's someone at the door. [Live Image](http://camera_url).`, type : 'photo', chatId: "xxxx" } msg.payload.options = { parse\_mode : "Markdown" }; return msg;

> [@Node red sending picture to telegram](https://discourse.nodered.org/t/node-red-sending-picture-to-telegram/39656/4):
>
> In your original example, the issue is likely because you are NOT sending a buffer. Here is a working example... To make it work import the demo flow setup the BOT connection send /picture to your bot NOTE: this demo uses [node-red-contrib-telegrambot](https://flows.nodered.org/node/node-red-contrib-telegrambot) The demo flow... [{"id":"4cdb400.5a8f3c","type":"telegram command","z":"5d3f964c.fef898","name":"/picture","command":"/picture","bot":"fa7a9376.321ce","strict":false,"hasresponse":false,"useregex":false,"removere…

> [@Taking a picture and sending it via telegram](https://discourse.nodered.org/t/taking-a-picture-and-sending-it-via-telegram/27905/4):
>
> msg.payload.content can also be a buffer object Are you able to get the image from the webcam into a buffer? Here is a demo i did... [{"id":"99ee972c.22d088","type":"telegram sender","z":"5d3f964c.fef898","name":"","bot":"fa7a9376.321ce","x":930,"y":280,"wires":[["72b71335.355a9c"]]},{"id":"58e78fc.dd0b27","type":"telegram command","z":"5d3f964c.fef898","name":"/pic","command":"/pic","bot":"fa7a9376.321ce","strict":false,"hasresponse":false,"x":130,"y":280,"wires":[["3eb66…

---

<div class="post-metadata">

**Author:** ![Yonny24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yonny24/32/49675_2.png) [@Yonny24](https://discourse.nodered.org/u/Yonny24)\
**Post date:** [26 November 2021 17:31 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/3 "2021-11-26T17:31:09Z")

</div>

Thanks for the examples. Still struggling to convert that mqtt data to a buffer msg.payload.content somehow. Your flows are great but not quite there for me yet.

It is being fed by the mqtt snapshot data from frigate. How does the image preview node using just the payload show the image? What is the coding behind that?

Think I need to wait down late Saturday night with a cool beer after the family are in bed and spend some time on this.

This is the output if I try a function with the content payload and markdown.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/197a6b9e8c05b8852a86262f359a1cbcb68e82cf.png)

Many thanks

---

<div class="post-metadata">

**Author:** ![Yonny24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yonny24/32/49675_2.png) [@Yonny24](https://discourse.nodered.org/u/Yonny24)\
**Post date:** [26 November 2021 17:51 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/4 "2021-11-26T17:51:34Z")

</div>

Also just to add the output from the mqtt is buffer.  
Does this shed some light on the issue I'm having?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87c7e3e757235e9c2df12ba949c11c3dcdf09638.png)

Also if I use the direct output of the mqtt buffer through your function example

```auto
msg.payload = {
  content: msg.payload, //the image buffer
  caption: `There's someone at the door. `,
  type : 'photo',
  chatId: "xxxx"
}
msg.payload.options = { parse_mode : "Markdown" };

return msg;

```

the debug shows buffer content. If I understand correctly this should send the image?

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

---

<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:** [26 November 2021 18:50 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/5 "2021-11-26T18:50:33Z")

</div>

Correct. However, there are more than one telegram contrib node.

Which one are you using?

---

<div class="post-metadata">

**Author:** ![Yonny24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yonny24/32/49675_2.png) [@Yonny24](https://discourse.nodered.org/u/Yonny24)\
**Post date:** [26 November 2021 18:54 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/6 "2021-11-26T18:54:20Z")

</div>

ah - using the other one to yours - telegrambot-home.  
So you would suggest I use your version? Could this be the issue?

May cause a conflict with both connected - had this issue before but I'll give it a go..

Thanks

---

<div class="post-metadata">

**Author:** ![Yonny24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yonny24/32/49675_2.png) [@Yonny24](https://discourse.nodered.org/u/Yonny24)\
**Post date:** [26 November 2021 18:58 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/7 "2021-11-26T18:58:17Z")

</div>

> [@Yonny24](#):
>
> ` chatId: "xxxx"`

Thanks so much. Had a spare bot, used your version of telegram and voila!! Picture came through!!

Awesome, thanks again

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 December 2021 18:59 UTC](https://discourse.nodered.org/t/help-with-generating-a-jpg-from-raw-mqtt-data-and-sending-via-telegam/54333/8 "2021-12-10T18:59:15Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
