From 250e67e7ae2d0e58d2a649dc6f2774d25198a9d0 Mon Sep 17 00:00:00 2001 From: Alan Mosko Date: Tue, 5 Sep 2023 17:44:47 -0300 Subject: [PATCH] Update whatsapp.service.ts --- src/whatsapp/services/whatsapp.service.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/whatsapp/services/whatsapp.service.ts b/src/whatsapp/services/whatsapp.service.ts index e99cee84..09c78078 100644 --- a/src/whatsapp/services/whatsapp.service.ts +++ b/src/whatsapp/services/whatsapp.service.ts @@ -1458,21 +1458,20 @@ export class WAStartupService { } public async fetchProfile(instanceName: string, number?: string) { - const jid = (number) - ? this.createJid(number) - : this.client?.user?.id; + const jid = number ? this.createJid(number) : this.client?.user?.id; + this.logger.verbose('Getting profile with jid: ' + jid); try { this.logger.verbose('Getting profile info'); - const business = await this.fetchBusinessProfile(jid); - + if (number) { const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); - const picture = await this.profilePicture(jid); - const status = await this.getStatus(jid); - + const picture = await this.profilePicture(info?.jid); + const status = await this.getStatus(info?.jid); + const business = await this.fetchBusinessProfile(info?.jid); + return { - wuid: jid, + wuid: info?.jid || jid, name: info?.name, numberExists: info?.exists, picture: picture?.profilePictureUrl, @@ -1484,7 +1483,8 @@ export class WAStartupService { }; } else { const info = await waMonitor.instanceInfo(instanceName); - + const business = await this.fetchBusinessProfile(jid); + return { wuid: jid, name: info?.instance?.profileName, @@ -1497,7 +1497,6 @@ export class WAStartupService { website: business?.website?.shift(), }; } - } catch (error) { this.logger.verbose('Profile not found'); return {