Skip to content

Commit 796287a

Browse files
committed
fix: Adjustments to search endpoint for contacts, chats, messages and Status messages
1 parent 763e30b commit 796287a

5 files changed

Lines changed: 26 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
### Fixed
44

55
* Fix in update settings that needed to restart after updated
6+
* Correction in the use of the api with mongodb
7+
* Adjustments to search endpoint for contacts, chats, messages and Status messages
68

79
# 1.3.1 (2023-07-20 07:48)
810

src/whatsapp/repository/auth.repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { join } from 'path';
2-
import { Auth, ConfigService } from '../../config/env.config';
2+
import { Auth, ConfigService, Database } from '../../config/env.config';
33
import { IInsert, Repository } from '../abstract/abstract.repository';
44
import { IAuthModel, AuthRaw } from '../models';
55
import { readFileSync } from 'fs';

src/whatsapp/services/monitor.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class WAMonitoringService {
9090

9191
const findChatwoot = await this.waInstances[key].findChatwoot();
9292

93-
if (findChatwoot.enabled) {
93+
if (findChatwoot && findChatwoot.enabled) {
9494
chatwoot = {
9595
...findChatwoot,
9696
webhook_url: `${urlServer}/chatwoot/webhook/${key}`,

src/whatsapp/services/whatsapp.service.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export class WAStartupService {
328328

329329
if (!data) {
330330
this.logger.verbose('Chatwoot not found');
331-
throw new NotFoundException('Chatwoot not found');
331+
return null;
332332
}
333333

334334
this.logger.verbose(`Chatwoot account id: ${data.account_id}`);
@@ -351,7 +351,7 @@ export class WAStartupService {
351351
const expose =
352352
this.configService.get<Auth>('AUTHENTICATION').EXPOSE_IN_FETCH_INSTANCES;
353353
const tokenStore = await this.repository.auth.find(this.instanceName);
354-
const instanceApikey = tokenStore.apikey || 'Apikey not found';
354+
const instanceApikey = tokenStore?.apikey || 'Apikey not found';
355355

356356
const globalApiKey = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
357357

@@ -1190,6 +1190,22 @@ export class WAStartupService {
11901190

11911191
this.logger.verbose('Sending data to webhook in event MESSAGE_DELETE');
11921192
await this.sendDataWebhook(Events.MESSAGES_DELETE, key);
1193+
1194+
const message: MessageUpdateRaw = {
1195+
...key,
1196+
status: 'DELETED',
1197+
datetime: Date.now(),
1198+
owner: this.instance.name,
1199+
};
1200+
1201+
this.logger.verbose(message);
1202+
1203+
this.logger.verbose('Inserting message in database');
1204+
await this.repository.messageUpdate.insert(
1205+
[message],
1206+
this.instance.name,
1207+
database.SAVE_DATA.MESSAGE_UPDATE,
1208+
);
11931209
return;
11941210
}
11951211

@@ -2351,6 +2367,9 @@ export class WAStartupService {
23512367
this.logger.verbose('Fetching contacts');
23522368
if (query?.where) {
23532369
query.where.owner = this.instance.name;
2370+
if (query.where?.id) {
2371+
query.where.id = this.createJid(query.where.id);
2372+
}
23542373
} else {
23552374
query = {
23562375
where: {

src/whatsapp/types/wa.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export declare namespace wa {
6363
| 'SERVER_ACK'
6464
| 'DELIVERY_ACK'
6565
| 'READ'
66+
| 'DELETED'
6667
| 'PLAYED';
6768
}
6869

0 commit comments

Comments
 (0)