Skip to content

Commit cf89601

Browse files
committed
fix: include instance Id field in the instance configuration
1 parent c07e23b commit cf89601

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
* Fixed sending variables to typebot
77
* Fixed sending variables from typebot
88
* Correction sending s3/minio media to chatwoot and typebot
9+
* Fixed the problem with typebot closing at the end of the flow, now this is optional with the TYPEBOT_KEEP_OPEN variable
10+
* Fixed chatwoot Bold, Italic and Underline formatting using Regex
11+
* Added the sign_delimiter property to the Chatwoot configuration, allowing you to set a different delimiter for the signature. Default when not defined \n
12+
* Include instance Id field in the instance configuration
913

1014
# 1.6.0 (2023-12-12 17:24)
1115

src/whatsapp/controllers/instance.controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { delay } from '@whiskeysockets/baileys';
22
import { isURL } from 'class-validator';
33
import EventEmitter2 from 'eventemitter2';
4+
import { v4 } from 'uuid';
45

56
import { ConfigService, HttpServer } from '../../config/env.config';
67
import { Logger } from '../../config/logger.config';
@@ -87,8 +88,11 @@ export class InstanceController {
8788
const instance = new WAStartupService(this.configService, this.eventEmitter, this.repository, this.cache);
8889
instance.instanceName = instanceName;
8990

91+
const instanceId = v4();
92+
9093
instance.sendDataWebhook(Events.INSTANCE_CREATE, {
9194
instanceName,
95+
instanceId: instanceId,
9296
});
9397

9498
this.logger.verbose('instance: ' + instance.instanceName + ' created');
@@ -100,6 +104,7 @@ export class InstanceController {
100104
const hash = await this.authService.generateHash(
101105
{
102106
instanceName: instance.instanceName,
107+
instanceId: instanceId,
103108
},
104109
token,
105110
);
@@ -367,6 +372,7 @@ export class InstanceController {
367372
const result = {
368373
instance: {
369374
instanceName: instance.instanceName,
375+
instanceId: instanceId,
370376
status: 'created',
371377
},
372378
hash,
@@ -459,6 +465,7 @@ export class InstanceController {
459465
return {
460466
instance: {
461467
instanceName: instance.instanceName,
468+
instanceId: instanceId,
462469
status: 'created',
463470
},
464471
hash,

src/whatsapp/dto/instance.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export class InstanceDto {
22
instanceName: string;
3+
instanceId?: string;
34
qrcode?: boolean;
45
number?: string;
56
token?: string;

src/whatsapp/models/auth.model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ export class AuthRaw {
66
_id?: string;
77
jwt?: string;
88
apikey?: string;
9+
instanceId?: string;
910
}
1011

1112
const authSchema = new Schema<AuthRaw>({
1213
_id: { type: String, _id: true },
1314
jwt: { type: String, minlength: 1 },
1415
apikey: { type: String, minlength: 1 },
16+
instanceId: { type: String, minlength: 1 },
1517
});
1618

1719
export const AuthModel = dbserver?.model(AuthRaw.name, authSchema, 'authentication');

src/whatsapp/repository/auth.repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export class AuthRepository extends Repository {
1919
public async create(data: AuthRaw, instance: string): Promise<IInsert> {
2020
try {
2121
this.logger.verbose('creating auth');
22+
2223
if (this.dbSettings.ENABLED) {
2324
this.logger.verbose('saving auth to db');
2425
const insert = await this.authModel.replaceOne({ _id: instance }, { ...data }, { upsert: true });

src/whatsapp/services/auth.service.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ export class AuthService {
4646

4747
this.logger.verbose('JWT token created: ' + token);
4848

49-
const auth = await this.repository.auth.create({ jwt: token }, instance.instanceName);
49+
const auth = await this.repository.auth.create(
50+
{ jwt: token, instanceId: instance.instanceId },
51+
instance.instanceName,
52+
);
5053

5154
this.logger.verbose('JWT token saved in database');
5255

@@ -66,7 +69,7 @@ export class AuthService {
6669

6770
this.logger.verbose(token ? 'APIKEY defined: ' + apikey : 'APIKEY created: ' + apikey);
6871

69-
const auth = await this.repository.auth.create({ apikey }, instance.instanceName);
72+
const auth = await this.repository.auth.create({ apikey, instanceId: instance.instanceId }, instance.instanceName);
7073

7174
this.logger.verbose('APIKEY saved in database');
7275

src/whatsapp/services/monitor.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class WAMonitoringService {
112112
const instanceData = {
113113
instance: {
114114
instanceName: key,
115+
instanceId: (await this.repository.auth.find(key))?.instanceId,
115116
owner: value.wuid,
116117
profileName: (await value.getProfileName()) || 'not loaded',
117118
profilePictureUrl: value.profilePictureUrl,
@@ -135,6 +136,7 @@ export class WAMonitoringService {
135136
const instanceData = {
136137
instance: {
137138
instanceName: key,
139+
instanceId: (await this.repository.auth.find(key))?.instanceId,
138140
status: value.connectionStatus.state,
139141
},
140142
};

0 commit comments

Comments
 (0)