From 5decfb9fadc71f2099809aff69b4e45fb7e3330f Mon Sep 17 00:00:00 2001 From: Gero Gerke Date: Tue, 5 Oct 2021 20:03:56 +0200 Subject: [PATCH 1/9] Matrix Notifications --- server/notification-providers/matrix.js | 37 +++++++++++++++++++++++++ server/notification.js | 2 ++ src/components/notifications/Matrix.vue | 25 +++++++++++++++++ src/components/notifications/index.js | 4 ++- src/languages/en.js | 1 + 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/matrix.js create mode 100644 src/components/notifications/Matrix.vue diff --git a/server/notification-providers/matrix.js b/server/notification-providers/matrix.js new file mode 100644 index 000000000..4593be6a6 --- /dev/null +++ b/server/notification-providers/matrix.js @@ -0,0 +1,37 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const Crypto = require('crypto') + +class Matrix extends NotificationProvider { + + name = "matrix"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully. "; + + const size = 20; + const randomString = Crypto + .randomBytes(size) + .toString('base64') + .slice(0, size); + + try { + let config = { + headers: { + "Authorization": `Bearer ${notification.accessToken}`, + } + }; + let data = { + "msgtype": "m.text", + "body": msg + }; + + await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${notification.internalRoomId}/send/m.room.message/${randomString}`, data, config) + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Matrix; 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..12c7dad80 --- /dev/null +++ b/src/components/notifications/Matrix.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index e377803e6..6dd9ed928 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 46298b015..ccc7290d6 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -195,4 +195,5 @@ export default { "pushbullet": "Pushbullet", "line": "Line Messenger", "mattermost": "Mattermost", + "matrix": "Matrix", }; From 8c357a04bfdf824741e870006e28c773ef08414d Mon Sep 17 00:00:00 2001 From: Gero Gerke <11deutron11@gmail.com> Date: Tue, 5 Oct 2021 20:42:36 +0200 Subject: [PATCH 2/9] Update src/components/notifications/index.js Co-authored-by: Adam Stachowicz --- src/components/notifications/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 6dd9ed928..fab4075e7 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -40,7 +40,7 @@ const NotificationFormList = { "pushbullet": Pushbullet, "line": Line, "mattermost": Mattermost, - "matrix": Matrix + "matrix": Matrix, } export default NotificationFormList From d7cc58510183240c41b3abc31d3ca97367aaee1e Mon Sep 17 00:00:00 2001 From: Gero Gerke <11deutron11@gmail.com> Date: Tue, 5 Oct 2021 20:42:44 +0200 Subject: [PATCH 3/9] Update server/notification-providers/matrix.js Co-authored-by: Adam Stachowicz --- server/notification-providers/matrix.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/notification-providers/matrix.js b/server/notification-providers/matrix.js index 4593be6a6..581218ea7 100644 --- a/server/notification-providers/matrix.js +++ b/server/notification-providers/matrix.js @@ -3,7 +3,6 @@ const axios = require("axios"); const Crypto = require('crypto') class Matrix extends NotificationProvider { - name = "matrix"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { From 99e8a331184e0dffdf70e500fe729dc133e04768 Mon Sep 17 00:00:00 2001 From: Gero Gerke Date: Tue, 5 Oct 2021 21:36:01 +0200 Subject: [PATCH 4/9] escape room characters --- server/notification-providers/matrix.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/notification-providers/matrix.js b/server/notification-providers/matrix.js index 581218ea7..24d45239e 100644 --- a/server/notification-providers/matrix.js +++ b/server/notification-providers/matrix.js @@ -13,6 +13,10 @@ class Matrix extends NotificationProvider { .randomBytes(size) .toString('base64') .slice(0, size); + const roomId = notification + .internalRoomId + .replaceALl(":", "%3A") + .replaceAll("!", "%21"); try { let config = { @@ -25,7 +29,7 @@ class Matrix extends NotificationProvider { "body": msg }; - await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${notification.internalRoomId}/send/m.room.message/${randomString}`, data, config) + await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${roomId}/send/m.room.message/${randomString}`, data, config) return okMsg; } catch (error) { this.throwGeneralAxiosError(error); From 34b86352f24bf36084e58f96bf7a8149c2b63414 Mon Sep 17 00:00:00 2001 From: Gero Gerke Date: Tue, 5 Oct 2021 21:40:59 +0200 Subject: [PATCH 5/9] remove double spaces --- server/notification-providers/discord.js | 2 +- server/notification-providers/gotify.js | 2 +- server/notification-providers/line.js | 2 +- server/notification-providers/lunasea.js | 2 +- server/notification-providers/matrix.js | 2 +- server/notification-providers/mattermost.js | 2 +- server/notification-providers/octopush.js | 2 +- server/notification-providers/pushbullet.js | 2 +- server/notification-providers/pushover.js | 2 +- server/notification-providers/pushy.js | 2 +- server/notification-providers/rocket-chat.js | 2 +- server/notification-providers/signal.js | 2 +- server/notification-providers/slack.js | 2 +- server/notification-providers/teams.js | 2 +- server/notification-providers/telegram.js | 2 +- server/notification-providers/webhook.js | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) 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 index 24d45239e..cd5c2426a 100644 --- a/server/notification-providers/matrix.js +++ b/server/notification-providers/matrix.js @@ -6,7 +6,7 @@ class Matrix extends NotificationProvider { name = "matrix"; async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { - let okMsg = "Sent Successfully. "; + let okMsg = "Sent Successfully."; const size = 20; const randomString = Crypto 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 149189650..d61058489 100644 --- a/server/notification-providers/rocket-chat.js +++ b/server/notification-providers/rocket-chat.js @@ -6,7 +6,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 661df5a0f..3d5a3bed4 100644 --- a/server/notification-providers/slack.js +++ b/server/notification-providers/slack.js @@ -6,7 +6,7 @@ class Slack extends NotificationProvider { name = "slack"; 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 = { From 6bebc623f98bc2e67f4d7a6d3ea8746081a41692 Mon Sep 17 00:00:00 2001 From: Gero Gerke Date: Tue, 5 Oct 2021 21:59:58 +0200 Subject: [PATCH 6/9] UI polish --- server/notification-providers/matrix.js | 2 +- src/components/notifications/Matrix.vue | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/server/notification-providers/matrix.js b/server/notification-providers/matrix.js index cd5c2426a..eeaa9eb91 100644 --- a/server/notification-providers/matrix.js +++ b/server/notification-providers/matrix.js @@ -15,7 +15,7 @@ class Matrix extends NotificationProvider { .slice(0, size); const roomId = notification .internalRoomId - .replaceALl(":", "%3A") + .replaceAll(":", "%3A") .replaceAll("!", "%21"); try { diff --git a/src/components/notifications/Matrix.vue b/src/components/notifications/Matrix.vue index 12c7dad80..acce9466e 100644 --- a/src/components/notifications/Matrix.vue +++ b/src/components/notifications/Matrix.vue @@ -1,17 +1,26 @@