Skip to content

Commit 75b48aa

Browse files
committed
fix error after logout and try to get status or to connect again
1 parent 573e56c commit 75b48aa

6 files changed

Lines changed: 39 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
* Adjust dockerfile variables
1414
* tweaks in docker-compose to pass variables
15+
* Adjust the route getProfileBusiness to fetchProfileBusiness
16+
* fix error after logout and try to get status or to connect again
1517

1618
# 1.0.9 (2023-06-10)
1719

src/whatsapp/controllers/chat.controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@ export class ChatController {
7575
return await this.waMonitor.waInstances[instanceName].updatePrivacySettings(data);
7676
}
7777

78-
public async getBusinessProfile(
78+
public async fetchBusinessProfile(
7979
{ instanceName }: InstanceDto,
8080
data: ProfilePictureDto,
8181
) {
82-
return await this.waMonitor.waInstances[instanceName].getBusinessProfile(data.number);
82+
return await this.waMonitor.waInstances[instanceName].fetchBusinessProfile(
83+
data.number,
84+
);
8385
}
8486

8587
public async updateProfileName({ instanceName }: InstanceDto, data: ProfileNameDto) {

src/whatsapp/controllers/instance.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class InstanceController {
100100
public async connectToWhatsapp({ instanceName }: InstanceDto) {
101101
try {
102102
const instance = this.waMonitor.waInstances[instanceName];
103-
const state = instance.connectionStatus?.state;
103+
const state = instance?.connectionStatus?.state ?? null;
104104

105105
switch (state) {
106106
case 'close':
@@ -118,7 +118,7 @@ export class InstanceController {
118118
}
119119

120120
public async connectionState({ instanceName }: InstanceDto) {
121-
return this.waMonitor.waInstances[instanceName].connectionStatus;
121+
return this.waMonitor.waInstances[instanceName]?.connectionStatus;
122122
}
123123

124124
public async fetchInstances({ instanceName }: InstanceDto) {

src/whatsapp/routers/chat.router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,13 @@ export class ChatRouter extends RouterBroker {
163163

164164
return res.status(HttpStatus.CREATED).json(response);
165165
})
166-
.post(this.routerPath('getBusinessProfile'), ...guards, async (req, res) => {
166+
.post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => {
167167
const response = await this.dataValidate<ProfilePictureDto>({
168168
request: req,
169169
schema: profilePictureSchema,
170170
ClassRef: ProfilePictureDto,
171-
execute: (instance, data) => chatController.getBusinessProfile(instance, data),
171+
execute: (instance, data) =>
172+
chatController.fetchBusinessProfile(instance, data),
172173
});
173174

174175
return res.status(HttpStatus.OK).json(response);

src/whatsapp/services/whatsapp.service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import makeWASocket, {
2929
WAMessage,
3030
WAMessageUpdate,
3131
WASocket,
32-
WAReadReceiptsValue,
33-
WAPrivacyValue,
34-
WAPrivacyOnlineValue,
3532
} from '@evolution/base';
3633
import {
3734
Auth,
@@ -1502,6 +1499,9 @@ export class WAStartupService {
15021499
await this.client.updateOnlinePrivacy(settings.privacySettings.online);
15031500
await this.client.updateLastSeenPrivacy(settings.privacySettings.last);
15041501
await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd);
1502+
1503+
// reinicia a instancia
1504+
15051505
return { update: 'success', data: await this.client.fetchPrivacySettings() };
15061506
} catch (error) {
15071507
throw new InternalServerErrorException(
@@ -1511,7 +1511,7 @@ export class WAStartupService {
15111511
}
15121512
}
15131513

1514-
public async getBusinessProfile(number: string) {
1514+
public async fetchBusinessProfile(number: string) {
15151515
try {
15161516
let jid;
15171517

start.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
if [ "$DOCKER_ENV" = "true" ];
4+
then
5+
echo "Enabling environment variables for Docker"
6+
echo "DOCKER_ENV=$DOCKER_ENV"
7+
echo
8+
else
9+
cp ./src/env.yml ./dist/src
10+
fi
11+
echo "> removing dist"
12+
rm -rf ./dist
13+
echo
14+
echo "> transpiling..."
15+
npm run build
16+
17+
echo
18+
echo "> Successfully build "
19+
20+
echo
21+
echo "> Starting application..."
22+
echo
23+
24+
node ./dist/src/main.js

0 commit comments

Comments
 (0)