diff --git a/CHANGELOG.md b/CHANGELOG.md index 384a28af..875d7ac4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ### Fixed * Fix in update settings that needed to restart after updated +* Correction in the use of the api with mongodb +* Adjustments to search endpoint for contacts, chats, messages and Status messages # 1.3.1 (2023-07-20 07:48) diff --git a/src/whatsapp/repository/auth.repository.ts b/src/whatsapp/repository/auth.repository.ts index c795737c..0d7e177f 100644 --- a/src/whatsapp/repository/auth.repository.ts +++ b/src/whatsapp/repository/auth.repository.ts @@ -1,5 +1,5 @@ import { join } from 'path'; -import { Auth, ConfigService } from '../../config/env.config'; +import { Auth, ConfigService, Database } from '../../config/env.config'; import { IInsert, Repository } from '../abstract/abstract.repository'; import { IAuthModel, AuthRaw } from '../models'; import { readFileSync } from 'fs'; diff --git a/src/whatsapp/services/monitor.service.ts b/src/whatsapp/services/monitor.service.ts index 8b347c21..8fdac88a 100644 --- a/src/whatsapp/services/monitor.service.ts +++ b/src/whatsapp/services/monitor.service.ts @@ -90,7 +90,7 @@ export class WAMonitoringService { const findChatwoot = await this.waInstances[key].findChatwoot(); - if (findChatwoot.enabled) { + if (findChatwoot && findChatwoot.enabled) { chatwoot = { ...findChatwoot, webhook_url: `${urlServer}/chatwoot/webhook/${key}`, diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 6fead74a..8035bbfb 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -328,7 +328,7 @@ export class WAStartupService { if (!data) { this.logger.verbose('Chatwoot not found'); - throw new NotFoundException('Chatwoot not found'); + return null; } this.logger.verbose(`Chatwoot account id: ${data.account_id}`); @@ -351,7 +351,7 @@ export class WAStartupService { const expose = this.configService.get('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES; const tokenStore = await this.repository.auth.find(this.instanceName); - const instanceApikey = tokenStore.apikey || 'Apikey not found'; + const instanceApikey = tokenStore?.apikey || 'Apikey not found'; const globalApiKey = this.configService.get('AUTHENTICATION').API_KEY.KEY; @@ -1190,6 +1190,22 @@ export class WAStartupService { this.logger.verbose('Sending data to webhook in event MESSAGE_DELETE'); await this.sendDataWebhook(Events.MESSAGES_DELETE, key); + + const message: MessageUpdateRaw = { + ...key, + status: 'DELETED', + datetime: Date.now(), + owner: this.instance.name, + }; + + this.logger.verbose(message); + + this.logger.verbose('Inserting message in database'); + await this.repository.messageUpdate.insert( + [message], + this.instance.name, + database.SAVE_DATA.MESSAGE_UPDATE, + ); return; } @@ -2351,6 +2367,9 @@ export class WAStartupService { this.logger.verbose('Fetching contacts'); if (query?.where) { query.where.owner = this.instance.name; + if (query.where?.id) { + query.where.id = this.createJid(query.where.id); + } } else { query = { where: { diff --git a/src/whatsapp/types/wa.types.ts b/src/whatsapp/types/wa.types.ts index 169df515..6869545f 100644 --- a/src/whatsapp/types/wa.types.ts +++ b/src/whatsapp/types/wa.types.ts @@ -63,6 +63,7 @@ export declare namespace wa { | 'SERVER_ACK' | 'DELIVERY_ACK' | 'READ' + | 'DELETED' | 'PLAYED'; }