From 419cc923e428dcd68ca92906bf6511cbd574b8c2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 29 Jun 2021 20:01:58 -0700 Subject: Make Telegram location configurable --- src/main/java/org/traccar/config/Keys.java | 7 +++++++ src/main/java/org/traccar/notificators/NotificatorTelegram.java | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index 6d2296fb1..167627b1d 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -758,6 +758,13 @@ public final class Keys { "notificator.telegram.chatId", Collections.singletonList(KeyType.GLOBAL)); + /** + * Telegram notification send location message. + */ + public static final ConfigKey NOTIFICATOR_TELEGRAM_SEND_LOCATION = new ConfigKey<>( + "notificator.telegram.sendLocation", + Collections.singletonList(KeyType.GLOBAL)); + /** * Maximum time period for reports in seconds. Can be useful to prevent users to request unreasonably long reports. * By default there is no limit. diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java index 00baa2540..dbba0d31d 100644 --- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java +++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java @@ -36,6 +36,7 @@ public class NotificatorTelegram extends Notificator { private final String urlSendText; private final String urlSendLocation; private final String chatId; + private final boolean sendLocation; public static class TextMessage { @JsonProperty("chat_id") @@ -67,6 +68,7 @@ public class NotificatorTelegram extends Notificator { "https://api.telegram.org/bot%s/sendLocation", Context.getConfig().getString(Keys.NOTIFICATOR_TELEGRAM_KEY)); chatId = Context.getConfig().getString(Keys.NOTIFICATOR_TELEGRAM_CHAT_ID); + sendLocation = Context.getConfig().getBoolean(Keys.NOTIFICATOR_TELEGRAM_SEND_LOCATION); } private void executeRequest(String url, Object message) { @@ -103,7 +105,7 @@ public class NotificatorTelegram extends Notificator { } message.text = NotificationFormatter.formatShortMessage(userId, event, position); executeRequest(urlSendText, message); - if (position != null) { + if (sendLocation && position != null) { executeRequest(urlSendLocation, createLocationMessage(message.chatId, position)); } } -- cgit v1.2.3