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

Code before:
                } else if (notification.smseagleRecipientType === "smseagle-to") {
                    recipientType = "to";
                    sendMethod = "/send_sms";
                    if (notification.smseagleMsgType !== "smseagle-sms") {
                        if (notification.smseagleDuration) {
                            duration = notification.smseagleDuration;
                        } else {
                            duration = 10;
                        }

                        if (notification.smseagleMsgType === "smseagle-ring") {
                            sendMethod = "/ring_call";
                        } else if (notification.smseagleMsgType === "smseagle-tts") {
                            sendMethod = "/tts_call";
                        } else if (notification.smseagleMsgType === "smseagle-tts-advanced") {
                            sendMethod = "/tts_adv_call";
                            voiceId = notification.smseagleTtsModel ? notification.smseagleTtsModel : 1;
                        }
                    }
                }

                const url = new URL(notification.smseagleUrl + "/http_api" + sendMethod);

                url.searchParams.append("access_token", notification.smseagleToken);
                url.searchParams.append(recipientType, notification.smseagleRecipient);
                if (![ "smseagle-ring", "smseagle-tts", "smseagle-tts-advanced" ].includes(notification.smseagleRecipientType)) {
                    url.searchParams.append("unicode", (notification.smseagleEncoding) ? "1" : "0");
                    url.searchParams.append("highpriority", (notification.smseaglePriority) ? notification.smseaglePriority : "0");
                } else {
                    url.searchParams.append("duration", duration);
                }
                if (notification.smseagleRecipientType !== "smseagle-ring") {
                    url.searchParams.append("message", msg);
                }
                if (voiceId) {
                    url.searchParams.append("voice_id", voiceId);
                }

                let resp = await axios.get(url.toString(), config);

                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",

Review comment (refactor):
lets simplify

```suggestion
                if ("smseagle-sms" === notification.smseagleRecipientType) {
```

Code after:
                } else if (notification.smseagleRecipientType === "smseagle-to") {
                    recipientType = "to";
                    sendMethod = "/send_sms";
                    if (notification.smseagleMsgType !== "smseagle-sms") {
                        duration = notification.smseagleDuration ?? 10;

                        if (notification.smseagleMsgType === "smseagle-ring") {
                            sendMethod = "/ring_call";
                        } else if (notification.smseagleMsgType === "smseagle-tts") {
                            sendMethod = "/tts_call";
                        } else if (notification.smseagleMsgType === "smseagle-tts-advanced") {
                            sendMethod = "/tts_adv_call";
                            voiceId = notification.smseagleTtsModel ? notification.smseagleTtsModel : 1;
                        }
                    }
                }

                const url = new URL(notification.smseagleUrl + "/http_api" + sendMethod);

                url.searchParams.append("access_token", notification.smseagleToken);
                url.searchParams.append(recipientType, notification.smseagleRecipient);
                if (!notification.smseagleRecipientType || notification.smseagleRecipientType === "smseagle-sms") {
                    url.searchParams.append("unicode", (notification.smseagleEncoding) ? "1" : "0");
                    url.searchParams.append("highpriority", notification.smseaglePriority ?? "0");
                } else {
                    url.searchParams.append("duration", duration);
                }
                if (notification.smseagleRecipientType !== "smseagle-ring") {
                    url.searchParams.append("message", msg);
                }
                if (voiceId) {
                    url.searchParams.append("voice_id", voiceId);
                }

                let resp = await axios.get(url.toString(), config);

                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";