How To Send Blue Iris Images to Telegram

by Danny
34 comments

READING TIME: 8 MINUTES

In this guide, I’m going to show you how to send motion alerts (analyzed by Deepstack) from your Blue Iris NVR to Telegram (Option 1). I will also show you how to attach a Deepstack-analyzed photo of your tracked object and send it to Telegram (Option 2).

One of the biggest advantages of using a Telegram bot for Blue Iris alerts is that it will show you a history of every alert that has ever been triggered with the included image.


Prerequisites

You will need the following items setup:

Once you have those items ready to go, you can continue following this guide.


Set Up Telegram Bot

Before you can get Telegram alerts from Blue Iris, you first need to create a Telegram bot to get your API key and Chat ID.


Option 1: Send Generic Text Message to Telegram

Create & Test Telegram Message

Before we start messing around in Blue Iris to receive motion alerts, we should first check to make sure you can receive ANY alerts at all in Telegram from a web request.

To test, create a Telegram HTTP Web Request URL.

https://api.telegram.org/botTelegramAPIKey/sendMessage?chat_id=ChatID&text=Motion detected in Driveway!

Once you replace the API key and Chat ID with your own, paste the URL into a browser. You should receive a Telegram text notification with a generic “Motion detected in Driveway!” message.

This image has an empty alt attribute; its file name is image-132.png

Once you’ve received the message, you can now add the URL to Blue Iris.

If your ChatID came with a hyphen – use it. If it doesn’t have a hyphen, don’t add it at the front like I did.


Edit Blue Iris Camera Alert

Next, log into your Blue Iris server.

Right-click a camera > Camera Settings.

Click the Alerts tab > On Alert.

Click the + button > Web request or MQTT.

Switch to https:// and then paste the URL from the previous step. Leave out the https:// as it’s already in the dropdown.


Test Sending Motion Alerts to Telegram

Now, you can simply walk in front of your camera. Within a second or two, you should receive a text alert in Telegram!

Once you verify that this works for one camera, you can set the alerts for each camera. The only thing you’ll need to change is the message (For example, change Motion detected in Driveway to Patio).


Option 2: Send Deepstack-analyzed images from Blue Iris to Telegram

Step 1: Download CURL

Download CURL for Windows on your Blue Iris server.

Choose 64 bit.

Right click the zip > Extract to your Downloads folder.


Step 2: Create 2 new Windows Folders

Next, create two new folders in your parent “BlueIris” folder (This is the Windows folder where you already have New, Alerts, Stored, and db folders). Name them:

  • Telegram_Alerts
  • Telegram_Upload

Your parent BlueIris folder should now look like this:


Step 3: Copy BIN folder to Telegram_Upload folder

Click into your extracted CURL folder. The folder should be named something like curl-7.78.0-win64-mingw.

Copy the entire BIN directory to the S:\BlueIris\Telegram_Upload folder.


Step 4: Add Telegram_Alerts folder to Blue Iris

For this step, we are adding a new folder to Blue Iris. We are doing this so Blue Iris will copy JPEG images (that Deepstack has already analyzed and detected as a “person” object) into the Telegram_Alerts folder.

Within Blue Iris Admin, click the gear at the very top to edit the global settings.

Click the Clips and archiving tab.

Under Folders, choose one your spare Aux folders (Aux 1). Then, add the path to your Telegram_Alerts folder. (S:\BlueIris\Telegram_Alerts). Then click OK.

Step 5: Edit camera settings (to save JPEG files to new folder)

Log into your Blue Iris server. Right-click a camera > camera settings.

Switch to the Record tab.

Check the box for JPEGs, set it to When Alerted, change the folder to Aux 1, and set the quality to 100%. If you have 4k cameras, you might want to adjust the quality and/or resize it so it uploads quicker.

Now, whenever Blue Iris/Deepstack detects motion, it will place the image in your Telegram_Alerts folder, which is exactly what we need for the next step. The next step will have you create a command to copy the latest image in that folder & send it to Telegram.


Step 6: Create Telegram_upload.cmd file

Open Notepad on your Blue Iris server. Paste in the command below. Edit the paths in green, the Telegram API key in red, and the Chat ID in orange.

Reminder: If your ChatID came with a hyphen – use it. If it doesn’t have a hyphen, don’t add it at the front like I did.

SET PICFolder=S:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%%i
rem for /f %i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%i

CURL https://api.telegram.org/botTelegramAPIkey/sendphoto -F chat_id=-ChatID -F photo=@S:\BlueIris\Telegram_Alerts\%LAST%

Then go to File > Save As. Name the file Telegram_Upload.cmd and save it to your S:\BlueIris\Telegram_Upload folder.


Final Step: Create Blue Iris Camera Alert to run command

Edit your camera again. Switch to the Alerts tab.

