Conversation
- 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>
There was a problem hiding this comment.
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
/apiservlet 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.
| 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(); |
There was a problem hiding this comment.
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.
| 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()) |
There was a problem hiding this comment.
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.
| import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardRow; | ||
|
|
||
| @Component | ||
| public class ManegeCategoryCallbackHandler implements TelegramCallbackHandler { |
There was a problem hiding this comment.
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.
| public class ManegeCategoryCallbackHandler implements TelegramCallbackHandler { | |
| public class ManageCategoryCallbackHandler implements TelegramCallbackHandler { |
| - A API estará rodando em: `http://localhost:8080` | ||
| - O Bot estará ativo no seu Telegram. |
There was a problem hiding this comment.
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.
|
|
||
| Após iniciar a aplicação, acesse: | ||
| 👉 **[http://localhost:8080/scalar](http://localhost:8080/scalar)** | ||
| 👉 **[http://localhost:8080/scalar](http://localhost:8080/api/docs)** |
There was a problem hiding this comment.
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.
| 👉 **[http://localhost:8080/scalar](http://localhost:8080/api/docs)** | |
| 👉 **[http://localhost:8080/api/docs](http://localhost:8080/api/docs)** |
| 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 👇 | ||
| """) |
There was a problem hiding this comment.
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.
| @@ -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"); | |||
|
|
|||
There was a problem hiding this comment.
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.
| 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()); | ||
|
|
There was a problem hiding this comment.
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.
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class ManegeUserCallbackHandler implements TelegramCallbackHandler { |
There was a problem hiding this comment.
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.
| public class ManegeUserCallbackHandler implements TelegramCallbackHandler { | |
| public class ManageUserCallbackHandler implements TelegramCallbackHandler { |
[Copilot is generating a summary...]