# Sending group of photos with telegram bot

**URL:** https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228
**Category:** General
**Tags:** telegram
**Created:** [7 February 2025 21:22 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228 "2025-02-07T21:22:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![yusufscelik](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yusufscelik/32/98689_2.png) [@yusufscelik](https://discourse.nodered.org/u/yusufscelik)
#### Post date: [7 February 2025 21:22 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/1 "2025-02-07T21:22:31Z")

</div>

I want to send group of photos via using telegram sender. I am using "node-red-contrib-telegrambot"

My nodes looks like this

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf4f19b2180d6b59f9ecc92c295027dd9820681b.png)

the first function returns the path of the photos like this; (the photos are located on my server locally)

```auto
//return path of photos
let numberpage = 609;

msg.payload = [
    `/data/photos/${numberpage}.jpg`,
    `/data/photos/${numberpage + 1}.jpg`,
];
return [msg];

```

Then i split them and i read these files and join together and i create a buffer like this which contains two images.

//debug 7 looks like this  
msg.payload : array[2]  
array[2]  
0: buffer[1892013]  
1: buffer[1651348]

And then i take this two array as content for sending as a message. It looks like this;

```auto
//content for message function node
var msg = {
    chatId: 9999999, //example
    content: msg.payload, //here should come the 2 images.
    type: "photo"
}
return msg;

```

But i get this error.

**msg : string[20]**

**"msg.payload is empty"**

I think there is a problem with the last function. Because it gives me msg.payload is empty.

Can someone help me? Thanks 🙂

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 February 2025 21:35 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/2 "2025-02-07T21:35:44Z")

</div>

> [@yusufscelik](#):
>
> ```auto
> var msg = {
> chatId: 9999999, //example
> content: msg.payload, //here should come the 2 images.
> type: "photo"
> }
> 
> ```

should be

```auto
msg.payload = {
    chatId: 9999999, //example
    content: msg.payload, //here should come the 2 images.
    type: "photo"
}

```

But if you add all photos to a httpstatic folder you can just us the file uri's [Configuration : Node-RED](https://nodered.org/docs/user-guide/runtime/configuration#runtime-configuration)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [7 February 2025 22:16 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/4 "2025-02-07T22:16:26Z")

</div>

First try sending one photo

[edit] I have no issues sending single buffer images, using this, you could split your payload and send multiple messages. Not sure if the telegram bot can send group media messages.

```auto
msg.payload = {
  caption: msg.topic,
  type : 'photo',
  chatId: chatid,
  content: msg.buffer,
  fileOptions:{
    filename: msg.topic + '.jpg',
    contentType: 'image/jpeg',
  }
}
```

---

<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 February 2025 17:33 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/5 "2025-02-08T17:33:53Z")

</div>

> [@yusufscelik](#):
>
> `<hr><center>nginx/1.18.0</center>`

Oooh, naughty Telegram.

Not a good idea to show everyone what web server/proxy they are using and its version. They are asking to be hacked.

---

<div class="post-metadata">

### Author: ![yusufscelik](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yusufscelik/32/98689_2.png) [@yusufscelik](https://discourse.nodered.org/u/yusufscelik)
#### Post date: [8 February 2025 22:13 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/6 "2025-02-08T22:13:52Z")

</div>

I can send one photo its not the problem i can even send more photos but it can not send group of photos at the same time.

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/2/12208f0561db45a82fe54bb8e5ce058147876e61.png)

### My Process:

1. **Generating the File Paths:**

- The first function determines the file paths of the three images dynamically.
- It constructs an array of file paths based on a variable `number_of_pages`:

```auto
var number_of_pages = 1;

msg.payload = [  
  `/data/photos/${number_of_pages}.jpg`,
  `/data/photos/${number_of_pages+1}.jpg`,
  `/data/photos/${number_of_pages+2}.jpg`
];

return msg;

```

**Processing the Images:**

The paths are split, and each file is read individually.  
After reading, the images are grouped together again.  
Once joined, the msg.payload appears as an array of buffers:

```auto
2.2025, 22:10:08 node: debug 2
msg.payload : array[3]
[buffer[3097142], buffer[1620527], buffer[1667224] ]

```

**Formatting the Telegram Message:**

- A function formats the message to be sent via the Telegram bot.  
It encapsulates the buffer array within an object containing the chat\_id, content, and type:

```auto
msg.payload = {
    chat_id: 1099927519, //example
    content: msg.payload,
    type: "photo"
};

return msg;

```

**Final node before sending;**

```auto
msg.payload : Object
object
chat_id: 1099927519 //example
content: array[3]
type: "photo"

```

The error that i got;

```auto
Caught exception in sender node:

Error: EPARSE: Error parsing response: <html>

<head><title>414 Request-URI Too Large</title></head>

<body>

<center><h1>414 Request-URI Too Large</h1></center>

<hr><center>nginx/1.18.0</center>

</body>

</html>
when processing message: 
{"payload":{"content":[{"type":"Buffer","data":[255,216,255,225,31,136,69,120,105,102,0,0,77,77,0,42,0,0,0,8,0,12,1,0,0,3,0,0,0,1,7,181,0,0,1,1,0,3,0,0,0,1,11,4

```

I also tried "sendMediaGroup" method but it didnt work.

Any suggestions?

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [8 February 2025 22:16 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/7 "2025-02-08T22:16:10Z")

</div>

So after investigating the examples it is possible, but the example shows a uri not a buffer

```auto
msg.payload.type = "mediaGroup";
msg.payload.content = [
    {
        type : "photo",
        media : "path1.jpg",
        caption : "Photo 1"
    },
    {
        type : "photo",
        media : "path2.jpg",
        caption : "Photo 2"
    }
];

```

You could attempt replacing the uri with a buffer in similar format, it may work.

---

<div class="post-metadata">

### Author: ![yusufscelik](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yusufscelik/32/98689_2.png) [@yusufscelik](https://discourse.nodered.org/u/yusufscelik)
#### Post date: [8 February 2025 22:39 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/8 "2025-02-08T22:39:26Z")

</div>

> [@E1cid](#):
>
> First try sending one photo
> 
> [edit] I have no issues sending single buffer images, using this, you could split your paylload and send multiple massages. Not sure if the telegram bot can send group media messages.
> 
> ```auto
> msg.payload = {
> caption: msg.topic,
> type : 'photo',
> chatId: chatid,
> content: msg.buffer,
> fileOptions:{
> filename: msg.topic + '.jpg',
> contentType: 'image/jpeg',
> }
> }
> 
> ```

the solution you referenced is about sending **multiple separate messages** , not a **grouped album of photos** in a single message. Like photo1, photo2 etc.. not [photo1,photo2] together. The `Telegram Sender` node in Node-RED as i read **only supports sending individual messages**. Because of that I need to use `sendMediaGroup`from Telegram API and i'll use HTTP Request node for that. I'll post my solution here later.

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [8 February 2025 22:40 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/9 "2025-02-08T22:40:38Z")

</div>

see above.

[edit] Just tested and is possible using a buffer in the format i posted above

```auto
msg.payload = {
    type: "mediaGroup",
    chatId: chatid,
    content: [
        {
            type: "photo",
            media: buffer1,
            caption: "Photo 1"
        },
        {
            type: "photo",
            media: buffer2
            caption: "Photo 2"
        }
    ]
}

```

---

<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: [22 February 2025 22:41 UTC](https://discourse.nodered.org/t/sending-group-of-photos-with-telegram-bot/95228/10 "2025-02-22T22:41:32Z")

</div>

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