Under the Actions section, click On alert.

Click the + button to create a new alert. For the action, select Run program/script and point it to the path of your Telegram_upload.cmd file.

Then click OK on all the camera settings screens to save everything.


Testing it Out

Now, simply walk in front of your camera. If all goes well, the command should run and you should receive the latest image from the S:\BlueIris\Telegram_Alerts folder directly in Telegram!

Hint: As long as there is at least 1 image in the Telegram_Alerts folder, you can also simply run the Telegram_Upload.cmd file by clicking it. That way you don’t have to run in front of your camera a bunch of times. If you receive the image, then you know it worked!


Optional Tweaks

If you notice it’s taking a while to get the image in Telegram, you might want to change the quality/resolution from 100% to 50% so the filesize is smaller. 4k cameras obviously have a much larger file size and will take the longest to upload to Telegram. For reference, my images are 1080p. I receive text messages almost immediately, and pictures within 5-10 seconds.

If you are receiving too many alerts, you can edit that as well. Camera > Camera Settings > Alerts tab. Check the box for “minimum wait time between alerts” and set a threshold.

If you would like to include a message with your picture, then create both Option 1 and Option 2. You will have 2 alerts configured for each camera. You will first receive the text message letting you know which camera was triggered, and then a few seconds later you’ll get the corresponding picture.

If you would like to only receive alerts during a specified time frame (such as overnight), you can create a 2nd script with a set time frame that calls the Telegram_Upload.cmd file. If between the hours you specify, the script runs. If it doesn’t meet your criteria, it doesn’t. Here’s how to set that up: https://smarthomepursuits.com/run-batch-file-during-certain-time-window/


Wrapping Up

This guide took me way too long to figure out and script together, so if it worked for you – please let me know in the comments below and share it in any forums/threads where you see others requesting how to do this.

Good luck, and hopefully this helps you send pictures to your Telegram bot when Blue Iris and Deepstack detects motion!


My Homelab Equipment

Here is some of the gear I use in my Homelab. I highly recommend each of them.

The full list of server components I use can be found on my Equipment List page.

34 comments

You may also like

34 comments

Ian Butcher August 19, 2021 - 11:53 am

Hi Danny

Great write up thank you – this is exactly what I wanted to do, using inbuilt deepstack and push images to an app (other than the BlueIris app)

I wonder if you can help though – it’s not quite working. I’m getting the picture in the Telegram_Alerts directory, and the alert is triggering, but the response from the script is giving me the following error:
{“ok”:false,”error_code”:404,”description”:”Not Found”}
This means I am not getting the message with the picture attached.

Any ideas?

Reply
Danny September 1, 2021 - 4:12 am

Sorry for the late response! I just realized my replies were never sending out to commenters.

Hey Ian,

I received that error several times when writing the script, but it was usually due a bad path.

Just in case you hadn’t figured it out yet, I was missing the word “bot” in my command. Put bot before the TelegramAPIkey. I’ve also updated my guide with the correct syntax for you. Let me know if that works!

Reply
Ian September 1, 2021 - 7:21 am

Hi Danny

Yes, I managed to work it out, but thanks anyway!

Reply
Jeff August 21, 2021 - 3:51 pm

I just followed the steps and got it working, was wondering if it’s possible to get the Deepstack analyzed images? Would I have to copy it from the alerts folder?

Reply
Danny September 1, 2021 - 4:10 am

That’s exactly what it does already. If you look in your current Alerts folder, it contains all images – both images taken every few seconds and the Deepstack ones. I basically just configured Deepstack to copy the “alerted” files to separate folder for use with Telegram image messages.

Reply
Michael September 5, 2021 - 4:06 am

Thank you very much for this good description on how to get telegram working with BlueIris. It must have been a lot of work for you!

Reply
Danny September 5, 2021 - 10:00 am

You’re welcome Michael, I’m glad it helped you send images to Telegram!

Reply
Richie October 13, 2021 - 10:15 am

Very good article. The only issue I have is that the script is sometimes sending the same image twice, as BI hasn’t sent the new alert JPEG to the folder yet.

Reply
Richie October 13, 2021 - 12:01 pm

Thank you for this write up! Got it working as it should, although there’s a slight flaw with the script I wonder if you can assist with. I have an issue where an alert will take place, but the last image is sent again. So I end up with many copies of the same image alert. Is there a way to adjust the script so this doesn’t happen?

Thanks again!

Reply
Danny October 13, 2021 - 2:47 pm

Great! I’m glad you got it working following my guide.

I do occasionally get double images, but I haven’t looked into why yet. I think a few possible things you can look into are:

