pub / pp-notifier

Instant Messenger Notification daemon for the PinePhone
git clone https://https://src.jayvii.de/pub/pp-notifier.git
Home | Log | Files | Exports | Refs | README | RSS

commit f6e1931d36e2ecece4c7b401a82cdd18b85d3865
parent 3e642a338a85bfc60059c584eda462dd1ef3c96e
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Sun, 22 Aug 2021 14:50:16 +0200

renaming, refactoring

Diffstat:
MMakefile | 9+++++++--
MREADME.md | 48++++++++++++++++++++++++++----------------------
Aim-notifier.services | 9+++++++++
Aim-notifier.sh | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dtelegram-notifier.service | 9---------
Dtelegram-notifier.sh | 61-------------------------------------------------------------
6 files changed, 116 insertions(+), 94 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,6 +1,11 @@ install: mkdir -p ${HOME}/.local/bin mkdir -p ${HOME}/.config/systemd/user - install -m 700 ./telegram-notifier.sh ${HOME}/.local/bin/ - install -m 755 ./telegram-notifier.service ${HOME}/.config/systemd/user/ + install -m 700 ./im-notifier.sh ${HOME}/.local/bin/ + install -m 755 ./im-notifier.service ${HOME}/.config/systemd/user/ + systemctl --user daemon-reload + +uninstall: + ${RM} ${HOME}/.local/bin/im-notifier.sh + ${RM} ${HOME}/.config/systemd/user/im-notifier.service systemctl --user daemon-reload diff --git a/README.md b/README.md @@ -1,22 +1,34 @@ -# Telegram Notifier +# Instant Message Notifier ## What does it do? -It checks your current telegram messages via -`[telegram-cli]`(https://github.com/vysheng/tg) and notifies you about -any potential messages. +It checks your current IM messages via several CLI clients for different +plattform and notifies you about potential messages. + +Currently supported: +- Telegram via `[telegram-cli](https://github.com/vysheng/tg)` + +Future work (WIP, currently not implemented): +- Matrix via `[matrix-commander](https://github.com/8go/matrix-commander)` +- Signal via `[signal-cli](https://github.com/AsamK/signal-cli)` ## Why? -The Telegram Desktop client is somewhat ressource intensive, particularly -on the CPU, leading to high(er) power consumption. With this lightweight -notifier script, you are not required to have the desktop client running -in the background at all times. +Many IM clients, such as the Telegram Desktop client or the Signal Desktop +client are somewhat ressource intensive, particularly on the CPU, leading to +high(er) power consumption. With this lightweight notifier script, you are not +required to have the desktop client running in the background at all times. ## Are there system requirements? Yes. +### Common + +Sending Notifications: `gdbus` (likely installed already) + +### Telegram + Checking Telegram Messages: `[telegram-cli]`(https://github.com/vysheng/tg) ``` # Debian @@ -28,23 +40,15 @@ Set it up via commandline: telegram-cli ``` -Sending Notifications: `gdbus` (likely installed already) - -## Use Telegram Notifier - -Make sure, you fullfill the above requirements and set up `telegram-cli` -with your account. +## Use IM Notifier Pull this source directory, and run the Makefile: ``` -git pull https://src.jayvii.de/Hobby/PinePhoneScripts -cd PinePhoneScripts/telegram-notifier +git pull https://src.jayvii.de/PinePhone/Notifier +cd Notifier make install ``` -This will place `telegram-notifier.sh` into `~/.local/bin/telegram-notifier.sh` -and places the systemd-service file under your user's directory. You can enable -& start telegram-notifier with: -``` -systemctl --user enable telegram-notifier --now -``` +This will place `im-notifier.sh` into `~/.local/bin/im-notifier.sh` and places +the systemd-service file under your user's directory. You can enable & start +telegram-notifier with: ``` systemctl --user enable im-notifier --now ``` diff --git a/im-notifier.services b/im-notifier.services @@ -0,0 +1,9 @@ +[Unit] +Description=Instant Messaage Notifier + +[Service] +ExecStart=%h/.local/bin/im-notifier.sh +Restart=always + +[Install] +WantedBy=default.target diff --git a/im-notifier.sh b/im-notifier.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash + +POLLTIME=30 +TIMEOUT=25 + +TELEGRAM=1 +TG_NOTIFICATION_ID=0 + +# Modules --------------------------------------------------------------------- + +## Common +function im_notify { + gdbus call --session \ + --dest=org.freedesktop.Notifications \ + --object-path=/org/freedesktop/Notifications \ + --method=org.freedesktop.Notifications.Notify \ + "$1" $2 "$3" "$1" '[]' '{"category": <"im.received">}' 3000 + echo 1 > /sys/devices/platform/leds/leds/pinephone\:blue/brightness +} +function im_unnotify { + gdbus call --session \ + --dest=org.freedesktop.Notifications \ + --object-path=/org/freedesktop/Notifications \ + --method=org.freedesktop.Notifications.CloseNotification \ + $1 + echo 0 > /sys/devices/platform/leds/leds/pinephone\:blue/brightness +} + +## Telegram +function tg_check { + telegram-cli --disable-colors \ + --exec dialog_list | \ + grep -E "[1-9][0-9]* unread" +} +function tg_kill { + sleep $1 + if [[ ! -z $(pidof telegram-cli) ]]; then + pkill telegram-cli + fi +} +function tg_notify { + im_notify "Telegram" $2 "telegram" +} + +# Run Daemon ------------------------------------------------------------------ + +while :; do + + if [[ $TELEGRAM == 0 ]]; then + + # kill after some time + tg_kill $TIMEOUT & + + # Check Telegram Messages + TG_UNREAD=$(tg_check) + + if [[ ! -z "$TG_UNREAD" ]]; then + # Notify Telegram Messages + TG_NOTIFICATION_ID=$(tg_notify \ + "$TG_UNREAD" $TG_NOTIFICATION_ID | \ + sed -e 's/^.*\s//' -e 's/[^0-9]//g') + else + # Close Notification + im_unnotify $TG_NOTIFICATION_ID + TG_NOTIFICATION_ID=0 + fi + fi + + # Sleep until next round... + sleep $POLLTIME + +done + +# EOF diff --git a/telegram-notifier.service b/telegram-notifier.service @@ -1,9 +0,0 @@ -[Unit] -Description=Telegram Notifier - -[Service] -ExecStart=%h/.local/bin/telegram-notifier.sh -Restart=always - -[Install] -WantedBy=default.target diff --git a/telegram-notifier.sh b/telegram-notifier.sh @@ -1,61 +0,0 @@ -#!/usr/bin/env bash - -POLLTIME=30 -TIMEOUT=25 -REPLACEID=0 # initial value should be 0 - -function check_telegram { - telegram-cli --disable-colors \ - --exec dialog_list | \ - grep -E "[1-9][0-9]* unread" -} - -function kill_tgc { - sleep $1 - if [[ ! -z $(pidof telegram-cli) ]]; then - pkill telegram-cli - fi -} - -function notify_telegram { - gdbus call --session \ - --dest=org.freedesktop.Notifications \ - --object-path=/org/freedesktop/Notifications \ - --method=org.freedesktop.Notifications.Notify \ - "Telegram" $2 "telegram" "Telegram" "$1" \ - '[]' '{"category": <"im.received">, "desktop-entry": <"telegram">}' \ - 3000 - echo 1 > /sys/devices/platform/leds/leds/pinephone\:blue/brightness -} - -function unnotify_tg { - gdbus call --session \ - --dest=org.freedesktop.Notifications \ - --object-path=/org/freedesktop/Notifications \ - --method=org.freedesktop.Notifications.CloseNotification \ - $1 - echo 0 > /sys/devices/platform/leds/leds/pinephone\:blue/brightness -} - -while :; do - - if [[ -z $(pidof telegram-desktop) ]]; then - - # kill after some time - kill_tgc $TIMEOUT & - - UNREADMSG=$(check_telegram) - - if [[ ! -z "$UNREADMSG" ]]; then - REPLACEID=$(notify_telegram "$UNREADMSG" "$REPLACEID" | sed -e 's/^.*\s//' -e 's/[^0-9]//g') - else - unnotify_tg $REPLACEID - REPLACEID=0 - fi - fi - - sleep $POLLTIME - -done - -# EOF