This commit is contained in:
Pargorn Ruasijan 2025-01-26 13:21:51 +00:00 committed by GitHub
commit f435eb6607
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 146 additions and 1 deletions

View file

@ -0,0 +1,73 @@
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,
},
};
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);
}
}
}
}
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,64 @@
<template>
<div class="mb-3">
<!-- Access Token Input -->
<div class="mb-3">
<label for="onechat-access-token" class="form-label">
OneChat Access Token<span style="color: red;"><sup>*</sup></span>
</label>
<HiddenInput
id="onechat-access-token"
v-model="$parent.notification.accessToken"
:required="true"
>
</HiddenInput>
<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>
<!-- Document Link -->
<div class="form-text">
<i18n-t tag="p" keypath="Read more:">
<a href="https://chat-develop.one.th/docs" target="_blank">https://chat-develop.one.th/docs</a>
</i18n-t>
</div>
</div>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
};
</script>

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,

View file

@ -1051,5 +1051,8 @@
"RabbitMQ Password": "RabbitMQ Password",
"rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.",
"SendGrid API Key": "SendGrid API Key",
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas",
"OneChatAccessToken": "OneChat Access Token",
"OneChatUserIdOrGroupId": "OneChat User ID or Group ID",
"OneChatBotId": "OneChat Bot ID"
}