Skip to content

Refactor/telegram#23

Merged
WillianSilva51 merged 4 commits intomainfrom
refactor/telegram
Feb 25, 2026
Merged

Refactor/telegram#23
WillianSilva51 merged 4 commits intomainfrom
refactor/telegram

Conversation

@WillianSilva51
Copy link
Copy Markdown
Owner

[Copilot is generating a summary...]

- Added `ManegeUserCallbackHandler` and `ManegeCategoryCallbackHandler` for managing users and categories respectively.
- Migrated `CreateWalletCallbackHandler` to use `EditMessageText` for a consistent user experience.
- Updated `BotAction` with new actions (`MANEGE_USER`, `EDIT_USER`, `MANEGE_CATEGORY`) to support the new functionalities.
- Refactored `MenuUtils` to include new user and category management keyboards.
- Improved error handling and logging in `ZaldoTelegramBot`.

Signed-off-by: Willian Silva <williansilva@alu.ufc.br>
- Renamed `EDIT_USER` to `EDIT_USERNAME` in `BotAction` for consistency.
- Replaced "MAIN_MENU" with "MANEGE_USER" in `LoginCallbackHandler` back button action.
- Fixed `MenuUtils.createManegeUserKeyboard` to include login option in the Telegram keyboard.

Signed-off-by: Willian Silva <williansilva@alu.ufc.br>
- Introduced `EditUsernameCallbackHandler` and `EditUsernameFlowHandler` for handling username edits in Telegram.
- Added `WAITING_USERNAME` to `ChatState` enum for username editing workflow.
- Updated `MenuUtils` to include "Edit Username" button in the user management menu.
- Enhanced `application.yaml` with custom server paths and context configuration (`/api`, `/docs`).

Signed-off-by: Willian Silva <williansilva@alu.ufc.br>
- Changed `baseUrl` in `local.bru` and `bruno.json` to include `/api` path.
- Updated `bruno.json` file size and file count metadata to reflect recent changes.

Signed-off-by: Willian Silva <williansilva@alu.ufc.br>
@WillianSilva51 WillianSilva51 self-assigned this Feb 25, 2026
@WillianSilva51 WillianSilva51 added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 25, 2026
@WillianSilva51 WillianSilva51 merged commit 09bfa46 into main Feb 25, 2026
3 checks passed
@WillianSilva51 WillianSilva51 deleted the refactor/telegram branch February 25, 2026 01:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors parts of the Telegram bot UX (account management, username edit flow, and menu navigation) and aligns local tooling/docs with a new API base path under /api.

