mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-01-09 05:12:28 -06:00
add send presence router
This commit is contained in:
@@ -109,6 +109,7 @@ import {
|
||||
SendLocationDto,
|
||||
SendMediaDto,
|
||||
SendPollDto,
|
||||
SendPresenceDto,
|
||||
SendReactionDto,
|
||||
SendStatusDto,
|
||||
SendStickerDto,
|
||||
@@ -2387,6 +2388,38 @@ export class WAStartupService {
|
||||
return this.stateConnection;
|
||||
}
|
||||
|
||||
public async sendPresence(data: SendPresenceDto) {
|
||||
try {
|
||||
const { number } = data;
|
||||
|
||||
this.logger.verbose(`Check if number "${number}" is WhatsApp`);
|
||||
const isWA = (await this.whatsappNumber({ numbers: [number] }))?.shift();
|
||||
|
||||
this.logger.verbose(`Exists: "${isWA.exists}" | jid: ${isWA.jid}`);
|
||||
if (!isWA.exists && !isJidGroup(isWA.jid) && !isWA.jid.includes('@broadcast')) {
|
||||
throw new BadRequestException(isWA);
|
||||
}
|
||||
|
||||
const sender = isWA.jid;
|
||||
|
||||
this.logger.verbose('Sending presence');
|
||||
await this.client.presenceSubscribe(sender);
|
||||
this.logger.verbose('Subscribing to presence');
|
||||
|
||||
await this.client.sendPresenceUpdate(data.options?.presence ?? 'composing', sender);
|
||||
this.logger.verbose('Sending presence update: ' + data.options?.presence ?? 'composing');
|
||||
|
||||
await delay(data.options.delay);
|
||||
this.logger.verbose('Set delay: ' + data.options.delay);
|
||||
|
||||
await this.client.sendPresenceUpdate('paused', sender);
|
||||
this.logger.verbose('Sending presence update: paused');
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
throw new BadRequestException(error.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Send Message Controller
|
||||
public async textMessage(data: SendTextDto, isChatwoot = false) {
|
||||
this.logger.verbose('Sending text message');
|
||||
|
||||
Reference in New Issue
Block a user