mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
Merge pull request #1481 from AlexSzefezuk/fix-chatwoot-import
Fix-chatwoot-import
This commit is contained in:
commit
fcde1f9acc
@ -930,7 +930,7 @@ export class ChatwootService {
|
||||
quotedMsg?: MessageModel,
|
||||
) {
|
||||
if (sourceId && this.isImportHistoryAvailable()) {
|
||||
const messageAlreadySaved = await chatwootImport.getExistingSourceIds([sourceId]);
|
||||
const messageAlreadySaved = await chatwootImport.getExistingSourceIds([sourceId], conversationId);
|
||||
if (messageAlreadySaved) {
|
||||
if (messageAlreadySaved.size > 0) {
|
||||
this.logger.warn('Message already saved on chatwoot');
|
||||
|
@ -169,7 +169,7 @@ class ChatwootImport {
|
||||
}
|
||||
}
|
||||
|
||||
public async getExistingSourceIds(sourceIds: string[]): Promise<Set<string>> {
|
||||
public async getExistingSourceIds(sourceIds: string[], conversationId?: number): Promise<Set<string>> {
|
||||
try {
|
||||
const existingSourceIdsSet = new Set<string>();
|
||||
|
||||
@ -178,9 +178,17 @@ class ChatwootImport {
|
||||
}
|
||||
|
||||
const formattedSourceIds = sourceIds.map((sourceId) => `WAID:${sourceId.replace('WAID:', '')}`); // Make sure the sourceId is always formatted as WAID:1234567890
|
||||
const query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
||||
let query: string;
|
||||
if (conversationId) {
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1)';
|
||||
}
|
||||
|
||||
if(!conversationId) {
|
||||
query = 'SELECT source_id FROM messages WHERE source_id = ANY($1) AND conversation_id = $2';
|
||||
}
|
||||
|
||||
const pgClient = postgresClient.getChatwootConnection();
|
||||
const result = await pgClient.query(query, [formattedSourceIds]);
|
||||
const result = await pgClient.query(query, [formattedSourceIds, conversationId]);
|
||||
|
||||
for (const row of result.rows) {
|
||||
existingSourceIdsSet.add(row.source_id);
|
||||
|
Loading…
Reference in New Issue
Block a user