homebridge-telegram icon indicating copy to clipboard operation
homebridge-telegram copied to clipboard

Send a jpeg as part of the message?

Open ambanmba opened this issue 4 years ago • 6 comments

My doorbell produces a static small .jpeg file at http://192.168.xx.xx/snap.jpeg ... would it be possible to embed that image (not a link to the image, but the actual image?)

ambanmba avatar Sep 23 '20 07:09 ambanmba

Did you manage to fix this? I have the same question at this moment...

JohnF87 avatar May 20 '21 07:05 JohnF87

@JohnF87 , I ended up switching to a different plugin (https://github.com/pponce/homebridge-script2) and then using a script to send the picture.

You can easily send a picture via a bash script (Google is your friend here... curl -X POST....)

ambanmba avatar May 20 '21 11:05 ambanmba

Can you give me some help? I found this, but the JSON is invalid. What is the code you used?

#!/bin/sh

$1 = Chat ID

$2 = Caption

$3 = Disable Notification (true or false)

TelegramToken="12345678:AABBCCDDEEFFasdfjasdhfkashdf" SnapFile="/var/tmp/camsnapshot.jpg"

Get snapshot via Domoticz server

wget -O $SnapFile "http://192.168.123.100:8080/camsnapshot.jpg?idx=1"

Send Telegram message with image

curl -s -X POST "https://api.telegram.org/bot$TelegramToken/sendPhoto" -F chat_id=$1 -F caption="$2" -F disable_notification=$3 -F photo="@$SnapFile"

Remove SnapFile

/bin/rm $SnapFile

JohnF87 avatar May 20 '21 11:05 JohnF87

The exact code is below. Obviously you need to change the wget command (line 6) to point to where your image is and also change the "bot ID" and "chat ID" to match your circumstances. This will send a photo via the bot each time the doorbell script is activated.

`#!/bin/sh

current_time=$(date "+%Y.%m.%d-%H.%M.%S") new_filename=$current_time.jpeg new_message=$(date) wget http://192.168.1.19/snap.jpeg cp snap.jpeg ~/doorbell/$new_filename

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=111111111 -F parse_mode="MarkdownV2" -F text="${new_message} \- 🔔Doorbell Ring🔔"

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=1111111111 -F photo="@snap.jpeg"

rm snap.jpeg

`

ambanmba avatar May 20 '21 23:05 ambanmba

The exact code is below. Obviously you need to change the wget command (line 6) to point to where your image is and also change the "bot ID" and "chat ID" to match your circumstances. This will send a photo via the bot each time the doorbell script is activated.

`#!/bin/sh

current_time=$(date "+%Y.%m.%d-%H.%M.%S") new_filename=$current_time.jpeg new_message=$(date) wget http://192.168.1.19/snap.jpeg cp snap.jpeg ~/doorbell/$new_filename

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=111111111 -F parse_mode="MarkdownV2" -F text="${new_message} - 🔔_Doorbell Ring🔔_"

curl -X POST "https://api.telegram.org/bot1111111111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" -F chat_id=1111111111 -F photo="@snap.jpeg"

rm snap.jpeg

`

Thanks for the code. Can you help me one more time. I have zero experience with scripting. When I add the code to the JSON file it shows so errors in the code. What am I doing wrong? Schermafbeelding 2021-05-21 om 08 23 56

JohnF87 avatar May 21 '21 06:05 JohnF87

@JohnF87 , the code above needs to be placed into a separate file, not within the JSON. The JSON config is simply to call the file to execute when certain triggers are met.

ambanmba avatar May 24 '21 00:05 ambanmba