send Telegram notifications with pictures

address was long one I corrected to now when alert goes, or when I send test alert it crashes:

Code:
5. Use {ip}:3000/snapshot?camera=$CAM in blue iris alert web request to get a snapshot
(node:2280) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'C:\blue-iris-telegram-bot\images\snapshot.jpg'
(node:2280) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)
(node:2280) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
events.js:288
      throw er; / Unhandled 'error' event
      ^

Error: Cannot find ffmpeg
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\processor.js:136:22
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\capabilities.js:123:9
    at wrapper (C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:272:20)
    at next (C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:4584:24)
    at C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:325:20
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\capabilities.js:116:11
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\utils.js:223:16
    at F (C:\blue-iris-telegram-bot\node_modules\which\which.js:68:16)
    at E (C:\blue-iris-telegram-bot\node_modules\which\which.js:80:29)
    at C:\blue-iris-telegram-bot\node_modules\which\which.js:89:16
Emitted 'error' event on FfmpegCommand instance at:
    at emitEnd (C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\processor.js:424:16)
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\processor.js:433:16
    at wrapper (C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:272:20)
    at next (C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:4584:24)
    at C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:325:20
    at wrapper (C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:272:20)
    at next (C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:4584:24)
    at C:\blue-iris-telegram-bot\node_modules\async\dist\async.js:325:20
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\capabilities.js:519:16
    at C:\blue-iris-telegram-bot\node_modules\fluent-ffmpeg\lib\processor.js:136:16
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! blue-iris-telegram-bot@1.0.0 start: `node index.js "index.js"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the blue-iris-telegram-bot@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\root\AppData\Roaming\npm-cache\_logs\2020-02-25T12_00_12_052Z-debug.log

For creating the gif's from images you need to install ffmpeg. I forgot about it, since its a pretty common thing that is often installed along with other software.

You can download it from here Builds - Zeranoe FFmpeg.

Please try if it works for you, otherwise you may need to add it to your windows PATH environment variable.
 
thanks, I did download ffmpeg and put it to c:\ffmpeg , then I added in windows environment settings path c:\ffmpeg\bin
it still doesnt work, or no messages send thru telegram.
I got first errors, but it was missing path in windows enviroment should be like "c:\ffmpeg\bin\" (without quotes).
however chat is working:

Code:
Blue Iris Alert bot listening on port 3000!
1. enter your settings in conf.json and restart
2. contact the bot with /start
3. check this console output for the userId
4. add the userId to the ALLOWED_USER in conf.json
5. restart this bot
5. Use {ip}:3000/snapshot?camera=$CAM in blue iris alert web request to get a snapshot
{"gif":[],"snapshot":[xxxxxxxxx]}
writing to chats.json
{"gif":[544227395],"snapshot":[xxxxxxx]}
writing to chats.json
 
Last edited:
ok, now it works almost. I have to run test from camera alert.
almost: it triggers when I made movement, but snapshot or gif what it sends is 4days ago :rofl:
 
ok, now it works almost. I have to run test from camera alert.
almost: it triggers when I made movement, but snapshot or gif what it sends is 4days ago :rofl:

Are u on windows?
I can't get it to send; always errors out
 
yes, windows10.
what I have now done:
1. download and extract from tlow92/blue-iris-telegram-bot clone/download button, extracted it to C:\blue-iris-telegram-bot
2. installed NodeJS Node.js node-v12.16.1-x64.msi
3. from "Node.js command prompt" I did go to C:\blue-iris-telegram-bot folder and run npm install
4. configure C:\blue-iris-telegram-bot conf.json except "ALLOWED_USER" this one comes after you have started chat with bot (I made new one for cameras)
5. ctrl +c command prompt, and add number from command prompt to ALLOWED_USER in config.json.
5. download Builds - Zeranoe FFmpeg selecting 4.2.2 windows 10 64bit static, and extract it to c:\ffmpeg
6. add windows path c:\ffmpeg\bin\ like instructed in here: How to Install FFmpeg on Windows 10 & Add FFmpeg to Windows Path
7. reboot
8. run test from one camera it send picture or gif add to cameras alert : http 127.0.0.1:3000/snapshot?camera=&CAM

but in my case, I have 4 cameras and all cameras sends snapshot from 4 days ago from that one camera only. all cameras have that shoud it be something else like I have in mqtt alerts Blueiris/&CAM/&TYPE
 
Last edited:
Heres how I do it:
1) Download curl for Windows from curl for Windows and copy the bin folder (in the zip file) to a location (I put mine into D:\BlueIris\Telegram_Upload)

2) Configure the BlueIris Camera: Post. Define what folder you are going to export the motion snapshots. Make sure it is a folder with the same shortname as the BlueIris camera.
2020-11-19 12_17_20-srv-cctv-01 - TightVNC Viewer.png
3) Download, extract the zip file Telegram_Upload.cmd.txt (rename to .cmd) to the same location as step 1.

4) Modify Telegram_Upload.cmd (previous step) to reflect your details and file locations

5) Configure the BlueIris Camera: Alert
Tick "Run a program or execute a script" then click Configure button next to that
2020-11-19 12_38_53-srv-cctv-01 - TightVNC Viewer.png
 

Attachments

  • Like
Reactions: tms5d
Heres how I do it:
1) Download curl for Windows from curl for Windows and copy the bin folder (in the zip file) to a location (I put mine into D:\BlueIris\Telegram_Upload)

2) Configure the BlueIris Camera: Post. Define what folder you are going to export the motion snapshots. Make sure it is a folder with the same shortname as the BlueIris camera.
View attachment 75307
3) Download, extract the zip file Telegram_Upload.cmd.txt (rename to .cmd) to the same location as step 1.

4) Modify Telegram_Upload.cmd (previous step) to reflect your details and file locations

5) Configure the BlueIris Camera: Alert
Tick "Run a program or execute a script" then click Configure button next to that
View attachment 75310
really like this approach! could you help me adjust the code so it sends the latest N pictures instead of a single one? thanks!!
 
Hi All,

Thanks for the work on this, especially @tlow for creating the telegram bot and @pumo for documenting their troubleshooting steps.

I have done the installation now and successfully receive images and gifs on telegram.

However, the messages go directly to the bot itself. I would like to send the messages to a group instead (the bot is a member of the group).

Has anyone tried to figure this out?

I've googled a bit and it seems that the messages should be directed with "chatID" instead of "userID" if I want it to go to the group. But I am not sure how to implement this.

Any help will be appreciated.
 
I do similar but just call curl directly from BI so no need for a shell script...

BlueIris_rm1mTtc3oJ.png


Code:
https://api.telegram.org/bot<BOTID>/sendphoto -F chat_id=<CHATID> -F photo=@D:\BlueIris\Alerts\&ALERT_PATH -F caption="[*&NAME*](http://<BIDOMAIN>/live.htm#&CAM) \- &MEMO" -F parse_mode=MarkdownV2

Obviously you need to set a bot up first and add it's API token, as well as the user/group ID you want the bot to post to.

End Result...

ApplicationFrameHost_vbJcLJSpPc.png


NB: The link to live.htm is a custom page I added to the BI www directory which displays a live view of the alerted camera and nice big clickable thumbnails of recent alert clips.
 
Last edited:
The link to live.htm is a custom page
An alternative to your custom web page could be to open ui3 and directly stream the alert.
To try it, replace the caption section of your code with the following:
caption="[*&NAME*](&WAN/ui3.htm?rec=&ALERT_DB&maximize=1) \- &MEMO"
or for mobile devices you can use a less demanding (and perfectly adequate) stream:
caption="[*&NAME*](&WAN/ui3.htm?rec=&ALERT_DB&maximize=1&streamingprofile=Jpeg HD) \- &MEMO"

I've tested this with your code (using hard-code values for the macros) in a cmd.exe window and it works just fine.
But I'm struggling to make it work in a camera 'On alert' action. Maybe you could try?
EDIT: I got it to work in the camera 'on alert' action was well - but I had to replace the &NAME macro with &CAM.
EDIT: (Solved) The camera I was testing had a long name with a hyphen ('FrontDoor-PTZ'). Apparently the Telegram API does not like this.

BTW, the &WAN macro on my system (5.4.9.18) includes the 'http://', so I've dropped it in my code above.
To preview the value of macros, you can use the following action and edit 'Parameters' field for the macro in question.
I've assigned this action to a camera preset 'On call' action which I use as a utility.

1629576871850.png


It will pop up a 5-second duration self-closing window like this

1629571942172.png
 
Last edited:
I do similar but just call curl directly from BI so no need for a shell script...


Code:
https://api.telegram.org/bot<BOTID>/sendphoto -F chat_id=<CHATID> -F photo=@D:\BlueIris\Alerts\&ALERT_PATH -F caption="[*&NAME*](http://<BIDOMAIN>/live.htm#&CAM) \- &MEMO" -F parse_mode=MarkdownV2

Nice..... I did this method and way easier. Just had to change the ALERT_PATH and what not since mines a little different, then removed the live.html link which is cool that you do that. I like this better than the script method because first and foremost this gives me the actual DeepStack alert image, the script method won't unless you modify it, that script method is setup to basically create another folder of alerts (again why duplicate when DeepStack already generating it) and then the script fires the image off that which doesn't have the DeepStack highlight. Definitely like this.

Now may play with it more, would love if it sent the higher res one, but then gotta completely change how DeepStack is working cause its working off the sub stream for me, so thats the image it gets.
 
BTW, the &WAN macro on my system (5.4.9.18) includes the 'http://', so I've dropped it in my code above.

Yes my bad, I still had the domain hardcoded on a couple of cams and using the &WAN token on the rest.
The one I took a screenshot of and copied the line from used a hardcoded address but I futzed it when I swapped it to using the token. Have edited now to fix.


An alternative to your custom web page could be to open ui3 and directly stream the alert.
UI3 always seems to take a while to load when I'm away from home on mobile, A custom lightweight page which only loads the elements I want to see loads instantly.
 
caption="[*&NAME*](&WAN/ui3.htm?rec=&ALERT_DB&maximize=1) \- &MEMO"
or for mobile devices you can use a less demanding (and perfectly adequate) stream:
caption="[*&NAME*](&WAN/ui3.htm?rec=&ALERT_DB&maximize=1&streamingprofile=Jpeg HD) \- &MEMO"

Im having trouble with the caption="[*&NAME*](&WAN/ui3.html......
It partially works but its not embedding the link and the * seems to be before and after the CAM name like below as an example:
Code:
[*FrontYard*](http://WANIP/ui3.htm?rec=@3131123123&maximize=1) \- car:81%

Not sure what Im doing wrong there. Its also putting that backslash in too before the dash


EDIT
Nevermind, I figured it out, wasn't passing the parse_mode=MarkdownV2, that was it.
 
Last edited:
  • Like
Reactions: jaydeel
Yes my bad, I still had the domain hardcoded on a couple of cams and using the &WAN token on the rest.
I intended no criticism; was just genuinely curious if the macro might be expanding differently on your system.

UI3 always seems to take a while to load when I'm away from home on mobile
I understand.
OTOH why settle for only one… when we can do both :p, just in case the cell signal is good.

Example…
Code:
https://api.telegram.org/bot{KEY}/sendphoto -F chat_id={ID} -F photo=@"D:\Blue Iris\Alerts\&ALERT_PATH" -F caption="[*&CAM*](&WAN/alerts/&ALERT_DB?fulljpeg)  [UI3](&WAN/ui3.htm?rec=&ALERT_DB&maximize=1) \- &MEMO" -F parse_mode=MarkdownV2

1629953894003.jpeg
 
Last edited: