procesar bien el primer mensaje de voz ya no enreda al proceso de manejo de la conversacion. probablemente necesitemos refactorizar todo este codigo eventualmente

This commit is contained in:
2025-06-06 21:41:56 -06:00
parent d2fec7fb4e
commit 48c2b21dad
2 changed files with 6 additions and 3 deletions

View File

@@ -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); messages.sort((a, b) => a.ts - b.ts);
const conv: Conversation = { const conv: Conversation = {
@@ -113,6 +113,7 @@ export async function addMessageToConversation(
msg: WhatsAppMessage, msg: WhatsAppMessage,
openWaUrl: string openWaUrl: string
): Promise<Conversation> { ): Promise<Conversation> {
console.log(`[conversationStore] Adding message to ${chatId}`);
const conv = await getConversation(chatId, openWaUrl, msg); const conv = await getConversation(chatId, openWaUrl, msg);
// Delegate message processing to the new function // 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) // Ensure the conversation is updated in the map (though it's by reference as conv is an object)
conversations.set(chatId, conv); conversations.set(chatId, conv);
return conv; return conv;
} }

View File

@@ -62,6 +62,8 @@ export function registerWebhookRoutes(
if (chatId) { if (chatId) {
try { try {
conv = await addMessageToConversation(chatId, message, openWaUrl); conv = await addMessageToConversation(chatId, message, openWaUrl);
console.log(`🔄 Updated conversation for ${chatId}`, conv);
} catch (err: any) { } catch (err: any) {
console.warn('Failed updating conversation:', err.message); console.warn('Failed updating conversation:', err.message);
} }
@@ -151,7 +153,7 @@ export async function registerWebhook(config: WebhookConfig, port: number) {
onChatDeleted: true, onChatDeleted: true,
onChatOpened: true, onChatOpened: true,
onChatState: true, onChatState: true,
onContactAdded: true, onContactAdded: true,
onGlobalParticipantsChanged: true, onGlobalParticipantsChanged: true,
onGroupApprovalRequest: true, onGroupApprovalRequest: true,
onGroupChange: true, onGroupChange: true,