mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-25 01:48:39 -06:00
feat(endpoint): add setPresence endpoint
This commit is contained in:
parent
5f5db2011e
commit
e58f1d778e
@ -161,6 +161,18 @@ export const presenceSchema: JSONSchema7 = {
|
|||||||
required: ['options', 'number'],
|
required: ['options', 'number'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const presenceOnlySchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
presence: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['unavailable', 'available', 'composing', 'recording', 'paused'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['presence'],
|
||||||
|
};
|
||||||
|
|
||||||
export const pollMessageSchema: JSONSchema7 = {
|
export const pollMessageSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -11,6 +11,7 @@ import {
|
|||||||
ProfileStatusDto,
|
ProfileStatusDto,
|
||||||
ReadMessageDto,
|
ReadMessageDto,
|
||||||
SendPresenceDto,
|
SendPresenceDto,
|
||||||
|
SetPresenceDto,
|
||||||
UpdateMessageDto,
|
UpdateMessageDto,
|
||||||
WhatsAppNumberDto,
|
WhatsAppNumberDto,
|
||||||
} from '../dto/chat.dto';
|
} from '../dto/chat.dto';
|
||||||
@ -85,6 +86,11 @@ export class ChatController {
|
|||||||
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
|
return await this.waMonitor.waInstances[instanceName].sendPresence(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async setPresence({ instanceName }: InstanceDto, data: SetPresenceDto) {
|
||||||
|
logger.verbose('requested sendPresence from ' + instanceName + ' instance');
|
||||||
|
return await this.waMonitor.waInstances[instanceName].setPresence(data);
|
||||||
|
}
|
||||||
|
|
||||||
public async fetchPrivacySettings({ instanceName }: InstanceDto) {
|
public async fetchPrivacySettings({ instanceName }: InstanceDto) {
|
||||||
logger.verbose('requested fetchPrivacySettings from ' + instanceName + ' instance');
|
logger.verbose('requested fetchPrivacySettings from ' + instanceName + ' instance');
|
||||||
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
||||||
|
@ -110,6 +110,10 @@ export class SendPresenceDto extends Metadata {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SetPresenceDto {
|
||||||
|
presence: WAPresence;
|
||||||
|
}
|
||||||
|
|
||||||
export class UpdateMessageDto extends Metadata {
|
export class UpdateMessageDto extends Metadata {
|
||||||
number: string;
|
number: string;
|
||||||
key: proto.IMessageKey;
|
key: proto.IMessageKey;
|
||||||
|
@ -9,6 +9,7 @@ import {
|
|||||||
messageUpSchema,
|
messageUpSchema,
|
||||||
messageValidateSchema,
|
messageValidateSchema,
|
||||||
presenceSchema,
|
presenceSchema,
|
||||||
|
presenceOnlySchema,
|
||||||
privacySettingsSchema,
|
privacySettingsSchema,
|
||||||
profileNameSchema,
|
profileNameSchema,
|
||||||
profilePictureSchema,
|
profilePictureSchema,
|
||||||
@ -31,6 +32,7 @@ import {
|
|||||||
ProfileStatusDto,
|
ProfileStatusDto,
|
||||||
ReadMessageDto,
|
ReadMessageDto,
|
||||||
SendPresenceDto,
|
SendPresenceDto,
|
||||||
|
SetPresenceDto,
|
||||||
UpdateMessageDto,
|
UpdateMessageDto,
|
||||||
WhatsAppNumberDto,
|
WhatsAppNumberDto,
|
||||||
} from '../dto/chat.dto';
|
} from '../dto/chat.dto';
|
||||||
@ -250,6 +252,22 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.CREATED).json(response);
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
})
|
})
|
||||||
|
.post(this.routerPath('setPresence'), ...guards, async (req, res) => {
|
||||||
|
logger.verbose('request received in setPresence');
|
||||||
|
logger.verbose('request body: ');
|
||||||
|
logger.verbose(req.body);
|
||||||
|
|
||||||
|
logger.verbose('request query: ');
|
||||||
|
logger.verbose(req.query);
|
||||||
|
const response = await this.dataValidate<null>({
|
||||||
|
request: req,
|
||||||
|
schema: presenceOnlySchema,
|
||||||
|
ClassRef: SetPresenceDto,
|
||||||
|
execute: (instance, data) => chatController.setPresence(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
// Profile routes
|
// Profile routes
|
||||||
.get(this.routerPath('fetchPrivacySettings'), ...guards, async (req, res) => {
|
.get(this.routerPath('fetchPrivacySettings'), ...guards, async (req, res) => {
|
||||||
logger.verbose('request received in fetchPrivacySettings');
|
logger.verbose('request received in fetchPrivacySettings');
|
||||||
|
@ -72,6 +72,7 @@ import {
|
|||||||
PrivacySettingDto,
|
PrivacySettingDto,
|
||||||
ReadMessageDto,
|
ReadMessageDto,
|
||||||
SendPresenceDto,
|
SendPresenceDto,
|
||||||
|
SetPresenceDto,
|
||||||
UpdateMessageDto,
|
UpdateMessageDto,
|
||||||
WhatsAppNumberDto,
|
WhatsAppNumberDto,
|
||||||
} from '../dto/chat.dto';
|
} from '../dto/chat.dto';
|
||||||
@ -1830,7 +1831,6 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Instance Controller
|
// Instance Controller
|
||||||
|
|
||||||
public async sendPresence(data: SendPresenceDto) {
|
public async sendPresence(data: SendPresenceDto) {
|
||||||
try {
|
try {
|
||||||
const { number } = data;
|
const { number } = data;
|
||||||
@ -1863,6 +1863,17 @@ export class BaileysStartupService extends WAStartupService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Presence Controller
|
||||||
|
public async setPresence(data: SetPresenceDto) {
|
||||||
|
try {
|
||||||
|
await this.client.sendPresenceUpdate(data.presence);
|
||||||
|
this.logger.verbose('Sending presence update: ' + data.presence);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger.error(error);
|
||||||
|
throw new BadRequestException(error.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Send Message Controller
|
// Send Message Controller
|
||||||
public async textMessage(data: SendTextDto, isChatwoot = false) {
|
public async textMessage(data: SendTextDto, isChatwoot = false) {
|
||||||
this.logger.verbose('Sending text message');
|
this.logger.verbose('Sending text message');
|
||||||
|
@ -1185,6 +1185,9 @@ export class BusinessStartupService extends WAStartupService {
|
|||||||
public async sendPresence() {
|
public async sendPresence() {
|
||||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
}
|
}
|
||||||
|
public async setPresence() {
|
||||||
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
|
}
|
||||||
public async fetchPrivacySettings() {
|
public async fetchPrivacySettings() {
|
||||||
throw new BadRequestException('Method not available on WhatsApp Business API');
|
throw new BadRequestException('Method not available on WhatsApp Business API');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user