diff options
-rw-r--r-- | src/main/java/org/traccar/config/Keys.java | 7 | ||||
-rw-r--r-- | src/main/java/org/traccar/notificators/NotificatorTelegram.java | 4 |
2 files changed, 10 insertions, 1 deletions
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 @@ -759,6 +759,13 @@ public final class Keys { Collections.singletonList(KeyType.GLOBAL)); /** + * Telegram notification send location message. + */ + public static final ConfigKey<Boolean> 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)); } } |