Added telegram support

This commit is contained in:
Ziver Koc 2023-03-04 00:24:20 +01:00
parent aff64c354c
commit bda3f270af
4 changed files with 34 additions and 3 deletions

0
gradlew vendored Executable file → Normal file
View file

View file

@ -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;
}
}

View file

@ -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"}
]
}

5
run.sh
View file

@ -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