aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTelegram.java51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
index f4e748881..607eeaf24 100644
--- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java
+++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java
@@ -25,6 +25,7 @@ import org.traccar.model.Event;
import org.traccar.model.Position;
import org.traccar.notification.NotificationFormatter;
+import javax.annotation.Nullable;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.InvocationCallback;
@@ -36,11 +37,14 @@ public class NotificatorTelegram extends Notificator {
private final String urlSendLocation;
private final String chatId;
- public static class Message {
+ public static class TextMessage {
@JsonProperty("chat_id")
private String chatId;
@JsonProperty("text")
private String text;
+ @Nullable
+ @JsonProperty("reply_to_message_id")
+ private Long replyToMessageId;
@JsonProperty("parse_mode")
private String parseMode = "html";
}
@@ -55,9 +59,7 @@ public class NotificatorTelegram extends Notificator {
@JsonProperty("horizontal_accuracy")
private double accuracy;
@JsonProperty("bearing")
- private double bearing;
- @JsonProperty("parse_mode")
- private String parseMode = "html";
+ private int bearing;
}
public NotificatorTelegram() {
@@ -70,23 +72,36 @@ public class NotificatorTelegram extends Notificator {
chatId = Context.getConfig().getString(Keys.NOTIFICATOR_TELEGRAM_CHAT_ID);
}
- @Override
- public void sendSync(long userId, Event event, Position position) {
+ private void executeRequest(String url, Object message) {
+ Context.getClient().target(url).request()
+ .async().post(Entity.json(message), new InvocationCallback<Object>() {
+ @Override
+ public void completed(Object o) {
+ }
- Message message = new Message();
- message.chatId = chatId;
- message.text = NotificationFormatter.formatFullMessage(userId, event, position);
- executeRequest(urlSendText, message);
+ @Override
+ public void failed(Throwable throwable) {
+ LOGGER.warn("Telegram API error", throwable);
+ }
+ });
+ }
+ @Override
+ public void sendSync(long userId, Event event, Position position) {
if (position != null) {
LocationMessage locationMessage = new LocationMessage();
locationMessage.chatId = chatId;
locationMessage.latitude = position.getLatitude();
locationMessage.longitude = position.getLongitude();
- locationMessage.bearing = position.getCourse();
+ locationMessage.bearing = (int) Math.ceil(position.getCourse());
locationMessage.accuracy = position.getAccuracy();
executeRequest(urlSendLocation, locationMessage);
}
+ TextMessage message = new TextMessage();
+ message.chatId = chatId;
+ // message.replyToMessageId = Long.MIN_VALUE; TODO add message ID from the first request here
+ message.text = NotificationFormatter.formatFullMessage(userId, event, position).getBody();
+ executeRequest(urlSendText, message);
}
@Override
@@ -94,18 +109,4 @@ public class NotificatorTelegram extends Notificator {
sendSync(userId, event, position);
}
- private void executeRequest(String url, Object message) {
- Context.getClient().target(url).request()
- .async().post(Entity.json(message), new InvocationCallback<Object>() {
- @Override
- public void completed(Object o) {
- }
-
- @Override
- public void failed(Throwable throwable) {
- LOGGER.warn("Telegram API error", throwable);
- }
- });
- }
-
}