From b44b3bde93c0ff80e4c3998c8bb18e24d6f70cff Mon Sep 17 00:00:00 2001 From: whekin Date: Sat, 14 Mar 2026 14:33:29 +0400 Subject: [PATCH] fix(bot): silence topic processor failure messages unless explicitly mentioned Previously, the bot would reply with a 'Zzz...' message to every message in a topic if the topic processor failed or was missing. This change ensures the bot remains silent unless it is explicitly mentioned by the user. --- apps/bot/src/payment-topic-ingestion.ts | 47 +++++++++++++-------- apps/bot/src/purchase-topic-ingestion.ts | 52 ++++++++++++++---------- 2 files changed, 60 insertions(+), 39 deletions(-) diff --git a/apps/bot/src/payment-topic-ingestion.ts b/apps/bot/src/payment-topic-ingestion.ts index dc8a6a3..85170a4 100644 --- a/apps/bot/src/payment-topic-ingestion.ts +++ b/apps/bot/src/payment-topic-ingestion.ts @@ -635,18 +635,22 @@ export function registerConfiguredPaymentTopicIngestion( engagementAssessment: conversationContext.engagement }) - // Handle processor failure + // Handle processor failure - only if explicitly mentioned if (!processorResult) { - const { botSleepsMessage } = await import('./topic-processor') - await replyToPaymentMessage( - ctx, - botSleepsMessage(locale === 'ru' ? 'ru' : 'en'), - undefined, - { - repository: options.historyRepository, - record - } - ) + if (conversationContext.explicitMention) { + const { botSleepsMessage } = await import('./topic-processor') + await replyToPaymentMessage( + ctx, + botSleepsMessage(locale === 'ru' ? 'ru' : 'en'), + undefined, + { + repository: options.historyRepository, + record + } + ) + } else { + await next() + } return } @@ -856,12 +860,21 @@ export function registerConfiguredPaymentTopicIngestion( } } - // No topic processor available - bot sleeps - const { botSleepsMessage } = await import('./topic-processor') - await replyToPaymentMessage(ctx, botSleepsMessage(locale === 'ru' ? 'ru' : 'en'), undefined, { - repository: options.historyRepository, - record - }) + // No topic processor available + if (stripExplicitBotMention(ctx) !== null) { + const { botSleepsMessage } = await import('./topic-processor') + await replyToPaymentMessage( + ctx, + botSleepsMessage(locale === 'ru' ? 'ru' : 'en'), + undefined, + { + repository: options.historyRepository, + record + } + ) + } else { + await next() + } } catch (error) { options.logger?.error( { diff --git a/apps/bot/src/purchase-topic-ingestion.ts b/apps/bot/src/purchase-topic-ingestion.ts index 4df3e5c..9d54d75 100644 --- a/apps/bot/src/purchase-topic-ingestion.ts +++ b/apps/bot/src/purchase-topic-ingestion.ts @@ -2476,18 +2476,22 @@ export function registerConfiguredPurchaseTopicIngestion( engagementAssessment: conversationContext.engagement }) - // Handle processor failure - fun "bot sleeps" message + // Handle processor failure - fun "bot sleeps" message only if explicitly mentioned if (!processorResult) { - const { botSleepsMessage } = await import('./topic-processor') - await replyToPurchaseMessage( - ctx, - botSleepsMessage(householdContext.locale === 'ru' ? 'ru' : 'en'), - undefined, - { - repository: options.historyRepository, - record - } - ) + if (conversationContext.explicitMention) { + const { botSleepsMessage } = await import('./topic-processor') + await replyToPurchaseMessage( + ctx, + botSleepsMessage(householdContext.locale === 'ru' ? 'ru' : 'en'), + undefined, + { + repository: options.historyRepository, + record + } + ) + } else { + await next() + } return } @@ -2586,17 +2590,21 @@ export function registerConfiguredPurchaseTopicIngestion( } } - // No topic processor available - bot sleeps - const { botSleepsMessage } = await import('./topic-processor') - await replyToPurchaseMessage( - ctx, - botSleepsMessage(householdContext.locale === 'ru' ? 'ru' : 'en'), - undefined, - { - repository: options.historyRepository, - record - } - ) + // No topic processor available + if (conversationContext.explicitMention) { + const { botSleepsMessage } = await import('./topic-processor') + await replyToPurchaseMessage( + ctx, + botSleepsMessage(householdContext.locale === 'ru' ? 'ru' : 'en'), + undefined, + { + repository: options.historyRepository, + record + } + ) + } else { + await next() + } } catch (error) { options.logger?.error( {