From 8433bceb32fc6e5cfc040802cb8332a22e5f0c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Szczepa=C5=84ski?= Date: Thu, 12 Jan 2023 08:14:31 +0100 Subject: [PATCH] Trim message to maximum allowed length --- server/notification-providers/promosms.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/notification-providers/promosms.js b/server/notification-providers/promosms.js index 3ab94169..572a2132 100644 --- a/server/notification-providers/promosms.js +++ b/server/notification-providers/promosms.js @@ -12,6 +12,10 @@ class PromoSMS extends NotificationProvider { notification.promosmsAllowLongSMS = false; } + //TODO: Add option for enabling special characters. It will decrese message max length from 160 to 70 chars. + //Lets remove non ascii char + let cleanMsg = msg.replace(/[^\x00-\x7F]/g, ""); + try { let config = { headers: { @@ -22,8 +26,8 @@ class PromoSMS extends NotificationProvider { }; let data = { "recipients": [ notification.promosmsPhoneNumber ], - //Lets remove non ascii char - "text": msg.replace(/[^\x00-\x7F]/g, ""), + //Trim message to maximum length of 1 SMS or 4 if we allowed long messages + "text": notification.promosmsAllowLongSMS ? cleanMsg.substring(0, 639) : cleanMsg.substring(0, 159), "long-sms": notification.promosmsAllowLongSMS, "type": Number(notification.promosmsSMSType), "sender": notification.promosmsSenderName