YI-HACK - Send video files to Telegram


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:

"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/, e.g.


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 :slight_smile:

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

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 :wink:

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

1 Like

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:


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

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

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

"files":[ "2021Y02M23D14H/29M00S60.mp4", "2021Y02M23D14H/28M23S36.mp4" ]

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

Now it works :slight_smile:

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

[{"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":"","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 :wink:


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