fix: receive medias on chatwoot

This commit is contained in:
Davidson Gomes 2024-10-18 19:49:14 -03:00
parent 5401ecd2c4
commit 34769e2293
2 changed files with 73 additions and 63 deletions

View File

@ -933,11 +933,13 @@ export class ChatwootService {
) {
if (sourceId && this.isImportHistoryAvailable()) {
const messageAlreadySaved = await chatwootImport.getExistingSourceIds([sourceId]);
if (messageAlreadySaved) {
if (messageAlreadySaved.size > 0) {
this.logger.warn('Message already saved on chatwoot');
return null;
}
}
}
const data = new FormData();
if (content) {
@ -2442,6 +2444,7 @@ export class ChatwootService {
chatwootConfig: ChatwootDto,
prepareMessage: (message: any) => any,
) {
try {
if (!this.isImportHistoryAvailable()) {
return;
}
@ -2494,5 +2497,8 @@ export class ChatwootService {
await chatwootImport.importHistoryMessages(instance, this, inbox, this.provider);
const waInstance = this.waMonitor.waInstances[instance.instanceName];
waInstance.clearCacheChatwoot();
} catch (error) {
return;
}
}
}

View File

@ -170,6 +170,7 @@ class ChatwootImport {
}
public async getExistingSourceIds(sourceIds: string[]): Promise<Set<string>> {
try {
const existingSourceIdsSet = new Set<string>();
if (sourceIds.length === 0) {
@ -186,6 +187,9 @@ class ChatwootImport {
}
return existingSourceIdsSet;
} catch (error) {
return null;
}
}
public async importHistoryMessages(