This commit is contained in:
Nayem Siddique 2025-07-18 12:01:22 +06:00 committed by GitHub
commit 95ec1ec734
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 24 deletions

View file

@ -1,6 +1,5 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const qs = require("qs");
const { DOWN, UP } = require("../../src/util");
class LineNotify extends NotificationProvider {
@ -11,36 +10,55 @@ class LineNotify extends NotificationProvider {
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
const url = "https://notify-api.line.me/api/notify";
const url = "https://api.line.me/v2/bot/message/broadcast";
try {
let config = {
const config = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Authorization": "Bearer " + notification.lineNotifyAccessToken
}
"Content-Type": "application/json",
Authorization:
"Bearer " + notification.lineNotifyAccessToken,
},
};
if (heartbeatJSON == null) {
let testMessage = {
"message": msg,
if (!heartbeatJSON) {
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) {
let downMessage = {
"message": "\n[🔴 Down]\n" +
"Name: " + monitorJSON["name"] + " \n" +
heartbeatJSON["msg"] + "\n" +
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
const downMessage = {
messages: [
{
type: "text",
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) {
let upMessage = {
"message": "\n[✅ Up]\n" +
"Name: " + monitorJSON["name"] + " \n" +
heartbeatJSON["msg"] + "\n" +
`Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
const upMessage = {
messages: [
{
type: "text",
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;
} catch (error) {

View file

@ -4,6 +4,6 @@
<input id="line-notify-access-token" v-model="$parent.notification.lineNotifyAccessToken" type="text" class="form-control" :required="true">
</div>
<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>
</template>

View file

@ -440,7 +440,7 @@
"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.",
"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",
"Home Assistant URL": "Home Assistant URL",
"Long-Lived Access Token": "Long-Lived Access Token",