Skip to content

Commit f9abd90

Browse files
committed
fix: connection state
1 parent f729325 commit f9abd90

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Fixed
44

55
* Fixed reconnect with pairing code or qrcode
6+
* Fixed problem in createJid
67

78
# 1.4.0 (2023-07-24 17:03)
89

src/validate/validate.schema.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ const optionsSchema: JSONSchema7 = {
124124

125125
const numberDefinition: JSONSchema7Definition = {
126126
type: 'string',
127-
// pattern: '^\\d+[\\.@\\w-]+',
128127
description: 'Invalid format',
129128
};
130129

@@ -446,7 +445,6 @@ export const whatsappNumberSchema: JSONSchema7 = {
446445
uniqueItems: true,
447446
items: {
448447
type: 'string',
449-
// pattern: '^\\d+',
450448
description: '"numbers" must be an array of numeric strings',
451449
},
452450
},

src/whatsapp/controllers/instance.controller.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,12 @@ export class InstanceController {
245245

246246
public async connectionState({ instanceName }: InstanceDto) {
247247
this.logger.verbose('requested connectionState from ' + instanceName + ' instance');
248-
return this.waMonitor.waInstances[instanceName]?.connectionStatus;
248+
return {
249+
instance: {
250+
instanceName: instanceName,
251+
state: this.waMonitor.waInstances[instanceName]?.connectionStatus?.state,
252+
},
253+
};
249254
}
250255

251256
public async fetchInstances({ instanceName }: InstanceDto) {
@@ -260,9 +265,9 @@ export class InstanceController {
260265

261266
public async logout({ instanceName }: InstanceDto) {
262267
this.logger.verbose('requested logout from ' + instanceName + ' instance');
263-
const stateConn = await this.connectionState({ instanceName });
268+
const { instance } = await this.connectionState({ instanceName });
264269

265-
if (stateConn.state === 'close') {
270+
if (instance.state === 'close') {
266271
throw new BadRequestException(
267272
'The "' + instanceName + '" instance is not connected',
268273
);
@@ -285,15 +290,15 @@ export class InstanceController {
285290

286291
public async deleteInstance({ instanceName }: InstanceDto) {
287292
this.logger.verbose('requested deleteInstance from ' + instanceName + ' instance');
288-
const stateConn = await this.connectionState({ instanceName });
293+
const { instance } = await this.connectionState({ instanceName });
289294

290-
if (stateConn.state === 'open') {
295+
if (instance.state === 'open') {
291296
throw new BadRequestException(
292297
'The "' + instanceName + '" instance needs to be disconnected',
293298
);
294299
}
295300
try {
296-
if (stateConn.state === 'connecting') {
301+
if (instance.state === 'connecting') {
297302
this.logger.verbose('logging out instance: ' + instanceName);
298303

299304
await this.logout({ instanceName });

src/whatsapp/services/whatsapp.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ export class WAStartupService {
15171517
.split(/\:/)[0]
15181518
.split('@')[0];
15191519

1520-
if (number.includes('-') && number.length >= 24) {
1520+
if (number.length >= 18) {
15211521
this.logger.verbose('Jid created is group: ' + `${number}@g.us`);
15221522
number = number.replace(/[^\d-]/g, '');
15231523
return `${number}@g.us`;

0 commit comments

Comments
 (0)