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

Code before:
            // Send a test message if the monitor is null
            if (heartbeatJSON == null) {
                const testMessage = {
                    to: notification.recieverId,
                    bot_id: notification.botId,
                    type: "text",
                    message: "Test Successful!",
                };
                await axios.post(url, testMessage, config);
            } else if (heartbeatJSON["status"] === DOWN) {
                const downMessage = {
                    to: notification.recieverId,
                    bot_id: notification.botId,
                    type: "text",
                    message:
                        "UptimeKuma Alert:\n" +
                        "[🔴 Down]\n" +
                        "Name: " +
                        monitorJSON["name"] +
                        "\n" +
                        heartbeatJSON["msg"] +
                        "\n" +
                        "Time (" +
                        heartbeatJSON["timezone"] +
                        "): " +
                        heartbeatJSON["localDateTime"],
                };
                await axios.post(url, downMessage, config);
            } else if (heartbeatJSON["status"] === UP) {
                const upMessage = {
                    to: notification.recieverId,
                    bot_id: notification.botId,
                    type: "text",
                    message:
                        "UptimeKuma Alert:\n" +
                        "[🟢 Up]\n" +
                        "Name: " +
                        monitorJSON["name"] +
                        "\n" +
                        heartbeatJSON["msg"] +
                        "\n" +
                        "Time (" +
                        heartbeatJSON["timezone"] +
                        "): " +
                        heartbeatJSON["localDateTime"],
                };
                await axios.post(url, upMessage, config);
            }

            return okMsg;
        } catch (error) {

Review comment (suggestion):
Please use a [template literal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) instead.

Please change Up accordingly too ^^

```suggestion
                        `UptimeKuma Alert:
[🔴 Down]
Name: ${monitorJSON["name"]}
${heartbeatJSON["msg"]}
Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
```

Code after:
            if (heartbeatJSON == null) {
                const testMessage = {
                    to: notification.recieverId,
                    bot_id: notification.botId,
                    type: "text",
                    message: "Test Successful!",
                };
                await axios.post(url, testMessage, config);
            } else if (heartbeatJSON["status"] === DOWN) {
                const downMessage = {
                    to: notification.recieverId,
                    bot_id: notification.botId,
                    type: "text",
                    message:
                        `UptimeKuma Alert:
[🔴 Down]
Name: ${monitorJSON["name"]}
${heartbeatJSON["msg"]}
Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
                };
                await axios.post(url, downMessage, config);
            } else if (heartbeatJSON["status"] === UP) {
                const upMessage = {
                    to: notification.recieverId,
                    bot_id: notification.botId,
                    type: "text",
                    message:
                        `UptimeKuma Alert:
[🟢 Up]
Name: ${monitorJSON["name"]}
${heartbeatJSON["msg"]}
Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
                };
                await axios.post(url, upMessage, config);
            }

            return okMsg;
        } catch (error) {
            // Handle errors and throw a descriptive message
            if (error.response) {
                const errorMessage =
                    error.response.data?.message ||
                    "Unknown API error occurred.";
                throw new Error(`OneChat API Error: ${errorMessage}`);
            } else {
                this.throwGeneralAxiosError(error);
            }
        }
    }
}