Update serwersms.js

This commit is contained in:
miesiu 2025-07-18 12:54:52 +02:00 committed by GitHub
parent 6a34cecc93
commit c658beeddd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,17 +21,18 @@ class SerwerSMS extends NotificationProvider {
let data = {
"username": notification.serwersmsUsername,
"password": notification.serwersmsPassword,
"text": msg.replace(/[^\x00-\x7F]/g, ""), // SerwerSMS może nie obsługiwać znaków specjalnych bez utf
"text": msg.replace(/[^\x00-\x7F]/g, ""), // SerwerSMS may not support special characters without UTF-8 encoding
"sender": notification.serwersmsSenderName,
};
// Obsługa numeru telefonu lub grupy
if (notification.serwersmsGroupId) {
data.group_id = notification.serwersmsGroupId;
} else if (notification.serwersmsPhoneNumber) {
data.phone = notification.serwersmsPhoneNumber;
// **CHANGED:** Now uses notification.destinationType and notification.destinationValue directly
if (notification.destinationType === "group") {
data.group_id = notification.destinationValue;
} else if (notification.destinationType === "phone") {
data.phone = notification.destinationValue;
} else {
throw new Error("SerwerSMS: Either phone number or group_id must be provided.");
// Throws an error if recipient type is not defined or invalid
throw new Error("SerwerSMS: Recipient type (phone number or group ID) must be defined.");
}
let resp = await axios.post(url, data, config);
@ -41,8 +42,7 @@ class SerwerSMS extends NotificationProvider {
let error = `SerwerSMS.pl API returned error code ${resp.data.error.code} (${resp.data.error.type}) with error message: ${resp.data.error.message}`;
this.throwGeneralAxiosError(error);
} else {
let error = "SerwerSMS.pl API returned an unexpected response";
this.throwGeneralAxiosError(error);
this.throwGeneralAxiosError("SerwerSMS.pl API returned an unexpected response");
}
}