diff --git a/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts b/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts index 6bbfdb026..f927988ce 100644 --- a/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts +++ b/packages/bot-engine/whatsapp/resumeWhatsAppFlow.ts @@ -75,10 +75,10 @@ export const resumeWhatsAppFlow = async ({ credentials: { ...credentials, id: credentialsId as string }, contact, }) - : undefined + : { error: 'workspaceId not found' } - if (!resumeResponse) { - console.error('Could not find or create session', sessionId) + if ('error' in resumeResponse) { + console.log('Chat not starting:', resumeResponse.error) return { message: 'Message received', } diff --git a/packages/bot-engine/whatsapp/startWhatsAppSession.ts b/packages/bot-engine/whatsapp/startWhatsAppSession.ts index 92377e2b6..176d35ff9 100644 --- a/packages/bot-engine/whatsapp/startWhatsAppSession.ts +++ b/packages/bot-engine/whatsapp/startWhatsAppSession.ts @@ -31,7 +31,7 @@ export const startWhatsAppSession = async ({ | (ChatReply & { newSessionState: SessionState }) - | undefined + | { error: string } > => { const publicTypebotsWithWhatsAppEnabled = (await prisma.publicTypebot.findMany({ @@ -72,7 +72,10 @@ export const startWhatsAppSession = async ({ (publicTypebot) => !publicTypebot.settings.whatsApp?.startCondition ) - if (isNotDefined(publicTypebot)) return + if (isNotDefined(publicTypebot)) + return botsWithWhatsAppEnabled.length > 0 + ? { error: 'Message did not matched any condition' } + : { error: 'No public typebot with WhatsApp integration found' } const sessionExpiryTimeoutHours = publicTypebot.settings.whatsApp?.sessionExpiryTimeout ??