mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-18 23:34:04 +02:00
Merge bcb6f599a1
into 2fd4e1cc72
This commit is contained in:
commit
95ec1ec734
3 changed files with 42 additions and 24 deletions
|
@ -1,6 +1,5 @@
|
||||||
const NotificationProvider = require("./notification-provider");
|
const NotificationProvider = require("./notification-provider");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const qs = require("qs");
|
|
||||||
const { DOWN, UP } = require("../../src/util");
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
class LineNotify extends NotificationProvider {
|
class LineNotify extends NotificationProvider {
|
||||||
|
@ -11,36 +10,55 @@ class LineNotify extends NotificationProvider {
|
||||||
*/
|
*/
|
||||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
const okMsg = "Sent Successfully.";
|
const okMsg = "Sent Successfully.";
|
||||||
const url = "https://notify-api.line.me/api/notify";
|
const url = "https://api.line.me/v2/bot/message/broadcast";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let config = {
|
const config = {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/x-www-form-urlencoded",
|
"Content-Type": "application/json",
|
||||||
"Authorization": "Bearer " + notification.lineNotifyAccessToken
|
Authorization:
|
||||||
}
|
"Bearer " + notification.lineNotifyAccessToken,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
if (heartbeatJSON == null) {
|
|
||||||
let testMessage = {
|
if (!heartbeatJSON) {
|
||||||
"message": msg,
|
const testMessage = {
|
||||||
|
messages: [
|
||||||
|
{
|
||||||
|
type: "text",
|
||||||
|
text: msg,
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
await axios.post(url, qs.stringify(testMessage), config);
|
await axios.post(url, testMessage, config);
|
||||||
} else if (heartbeatJSON["status"] === DOWN) {
|
} else if (heartbeatJSON["status"] === DOWN) {
|
||||||
let downMessage = {
|
const downMessage = {
|
||||||
"message": "\n[🔴 Down]\n" +
|
messages: [
|
||||||
"Name: " + monitorJSON["name"] + " \n" +
|
{
|
||||||
heartbeatJSON["msg"] + "\n" +
|
type: "text",
|
||||||
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
text:
|
||||||
|
"🔴 [Down]\n" +
|
||||||
|
`Name: ${monitorJSON["name"]}\n` +
|
||||||
|
`${heartbeatJSON["msg"]}\n` +
|
||||||
|
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
await axios.post(url, qs.stringify(downMessage), config);
|
await axios.post(url, downMessage, config);
|
||||||
} else if (heartbeatJSON["status"] === UP) {
|
} else if (heartbeatJSON["status"] === UP) {
|
||||||
let upMessage = {
|
const upMessage = {
|
||||||
"message": "\n[✅ Up]\n" +
|
messages: [
|
||||||
"Name: " + monitorJSON["name"] + " \n" +
|
{
|
||||||
heartbeatJSON["msg"] + "\n" +
|
type: "text",
|
||||||
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
text:
|
||||||
|
"✅ [Up]\n" +
|
||||||
|
`Name: ${monitorJSON["name"]}\n` +
|
||||||
|
`${heartbeatJSON["msg"]}\n` +
|
||||||
|
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
await axios.post(url, qs.stringify(upMessage), config);
|
await axios.post(url, upMessage, config);
|
||||||
}
|
}
|
||||||
return okMsg;
|
return okMsg;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
<input id="line-notify-access-token" v-model="$parent.notification.lineNotifyAccessToken" type="text" class="form-control" :required="true">
|
<input id="line-notify-access-token" v-model="$parent.notification.lineNotifyAccessToken" type="text" class="form-control" :required="true">
|
||||||
</div>
|
</div>
|
||||||
<i18n-t tag="div" keypath="wayToGetLineNotifyToken" class="form-text" style="margin-top: 8px;">
|
<i18n-t tag="div" keypath="wayToGetLineNotifyToken" class="form-text" style="margin-top: 8px;">
|
||||||
<a href="https://notify-bot.line.me/" target="_blank">https://notify-bot.line.me/</a>
|
<a href="https://developers.line.biz/console/" target="_blank">{{ $t("Line Developers Console") }}</a>
|
||||||
</i18n-t>
|
</i18n-t>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -440,7 +440,7 @@
|
||||||
"chatIDNotFound": "Chat ID is not found; please send a message to this bot first",
|
"chatIDNotFound": "Chat ID is not found; please send a message to this bot first",
|
||||||
"disableCloudflaredNoAuthMsg": "You are in No Auth mode, a password is not required.",
|
"disableCloudflaredNoAuthMsg": "You are in No Auth mode, a password is not required.",
|
||||||
"trustProxyDescription": "Trust 'X-Forwarded-*' headers. If you want to get the correct client IP and your Uptime Kuma is behind a proxy such as Nginx or Apache, you should enable this.",
|
"trustProxyDescription": "Trust 'X-Forwarded-*' headers. If you want to get the correct client IP and your Uptime Kuma is behind a proxy such as Nginx or Apache, you should enable this.",
|
||||||
"wayToGetLineNotifyToken": "You can get an access token from {0}",
|
"wayToGetLineNotifyToken": "First access the {0}, create a provider and channel (Messaging API), then you can get the channel access token",
|
||||||
"Examples": "Examples",
|
"Examples": "Examples",
|
||||||
"Home Assistant URL": "Home Assistant URL",
|
"Home Assistant URL": "Home Assistant URL",
|
||||||
"Long-Lived Access Token": "Long-Lived Access Token",
|
"Long-Lived Access Token": "Long-Lived Access Token",
|
||||||
|
|
Loading…
Add table
Reference in a new issue