Add OneChat notification provider

This commit is contained in:
Pargorn.Ru 2025-01-17 17:05:18 +07:00
parent be2faf64ce
commit dab089086c
6 changed files with 125 additions and 2 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "uptime-kuma",
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "uptime-kuma",
"version": "2.0.0-beta.0",
"version": "2.0.0-beta.1",
"license": "MIT",
"dependencies": {
"@grpc/grpc-js": "~1.8.22",

View file

@ -0,0 +1,70 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class OneChat extends NotificationProvider {
name = "OneChat";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
const url = "https://chat-api.one.th/message/api/v1/push_message";
try {
const config = {
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + notification.accessToken,
},
};
// 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) {
// 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 {
throw new Error(`Network or unexpected error: ${error.message}`);
}
}
}
}
module.exports = OneChat;

View file

@ -30,6 +30,7 @@ const Mattermost = require("./notification-providers/mattermost");
const Nostr = require("./notification-providers/nostr");
const Ntfy = require("./notification-providers/ntfy");
const Octopush = require("./notification-providers/octopush");
const OneChat = require("./notification-providers/onechat");
const OneBot = require("./notification-providers/onebot");
const Opsgenie = require("./notification-providers/opsgenie");
const PagerDuty = require("./notification-providers/pagerduty");
@ -116,6 +117,7 @@ class Notification {
new Nostr(),
new Ntfy(),
new Octopush(),
new OneChat(),
new OneBot(),
new Onesender(),
new Opsgenie(),

View file

@ -135,6 +135,7 @@ export default {
"nostr": "Nostr",
"ntfy": "Ntfy",
"octopush": "Octopush",
"OneChat": "OneChat",
"OneBot": "OneBot",
"Onesender": "Onesender",
"Opsgenie": "Opsgenie",

View file

@ -0,0 +1,48 @@
<template>
<div class="mb-3">
<!-- Access Token Input -->
<div class="mb-3">
<label for="onechat-access-token" class="form-label">
Access Token<span style="color: red;"><sup>*</sup></span>
</label>
<input
id="onechat-access-token"
v-model="$parent.notification.accessToken"
type="text"
class="form-control"
required
/>
<div class="form-text">
<p>{{ $t("OneChatAccessToken") }}</p>
</div>
</div>
<!-- Receiver ID Input -->
<div class="mb-3">
<label for="onechat-receiver-id" class="form-label">
{{ $t("OneChatUserIdOrGroupId") }}<span style="color: red;"><sup>*</sup></span>
</label>
<input
id="onechat-receiver-id"
v-model="$parent.notification.recieverId"
type="text"
class="form-control"
required
/>
</div>
<!-- Bot ID Input -->
<div class="mb-3">
<label for="onechat-bot-id" class="form-label">
{{ $t("OneChatBotId") }}<span style="color: red;"><sup>*</sup></span>
</label>
<input
id="onechat-bot-id"
v-model="$parent.notification.botId"
type="text"
class="form-control"
required
/>
</div>
</div>
</template>

View file

@ -29,6 +29,7 @@ import Mattermost from "./Mattermost.vue";
import Nostr from "./Nostr.vue";
import Ntfy from "./Ntfy.vue";
import Octopush from "./Octopush.vue";
import OneChat from "./OneChat.vue";
import OneBot from "./OneBot.vue";
import Onesender from "./Onesender.vue";
import Opsgenie from "./Opsgenie.vue";
@ -103,6 +104,7 @@ const NotificationFormList = {
"nostr": Nostr,
"ntfy": Ntfy,
"octopush": Octopush,
"OneChat": OneChat,
"OneBot": OneBot,
"Onesender": Onesender,
"Opsgenie": Opsgenie,