# YI-HACK - Send video files to Telegram

**URL:** https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490
**Category:** General
**Created:** [23 February 2021 13:59 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490 "2021-02-23T13:59:43Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Grist](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Grist](https://discourse.nodered.org/u/Grist)
#### Post date: [23 February 2021 13:59 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/1 "2021-02-23T13:59:43Z")

</div>

Hi,

I am using an YI camera that has the MQTT service enabled. When a motion is detected, then there is a topic on the MQTT broker with e.g. the following value:

```auto
{
"start":"2021-02-23T14:28:47+0100",
"end":"2021-02-23T14:29:47+0100",
"files":["2021Y02M23D14H/29M00S60.mp4", "2021Y02M23D14H/28M23S36.mp4"]
}

```

The **number of the files listed** within the "files" value can vary.... The files are accessible at [http://ycamera/record/](http://ycamera/record/), e.g.

```auto
http://ycamera/record/2021Y02M23D14H/29M00S60.mp4
http://ycamera/record/2021Y02M23D14H/28M23S36.mp4

```

I am able so far to send text messages and single photos to my Telegram account...one message -\> one action to send this payload text to Telegram...same for the photos.

How can I dynamically get these 1..n video files and send them one after another to telegram?

Thanks in advance 🙂

---

<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: [23 February 2021 21:13 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/2 "2021-02-23T21:13:17Z")

</div>

Is your question about how to send video to Telegram or how to process an array of filenames?

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [24 February 2021 06:26 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/3 "2021-02-24T06:26:49Z")

</div>

> [@Grist](#):
>
> How can I dynamically get these 1..n video files and send them one after another to telegram?

If the video files would be accessable from internet, you could send the http links to Telegram but I assume you have and want to keep them locally only. So you will have to do it in a two-step approach

For each file

1. Get it and save it to your local file system
2. Read the file and send it via Telegram

This is a simple flow demonstrating the second part, it works well, sending video files via Telegram. I decided to use a Change node with a JSONata expression, you just have to set your chatId and configure your Telegram node and the Bot

Obviously my flow doesn't solve the first part so that remains for you to be figured out 😉

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c8c05461c657c9c977d806e7b859bc1d448898e0.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/a/faca06fe06faff5b7c6a5518c79cc7945c7411f7.png)

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [24 February 2021 08:38 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/4 "2021-02-24T08:38:44Z")

</div>

Here is a simple flow pattern I just made showing how to get the images, save to file system and then send them via Telegram

There are two rate limiting nodes in there as well. The first is to give some time to finish writing the file. The second is to give Telegram node "some time" to do it's stuff

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/4/54487a780bb3131ec46a1cfae444f0b070052efe.png)

---

<div class="post-metadata">

### Author: ![Grist](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Grist](https://discourse.nodered.org/u/Grist)
#### Post date: [24 February 2021 10:30 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/5 "2021-02-24T10:30:48Z")

</div>

Thank you for your help so far! I was able to simulate the flow by injecting a string from the array...then I change the string in the function-node to have the whole url needed...like http://......./filename.mp4

Next step, I use a change node to set the method and url by using the **msg.method** and **msg.url** properties:

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

and the http request returns a binary object that can send the video without having to save it locally:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/498e6e5a0e95e5c35d1465a5dabe6c6fae60a11b.png)

So far so good...I get the video on my Telegram account 🙂

The only thing that I miss is how to process the array of the "files" filenames:

```auto
{
"start":"2021-02-23T14:28:47+0100",
"end":"2021-02-23T14:29:47+0100",
"files":["2021Y02M23D14H/29M00S60.mp4", "2021Y02M23D14H/28M23S36.mp4"]
}

```

---

<div class="post-metadata">

### Author: ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)
#### Post date: [24 February 2021 12:23 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/6 "2021-02-24T12:23:50Z")

</div>

> [@Grist](#):
>
> The only thing that I miss is how to process the array of the "files" filenames

To do that you need to create a loop that takes the msg.files array, iterates through the array and for each file, just do the stuff, inject each into your function node

---

<div class="post-metadata">

### Author: ![Grist](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Grist](https://discourse.nodered.org/u/Grist)
#### Post date: [24 February 2021 15:00 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/7 "2021-02-24T15:00:26Z")

</div>

Now it works 🙂

I am posting the soluton...in case someone is looking for it in the future:

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

```auto
[{"id":"b362cab5.0c908","type":"json","z":"e05dcd57.8b6d6","name":"","property":"payload","action":"","pretty":false,"x":330,"y":140,"wires":[["cca9d95f.c46918"]]},{"id":"cca9d95f.c46918","type":"function","z":"e05dcd57.8b6d6","name":"","func":"var videofileList = [];\nvar videofiles = msg.payload.files;\nfor (var i =0 ; i < videofiles.length; i++){\n videofileList.push({payload:videofiles[i]});\n}\nreturn [videofileList];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":140,"wires":[["5cef4.3616110cc"]]},{"id":"5cef4.3616110cc","type":"function","z":"e05dcd57.8b6d6","name":"","func":"var newMsg = {};\nnewMsg.topic = \"message\";\nnewMsg.payload = \"http://\" + global.get('y_username') + \":\" + global.get('y_password') + \"@\" + global.get('yihack_record') + msg.payload;\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":140,"wires":[["84498846.d619c8"]]},{"id":"84498846.d619c8","type":"change","z":"e05dcd57.8b6d6","name":"","rules":[{"t":"set","p":"method","pt":"msg","to":"get","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":140,"wires":[["9a0ad461.d7679"]]},{"id":"7381f27d.958964","type":"mqtt in","z":"e05dcd57.8b6d6","name":"yihack/motion_files","topic":"yihack/motion_files","qos":"2","datatype":"auto","broker":"5779f087.962a9","x":150,"y":140,"wires":[["b362cab5.0c908"]]},{"id":"9a0ad461.d7679","type":"http request","z":"e05dcd57.8b6d6","name":"","method":"use","ret":"bin","paytoqs":"body","url":"","tls":"","persist":false,"proxy":"","authType":"","x":350,"y":220,"wires":[["47ccf24f.d65894"]]},{"id":"47ccf24f.d65894","type":"delay","z":"e05dcd57.8b6d6","name":"Limit 1 msg / 5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":560,"y":220,"wires":[["7d9c9ade.e44d7c"]]},{"id":"7d9c9ade.e44d7c","type":"function","z":"e05dcd57.8b6d6","name":"Video -> Telegram-Payload","func":"var newMsg = {};\nnewMsg.topic = \"Telegram Message\";\nnewMsg.payload = { chatId: 1234567890,\n type: \"video\",\n content: msg.payload };\nreturn newMsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":810,"y":220,"wires":[[]]},{"id":"5779f087.962a9","type":"mqtt-broker","name":"","broker":"192.168.1.100","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

It requires of course editing the MQTT broker settings and the chatId of the Telegram account 😉

---

<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: [25 April 2021 15:00 UTC](https://discourse.nodered.org/t/yi-hack-send-video-files-to-telegram/41490/8 "2021-04-25T15:00:28Z")

</div>

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