1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-09 15:40:45 +02:00

Telegram bot: Option to configure alert type - text/image (#855)

* Update common_functions.sh

* Update telegram-bot-daemon.sh

* Update detectionOn.sh
This commit is contained in:
saipsa
2018-12-29 11:01:29 +05:30
committed by jmtatsch
parent e7adb162a2
commit 4014384d7a
3 changed files with 30 additions and 6 deletions

View File

@@ -3,6 +3,10 @@
# This file is supposed to bundle some frequently used functions
# so they can be easily improved in one place and be reused all over the place
include () {
[[ -f "$1" ]] && source "$1"
}
# Initialize gpio pin
init_gpio(){
GPIOPIN=$1

View File

@@ -4,6 +4,8 @@
. /system/sdcard/config/motion.conf
. /system/sdcard/scripts/common_functions.sh
include /system/sdcard/config/telegram.conf
# Turn on the amber led
if [ "$motion_trigger_led" = true ] ; then
yellow_led on
@@ -45,6 +47,9 @@ fi
# Send a telegram message
if [ "$send_telegram" = true ]; then
if [ "$telegram_alert_type" = "text" ] ; then
/system/sdcard/bin/telegram m "Motion detected"
else
if [ "$save_snapshot" = true ] ; then
/system/sdcard/bin/telegram p "$save_dir/$filename"
else
@@ -52,6 +57,7 @@ if [ "$send_telegram" = true ]; then
/system/sdcard/bin/telegram p "/tmp/telegram_image.jpg"
rm "/tmp/telegram_image.jpg"
fi
fi
fi
# Run any user scripts.

View File

@@ -29,13 +29,27 @@ detectionOff() {
motion_detection off && $TELEGRAM m "Motion detection stopped"
}
textAlerts() {
. /system/sdcard/scripts/common_functions.sh
rewrite_config /system/sdcard/config/telegram.conf telegram_alert_type "text"
$TELEGRAM m "Text alerts on motion detection"
}
imageAlerts() {
. /system/sdcard/scripts/common_functions.sh
rewrite_config /system/sdcard/config/telegram.conf telegram_alert_type "image"
$TELEGRAM m "Image alerts on motion detection"
}
respond() {
case $1 in
/mem) sendMem;;
/shot) sendShot;;
/on) detectionOn;;
/off) detectionOff;;
/help) $TELEGRAM m "######### Bot commands #########\n# /mem - show memory information\n# /shot - take a shot\n# /on - motion detect on\n# /off - motion detect off";;
/textalerts) textAlerts;;
/imagealerts) imageAlerts;;
/help) $TELEGRAM m "######### Bot commands #########\n# /mem - show memory information\n# /shot - take a shot\n# /on - motion detect on\n# /off - motion detect off\n# /textalerts - Text alerts on motion detection\n# /imagealerts - Image alerts on motion detection";;
*) $TELEGRAM m "I can't respond to '$1' command"
esac
}