mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-23 04:22:02 -06:00
Adição de Profile Route
This commit is contained in:
parent
3e3a175bdc
commit
e851696430
@ -587,6 +587,17 @@ export const profilePictureSchema: JSONSchema7 = {
|
||||
},
|
||||
};
|
||||
|
||||
export const profileSchema: JSONSchema7 = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
wuid: { type: 'string' },
|
||||
name: { type: 'string' },
|
||||
picture: { type: 'string' },
|
||||
status: { type: 'string' },
|
||||
isBusiness: { type: 'boolean' },
|
||||
},
|
||||
};
|
||||
|
||||
export const messageValidateSchema: JSONSchema7 = {
|
||||
$id: v4(),
|
||||
type: 'object',
|
||||
|
@ -47,6 +47,11 @@ export class ChatController {
|
||||
logger.verbose('requested fetchProfilePicture from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].profilePicture(data.number);
|
||||
}
|
||||
|
||||
public async fetchProfile({ instanceName }: InstanceDto, data: NumberDto) {
|
||||
logger.verbose('requested fetchProfile from ' + instanceName + ' instance');
|
||||
return await this.waMonitor.waInstances[instanceName].profile(instanceName, data.number);
|
||||
}
|
||||
|
||||
public async fetchContacts({ instanceName }: InstanceDto, query: ContactQuery) {
|
||||
logger.verbose('requested fetchContacts from ' + instanceName + ' instance');
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
privacySettingsSchema,
|
||||
profileNameSchema,
|
||||
profilePictureSchema,
|
||||
profileSchema,
|
||||
profileStatusSchema,
|
||||
readMessageSchema,
|
||||
whatsappNumberSchema,
|
||||
@ -129,6 +130,23 @@ export class ChatRouter extends RouterBroker {
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.get(this.routerPath('fetchProfile'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in fetchProfile');
|
||||
logger.verbose('request body: ');
|
||||
logger.verbose(req.body);
|
||||
|
||||
logger.verbose('request query: ');
|
||||
logger.verbose(req.query);
|
||||
|
||||
const response = await this.dataValidate<NumberDto>({
|
||||
request: req,
|
||||
schema: profileSchema,
|
||||
ClassRef: NumberDto,
|
||||
execute: (instance, data) => chatController.fetchProfile(instance, data),
|
||||
});
|
||||
|
||||
return res.status(HttpStatus.OK).json(response);
|
||||
})
|
||||
.post(this.routerPath('findContacts'), ...guards, async (req, res) => {
|
||||
logger.verbose('request received in findContacts');
|
||||
logger.verbose('request body: ');
|
||||
|
@ -1436,6 +1436,36 @@ export class WAStartupService {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async profile(instanceName: string) {
|
||||
const jid = 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',
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.verbose('Profile not found');
|
||||
return {
|
||||
wuid: jid,
|
||||
name: null,
|
||||
picture: null,
|
||||
status: null,
|
||||
os: null,
|
||||
isBusiness: false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private async sendMessageWithTyping<T = proto.IMessage>(
|
||||
number: string,
|
||||
|
Loading…
Reference in New Issue
Block a user