Updated support for SMSEagle APIv2 notifications

This commit is contained in:
AxeKam333 2025-02-27 09:03:15 +01:00
parent b45dc6787d
commit c154d8b214

View file

@ -13,56 +13,61 @@ class SMSEagle extends NotificationProvider {
try { try {
let config = { let config = {
headers: { headers: {
"access-token": notification.smseagleToken,
"Content-Type": "application/json", "Content-Type": "application/json",
} }
}; };
let postData; let postData;
let sendMethod;
let recipientType; let recipientType;
let encoding = (notification.smseagleEncoding) ? "1" : "0"; let encoding = (notification.smseagleEncoding) ? "unicode" : "standard";
let priority = (notification.smseaglePriority) ? notification.smseaglePriority : "0"; let priority = (notification.smseaglePriority) ? notification.smseaglePriority : 0;
let recipientList = notification.smseagleRecipient.split(",");
if (notification.smseagleRecipientType === "smseagle-contact") { if (notification.smseagleRecipientType === "smseagle-contact") {
recipientType = "contactname"; recipientType = "contacts";
sendMethod = "sms.send_tocontact"; recipientList = recipientList.map(e => {
return Number(e)
});
} }
if (notification.smseagleRecipientType === "smseagle-group") { if (notification.smseagleRecipientType === "smseagle-group") {
recipientType = "groupname"; recipientType = "groups";
sendMethod = "sms.send_togroup"; recipientList = recipientList.map(e => {
return Number(e)
});
} }
if (notification.smseagleRecipientType === "smseagle-to") { if (notification.smseagleRecipientType === "smseagle-to") {
recipientType = "to"; recipientType = "to";
sendMethod = "sms.send_sms";
} }
let params = {
access_token: notification.smseagleToken,
[recipientType]: notification.smseagleRecipient,
message: msg,
responsetype: "extended",
unicode: encoding,
highpriority: priority
};
postData = { postData = {
method: sendMethod, [recipientType]: recipientList,
params: params text: msg,
encoding: encoding,
priority: priority
}; };
let resp = await axios.post(notification.smseagleUrl + "/jsonrpc/sms", postData, config); let resp = await axios.post(notification.smseagleUrl + "/api/v2/messages/sms", postData, config);
if ((JSON.stringify(resp.data)).indexOf("message_id") === -1) { let countAll = resp.data.length;
let countQueued = resp.data.filter(x => x.status == "queued").length;
if (resp.status !== 200 || countQueued == 0) {
let error = ""; let error = "";
if (resp.data.result && resp.data.result.error_text) { if (resp.data.length > 0) {
error = `SMSEagle API returned error: ${JSON.stringify(resp.data.result.error_text)}`; error = `SMSEagle API returned error: ${JSON.stringify(resp.data)}`;
} else { } else {
error = "SMSEagle API returned an unexpected response"; error = "SMSEagle API returned an unexpected response";
} }
throw new Error(error); throw new Error(error);
} }
if (countAll !== countQueued) {
let okWithErrorsMsg = "Sent " + countQueued + "/" + countAll + " Messages Successfully.";
return okWithErrorsMsg;
}
return okMsg; return okMsg;
} catch (error) { } catch (error) {
this.throwGeneralAxiosError(error); this.throwGeneralAxiosError(error);