Merge branch 'main' of https://github.com/josedario87/conversation-layer
Some checks failed
Deploy conversation layer / deploy (push) Failing after 6s

This commit is contained in:
2025-06-05 18:34:56 -06:00
2 changed files with 22 additions and 12 deletions

View File

@@ -119,13 +119,21 @@ export async function addMessageToConversation(
waMsg: WhatsAppMessage, waMsg: WhatsAppMessage,
openWaUrl: string, openWaUrl: string,
): Promise<Conversation> { ): Promise<Conversation> {
const convo = await getConversation(chatId, openWaUrl); console.log(`[conversationStore] Adding message to ${chatId}`);
const msg = toMsg(waMsg); const conv = await getConversation(chatId, openWaUrl);
convo.messages.push(msg); const mapped = mapMessage(msg);
// avoid duplicates if multiple webhook events deliver the same message
// keep last 100 msgs only if (!conv.messages.some((m) => m.id === mapped.id)) {
if (convo.messages.length > 100) convo.messages.shift(); conv.messages.push(mapped);
if (conv.messages.length > 20) conv.messages.shift();
ensureParticipant(convo.participants, waMsg.sender); }
return convo; const s = msg.sender;
} if (s && !conv.participants.some((p) => p.id === s.id)) {
conv.participants.push({
id: s.id,
name: s.pushname || s.name || '',
isMe: s.isMe,
});
}
return conv;
}

View File

@@ -120,7 +120,8 @@ export async function registerWebhook(config: WebhookConfig, port: number) {
const eventConfig = { const eventConfig = {
onAck: false, onAck: false,
onAddedToGroup: true, onAddedToGroup: true,
onAnyMessage: false, // use onAnyMessage to also receive messages sent by nucleo-whatsapp itself
onAnyMessage: true,
onBattery: true, onBattery: true,
onBroadcast: true, onBroadcast: true,
onButton: true, onButton: true,
@@ -135,7 +136,8 @@ export async function registerWebhook(config: WebhookConfig, port: number) {
onIncomingCall: false, onIncomingCall: false,
onLabel: true, onLabel: true,
onLogout: true, onLogout: true,
onMessage: true, // disable onMessage to avoid duplicates with onAnyMessage
onMessage: false,
onMessageDeleted: true, onMessageDeleted: true,
onNewProduct: true, onNewProduct: true,
onOrder: true, onOrder: true,