diff --git a/server/notification-providers/discord.js b/server/notification-providers/discord.js index 971c26e5e..881ad2113 100644 --- a/server/notification-providers/discord.js +++ b/server/notification-providers/discord.js @@ -7,7 +7,7 @@ class Discord extends NotificationProvider { name = "discord"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { const discordDisplayName = notification.discordUsername || "Uptime Kuma"; diff --git a/server/notification-providers/gotify.js b/server/notification-providers/gotify.js index 9d2d55aa5..085261897 100644 --- a/server/notification-providers/gotify.js +++ b/server/notification-providers/gotify.js @@ -6,7 +6,7 @@ class Gotify extends NotificationProvider { name = "gotify"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { if (notification.gotifyserverurl && notification.gotifyserverurl.endsWith("/")) { notification.gotifyserverurl = notification.gotifyserverurl.slice(0, -1); diff --git a/server/notification-providers/line.js b/server/notification-providers/line.js index 830969034..327696edd 100644 --- a/server/notification-providers/line.js +++ b/server/notification-providers/line.js @@ -7,7 +7,7 @@ class Line extends NotificationProvider { name = "line"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { let lineAPIUrl = "https://api.line.me/v2/bot/message/push"; let config = { diff --git a/server/notification-providers/lunasea.js b/server/notification-providers/lunasea.js index fb6cd2368..c41f400e2 100644 --- a/server/notification-providers/lunasea.js +++ b/server/notification-providers/lunasea.js @@ -7,7 +7,7 @@ class LunaSea extends NotificationProvider { name = "lunasea"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; let lunaseadevice = "https://notify.lunasea.app/v1/custom/device/" + notification.lunaseaDevice try { diff --git a/server/notification-providers/matrix.js b/server/notification-providers/matrix.js new file mode 100644 index 000000000..c1054fce6 --- /dev/null +++ b/server/notification-providers/matrix.js @@ -0,0 +1,45 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const Crypto = require("crypto"); +const { debug } = require("../../src/util"); + +class Matrix extends NotificationProvider { + name = "matrix"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + const size = 20; + const randomString = encodeURIComponent( + Crypto + .randomBytes(size) + .toString("base64") + .slice(0, size) + ); + + debug("Random String: " + randomString); + + const roomId = encodeURIComponent(notification.internalRoomId); + + debug("Matrix Room ID: " + roomId); + + try { + let config = { + headers: { + "Authorization": `Bearer ${notification.accessToken}`, + } + }; + let data = { + "msgtype": "m.text", + "body": msg + }; + + await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${roomId}/send/m.room.message/${randomString}`, data, config); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Matrix; diff --git a/server/notification-providers/mattermost.js b/server/notification-providers/mattermost.js index 97779435a..d776284be 100644 --- a/server/notification-providers/mattermost.js +++ b/server/notification-providers/mattermost.js @@ -7,7 +7,7 @@ class Mattermost extends NotificationProvider { name = "mattermost"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { const mattermostUserName = notification.mattermostusername || "Uptime Kuma"; // If heartbeatJSON is null, assume we're testing. diff --git a/server/notification-providers/octopush.js b/server/notification-providers/octopush.js index 40273f9b8..76c3e498f 100644 --- a/server/notification-providers/octopush.js +++ b/server/notification-providers/octopush.js @@ -6,7 +6,7 @@ class Octopush extends NotificationProvider { name = "octopush"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { let config = { diff --git a/server/notification-providers/pushbullet.js b/server/notification-providers/pushbullet.js index 0ed6f0fdf..c7b824a2c 100644 --- a/server/notification-providers/pushbullet.js +++ b/server/notification-providers/pushbullet.js @@ -8,7 +8,7 @@ class Pushbullet extends NotificationProvider { name = "pushbullet"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { let pushbulletUrl = "https://api.pushbullet.com/v2/pushes"; diff --git a/server/notification-providers/pushover.js b/server/notification-providers/pushover.js index 2133ca1cf..77ef1a3f0 100644 --- a/server/notification-providers/pushover.js +++ b/server/notification-providers/pushover.js @@ -6,7 +6,7 @@ class Pushover extends NotificationProvider { name = "pushover"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; let pushoverlink = "https://api.pushover.net/1/messages.json" try { diff --git a/server/notification-providers/pushy.js b/server/notification-providers/pushy.js index 431cf8c37..2bb899349 100644 --- a/server/notification-providers/pushy.js +++ b/server/notification-providers/pushy.js @@ -6,7 +6,7 @@ class Pushy extends NotificationProvider { name = "pushy"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { await axios.post(`https://api.pushy.me/push?api_key=${notification.pushyAPIKey}`, { diff --git a/server/notification-providers/rocket-chat.js b/server/notification-providers/rocket-chat.js index a9bd40091..25b0b945f 100644 --- a/server/notification-providers/rocket-chat.js +++ b/server/notification-providers/rocket-chat.js @@ -9,7 +9,7 @@ class RocketChat extends NotificationProvider { name = "rocket.chat"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { if (heartbeatJSON == null) { let data = { diff --git a/server/notification-providers/signal.js b/server/notification-providers/signal.js index ba5f87f9c..fee65754e 100644 --- a/server/notification-providers/signal.js +++ b/server/notification-providers/signal.js @@ -6,7 +6,7 @@ class Signal extends NotificationProvider { name = "signal"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { let data = { diff --git a/server/notification-providers/slack.js b/server/notification-providers/slack.js index 271ee3dc0..5132ba977 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -25,7 +25,7 @@ class Slack extends NotificationProvider { } async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { if (heartbeatJSON == null) { let data = { diff --git a/server/notification-providers/teams.js b/server/notification-providers/teams.js index 72409ffc8..859af569c 100644 --- a/server/notification-providers/teams.js +++ b/server/notification-providers/teams.js @@ -87,7 +87,7 @@ class Teams extends NotificationProvider { }; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { if (heartbeatJSON == null) { diff --git a/server/notification-providers/telegram.js b/server/notification-providers/telegram.js index f88dcf5de..54d33bfbd 100644 --- a/server/notification-providers/telegram.js +++ b/server/notification-providers/telegram.js @@ -6,7 +6,7 @@ class Telegram extends NotificationProvider { name = "telegram"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, { diff --git a/server/notification-providers/webhook.js b/server/notification-providers/webhook.js index 197e9f9f3..9cb361f30 100644 --- a/server/notification-providers/webhook.js +++ b/server/notification-providers/webhook.js @@ -7,7 +7,7 @@ class Webhook extends NotificationProvider { name = "webhook"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; try { let data = { diff --git a/server/notification.js b/server/notification.js index 134472410..207e0a37f 100644 --- a/server/notification.js +++ b/server/notification.js @@ -5,6 +5,7 @@ const Gotify = require("./notification-providers/gotify"); const Line = require("./notification-providers/line"); const LunaSea = require("./notification-providers/lunasea"); const Mattermost = require("./notification-providers/mattermost"); +const Matrix = require("./notification-providers/matrix"); const Octopush = require("./notification-providers/octopush"); const Pushbullet = require("./notification-providers/pushbullet"); const Pushover = require("./notification-providers/pushover"); @@ -34,6 +35,7 @@ class Notification { new Line(), new LunaSea(), new Mattermost(), + new Matrix(), new Octopush(), new Pushbullet(), new Pushover(), diff --git a/src/components/notifications/Matrix.vue b/src/components/notifications/Matrix.vue new file mode 100644 index 000000000..d1e973cd1 --- /dev/null +++ b/src/components/notifications/Matrix.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index e377803e6..fab4075e7 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -15,6 +15,7 @@ import Apprise from "./Apprise.vue"; import Pushbullet from "./Pushbullet.vue"; import Line from "./Line.vue"; import Mattermost from "./Mattermost.vue"; +import Matrix from "./Matrix.vue"; /** * Manage all notification form. @@ -38,7 +39,8 @@ const NotificationFormList = { "apprise": Apprise, "pushbullet": Pushbullet, "line": Line, - "mattermost": Mattermost + "mattermost": Mattermost, + "matrix": Matrix, } export default NotificationFormList diff --git a/src/languages/en.js b/src/languages/en.js index 3395bb30c..aa2737fe5 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -240,5 +240,6 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + "matrix": "Matrix", // End notification form };