-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TRAC-6] Implement Message Service and basic Command Handling #7
Conversation
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.telegram.telegrambots.meta.generics.TelegramClient; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Getter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this getter?
private final String command; | ||
private final String description; | ||
|
||
Command(String command, String description) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use @requiredargsconstructor instead of creating manually constructor
@Getter | ||
public enum Command { | ||
|
||
START("/start", "Welcome to TrackMyCoin 📈💰!\nThis bot helps you track cryptocurrency prices\nand will send you notifications when your target price \nis reached.\n\nFor more information about the bot, type /info."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move all static values (text) to application.yml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please create task in Jira to move this values from application.yml to database. It will increase flexibility in changes for us
@Autowired | ||
private TelegramBotClient telegramBotClient; | ||
|
||
private final List<Command> commands = List.of(Command.START , Command.INFO , Command.HELP); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use strategy pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be like this
commandProcessorsRegistry.getProcessor(Command).process(chatId)
try { | ||
telegramBotClient.getTelegramClient().execute(message); | ||
} catch (TelegramApiException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never just print stack trace, you should use log
} | ||
} | ||
|
||
private void sendWelcomeMessage(Long chatId , String messageText) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is separate responsibility (SRP), not for MessageHandler
Move this method to telegramBotClient
@@ -0,0 +1,14 @@ | |||
FROM maven:3.9.4-eclipse-temurin-21-alpine as build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be here
No description provided.