-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageHandler.java
43 lines (36 loc) · 1.54 KB
/
MessageHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package dev.vality.alert.tg.bot.handler;
import dev.vality.alert.tg.bot.constants.TextConstants;
import dev.vality.alert.tg.bot.dao.StateDataDao;
import dev.vality.alert.tg.bot.domain.tables.pojos.StateData;
import lombok.RequiredArgsConstructor;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import static dev.vality.alert.tg.bot.utils.MainMenuBuilder.buildMainInlineKeyboardMarkup;
import static dev.vality.alert.tg.bot.utils.UserUtils.isUserInBot;
@Component
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
public class MessageHandler implements CommonHandler<SendMessage> {
private final StateDataDao stateDataDao;
@Override
public boolean filter(Update update) {
return update.hasMessage()
&& update.getMessage().hasText()
&& update.getMessage().getReplyToMessage() == null
&& !update.getMessage().hasViaBot()
&& isUserInBot(update);
}
@Override
public SendMessage handle(Update update, long userId) {
SendMessage message = new SendMessage();
message.setText(TextConstants.SELECT_ACTION.getText());
StateData stateData = new StateData();
stateData.setUserId(userId);
stateDataDao.save(stateData);
message.setReplyMarkup(buildMainInlineKeyboardMarkup());
return message;
}
}