From 48c2b21dad498f01f65fd15b4fefaf6f66f38642 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Fri, 6 Jun 2025 21:41:56 -0600 Subject: [PATCH] procesar bien el primer mensaje de voz ya no enreda al proceso de manejo de la conversacion. probablemente necesitemos refactorizar todo este codigo eventualmente --- whatsapp-router/src/store/conversation.ts | 5 +++-- whatsapp-router/src/webhook.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/whatsapp-router/src/store/conversation.ts b/whatsapp-router/src/store/conversation.ts index c22575f..6d494b3 100644 --- a/whatsapp-router/src/store/conversation.ts +++ b/whatsapp-router/src/store/conversation.ts @@ -86,7 +86,7 @@ export async function buildConversation( } } - const messages: Msg[] = rawMessages.slice(-20).map(mapWhatsAppMessageToMsg); + const messages: Msg[] = rawMessages.map(mapWhatsAppMessageToMsg); messages.sort((a, b) => a.ts - b.ts); const conv: Conversation = { @@ -113,6 +113,7 @@ export async function addMessageToConversation( msg: WhatsAppMessage, openWaUrl: string ): Promise { + console.log(`[conversationStore] Adding message to ${chatId}`); const conv = await getConversation(chatId, openWaUrl, msg); // Delegate message processing to the new function @@ -122,6 +123,6 @@ export async function addMessageToConversation( // Ensure the conversation is updated in the map (though it's by reference as conv is an object) conversations.set(chatId, conv); - + return conv; } \ No newline at end of file diff --git a/whatsapp-router/src/webhook.ts b/whatsapp-router/src/webhook.ts index f433821..4449a78 100644 --- a/whatsapp-router/src/webhook.ts +++ b/whatsapp-router/src/webhook.ts @@ -62,6 +62,8 @@ export function registerWebhookRoutes( if (chatId) { try { conv = await addMessageToConversation(chatId, message, openWaUrl); + console.log(`🔄 Updated conversation for ${chatId}`, conv); + } catch (err: any) { console.warn('Failed updating conversation:', err.message); } @@ -151,7 +153,7 @@ export async function registerWebhook(config: WebhookConfig, port: number) { onChatDeleted: true, onChatOpened: true, onChatState: true, - onContactAdded: true, + onContactAdded: true, onGlobalParticipantsChanged: true, onGroupApprovalRequest: true, onGroupChange: true,