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

Code before:
            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = "Uptime Kuma Test Alert";
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma" + monitorUrl;
                data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma" + monitorUrl;
                data["X-S4-Status"] = "new";
            }

            if (notification.webhookContentType === "custom") {
                // Initialize LiquidJS and parse the custom Body Template
                const engine = new Liquid();
                const tpl = engine.parse(notification.webhookCustomBody);

                // Insert templated values into Body
                data = await engine.render(tpl,
                    {
                        msg,
                        heartbeatJSON,
                        monitorJSON
                    });
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;

        } catch (error) {
            this.throwGeneralAxiosError(error);
        }

    }

}

module.exports = SIGNL4;


Review comment (refactor):
pelase move this code to `notification-provider.js` and lets share this betwen componets

```suggestion
                data = await this.renderTemplate(notification.signl4customBody,
                    {
                        msg,
                        heartbeatJSON,
                        monitorJSON
                    });
```

Code after:
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { UP, DOWN } = require("../../src/util");

class SIGNL4 extends NotificationProvider {
    name = "SIGNL4";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        const okMsg = "Sent Successfully.";

        try {
            let data = {
                heartbeat: heartbeatJSON,
                monitor: monitorJSON,
                msg,
                // Source system
                "X-S4-SourceSystem": "UptimeKuma",
                monitorUrl: this.extractAdress(monitorJSON),
            };

            const config = {
                headers: {
                    "Content-Type": "application/json"
                }
            };

            if (heartbeatJSON == null) {
                // Test alert
                data.title = "Uptime Kuma Alert";
                data.message = msg;
            } else if (heartbeatJSON.status === UP) {
                data.title = "Uptime Kuma Monitor ✅ Up";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "resolved";
            } else if (heartbeatJSON.status === DOWN) {
                data.title = "Uptime Kuma Monitor 🔴 Down";
                data["X-S4-ExternalID"] = "UptimeKuma-" + monitorJSON.monitorID;
                data["X-S4-Status"] = "new";
            }

            await axios.post(notification.webhookURL, data, config);
            return okMsg;
        } catch (error) {
            this.throwGeneralAxiosError(error);
        }
    }
}

module.exports = SIGNL4;