From ee67ac538e59ebb895538fff60f7eb1574a863f4 Mon Sep 17 00:00:00 2001 From: Horacio Daniel Ros Date: Sat, 19 Sep 2026 12:30:52 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20agregar=20soporte=20para=20plantillas?= =?UTF-8?q?=20de=20WhatsApp=20en=20el=20controlador=20de=20notificaciones,?= =?UTF-8?q?=20incluyendo=20nuevos=20par=C3=A1metros=20y=20un=20endpoint=20?= =?UTF-8?q?de=20prueba?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Jobs/NotificationJob.Adapter.Mongoose.ts | 3 + .../NotificationJobs.Interface.ts | 3 + .../Notifications.Adapter.Meta.ts | 2 +- .../Notifications/Notifications.Controller.ts | 83 ++++++++++++------- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/notification-sender/src/Models/Jobs/NotificationJob.Adapter.Mongoose.ts b/notification-sender/src/Models/Jobs/NotificationJob.Adapter.Mongoose.ts index 4346be0..a9b2730 100644 --- a/notification-sender/src/Models/Jobs/NotificationJob.Adapter.Mongoose.ts +++ b/notification-sender/src/Models/Jobs/NotificationJob.Adapter.Mongoose.ts @@ -20,6 +20,9 @@ export interface NotificationJobPayload { wapMessage?: string; systemSubject?: string; systemMessage?: string; + templateName?: string; + languageCode?: string; + templateVariables?: string[]; } export interface INotificationJob { diff --git a/server/src/Models/NotificationJobs/NotificationJobs.Interface.ts b/server/src/Models/NotificationJobs/NotificationJobs.Interface.ts index 083b896..665164e 100644 --- a/server/src/Models/NotificationJobs/NotificationJobs.Interface.ts +++ b/server/src/Models/NotificationJobs/NotificationJobs.Interface.ts @@ -28,6 +28,9 @@ export interface NotificationJobPayload { wapMessage?: string; systemSubject?: string; systemMessage?: string; + templateName?: string; + languageCode?: string; + templateVariables?: string[]; } export interface INotificationJob { diff --git a/server/src/Models/Notifications/Notifications.Adapter.Meta.ts b/server/src/Models/Notifications/Notifications.Adapter.Meta.ts index 67ca123..b4719d6 100644 --- a/server/src/Models/Notifications/Notifications.Adapter.Meta.ts +++ b/server/src/Models/Notifications/Notifications.Adapter.Meta.ts @@ -5,7 +5,7 @@ export class NotificationsMetaAdapter implements INotificationsAdapter { - await NotificationsManager.sendWap({ - phoneNumber: requestBody.phoneNumber, - message: requestBody.message, - companyId: requestBody.companyId, - sessionUser: requestBody.sessionUser, - }); +@Route("notifications/send-wap") +@Middlewares([rateLimiter, systemTokenMiddleware]) +export class SendWapByContentController extends Controller { + @SuccessResponse(200, "Done") + @Post() + public async sendWapByContent(@Body() requestBody: SendWapByContentParams): Promise { + await NotificationsManager.sendWap({ + phoneNumber: requestBody.phoneNumber, + message: requestBody.message, + companyId: requestBody.companyId, + sessionUser: requestBody.sessionUser, + }); - this.setStatus(200); - return { - message: "Done", - success: true, - }; - } + this.setStatus(200); + return { + message: "Done", + success: true, + }; } +} - @Route("notifications/send-whatsapp-template") - @Middlewares([rateLimiter, systemTokenMiddleware]) - export class SendWhatsAppTemplateController extends Controller { - @SuccessResponse(200, "Done") - @Post() - public async sendWhatsAppTemplate(@Body() requestBody: SendWhatsAppTemplateParams): Promise { +/** + * TEMPORARY TEST ENDPOINT — remove after testing meta_wap integration + * No auth required. Just for curl testing sendWhatsAppTemplate flow. + */ +@Route("notifications/test-meta-send") +export class TestMetaSendController extends Controller { + @SuccessResponse(200, "Done") + @Post() + public async testMetaSend(@Body() requestBody: SendWhatsAppTemplateParams): Promise { + try { await NotificationsManager.sendWhatsAppTemplate({ phoneNumber: requestBody.phoneNumber, templateName: requestBody.templateName, @@ -86,9 +90,32 @@ export class SendEmailByContentController extends Controller { }); this.setStatus(200); - return { - message: "Done", - success: true, - }; + return { message: "Test sent successfully", success: true }; + } catch (error) { + const msg = error instanceof Error ? error.message : String(error); + this.setStatus(500); + return { message: `Test failed: ${msg}`, success: false }; } } +} + +@Route("notifications/send-whatsapp-template") +@Middlewares([rateLimiter, systemTokenMiddleware]) +export class SendWhatsAppTemplateController extends Controller { + @SuccessResponse(200, "Done") + @Post() + public async sendWhatsAppTemplate(@Body() requestBody: SendWhatsAppTemplateParams): Promise { + await NotificationsManager.sendWhatsAppTemplate({ + phoneNumber: requestBody.phoneNumber, + templateName: requestBody.templateName, + languageCode: requestBody.languageCode, + templateVariables: requestBody.templateVariables, + }); + + this.setStatus(200); + return { + message: "Done", + success: true, + }; + } +}