Repository: louislam/uptime-kuma
File: server/notification-providers/smseagle.js (JavaScript)

Code before:
                if (resp.data.indexOf("OK") === -1) {
                    let error = `SMSEagle API returned error: ${resp.data}`;
                    throw new Error(error);
                }

                return okMsg;
            } else if (notification.smseagleApiType === "smseagle-apiv2") { // according to https://www.smseagle.eu/docs/apiv2/
                let config = {
                    headers: {
                        "access-token": notification.smseagleToken,
                        "Content-Type": "application/json",
                    }
                };

                let encoding = (notification.smseagleEncoding) ? "unicode" : "standard";
                let priority = (notification.smseaglePriority) ? notification.smseaglePriority : 0;

                let postData = {
                    text: msg,
                    encoding: encoding,
                    priority: priority
                };

                let to = notification.smseagleRecipientTo;
                let contacts = notification.smseagleRecipientContact;
                let groups = notification.smseagleRecipientGroup;

                if (contacts) {
                    contacts = contacts.split(",");
                    contacts = contacts.map(e => {
                        return Number(e);
                    });
                    postData["contacts"] = contacts;
                }

                if (groups) {
                    groups = groups.split(",");
                    groups = groups.map(e => {
                        return Number(e);
                    });
                    postData["groups"] = groups;
                }

                if (to) {
                    to = to.split(",");
                    postData["to"] = to;
                }

                let endpoint = "/messages/sms";

                if (notification.smseagleMsgType !== "smseagle-sms") {

Review comment (refactor):
reasigning variables like here is kind of messy. Lets not do that

Please also clean up the usages below

```suggestion
```

Code after:

                return okMsg;
            } else if (notification.smseagleApiType === "smseagle-apiv2") { // according to https://www.smseagle.eu/docs/apiv2/
                let config = {
                    headers: {
                        "access-token": notification.smseagleToken,
                        "Content-Type": "application/json",
                    }
                };

                let encoding = (notification.smseagleEncoding) ? "unicode" : "standard";
                let priority = (notification.smseaglePriority) ?? 0;

                let postData = {
                    text: msg,
                    encoding: encoding,
                    priority: priority
                };

                if (notification.smseagleRecipientContact) {
                    postData["contacts"] = notification.smseagleRecipientContact.split(",").map(Number);
                }
                if (notification.smseagleRecipientGroup) {
                    postData["groups"] = notification.smseagleRecipientGroup.split(",").map(Number);
                }
                if (notification.smseagleRecipientTo) {
                    postData["to"] = notification.smseagleRecipientTo.split(",");
                }

                let endpoint = "/messages/sms";

                if (notification.smseagleMsgType !== "smseagle-sms") {

                    postData["duration"] = notification.smseagleDuration ?? 10;

                    if (notification.smseagleMsgType === "smseagle-ring") {
                        endpoint = "/calls/ring";
                    } else if (notification.smseagleMsgType === "smseagle-tts") {
                        endpoint = "/calls/tts";
                    } else if (notification.smseagleMsgType === "smseagle-tts-advanced") {
                        endpoint = "/calls/tts_advanced";
                        postData["voice_id"] = notification.smseagleTtsModel ?? 1;
                    }
                }

                let resp = await axios.post(notification.smseagleUrl + "/api/v2" + endpoint, postData, config);

                const queuedCount = resp.data.filter(x => x.status === "queued").length;
                const unqueuedCount = resp.data.length - queuedCount;

                if (resp.status !== 200 || queuedCount === 0) {