mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-26 15:17:44 -06:00
Melhorias
This commit is contained in:
@@ -85,6 +85,7 @@ import {
|
||||
ArchiveChatDto,
|
||||
DeleteMessage,
|
||||
OnWhatsAppDto,
|
||||
NumberBusiness,
|
||||
PrivacySettingDto,
|
||||
ReadMessageDto,
|
||||
WhatsAppNumberDto,
|
||||
@@ -1437,23 +1438,66 @@ export class WAStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
public async profile(instanceName: string) {
|
||||
const jid = this.client?.user?.id;
|
||||
|
||||
public async getStatus(number: string) {
|
||||
const jid = this.createJid(number);
|
||||
|
||||
this.logger.verbose('Getting profile status with jid:' + jid);
|
||||
try {
|
||||
this.logger.verbose('Getting status');
|
||||
return {
|
||||
wuid: jid,
|
||||
status: (await this.client.fetchStatus(jid))?.status,
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.verbose('Status not found');
|
||||
return {
|
||||
wuid: jid,
|
||||
status: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchProfile(instanceName: string, number?: string) {
|
||||
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 info = await waMonitor.instanceInfo(instanceName);
|
||||
const business = await this.fetchBusinessProfile(jid);
|
||||
|
||||
return {
|
||||
wuid: jid,
|
||||
name: info?.instance?.profileName,
|
||||
picture: info?.instance?.profilePictureUrl,
|
||||
status: info?.instance?.profileStatus,
|
||||
os: this.client?.authState?.creds?.platform,
|
||||
isBusiness: typeof business !== 'undefined',
|
||||
};
|
||||
if (number) {
|
||||
const info = (await this.whatsappNumber({ numbers: [jid] }))?.shift();
|
||||
const picture = await this.profilePicture(jid);
|
||||
const status = await this.getStatus(jid);
|
||||
|
||||
return {
|
||||
wuid: jid,
|
||||
name: info?.name,
|
||||
numberExists: info?.exists,
|
||||
picture: picture?.profilePictureUrl,
|
||||
status: status?.status,
|
||||
isBusiness: business.isBusiness,
|
||||
email: business?.email,
|
||||
description: business?.description,
|
||||
website: business?.website?.shift(),
|
||||
};
|
||||
} else {
|
||||
const info = await waMonitor.instanceInfo(instanceName);
|
||||
|
||||
return {
|
||||
wuid: jid,
|
||||
name: info?.instance?.profileName,
|
||||
numberExists: true,
|
||||
picture: info?.instance?.profilePictureUrl,
|
||||
status: info?.instance?.profileStatus,
|
||||
isBusiness: business.isBusiness,
|
||||
email: business?.email,
|
||||
description: business?.description,
|
||||
website: business?.website?.shift(),
|
||||
};
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
this.logger.verbose('Profile not found');
|
||||
return {
|
||||
@@ -2463,29 +2507,31 @@ export class WAStartupService {
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchBusinessProfile(number: string) {
|
||||
public async fetchBusinessProfile(number: string) : Promise<NumberBusiness> {
|
||||
this.logger.verbose('Fetching business profile');
|
||||
try {
|
||||
let jid;
|
||||
|
||||
if (!number) {
|
||||
jid = this.instance.wuid;
|
||||
} else {
|
||||
jid = this.createJid(number);
|
||||
}
|
||||
const jid = (number)
|
||||
? this.createJid(number)
|
||||
: this.instance.wuid;
|
||||
|
||||
const profile = await this.client.getBusinessProfile(jid);
|
||||
this.logger.verbose('Trying to get business profile');
|
||||
|
||||
if (!profile) {
|
||||
const info = await this.whatsappNumber({ numbers: [jid] });
|
||||
|
||||
return {
|
||||
exists: false,
|
||||
message: 'Business profile not found',
|
||||
isBusiness: false,
|
||||
message: 'Not is business profile',
|
||||
...info?.shift()
|
||||
};
|
||||
}
|
||||
|
||||
this.logger.verbose('Business profile fetched');
|
||||
return profile;
|
||||
return {
|
||||
isBusiness: true,
|
||||
...profile
|
||||
};
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException(
|
||||
'Error updating profile name',
|
||||
|
||||
Reference in New Issue
Block a user