diff --git a/src/api/controllers/chat.controller.ts b/src/api/controllers/chat.controller.ts index a1f289cf2b..05e3fa0e3b 100644 --- a/src/api/controllers/chat.controller.ts +++ b/src/api/controllers/chat.controller.ts @@ -4,6 +4,7 @@ import { DecryptPollVoteDto, DeleteMessage, getBase64FromMediaMessageDto, + LimitSharingDto, MarkChatUnreadDto, MarkMessageAsPlayedDto, NumberDto, @@ -44,6 +45,10 @@ export class ChatController { return await this.waMonitor.waInstances[instanceName].markChatUnread(data); } + public async updateLimitSharing({ instanceName }: InstanceDto, data: LimitSharingDto) { + return await this.waMonitor.waInstances[instanceName].updateLimitSharing(data); + } + public async deleteMessage({ instanceName }: InstanceDto, data: DeleteMessage) { return await this.waMonitor.waInstances[instanceName].deleteMessage(data); } diff --git a/src/api/dto/chat.dto.ts b/src/api/dto/chat.dto.ts index 9c6be9f4c9..7552efde9e 100644 --- a/src/api/dto/chat.dto.ts +++ b/src/api/dto/chat.dto.ts @@ -90,6 +90,15 @@ export class MarkChatUnreadDto { chat?: string; } +/** Request to update WhatsApp Advanced Chat Privacy for a chat or group. */ +export class LimitSharingDto { + /** Required, non-empty chat identifier; normalized to a WhatsApp JID before sending. */ + chat: string; + + /** Required boolean: true enables limit sharing; false disables it. */ + limitSharing: boolean; +} + export class PrivacySettingDto { readreceipts: WAReadReceiptsValue; profile: WAPrivacyValue; diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 22839fd451..83a3ba7418 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -6,6 +6,7 @@ import { DeleteMessage, getBase64FromMediaMessageDto, LastMessage, + LimitSharingDto, MarkChatUnreadDto, MarkMessageAsPlayedDto, NumberBusiness, @@ -4263,6 +4264,25 @@ export class BaileysStartupService extends ChannelStartupService { } } + public async updateLimitSharing(data: LimitSharingDto) { + try { + const remoteJid = createJid(data.chat); + const response = await this.client.sendMessage(remoteJid, { limitSharing: data.limitSharing }); + + return { + chatId: remoteJid, + limitSharing: data.limitSharing, + message: response, + }; + } catch (error) { + this.logger.error(error); + throw new InternalServerErrorException({ + limitSharing: false, + message: ['Ocorreu um erro ao atualizar a privacidade avançada da conversa.'], + }); + } + } + public async deleteMessage(del: DeleteMessage) { try { const response = await this.client.sendMessage(del.remoteJid, { delete: del }); diff --git a/src/api/routes/chat.router.ts b/src/api/routes/chat.router.ts index 86f4d65bee..f3ec5a89e2 100644 --- a/src/api/routes/chat.router.ts +++ b/src/api/routes/chat.router.ts @@ -5,6 +5,7 @@ import { DecryptPollVoteDto, DeleteMessage, getBase64FromMediaMessageDto, + LimitSharingDto, MarkChatUnreadDto, MarkMessageAsPlayedDto, NumberDto, @@ -28,6 +29,7 @@ import { decryptPollVoteSchema, deleteMessageSchema, fetchLidSchema, + limitSharingSchema, markChatUnreadSchema, markMessageAsPlayedSchema, messageUpSchema, @@ -105,6 +107,27 @@ export class ChatRouter extends RouterBroker { return res.status(HttpStatus.CREATED).json(response); }) + /** + * @route POST /chat/updateLimitSharing/:instanceName + * @description Enable or disable WhatsApp Advanced Chat Privacy for a chat or group. + * @param {string} instanceName - Name of the WhatsApp instance. + * @body {LimitSharingDto} data - Non-empty chat identifier and required boolean limitSharing toggle. + * @returns {201} Chat ID, requested limitSharing state, and the Baileys message response. + * @throws {400} Invalid request body. + * @throws {401} Unauthorized request. + * @throws {404} Instance not found. + * @throws {500} Failed to update advanced chat privacy. + */ + .post(this.routerPath('updateLimitSharing'), ...guards, async (req, res) => { + const response = await this.dataValidate({ + request: req, + schema: limitSharingSchema, + ClassRef: LimitSharingDto, + execute: (instance, data) => chatController.updateLimitSharing(instance, data), + }); + + return res.status(HttpStatus.CREATED).json(response); + }) .delete(this.routerPath('deleteMessageForEveryone'), ...guards, async (req, res) => { const response = await this.dataValidate({ request: req, diff --git a/src/validate/chat.schema.ts b/src/validate/chat.schema.ts index 6677b652fd..75dd8e6d31 100644 --- a/src/validate/chat.schema.ts +++ b/src/validate/chat.schema.ts @@ -140,6 +140,17 @@ export const markChatUnreadSchema: JSONSchema7 = { required: ['lastMessage'], }; +export const limitSharingSchema: JSONSchema7 = { + $id: v4(), + type: 'object', + properties: { + chat: { type: 'string' }, + limitSharing: { type: 'boolean', enum: [true, false] }, + }, + required: ['chat', 'limitSharing'], + ...isNotEmpty('chat'), +}; + export const deleteMessageSchema: JSONSchema7 = { $id: v4(), type: 'object',