Skip to content

Commit 1017010

Browse files
committed
fix: fix problems in create instance and delete instance files
1 parent e0bd064 commit 1017010

17 files changed

+84
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
### Fixed
99

1010
* Adjust dockerfile variables
11+
* Fixed baileys version in package.json
12+
* Fixed problem that did not validate if the token passed in create instance already existed
13+
* Fixed problem that does not delete instance files in server mode
1114

1215
# 1.1.0 (2023-06-21 11:17)
1316

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"homepage": "https://github.com/DavidsonGomes/evolution-api#readme",
4242
"dependencies": {
4343
"@adiwajshing/keyed-db": "^0.2.4",
44-
"@evolution/base": "github:WhiskeySockets/Baileys",
44+
"@whiskeysockets/baileys": "^6.3.0",
4545
"@ffmpeg-installer/ffmpeg": "^1.1.0",
4646
"@hapi/boom": "^10.0.1",
4747
"axios": "^1.3.5",

src/db/redis.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createClient, RedisClientType } from '@redis/client';
22
import { Logger } from '../config/logger.config';
3-
import { BufferJSON } from '@evolution/base';
3+
import { BufferJSON } from '@whiskeysockets/baileys';
44
import { Redis } from '../config/env.config';
55

66
export class RedisCache {

src/utils/use-multi-file-auth-state-db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
initAuthCreds,
66
proto,
77
SignalDataTypeMap,
8-
} from '@evolution/base';
8+
} from '@whiskeysockets/baileys';
99
import { configService, Database } from '../config/env.config';
1010
import { Logger } from '../config/logger.config';
1111
import { dbserver } from '../db/db.connect';

src/utils/use-multi-file-auth-state-redis-db.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
initAuthCreds,
55
proto,
66
SignalDataTypeMap,
7-
} from '@evolution/base';
7+
} from '@whiskeysockets/baileys';
88
import { RedisCache } from '../db/redis.client';
99
import { Logger } from '../config/logger.config';
1010
import { Redis } from '../config/env.config';

src/whatsapp/controllers/chat.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { proto } from '@evolution/base';
1+
import { proto } from '@whiskeysockets/baileys';
22
import {
33
ArchiveChatDto,
44
DeleteMessage,

src/whatsapp/controllers/instance.controller.ts

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { delay } from '@evolution/base';
1+
import { delay } from '@whiskeysockets/baileys';
22
import EventEmitter2 from 'eventemitter2';
33
import { Auth, ConfigService } from '../../config/env.config';
44
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
@@ -41,6 +41,8 @@ export class InstanceController {
4141
]);
4242
}
4343

44+
await this.authService.checkDuplicateToken(token);
45+
4446
const instance = new WAStartupService(
4547
this.configService,
4648
this.eventEmitter,
@@ -84,6 +86,8 @@ export class InstanceController {
8486
events: getEvents,
8587
};
8688
} else {
89+
await this.authService.checkDuplicateToken(token);
90+
8791
const instance = new WAStartupService(
8892
this.configService,
8993
this.eventEmitter,
@@ -159,6 +163,26 @@ export class InstanceController {
159163
}
160164
}
161165

166+
public async restartInstance({ instanceName }: InstanceDto) {
167+
try {
168+
delete this.waMonitor.waInstances[instanceName];
169+
console.log(this.waMonitor.waInstances[instanceName]);
170+
const instance = new WAStartupService(
171+
this.configService,
172+
this.eventEmitter,
173+
this.repository,
174+
);
175+
176+
instance.instanceName = instanceName;
177+
await instance.connectToWhatsapp();
178+
this.waMonitor.waInstances[instance.instanceName] = instance;
179+
180+
return { error: false, message: 'Instance restarted' };
181+
} catch (error) {
182+
this.logger.error(error);
183+
}
184+
}
185+
162186
public async connectionState({ instanceName }: InstanceDto) {
163187
return this.waMonitor.waInstances[instanceName]?.connectionStatus;
164188
}
@@ -195,8 +219,15 @@ export class InstanceController {
195219
]);
196220
}
197221
try {
198-
delete this.waMonitor.waInstances[instanceName];
199-
return { error: false, message: 'Instance deleted' };
222+
if (stateConn.state === 'connecting') {
223+
await this.logout({ instanceName });
224+
delete this.waMonitor.waInstances[instanceName];
225+
return { error: false, message: 'Instance deleted' };
226+
} else {
227+
delete this.waMonitor.waInstances[instanceName];
228+
this.eventEmitter.emit('remove.instance', instanceName, 'inner');
229+
return { error: false, message: 'Instance deleted' };
230+
}
200231
} catch (error) {
201232
throw new BadRequestException(error.toString());
202233
}

src/whatsapp/dto/chat.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
WAPrivacyOnlineValue,
33
WAPrivacyValue,
44
WAReadReceiptsValue,
5-
} from '@evolution/base';
5+
} from '@whiskeysockets/baileys';
66

77
export class OnWhatsAppDto {
88
constructor(

src/whatsapp/dto/sendMessage.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { proto, WAPresence } from '@evolution/base';
1+
import { proto, WAPresence } from '@whiskeysockets/baileys';
22

33
export class Quoted {
44
key: proto.IMessageKey;

src/whatsapp/repository/auth.repository.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { IInsert, Repository } from '../abstract/abstract.repository';
44
import { IAuthModel, AuthRaw } from '../models';
55
import { readFileSync } from 'fs';
66
import { AUTH_DIR } from '../../config/path.config';
7+
import { InstanceDto } from '../dto/instance.dto';
78

89
export class AuthRepository extends Repository {
910
constructor(

0 commit comments

Comments
 (0)