diff --git a/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts b/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts index 147ff936..f58b28e4 100644 --- a/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts +++ b/src/api/integrations/chatbot/chatwoot/utils/chatwoot-import-helper.ts @@ -180,11 +180,10 @@ class ChatwootImport { const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); // Make sure the sourceId is always formatted as WAID:1234567890 let query: string; if (conversationId) { - query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)'; - } + query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2'; if (!conversationId) { - query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2'; + query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)'; } const pgClient = postgresClient.getChatwootConnection();