aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/TGBot.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/TGBot.java')
-rw-r--r--juick-api/src/main/java/com/juick/api/TGBot.java18
1 files changed, 11 insertions, 7 deletions
diff --git a/juick-api/src/main/java/com/juick/api/TGBot.java b/juick-api/src/main/java/com/juick/api/TGBot.java
index e67e3161..72097154 100644
--- a/juick-api/src/main/java/com/juick/api/TGBot.java
+++ b/juick-api/src/main/java/com/juick/api/TGBot.java
@@ -32,7 +32,9 @@ import com.pengrad.telegrambot.response.SendResponse;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.PingMessage;
import org.springframework.web.socket.TextMessage;
@@ -40,6 +42,7 @@ import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.handler.TextWebSocketHandler;
+import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.io.IOException;
import java.util.List;
@@ -50,12 +53,15 @@ import static com.juick.formatters.PlainTextFormatter.formatUrl;
/**
* Created by vt on 12/05/16.
*/
+@Component
public class TGBot extends TextWebSocketHandler {
private static final Logger logger = LoggerFactory.getLogger(TGBot.class);
private TelegramBot bot;
private ObjectMapper ms;
+ @Value("${telegram_token}")
+ private String telegramToken;
@Inject
private TelegramService telegramService;
@Inject
@@ -65,15 +71,13 @@ public class TGBot extends TextWebSocketHandler {
private WebSocketSession session;
- private TGBot() {
- throw new IllegalStateException();
- }
-
- public TGBot(String token) {
- if (StringUtils.isBlank(token)) {
+ @PostConstruct
+ public void init() {
+ if (StringUtils.isBlank(telegramToken)) {
+ logger.info("telegram token is not set, exiting");
return;
}
- bot = TelegramBotAdapter.build(token);
+ bot = TelegramBotAdapter.build(telegramToken);
ms = new ObjectMapper();
ms.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
ms.setSerializationInclusion(JsonInclude.Include.NON_NULL);