From bda3f270afbcd38f4824c99a11571f0d779b9945 Mon Sep 17 00:00:00 2001 From: Ziver Koc Date: Sat, 4 Mar 2023 00:24:20 +0100 Subject: [PATCH] Added telegram support --- gradlew | 0 .../se/hal/action/TelegramMessageAction.java | 29 +++++++++++++++++++ hal-core/src/se/hal/plugin.json | 3 +- run.sh | 5 ++-- 4 files changed, 34 insertions(+), 3 deletions(-) mode change 100755 => 100644 gradlew create mode 100644 hal-core/src/se/hal/action/TelegramMessageAction.java diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/hal-core/src/se/hal/action/TelegramMessageAction.java b/hal-core/src/se/hal/action/TelegramMessageAction.java new file mode 100644 index 00000000..12d8fa9c --- /dev/null +++ b/hal-core/src/se/hal/action/TelegramMessageAction.java @@ -0,0 +1,29 @@ +package se.hal.action; + +import se.hal.intf.HalAction; +import zutil.net.ws.app.TelegramBot; +import zutil.ui.conf.Configurator; + +/** + * Action that will send a telegram message to a user. + */ +public class TelegramMessageAction implements HalAction { + @Configurator.Configurable("Bot Token") + private String token = ""; + @Configurator.Configurable("Chat ID") + private long chatId = 0; + @Configurator.Configurable("Message") + private String message = ""; + + + @Override + public void execute() { + TelegramBot bot = new TelegramBot(token); + bot.sendMessage(chatId, message); + } + + + public String toString(){ + return "tgram://" + token + "/" + chatId; + } +} diff --git a/hal-core/src/se/hal/plugin.json b/hal-core/src/se/hal/plugin.json index 91a89ae0..eb02fcaa 100644 --- a/hal-core/src/se/hal/plugin.json +++ b/hal-core/src/se/hal/plugin.json @@ -38,6 +38,7 @@ {"se.hal.intf.HalAction": "se.hal.action.AlertAction"}, {"se.hal.intf.HalAction": "se.hal.action.DismissRoomAlertAction"}, {"se.hal.intf.HalAction": "se.hal.action.RoomAlertAction"}, - {"se.hal.intf.HalAction": "se.hal.action.SendEventAction"} + {"se.hal.intf.HalAction": "se.hal.action.SendEventAction"}, + {"se.hal.intf.HalAction": "se.hal.action.TelegramMessageAction"} ] } diff --git a/run.sh b/run.sh index 4ed21a92..9d5059bc 100644 --- a/run.sh +++ b/run.sh @@ -110,14 +110,15 @@ if [[ ${MODE} == "FOREGROUND" ]]; then while [[ ${EXIT_CODE} -eq 200 ]]; do # Restart as long as we have a exit code of 200, this allows the application to restart itself - startHal + #startHal + ./gradlew run EXIT_CODE=$? done elif [[ ${MODE} == "BACKGROUND" ]]; then # Kill current session screen -S hal -X kill # Start new session - screen -S hal -L -d -m ./run --foreground + screen -S hal -L -d -m $(dirname "$0")/run.sh --foreground echo "-------------------------" screen -list