mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-25 05:34:08 -08:00
Add OneBot notification service
This commit is contained in:
parent
0a5db0cecb
commit
4656ab3d57
45
server/notification-providers/onebot.js
Normal file
45
server/notification-providers/onebot.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
|
||||
class OneBot extends NotificationProvider {
|
||||
|
||||
name = "OneBot";
|
||||
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
let okMsg = "Sent Successfully.";
|
||||
try {
|
||||
let httpAddr = notification.httpAddr;
|
||||
if (!httpAddr.startsWith("http")) {
|
||||
httpAddr = "http://" + httpAddr;
|
||||
}
|
||||
if (!httpAddr.endsWith("/")) {
|
||||
httpAddr += "/";
|
||||
}
|
||||
let onebotAPIUrl = httpAddr + "send_msg";
|
||||
let config = {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": "Bearer " + notification.accessToken
|
||||
}
|
||||
};
|
||||
let psuhText = "UptimeKuma Alert: " + msg;
|
||||
let data = {
|
||||
"auto_escape": true,
|
||||
"message": psuhText
|
||||
};
|
||||
if (notification.msgType == "group") {
|
||||
data["message_type"] = "group";
|
||||
data["group_id"] = notification.recieverId;
|
||||
} else {
|
||||
data["message_type"] = "private";
|
||||
data["user_id"] = notification.recieverId;
|
||||
}
|
||||
await axios.post(onebotAPIUrl, data, config);
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OneBot;
|
|
@ -31,6 +31,7 @@ const WeCom = require("./notification-providers/wecom");
|
|||
const GoogleChat = require("./notification-providers/google-chat");
|
||||
const Gorush = require("./notification-providers/gorush");
|
||||
const Alerta = require("./notification-providers/alerta");
|
||||
const Onebot = require("./notification-providers/onebot");
|
||||
|
||||
class Notification {
|
||||
|
||||
|
@ -73,6 +74,8 @@ class Notification {
|
|||
new GoogleChat(),
|
||||
new Gorush(),
|
||||
new Alerta(),
|
||||
new GoogleChat(),
|
||||
new Onebot(),
|
||||
];
|
||||
|
||||
for (let item of list) {
|
||||
|
|
34
src/components/notifications/OneBot.vue
Normal file
34
src/components/notifications/OneBot.vue
Normal file
|
@ -0,0 +1,34 @@
|
|||
<template>
|
||||
<div class="mb-3">
|
||||
<div class="mb-3">
|
||||
<label for="onebot-http-addr" class="form-label">{{ $t("onebotHttpAddress") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||
<input id="HttpUrl" v-model="$parent.notification.httpAddr" type="text" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="onebot-access-token" class="form-label">AccessToken<span style="color: red;"><sup>*</sup></span></label>
|
||||
<input id="HttpUrl" v-model="$parent.notification.accessToken" type="text" class="form-control" required>
|
||||
<div class="form-text">
|
||||
<p>{{ $t("onebotSafetyTips") }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="onebot-msg-type" class="form-label">{{ $t("onebotMessageType") }}</label>
|
||||
<select id="onebot-msg-type" v-model="$parent.notification.msgType" class="form-select">
|
||||
<option value="group">{{ $t("onebotGroupMessage") }}</option>
|
||||
<option value="private">{{ $t("onebotPrivateMessage") }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="onebot-reciever-id" class="form-label">{{ $t("onebotUserOrGroupId") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||
<input id="secretKey" v-model="$parent.notification.recieverId" type="text" class="form-control" required>
|
||||
</div>
|
||||
|
||||
<div class="form-text">
|
||||
<i18n-t tag="p" keypath="Read more:">
|
||||
<a href="https://github.com/botuniverse/onebot-11" target="_blank">https://github.com/botuniverse/onebot-11</a>
|
||||
</i18n-t>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
|
@ -29,6 +29,7 @@ import WeCom from "./WeCom.vue";
|
|||
import GoogleChat from "./GoogleChat.vue";
|
||||
import Gorush from "./Gorush.vue";
|
||||
import Alerta from "./Alerta.vue";
|
||||
import OneBot from "./OneBot.vue";
|
||||
|
||||
/**
|
||||
* Manage all notification form.
|
||||
|
@ -67,6 +68,7 @@ const NotificationFormList = {
|
|||
"GoogleChat": GoogleChat,
|
||||
"gorush": Gorush,
|
||||
"alerta": Alerta,
|
||||
"OneBot": OneBot,
|
||||
};
|
||||
|
||||
export default NotificationFormList;
|
||||
|
|
|
@ -445,4 +445,10 @@ export default {
|
|||
"Domain Name Expiry Notification": "Domain Name Expiry Notification",
|
||||
"Proxy": "Proxy",
|
||||
"Date Created": "Date Created",
|
||||
onebotHttpAddress: "OneBot HTTP Address",
|
||||
onebotMessageType: "OneBot Message Type",
|
||||
onebotGroupMessage: "Group",
|
||||
onebotPrivateMessage: "Private",
|
||||
onebotUserOrGroupId: "Group/User ID",
|
||||
onebotSafetyTips: "For safety, must set access token",
|
||||
};
|
||||
|
|
|
@ -452,4 +452,10 @@ export default {
|
|||
"Domain Name Expiry Notification": "域名到期时通知",
|
||||
"Proxy": "代理",
|
||||
"Date Created": "创建于",
|
||||
onebotHttpAddress: "OneBot HTTP 地址",
|
||||
onebotMessageType: "OneBot 消息类型",
|
||||
onebotGroupMessage: "群聊",
|
||||
onebotPrivateMessage: "私聊",
|
||||
onebotUserOrGroupId: "群组/用户ID",
|
||||
onebotSafetyTips: "出于安全原因,请务必设置AccessToken",
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue