From 531e52b23884c40feea7f8a16fd3147dc57beda4 Mon Sep 17 00:00:00 2001 From: whekin Date: Sun, 15 Mar 2026 01:44:13 +0400 Subject: [PATCH] feat(bot): improve /setup UX and update checklist on /bind - Enhance /setup message with a warmer greeting and binding instructions\n- Rename 'Setup' buttons to 'Create' for clarity\n- Track /setup message ID to enable automatic checklist updates when /bind is used\n- Refresh /setup checklist after successful topic binding\n- Update English and Russian translations --- apps/bot/src/household-setup.test.ts | 8 ++--- apps/bot/src/household-setup.ts | 49 +++++++++++++++++++++++++++- apps/bot/src/i18n/locales/en.ts | 8 +++-- apps/bot/src/i18n/locales/ru.ts | 8 +++-- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/apps/bot/src/household-setup.test.ts b/apps/bot/src/household-setup.test.ts index 3df9365..81bbdf7 100644 --- a/apps/bot/src/household-setup.test.ts +++ b/apps/bot/src/household-setup.test.ts @@ -874,14 +874,14 @@ describe('registerHouseholdSetupCommands', () => { chat_id: -100123456 } }) - expect(sendPayload.text).toContain('Welcome! Kojori House is successfully registered') - expect(sendPayload.text).toContain("Let's configure your household topics to get started") - expect(sendPayload.text).toContain('(0/5)') + expect(sendPayload.text).toContain('New household! **Kojori House** is ready.') + expect(sendPayload.text).toContain('Current setup progress: 0/5') + expect(sendPayload.text).toContain('0/5') expect(sendPayload.text).toContain('⚪ Purchases') expect(sendPayload.text).toContain('⚪ Payments') // Check that join household button exists expect(JSON.stringify(sendPayload.reply_markup)).toContain('Join household') - expect(JSON.stringify(sendPayload.reply_markup)).toContain('Setup Purchases') + expect(JSON.stringify(sendPayload.reply_markup)).toContain('Create Purchases') expect(JSON.stringify(sendPayload.reply_markup)).toContain('setup_topic:create:purchase') }) diff --git a/apps/bot/src/household-setup.ts b/apps/bot/src/household-setup.ts index 4439afc..6199a4e 100644 --- a/apps/bot/src/household-setup.ts +++ b/apps/bot/src/household-setup.ts @@ -565,7 +565,20 @@ export function registerHouseholdSetupCommands(options: { household: result.household, created: result.status === 'created' }) - await ctx.reply(reply.text, 'reply_markup' in reply ? { reply_markup: reply.reply_markup } : {}) + const sent = await ctx.reply( + reply.text, + 'reply_markup' in reply ? { reply_markup: reply.reply_markup } : {} + ) + + if (options.promptRepository) { + await options.promptRepository.upsertPendingAction({ + telegramUserId: `setup_tracking:${result.household.householdId}`, + telegramChatId: ctx.chat.id.toString(), + action: 'setup_topic_binding', + payload: { setupMessageId: sent.message_id }, + expiresAt: null + }) + } }) options.bot.command('unsetup', async (ctx) => { @@ -1041,6 +1054,40 @@ export function registerHouseholdSetupCommands(options: { t.topicBoundSuccess(setupTopicRoleLabel(locale, role), result.household.householdName) ) } + + // Try to update the main /setup checklist if it exists + if (options.promptRepository) { + const setupTracking = await options.promptRepository.getPendingAction( + telegramChatId, + `setup_tracking:${result.household.householdId}` + ) + + if (setupTracking?.payload.setupMessageId) { + const setupMessageId = setupTracking.payload.setupMessageId as number + const refreshed = await buildSetupReplyForHousehold({ + ctx, + locale, + household: result.household, + created: false + }) + + try { + await ctx.api.editMessageText(telegramChatId, setupMessageId, refreshed.text, { + reply_markup: refreshed.reply_markup + } as any) + } catch (error) { + // Message might be deleted or too old, ignore + options.logger?.debug( + { + event: 'household_setup.update_checklist_failed', + error, + setupMessageId + }, + 'Failed to update setup checklist message' + ) + } + } + } } ) } diff --git a/apps/bot/src/i18n/locales/en.ts b/apps/bot/src/i18n/locales/en.ts index cdabba0..d9555f7 100644 --- a/apps/bot/src/i18n/locales/en.ts +++ b/apps/bot/src/i18n/locales/en.ts @@ -51,12 +51,14 @@ export const enBotTranslations: BotTranslationCatalog = { joinRequestSent: (householdName) => `Join request sent for ${householdName}. Wait for a household admin to confirm you.`, setupSummary: ({ householdName, created }) => - `${created ? '✨' : 'ℹ️'} Welcome! ${householdName} is ${created ? 'successfully registered' : 'already active'} and ready to help.`, + `🏡 ${created ? 'New household!' : 'Household active!'} **${householdName}** is ready.\n\n` + + `I've set up the basic configuration. Now, let's organize your communication by linking topics for specific roles.`, setupTopicsHeading: (configured, total) => - `Let's configure your household topics to get started (${configured}/${total}):`, + `Current setup progress: ${configured}/${total}\n\n` + + `Tap buttons below to create new topics automatically, or go to any existing topic and use /bind to link it manually.`, setupTopicBound: (role) => `✅ ${role}`, setupTopicMissing: (role) => `⚪ ${role}`, - setupTopicCreateButton: (role) => `Setup ${role}`, + setupTopicCreateButton: (role) => `Create ${role}`, setupTopicBindButton: (role) => `Bind ${role}`, useBindInTopic: 'Run /bind inside a topic to link it to a role.', topicAlreadyBound: (role) => `This topic is already linked to ${role}.`, diff --git a/apps/bot/src/i18n/locales/ru.ts b/apps/bot/src/i18n/locales/ru.ts index 73bb1fb..0a66bfb 100644 --- a/apps/bot/src/i18n/locales/ru.ts +++ b/apps/bot/src/i18n/locales/ru.ts @@ -53,12 +53,14 @@ export const ruBotTranslations: BotTranslationCatalog = { joinRequestSent: (householdName) => `Заявка на вступление в ${householdName} отправлена. Дождитесь подтверждения от админа дома.`, setupSummary: ({ householdName, created }) => - `${created ? '✨' : 'ℹ️'} Добро пожаловать! Дом ${householdName} ${created ? 'успешно зарегистрирован' : 'уже активен'} и готов к работе.`, + `🏡 ${created ? 'Новый дом!' : 'Дом активен!'} **${householdName}** готов.\n\n` + + `Базовая настройка выполнена. Теперь давайте распределим общение, привязав топики к конкретным ролям.`, setupTopicsHeading: (configured, total) => - `Давайте настроим топики для вашего дома (${configured}/${total}):`, + `Текущий прогресс настройки: ${configured}/${total}\n\n` + + `Нажмите кнопки ниже, чтобы создать топики автоматически, или перейдите в любой существующий топик и используйте /bind, чтобы привязать его вручную.`, setupTopicBound: (role) => `✅ ${role}`, setupTopicMissing: (role) => `⚪ ${role}`, - setupTopicCreateButton: (role) => `Настроить ${role}`, + setupTopicCreateButton: (role) => `Создать ${role}`, setupTopicBindButton: (role) => `Привязать ${role}`, useBindInTopic: 'Используйте /bind внутри топика, чтобы привязать его к роли.', topicAlreadyBound: (role) => `Этот топик уже привязан к роли «${role}».`,