From 5720bdc0efd75e6aaf71946ccd23946a5ac094b8 Mon Sep 17 00:00:00 2001 From: julianoaj Date: Thu, 20 Feb 2025 16:54:29 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20Remove=20reaction=20from=20a=20?= =?UTF-8?q?message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/sendMessage.controller.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/api/controllers/sendMessage.controller.ts b/src/api/controllers/sendMessage.controller.ts index ac40562c..865fb6ba 100644 --- a/src/api/controllers/sendMessage.controller.ts +++ b/src/api/controllers/sendMessage.controller.ts @@ -18,6 +18,13 @@ import { WAMonitoringService } from '@api/services/monitor.service'; import { BadRequestException } from '@exceptions'; import { isBase64, isURL } from 'class-validator'; +function isEmoji(str: string) { + if (str === '') return true; + + const emojiRegex = /^[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F000}-\u{1F02F}\u{1F0A0}-\u{1F0FF}\u{1F100}-\u{1F64F}\u{1F680}-\u{1F6FF}]$/u; + return emojiRegex.test(str); +} + export class SendMessageController { constructor(private readonly waMonitor: WAMonitoringService) {} @@ -81,8 +88,8 @@ export class SendMessageController { } public async sendReaction({ instanceName }: InstanceDto, data: SendReactionDto) { - if (!data.reaction.match(/[^()\w\sà-ú"-+]+/)) { - throw new BadRequestException('"reaction" must be an emoji'); + if (!isEmoji(data.reaction)) { + throw new BadRequestException('Reaction must be a single emoji or empty string'); } return await this.waMonitor.waInstances[instanceName].reactionMessage(data); } From 48b5fd41e09d046ea3beeb8b202fe76b0e1028cf Mon Sep 17 00:00:00 2001 From: julianoaj Date: Thu, 20 Feb 2025 17:25:39 -0300 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Linting=20requirement?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/sendMessage.controller.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/controllers/sendMessage.controller.ts b/src/api/controllers/sendMessage.controller.ts index 865fb6ba..18339ce5 100644 --- a/src/api/controllers/sendMessage.controller.ts +++ b/src/api/controllers/sendMessage.controller.ts @@ -20,8 +20,9 @@ import { isBase64, isURL } from 'class-validator'; function isEmoji(str: string) { if (str === '') return true; - - const emojiRegex = /^[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F000}-\u{1F02F}\u{1F0A0}-\u{1F0FF}\u{1F100}-\u{1F64F}\u{1F680}-\u{1F6FF}]$/u; + + const emojiRegex = + /^[\u{1F300}-\u{1F9FF}\u{2600}-\u{26FF}\u{2700}-\u{27BF}\u{1F000}-\u{1F02F}\u{1F0A0}-\u{1F0FF}\u{1F100}-\u{1F64F}\u{1F680}-\u{1F6FF}]$/u; return emojiRegex.test(str); }