Changes:

  • Added Telegram “Gerenciar conta” menu, including callbacks and a flow for editing the user name.
  • Switched some Telegram interactions to edit the existing message (e.g., wallet creation prompt).
  • Introduced /api servlet context-path and updated Bruno collection defaults and README references.

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
zaldo-api/zaldo/environments/local.bru Updates Bruno base URL to include /api.
zaldo-api/zaldo/bruno.json Updates default request URL to /api and collection metadata.
zaldo-api/src/main/resources/application.yaml Adds server.servlet.context-path: /api and sets Scalar path to /docs.
zaldo-api/src/main/java/.../telegram/utils/MenuUtils.java Refactors config menu; adds “manage user” keyboard builder.
zaldo-api/src/main/java/.../telegram/handler/flow/EditUsernameFlowHandler.java New flow handler to update the user’s name from chat input.
zaldo-api/src/main/java/.../telegram/handler/command/StartCommandHandler.java Normalizes username fallback and fixes generated email format.
zaldo-api/src/main/java/.../telegram/handler/callback/wallet/CreateWalletCallbackHandler.java Uses EditMessageText instead of sending a new message.
zaldo-api/src/main/java/.../telegram/handler/callback/user/ManegeUserCallbackHandler.java New callback to show account details and actions.
zaldo-api/src/main/java/.../telegram/handler/callback/user/LoginCallbackHandler.java Updates “back” navigation to return to manage-user screen.
zaldo-api/src/main/java/.../telegram/handler/callback/user/EditUsernameCallbackHandler.java New callback to start the edit-username flow.
zaldo-api/src/main/java/.../telegram/handler/callback/user/ConfirmDeleteUserCallbackHandler.java Updates “back” navigation to return to manage-user screen.
zaldo-api/src/main/java/.../telegram/handler/callback/category/ManegeCategoryCallbackHandler.java New placeholder callback for category management.
zaldo-api/src/main/java/.../telegram/enums/ChatState.java Adds WAITING_USERNAME state.
zaldo-api/src/main/java/.../telegram/enums/BotAction.java Adds new bot actions for manage-user/edit-username/manage-category.
zaldo-api/src/main/java/.../telegram/ZaldoTelegramBot.java Minor refactor around keyboard cleanup and improved debug logging for expired callbacks.
README.md Formatting and updates around docs/tooling (needs URL corrections).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +26 to +49
String informationUser = String.format(
"""
👤 <b>Seus dados</b>

🆔 <b>ID:</b> <code>%s</code>
📛 <b>Nome:</b> %s
📧 <b>Email:</b> %s
🔐 <b>Senha:</b> ***********
🤖 <b>Telegram ID:</b> <code>%s</code>

Você pode editar suas informações ou excluir sua conta abaixo 👇""",
safe(user.getId()),
safe(user.getName()),
safe(user.getEmail()),
safe(user.getTelegramId())
);

return EditMessageText.builder()
.chatId(chatId)
.messageId(messageId)
.text(informationUser)
.replyMarkup(MenuUtils.createManegeUserKeyboard())
.parseMode("HTML")
.build();
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Este handler usa parseMode("HTML") e interpolação direta de campos potencialmente controlados pelo usuário (ex.: user.getName()/user.getEmail()). Isso permite quebrar a formatação HTML ou injetar markup. Faça escaping de HTML (por exemplo, escapando &, <, > e aspas) antes de montar a mensagem, ou evite parseMode quando não for necessário.

Copilot uses AI. Check for mistakes.
Comment on lines +38 to +44
return EditMessageText.builder()
.chatId(chatId)
.messageId(messageId)
.text("✏\uFE0F Digite seu novo username:")
.replyMarkup(InlineKeyboardMarkup.builder()
.keyboardRow(new InlineKeyboardRow(MenuUtils.createBackButton(BotAction.MANEGE_USER.getActionName())))
.build())
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O fluxo altera User.name, mas o prompt pede "username". Para evitar confusão (principalmente para usuários que não associam username ao nome exibido), padronize a mensagem para "nome" / "nome de usuário" de forma consistente com o que é realmente atualizado.

Copilot uses AI. Check for mistakes.
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardRow;

