aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-06-29 20:01:58 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-06-29 20:01:58 -0700
commit419cc923e428dcd68ca92906bf6511cbd574b8c2 (patch)
tree702fa19ae8669bf85ceedd2871feedc33d70d5cf
parentfb886b6100493019ece6a9c53bd55280525efe2e (diff)
downloadtraccar-server-419cc923e428dcd68ca92906bf6511cbd574b8c2.tar.gz
traccar-server-419cc923e428dcd68ca92906bf6511cbd574b8c2.tar.bz2
traccar-server-419cc923e428dcd68ca92906bf6511cbd574b8c2.zip
Make Telegram location configurable
-rw-r--r--src/main/java/org/traccar/config/Keys.java7
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTelegram.java4
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));
}
}