diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d7a1be0..e924ebad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ * Adjust dockerfile variables * tweaks in docker-compose to pass variables +* Adjust the route getProfileBusiness to fetchProfileBusiness +* fix error after logout and try to get status or to connect again # 1.0.9 (2023-06-10) diff --git a/src/whatsapp/controllers/chat.controller.ts b/src/whatsapp/controllers/chat.controller.ts index a4d8d0d1..f04cd9de 100644 --- a/src/whatsapp/controllers/chat.controller.ts +++ b/src/whatsapp/controllers/chat.controller.ts @@ -75,11 +75,13 @@ export class ChatController { return await this.waMonitor.waInstances[instanceName].updatePrivacySettings(data); } - public async getBusinessProfile( + public async fetchBusinessProfile( { instanceName }: InstanceDto, data: ProfilePictureDto, ) { - return await this.waMonitor.waInstances[instanceName].getBusinessProfile(data.number); + return await this.waMonitor.waInstances[instanceName].fetchBusinessProfile( + data.number, + ); } public async updateProfileName({ instanceName }: InstanceDto, data: ProfileNameDto) { diff --git a/src/whatsapp/controllers/instance.controller.ts b/src/whatsapp/controllers/instance.controller.ts index 4f4716c0..2b43ede4 100644 --- a/src/whatsapp/controllers/instance.controller.ts +++ b/src/whatsapp/controllers/instance.controller.ts @@ -100,7 +100,7 @@ export class InstanceController { public async connectToWhatsapp({ instanceName }: InstanceDto) { try { const instance = this.waMonitor.waInstances[instanceName]; - const state = instance.connectionStatus?.state; + const state = instance?.connectionStatus?.state ?? null; switch (state) { case 'close': @@ -118,7 +118,7 @@ export class InstanceController { } public async connectionState({ instanceName }: InstanceDto) { - return this.waMonitor.waInstances[instanceName].connectionStatus; + return this.waMonitor.waInstances[instanceName]?.connectionStatus; } public async fetchInstances({ instanceName }: InstanceDto) { diff --git a/src/whatsapp/routers/chat.router.ts b/src/whatsapp/routers/chat.router.ts index be74a41d..9fe1141f 100644 --- a/src/whatsapp/routers/chat.router.ts +++ b/src/whatsapp/routers/chat.router.ts @@ -163,12 +163,13 @@ export class ChatRouter extends RouterBroker { return res.status(HttpStatus.CREATED).json(response); }) - .post(this.routerPath('getBusinessProfile'), ...guards, async (req, res) => { + .post(this.routerPath('fetchBusinessProfile'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, schema: profilePictureSchema, ClassRef: ProfilePictureDto, - execute: (instance, data) => chatController.getBusinessProfile(instance, data), + execute: (instance, data) => + chatController.fetchBusinessProfile(instance, data), }); return res.status(HttpStatus.OK).json(response); diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index 0ceafe98..9de6a544 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -29,9 +29,6 @@ import makeWASocket, { WAMessage, WAMessageUpdate, WASocket, - WAReadReceiptsValue, - WAPrivacyValue, - WAPrivacyOnlineValue, } from '@evolution/base'; import { Auth, @@ -1502,6 +1499,9 @@ export class WAStartupService { await this.client.updateOnlinePrivacy(settings.privacySettings.online); await this.client.updateLastSeenPrivacy(settings.privacySettings.last); await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd); + + // reinicia a instancia + return { update: 'success', data: await this.client.fetchPrivacySettings() }; } catch (error) { throw new InternalServerErrorException( @@ -1511,7 +1511,7 @@ export class WAStartupService { } } - public async getBusinessProfile(number: string) { + public async fetchBusinessProfile(number: string) { try { let jid; diff --git a/start.sh b/start.sh new file mode 100644 index 00000000..d716d558 --- /dev/null +++ b/start.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +if [ "$DOCKER_ENV" = "true" ]; +then + echo "Enabling environment variables for Docker" + echo "DOCKER_ENV=$DOCKER_ENV" + echo +else + cp ./src/env.yml ./dist/src +fi +echo "> removing dist" +rm -rf ./dist +echo +echo "> transpiling..." +npm run build + +echo +echo "> Successfully build " + +echo +echo "> Starting application..." +echo + +node ./dist/src/main.js \ No newline at end of file