1. Reducing image size/quality so Deepstack can process them quicker.
2. In the Alerts tab of the camera, look at the Timer settings. I’m not sure if the Timer settings also affect the Action settings, but if it does – maybe set the “Wait until triggered at least” option to 2 or 3.
3. You could add a “SLEEP 5” or something like that to the top of the .CMD file, but then it’ll delay ALL alerts by a few seconds, so idk if that’s something you’d want to do. I actually think what you’d have to do is create a 2nd batch file (Telegram_Upload_Wait.cmd) that calls the Telegram_Upload.cmd using an if/then statement. If Telegram_Upload.cmd hasn’t ran in the last 5 seconds, then call it. If not, do nothing.

If you do figure out a good solution or script, let me know and I’ll test it out!

Reply
Gerrit Johannes Human October 23, 2021 - 10:25 am

Thanks for the fantastic tutorial.

I’ve been working on this for a few hours and couldn’t get the picture to come through only the text.

I’ve even installed BlueIris on another PC just to try something else. My problem was my chat ID didn’t come with a hyphen “-“. In your tutorial you specifically say to remember the hyphen for the chat ID “…id=-ChatID…” . Maybe just add a sentence there to say that: “if your ChatID came with a hyphen use it, if it didn’t come with a hyphen don’t add it at the front”.

Thanks for the fantastic tutorial!

Reply
Danny October 23, 2021 - 10:32 am

Oh interesting, I assumed everyone’s chat ID included a hyphen. I will definitely update my post – thanks so much for the tip on that and I’m glad you got it working!

Reply
Joe October 23, 2021 - 4:03 pm

Awesome tutorial. I got this working for 2 days and it stopped working. Deepstack is still creating the files in the “Alerts” folder, but nothing is being copied into the “Telegram_Alerts” folder since 10/21. The bin folder is still in the “Telegram_Upload” folder and so is the cmd file. The trigger settings haven’t been changed in Blue Iris either. If I manually run the command file it pushes the old file from 10/21 through Telegram within a second or 2 without an issue. I think Curl might be the issue, but I’m not sure how Curl helps with copying the images from “Alerts” into “Telegram_Alerts”. Have you experienced this? Thanks

Reply
Danny October 23, 2021 - 4:13 pm

If it’s not copying new files to the Telegram_Alerts folder, then it’s got to be an issue with step 4 or 5. You’re right; the CURL command isn’t in play for the copy, and you’ve confirmed that the CURL command still works when running manually.

It could also be a random issue with BI or Windows, have you tried restarting the application or host computer to see if that helps?

Reply
Corne Ellis November 19, 2021 - 5:10 am

Hi Danny,
I wonder if possible if you can perhaps login to my pc and help setup,i do get alerts via telegram but no pictures.Followed you step by step but missing something.Please if you can.

Reply
Joe October 23, 2021 - 6:01 pm

Yeah, I’ve restarted Windows. Blue Iris is up to date as of today as well. It’s strange because the settings haven’t changed and it was working. It just stopped on its own on 10/21 at night. I haven’t tried disabling the JPEG setting and enabling it again. Maybe just BI glitching.

Reply
Corne Ellis November 18, 2021 - 12:32 pm

Hi Danny,
I wonder if possible if you can perhaps login to my pc and help setup,i do get alerts via telegram but no pictures.Followed you step by step but missing something.Please if you can.

Reply
ev March 8, 2022 - 11:14 am

if you add the following string to any notification (sms, email, Telegram), it will create a link at the end of the message to Ui3 >> &WAN/ui3.htm?rec=&ALERT_DB&maximize=1

https://ipcamtalk.com/threads/how-to-stream-blue-iris-alerts-directly-in-ui3-on-any-device.54886/

Reply
Sven April 5, 2022 - 1:13 am

Morning

is this still working as described above, I have followed the steps exactly and the images are being fed to the correct folder, but when running the cmd, it doesn’t upload to telegram, have created the bot and made a group, including the – at the front. I suppose we exclude the hashtag. got the word bot at the front of the api key

Reply
Danny April 5, 2022 - 4:34 pm

Mine is still working perfectly, no changes made since I wrote this.

Can you trigger a generic message from Option 1? Just wondering if it’s images only that aren’t sending or nothing at all.

Also – if your API key doesn’t have a dash, then remove it. Here’s my exact .cmd file (numbers changed, obviously):


SET PICFolder=S:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%%i
rem for /f %i in ('dir "%PICFolder%" /b/a-d/od/t:c') do set LAST=%i

CURL https://api.telegram.org/bot19777777777:BHFfRJjqL-V-xtGFJIUWorydlc31P3BiNwQ/sendphoto -F chat_id=-78656754 -F photo=@S:\BlueIris\Telegram_Alerts\%LAST%

Reply
Sven April 6, 2022 - 1:31 am

SET PICFolder=C:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i

