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

Code before:
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");

const NotificationProvider = require("./notification-provider");
const axios = require("axios");

const heiiOnCallBaseUrl = "https://heiioncall.com";

class HeiiOnCall extends NotificationProvider {
    name = "HeiiOnCall";

    /**
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        // Payload to Heii On-Call is the entire heartbat JSON
        const payload = heartbeatJSON ? heartbeatJSON : {};

        // If we can, add url back to monitor to payload
        const baseURL = await setting("primaryBaseURL");
        if (baseURL && monitorJSON) {
            payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
        }

        if (!heartbeatJSON) {
            // No heartbeatJSON. Could be test button, but not necessarily. Just pull msg into payload.
            payload["msg"] = msg;
            return this.postNotification(notification, "alert", payload);
        }

        if (heartbeatJSON.status === DOWN) {
            // Monitor is DOWN, alert on Heii On-Call
            return this.postNotification(notification, "alert", payload);
        }

        if (heartbeatJSON.status === UP) {
            // Monitor is UP, resolve on Heii On-Call
            return this.postNotification(notification, "resolve", payload);
        }
    }


Review comment (suggestion):
Don't really see the point why this comment is necessary ^^ (see [this video](https://www.youtube.com/watch?v=Bf7vDBBOBUA) for a more-in-depth take)

```suggestion
```

Code after:
const { UP, DOWN, getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");

const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class HeiiOnCall extends NotificationProvider {
    name = "HeiiOnCall";

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

        const baseURL = await setting("primaryBaseURL");
        if (baseURL && monitorJSON) {
            payload["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
        }

        const config = {
            headers: {
                Accept: "application/json",
                "Content-Type": "application/json",
                Authorization: "Bearer " + notification.heiiOnCallApiKey,
            },
        };
        const heiiUrl = `https://heiioncall.com/triggers/${notification.heiiOnCallTriggerId}/`;
        // docs https://heiioncall.com/docs#manual-triggers
        try {
            if (!heartbeatJSON) {
                // Testing or general notification like certificate expiry
                payload["msg"] = msg;
                await axios.post(heiiUrl + "alert", payload, config);
                return okMsg;
            }

            if (heartbeatJSON.status === DOWN) {
                await axios.post(heiiUrl + "alert", payload, config);
                return okMsg;
            }