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

Code before:
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        // See documentation at https://nextcloud-talk.readthedocs.io/en/latest/bots/#sending-a-chat-message
        const okMsg = "Sent Successfully.";
        const ocsApiBase = "/ocs/v2.php/apps/spreed/api/v1/bot";

        // Create a random string
        const talkRandom = encodeURIComponent(
            Crypto
                .randomBytes(64)
                .toString("hex")
                .slice(0, 64)
        );

        // Create the signature over random and message
        const talkSignature = Crypto
            .createHmac("sha256", Buffer.from(notification.botsecret, "utf8"))
            .update(Buffer.from(`${talkRandom}${msg}`, "utf8"))
            .digest("hex");

        let silentUp = (heartbeatJSON?.status === UP && notification.sendsilentup);
        let silentDown = (heartbeatJSON?.status === DOWN && notification.sendsilentdown);
        let silent = (silentUp || silentDown);

        let url = `${notification.host}/${ocsApiBase}/${notification.conversationtoken}/message`;
        let config = this.getAxiosConfigWithProxy({});

        const options = {
            config,
            url,
            method: "post",
            data: {
                message: msg,
                silent
            },
            headers: {
                "X-Nextcloud-Talk-Bot-Random": talkRandom,
                "X-Nextcloud-Talk-Bot-Signature": talkSignature,
                "OCS-APIRequest": true,
            }
        };

        try {
            let result = await axios.request(options);

            if (result?.status === 201) {
                return okMsg;
            }

            throw new Error("Nextcloud Talk Error " + (result?.status ?? "Unknown"));

Review comment (suggestion):
lets inline constants, this way the double "//" at the start that you currently have is not there and also easyier to read.

```suggestion
        let url = `${notification.host}/ocs/v2.php/apps/spreed/api/v1/bot/${notification.conversationtoken}/message`;
```

Code after:
     * @inheritdoc
     */
    async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
        // See documentation at https://nextcloud-talk.readthedocs.io/en/latest/bots/#sending-a-chat-message
        const okMsg = "Sent Successfully.";

        // Create a random string
        const talkRandom = encodeURIComponent(
            Crypto
                .randomBytes(64)
                .toString("hex")
                .slice(0, 64)
        );

        // Create the signature over random and message
        const talkSignature = Crypto
            .createHmac("sha256", Buffer.from(notification.botSecret, "utf8"))
            .update(Buffer.from(`${talkRandom}${msg}`, "utf8"))
            .digest("hex");

        let silentUp = (heartbeatJSON?.status === UP && notification.sendSilentUp);
        let silentDown = (heartbeatJSON?.status === DOWN && notification.sendSilentDown);
        let silent = (silentUp || silentDown);

        let url = `${notification.host}/ocs/v2.php/apps/spreed/api/v1/bot/${notification.conversationToken}/message`;
        let config = this.getAxiosConfigWithProxy({});

        const data = {
            message: msg,
            silent
        };

        const options = {
            ...config,
            headers: {
                "X-Nextcloud-Talk-Bot-Random": talkRandom,
                "X-Nextcloud-Talk-Bot-Signature": talkSignature,
                "OCS-APIRequest": true,
            }
        };

        try {
            let result = await axios.post(url, data, options);

            if (result?.status === 201) {
                return okMsg;
            }

            throw new Error("Nextcloud Talk Error " + (result?.status ?? "Unknown"));
        } catch (error) {
            this.throwGeneralAxiosError(error);