CURL https://api.telegram.org/bot5117555087:AAGT5JSPGVb3Rj26TXXXXXXXXX/sendphoto -F chat_id=-XXXXXXXXX -F photo=@C:\BlueIris\Telegram_Alerts\%LAST%

this is my command, do you see any issues?

Reply
Sven April 6, 2022 - 1:37 am

SET PICFolder=C:\BlueIris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i

CURL https://api.telegram.org/bot5117555087:AAGT5JSPGVb3Rj26TXXXXXXXXX/sendphoto -F chat_id=-XXXXXXXXX -F photo=@C:\BlueIris\Telegram_Alerts\%LAST%

this is my command, do you see any issues?

the message option does go through to the group

Reply
Danny April 6, 2022 - 9:17 pm

I copied both your code and my code into Notepad++ and ran Compare. When you switch between the two files you’ll notice the apostrophes, quotes, and parenthesis are slightly different (some are bolder, more italicized, etc.) The results of Compare also show these two files are different because of the quotes/parenthesis being different, too. I wonder if that has something to do with it.

I wish I knew how to explain this better, but here’s a screenshot: https://imgur.com/a/VDoSXjz

Reply
sven April 7, 2022 - 12:58 am

Understood, strange that it did that in notepad as I copy-pasted your code directly into it, perhaps it’s a region thing and windows adjust accordingly. will alter and let you know.

Reply
Sven April 12, 2022 - 12:42 am

So after checking this it doesnt appear to be a formatting issue, see attached screenshots of my entire setup, not sure what happened as to why you see it differently on your side than I do when copy pasting.

https://ibb.co/swyF8BK
https://ibb.co/WfS8zBg
https://ibb.co/kgk8Skp
https://ibb.co/sg8K1WT
https://ibb.co/DtmZWn6
https://ibb.co/QQtqYhB

Reply
Blaine April 18, 2022 - 11:32 pm

Seems like everything is working except I get the following error when curl tries to send the photo to Telegram:

curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) – The revocation function was unable to check revocation for the certificate.

Seems to be an issue with certificate

Reply
G July 1, 2022 - 11:46 am

At first I was setting TLS error, which was fixed by running: “[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12”
However, now I’m getting either of these errors (with or without “‘s)

CURL : {“ok”:false,”error_code”:404,”description”:”Not Found”}
Invoke-WebRequest : A parameter cannot be found that matches parameter name ‘F’

Reply
kevin July 23, 2022 - 10:12 pm

SET PICFolder=D:\Blue Iris\Telegram_Alerts
::Get Latest File
for /f %%i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%%i
rem for /f %i in (‘dir “%PICFolder%” /b/a-d/od/t:c’) do set LAST=%i

CURL https://api.telegram.org/bot5598689928:AAHskBrTfp1894dpgQpnFUjIxwBHWoIx0tE/sendphoto -F chat_id=-754844202 -F photo=@D:\Blue Iris\Telegram_Alerts\%LAST%

i get error curl: (26) Failed to open/read local data from file/application

Reply
kevin July 23, 2022 - 10:36 pm

curl: (26) Failed to open/read local data from file/application
how to fix this error

Reply
Marcus September 18, 2022 - 5:42 am

Hi
I tested my web browsers on both PCs, 1 at work and 1 at home, both browsers cannot load the
pictures / diagrams.

Can you fix the links to the pictures, there are not loading up.

Thank you.

Regards,
Marcus

Reply
Danny September 19, 2022 - 1:19 pm

Thanks for letting me know. I just fixed the caching issue, pics are now showing up correctly again.

Reply
Marcus September 20, 2022 - 5:21 am

Thanks, Danny the pics are loading now!

Reply
Marcus September 28, 2022 - 11:38 am

Hi Danny,

I double-check the path is correct = C:\BlueIris\Telegram_Upload\Telegram_Upload.cmd
All profiles: 1 to 7 are turned on (no grey out).
I tested the command: Telegram_Upload.cmd in the Action Set window, by pressing the “thunder” icon.
I get a response from Blue Iris: Web: HTTP/1..1 200 ok, I pressed OK button to close the window.
I do get notifications on my Telegram Bot.
I have double-checked there are lots of photos in Telegram_Alerts.
I have double-checked the command syntax is correct.
But I don’t get any photos sent to my Telegram Bot. I only received messages.

What could be the reason of not get the photos sent?

Thank you.

Reply
Omish October 26, 2022 - 12:37 pm

For anyone receiving doubles of images in their feed.

I fixed this by simply putting a timeout at the beginning of the curl script.

Timeout /t 5

I found that the alert was being sent out before my cpu could process the deepstack image and place it in the alerts folder. Therefore it was grabbing the previous image from an earlier time.

By delaying the entire script by 5 seconds it gave my cpu enough time to process the new image.

Hope this helps

Reply

Leave a Comment