[SOLVED] Send Image Item with Telegram

Hello,

I have a Synology with Surveillancestation installed. It’s great and has an API. I would like to send the latest snapshot image when the doorbell is pressed thru Telegram.

I got my Item & Rule setup so it gets the image in string from the Synology. Its saved in base64 (jpeg) in the Image Item. This works perfect. I can display the image in HABpanel.

Now I want to send this image thru telegram. From what I’ve researched is that you can send an image from URL and from File, but I doesn’t seem to have support from Image Item. (nice feature enhancement)

Is my findings correct? Is there some way to ‘convert’ my Image Item so the Telegram Action can use it?

Regards,
Bastiaan

I have forked the telegram action, and added the image via item myself. It’s working in my lab, will push the code asap.

1 Like

Hi, I use in my OH2.2 the new telegram action from Snapshot (org.openhab.action.telegram-1.12.0-SNAPSHOT.jar)

With this code I send an Image from wunderground weather via Telegram in a rule

    // Images
    var String base64Image0 = weatherunderground_weather_XXX_current_icon.state.toFullString
    sendTelegramPhoto("bot1", base64Image0, "Caption")

Using of …_icon.state.toString doesn’t work but …_icon.state.toFullString

1 Like

Hi @JMahmens, I take this is not a question but an example?

How did you do this?
I can send local files:

sendTelegramPhoto(“OH_Bot”, “http://192.168.178.50:8080/static/motion_d.jpg”, "Bewegung detektiert!\n Zeitpunkt: " + Dome_Motion.state)

But would prefer to use somthing like:

sendTelegramPhoto("OH_TeleBot", Syn_Tele_Snap.state.toString, "Zeitpunkt: " + Abus_Motion.state)

Where Syn_Tele_Snap is the snapshot (image item).

You need to use ‘.toFullString’ to get the image formatted as base64 string.

sendTelegramPhoto("OH_TeleBot", Syn_Tele_Snap.state.toFullString, "Text")
2 Likes

Thanks a lot - I will give it a try!

EDIT: Works, thanks

1 Like

Sorry for bumping but i see it as related.

When I send a base64 image to the bot, when viewing the bot the image always comes out as max zoom fitting the device screen although the image source is very small (like an icon viewed in sitemaps 64x64b).
How can I show a smaller image in the chat bot ?

I have made an updated script to send multiple camera images in one message with Telegram
its is faster as the previous version.

I used it with a switch in my mailbox and it captures three images.

The temporary images are stored in /var/temp and are removed after the images have been sent.
Just enter your IPADRESSES, USERNAME and PASSWORD, the text for the message and the captions in the curl commands.
Also enter your own Telegram TOKEN and the id for the RECEIVER

#!/bin/bash
# This script captures images from several cameras
# and sends it to Telegram

# Set a temporary directory for images variable names are in CAPITALS single quotation for non subsituted strings
TEMPFILEDIR='/var/tmp'

# Make an unique Timestamp for the images
TIMESTAMP=$(date +%Y%m%d_%H%M%S_%3N);
#Make a date that make sense to a human 28/01/202 at 11:13
HUMANTIME="$(date +%d/%m/%Y) at $(date +%H:%M)";

# Set a time value to wait between image captures (give it some time to save)
PAUSEBETWEEN=.05

# Set the name for the image files a variable is substituded by ${VAR} proper format
SNAPFILEA="${TEMPFILEDIR}/Entrance_${TIMESTAMP}.jpg"
SNAPFILEB="${TEMPFILEDIR}/Frontdoor_${TIMESTAMP}.jpg"
SNAPFILEC="${TEMPFILEDIR}/Parking_${TIMESTAMP}.jpg"

# Set the IP adress and Port per Camera
IPADRESSA="192.168.xxx.xxx:88"
IPADRESSB="192.168.xxx.xxx:88"
IPADRESSC="192.168.xxx.xxx:88"

# For Foscam cameras the script is
# /cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASWORD
# Find the proper script for your own camera on https://www.ispyconnect.com/sources.aspx


# Send Telegram message Silent (no sound on arrival) true = silent, false = with sound
SILENT='true'

# Get snapshots from the cameras
wget -O "${SNAPFILEA}" "http://${IPADRESSA}/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASSWORD"
sleep ${PAUSEBETWEEN}
wget -O "${SNAPFILEB}" "http://${IPADRESSB}/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASSWORD"
sleep ${PAUSEBETWEEN}
wget -O "${SNAPFILEC}" "http://${IPADRESSC}/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=USERNAME&pwd=PASSWORD"

# Set the Telegram token
TOKEN="000000000:gdgdgdgdgdgdgddgdg-utytyur-kkririir" 

# Set the receiver
RECEIVER="0000000000"

# Send Telegram message with just text
curl -s -X POST "https://api.telegram.org/bot${TOKEN}/sendMessage" -F chat_id="${RECEIVER}" -F  text="Mailbox on ${HUMANTIME} hour." -F disable_notification="${SILENT}"

# Send Telegram message with multiple images
curl -s -X POST "https://api.telegram.org/bot${TOKEN}/sendMediaGroup" -F chat_id="${RECEIVER}" -F media='[{"type":"photo","media":"attach://photo_1","caption":"Maildelivery"},{"type":"photo","media":"attach://photo_2","caption":"Mailman"},{"type":"photo","media":"attach://photo_3","caption":"Parking"}]' -F photo_1="@$SNAPFILEA" -F photo_2="@$SNAPFILEB" -F photo_3="@$SNAPFILEC" -F disable_notification="${SILENT}"


# Remove Image from /var/tmp
rm $SNAPFILEA 
rm $SNAPFILEB
rm $SNAPFILEC
exit 0