Update whatsapp.service.ts

This commit is contained in:
Alan Mosko 2023-09-05 17:44:47 -03:00
parent 1ec3ed32ee
commit 250e67e7ae

View File

@ -1458,21 +1458,20 @@ export class WAStartupService {
} }
public async fetchProfile(instanceName: string, number?: string) { public async fetchProfile(instanceName: string, number?: string) {
const jid = (number) const jid = number ? this.createJid(number) : this.client?.user?.id;
? this.createJid(number)
: this.client?.user?.id;
this.logger.verbose('Getting profile with jid: ' + jid); this.logger.verbose('Getting profile with jid: ' + jid);
try { try {
this.logger.verbose('Getting profile info'); this.logger.verbose('Getting profile info');
const business = await this.fetchBusinessProfile(jid);
if (number) { if (number) {
const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift(); const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
const picture = await this.profilePicture(jid); const picture = await this.profilePicture(info?.jid);
const status = await this.getStatus(jid); const status = await this.getStatus(info?.jid);
const business = await this.fetchBusinessProfile(info?.jid);
return { return {
wuid: jid, wuid: info?.jid || jid,
name: info?.name, name: info?.name,
numberExists: info?.exists, numberExists: info?.exists,
picture: picture?.profilePictureUrl, picture: picture?.profilePictureUrl,
@ -1484,7 +1483,8 @@ export class WAStartupService {
}; };
} else { } else {
const info = await waMonitor.instanceInfo(instanceName); const info = await waMonitor.instanceInfo(instanceName);
const business = await this.fetchBusinessProfile(jid);
return { return {
wuid: jid, wuid: jid,
name: info?.instance?.profileName, name: info?.instance?.profileName,
@ -1497,7 +1497,6 @@ export class WAStartupService {
website: business?.website?.shift(), website: business?.website?.shift(),
}; };
} }
} catch (error) { } catch (error) {
this.logger.verbose('Profile not found'); this.logger.verbose('Profile not found');
return { return {