From 6b93bac13dc044c3155794226a670257d841554e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 20 Apr 2019 10:40:51 -0700 Subject: Fix review comments --- .../traccar/notificators/NotificatorTelegram.java | 26 ++++++++++------------ 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src/main/java/org/traccar/notificators') diff --git a/src/main/java/org/traccar/notificators/NotificatorTelegram.java b/src/main/java/org/traccar/notificators/NotificatorTelegram.java index 34e9f9c9d..89c15ba7c 100644 --- a/src/main/java/org/traccar/notificators/NotificatorTelegram.java +++ b/src/main/java/org/traccar/notificators/NotificatorTelegram.java @@ -1,6 +1,5 @@ /* - * Copyright 2018 Anton Tananaev (anton@traccar.org) - * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2019 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +14,7 @@ * limitations under the License. */ package org.traccar.notificators; + import com.fasterxml.jackson.annotation.JsonProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,35 +30,33 @@ public class NotificatorTelegram extends Notificator { private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorTelegram.class); - private String urlString = "https://api.telegram.org/bot%s/sendMessage"; - private String apikey; - private String chatid; + private String url; + private String chatId; public static class Message { @JsonProperty("chat_id") - private String chatid; + private String chatId; @JsonProperty("text") private String text; @JsonProperty("parse_mode") - private String parsemode; - + private String parseMode = "html"; } public NotificatorTelegram() { - apikey = Context.getConfig().getString("notificator.Telegram.apikey"); - chatid = Context.getConfig().getString("notificator.Telegram.chatid"); + url = String.format( + "https://api.telegram.org/bot%s/sendMessage", + Context.getConfig().getString("notificator.telegram.key")); + chatId = Context.getConfig().getString("notificator.Telegram.chatid"); } @Override public void sendSync(long userId, Event event, Position position) { Message message = new Message(); - message.chatid = chatid; - message.parsemode = "html"; + message.chatId = chatId; message.text = NotificationFormatter.formatShortMessage(userId, event, position); - urlString = String.format(urlString, apikey); - Context.getClient().target(urlString).request() + Context.getClient().target(url).request() .async().post(Entity.json(message), new InvocationCallback() { @Override public void completed(Object o) { -- cgit v1.2.3