mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-24 17:38:40 -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 = {
|
export const messageValidateSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -48,6 +48,11 @@ export class ChatController {
|
|||||||
return await this.waMonitor.waInstances[instanceName].profilePicture(data.number);
|
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) {
|
public async fetchContacts({ instanceName }: InstanceDto, query: ContactQuery) {
|
||||||
logger.verbose('requested fetchContacts from ' + instanceName + ' instance');
|
logger.verbose('requested fetchContacts from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);
|
return await this.waMonitor.waInstances[instanceName].fetchContacts(query);
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
privacySettingsSchema,
|
privacySettingsSchema,
|
||||||
profileNameSchema,
|
profileNameSchema,
|
||||||
profilePictureSchema,
|
profilePictureSchema,
|
||||||
|
profileSchema,
|
||||||
profileStatusSchema,
|
profileStatusSchema,
|
||||||
readMessageSchema,
|
readMessageSchema,
|
||||||
whatsappNumberSchema,
|
whatsappNumberSchema,
|
||||||
@ -129,6 +130,23 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
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) => {
|
.post(this.routerPath('findContacts'), ...guards, async (req, res) => {
|
||||||
logger.verbose('request received in findContacts');
|
logger.verbose('request received in findContacts');
|
||||||
logger.verbose('request body: ');
|
logger.verbose('request body: ');
|
||||||
|
@ -1437,6 +1437,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>(
|
private async sendMessageWithTyping<T = proto.IMessage>(
|
||||||
number: string,
|
number: string,
|
||||||
message: T,
|
message: T,
|
||||||
|
Loading…
Reference in New Issue
Block a user