|
6 | 6 | import lombok.extern.slf4j.Slf4j; |
7 | 7 | import org.springframework.scheduling.annotation.EnableScheduling; |
8 | 8 | import org.springframework.stereotype.Service; |
9 | | -import org.telegram.telegrambots.bots.TelegramLongPollingBot; |
| 9 | +import org.telegram.telegrambots.longpolling.starter.SpringLongPollingBot; |
| 10 | +import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer; |
10 | 11 | import org.telegram.telegrambots.meta.api.methods.forum.CreateForumTopic; |
11 | 12 | import org.telegram.telegrambots.meta.api.methods.send.SendMessage; |
12 | | -import org.telegram.telegrambots.meta.api.objects.Message; |
13 | 13 | import org.telegram.telegrambots.meta.api.objects.Update; |
| 14 | +import org.telegram.telegrambots.meta.api.objects.message.Message; |
14 | 15 | import org.telegram.telegrambots.meta.exceptions.TelegramApiException; |
| 16 | +import org.telegram.telegrambots.meta.generics.TelegramClient; |
15 | 17 |
|
16 | 18 | import java.util.*; |
17 | 19 |
|
18 | 20 | @Slf4j |
19 | 21 | @Service |
20 | 22 | @RequiredArgsConstructor |
21 | 23 | @EnableScheduling |
22 | | -public class AlertBot extends TelegramLongPollingBot { |
| 24 | +public class AlertBot implements SpringLongPollingBot, LongPollingSingleThreadUpdateConsumer { |
23 | 25 |
|
24 | 26 | private final AlertBotProperties properties; |
| 27 | + private final TelegramClient telegramClient; |
25 | 28 | private static final Map<Long, List<String>> activeTopics = new HashMap<>(); |
26 | 29 | private static final Set<Long> waitingForTopicName = new HashSet<>(); |
27 | 30 |
|
28 | 31 | @Override |
29 | | - public String getBotUsername() { |
30 | | - return properties.getName(); |
| 32 | + public String getBotToken() { |
| 33 | + return properties.getToken(); |
31 | 34 | } |
32 | 35 |
|
33 | 36 | @Override |
34 | | - public String getBotToken() { |
35 | | - return properties.getToken(); |
| 37 | + public LongPollingSingleThreadUpdateConsumer getUpdatesConsumer() { |
| 38 | + return this; |
36 | 39 | } |
37 | 40 |
|
38 | 41 | @Override |
39 | | - public void onUpdateReceived(Update update) { |
| 42 | + public void consume(Update update) { |
40 | 43 | if (update.hasMessage() && update.getMessage().hasText()) { |
41 | 44 |
|
42 | 45 | log.debug("Получено сообщение: message={}, chatId={}, threadId={}, user=@{}, text='{}'", |
@@ -98,7 +101,7 @@ private void createTopic(Long chatId, String topicName) { |
98 | 101 | .name(topicName) |
99 | 102 | .build(); |
100 | 103 |
|
101 | | - Integer messageThreadId = execute(createForumTopic).getMessageThreadId(); |
| 104 | + Integer messageThreadId = telegramClient.execute(createForumTopic).getMessageThreadId(); |
102 | 105 | // activeTopics.put(chatId, String.valueOf(messageThreadId)); |
103 | 106 |
|
104 | 107 | // Добавляем топик в список, если у чата уже есть созданные топики |
@@ -231,7 +234,7 @@ private void sendResponse(Long chatId, Integer threadId, String messageText, Str |
231 | 234 | .build(); |
232 | 235 |
|
233 | 236 | try { |
234 | | - execute(message); |
| 237 | + telegramClient.execute(message); |
235 | 238 | } catch (TelegramApiException e) { |
236 | 239 | log.error("Ошибка при отправке сообщения", e); |
237 | 240 | } |
|
0 commit comments