@Component
public class ManegeCategoryCallbackHandler implements TelegramCallbackHandler {
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O nome da classe contém um erro de grafia (Manege). Considere renomear para ManageCategoryCallbackHandler (e ajustar referências) para evitar propagar a grafia incorreta.

Suggested change
public class ManegeCategoryCallbackHandler implements TelegramCallbackHandler {
public class ManageCategoryCallbackHandler implements TelegramCallbackHandler {

Copilot uses AI. Check for mistakes.
Comment thread README.md
Comment on lines +94 to +95
- A API estará rodando em: `http://localhost:8080`
- O Bot estará ativo no seu Telegram.
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O texto do README ainda indica que a API fica em http://localhost:8080, mas com server.servlet.context-path: /api o base URL passa a ser http://localhost:8080/api. Atualize esse trecho para evitar confusão ao testar/consumir os endpoints localmente.

Copilot uses AI. Check for mistakes.
Comment thread README.md

Após iniciar a aplicação, acesse:
👉 **[http://localhost:8080/scalar](http://localhost:8080/scalar)**
👉 **[http://localhost:8080/scalar](http://localhost:8080/api/docs)**
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O link de documentação do Scalar está inconsistente: o texto exibido é http://localhost:8080/scalar, mas o destino do link é http://localhost:8080/api/docs. Ajuste o texto do link (e/ou o destino) para refletir a URL real após o context-path e o scalar.path.

Suggested change
👉 **[http://localhost:8080/scalar](http://localhost:8080/api/docs)**
👉 **[http://localhost:8080/api/docs](http://localhost:8080/api/docs)**

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +56
if (user != null) {
user.update(User.builder().name(text).build());

updateUserUseCase.execute(user.getId(), user);
} else {
context.setChatState(ChatState.IDLE);
sessionManager.save(chatId, context);

return SendMessage.builder()
.chatId(chatId)
.text("Algo deu errado. Tente novamente.")
.replyMarkup(MenuUtils.createMainKeyboard())
.build();
}

sessionManager.clearSession(chatId);

return SendMessage.builder()
.chatId(chatId)
.text("""
✅ <b>Nome atualizado com sucesso!</b>

Seu novo nome foi salvo.
Você já pode voltar para o gerenciamento da sua conta 👇
""")
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se o usuário enviar um texto em branco, User.update(...) não altera o nome (porque ignora blank), mas o fluxo ainda chama updateUserUseCase e responde com "Nome atualizado com sucesso". Valide text (ex.: blank/tamanho mínimo) e, em caso inválido, retorne uma mensagem pedindo um nome válido sem persistir nem finalizar a sessão.

Copilot uses AI. Check for mistakes.
Comment on lines 11 to 38
@@ -30,7 +32,9 @@ public enum BotAction {
EDIT_TRANSACTION_FIELD("EDIT_TRANSACTION_FIELD"),
CONFIRM_DELETE_TRANSACTION("BTN_CONFIRM_DELETE_TRANSACTION"),
DELETE_TRANSACTION("BTN_DELETE_TRANSACTION"),
SKIP_DATE_TRANSACTION("BTN_SKIP_DATE");
SKIP_DATE_TRANSACTION("BTN_SKIP_DATE"),

MANEGE_CATEGORY("BTN_MANEGE_CATEGORY");

Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Há um erro de grafia em identificadores novos: MANEGE_* (BotAction) deveria ser MANAGE_*. Como esses valores são usados como chave de callback, considere corrigir agora (e ajustar referências) para evitar propagar a grafia incorreta pela base.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +76
public static InlineKeyboardMarkup createManegeUserKeyboard() {
InlineKeyboardButton btnEditUsername = createButton("✏\uFE0F Editar Nome de Usuário", BotAction.EDIT_USERNAME.getActionName());
InlineKeyboardButton btnLogin = createButton("\uD83D\uDD10 Login (Acesso Web)", BotAction.LOGIN.getActionName());
InlineKeyboardButton btnDeleteUser = createButton("⚠\uFE0F Deletar conta", BotAction.CONFIRM_DELETE_USER.getActionName());
InlineKeyboardButton btnReturn = createBackButton(BotAction.CONFIG.getActionName());

Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O método novo createManegeUserKeyboard contém o mesmo erro de grafia ("Manege" em vez de "Manage"). Renomear agora reduz ruído e evita que a API interna fique com nomes inconsistentes.

Copilot uses AI. Check for mistakes.

@Component
@RequiredArgsConstructor
public class ManegeUserCallbackHandler implements TelegramCallbackHandler {
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O nome da classe contém um erro de grafia (Manege). Considere renomear para ManageUserCallbackHandler (e ajustar pacote/arquivo/referências) para manter consistência e facilitar buscas futuras.

Suggested change
public class ManegeUserCallbackHandler implements TelegramCallbackHandler {
public class ManageUserCallbackHandler implements TelegramCallbackHandler {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants