Matrix Notifications

This commit is contained in:
Gero Gerke 2021-10-05 20:03:56 +02:00
parent c1501742f5
commit 5decfb9fad
5 changed files with 68 additions and 1 deletions

View file

@ -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;

View file

@ -5,6 +5,7 @@ const Gotify = require("./notification-providers/gotify");
const Line = require("./notification-providers/line"); const Line = require("./notification-providers/line");
const LunaSea = require("./notification-providers/lunasea"); const LunaSea = require("./notification-providers/lunasea");
const Mattermost = require("./notification-providers/mattermost"); const Mattermost = require("./notification-providers/mattermost");
const Matrix = require("./notification-providers/matrix");
const Octopush = require("./notification-providers/octopush"); const Octopush = require("./notification-providers/octopush");
const Pushbullet = require("./notification-providers/pushbullet"); const Pushbullet = require("./notification-providers/pushbullet");
const Pushover = require("./notification-providers/pushover"); const Pushover = require("./notification-providers/pushover");
@ -34,6 +35,7 @@ class Notification {
new Line(), new Line(),
new LunaSea(), new LunaSea(),
new Mattermost(), new Mattermost(),
new Matrix(),
new Octopush(), new Octopush(),
new Pushbullet(), new Pushbullet(),
new Pushover(), new Pushover(),

View file

@ -0,0 +1,25 @@
<template>
<div class="mb-3">
<label for="homeserver-url" class="form-label">Homeserver URL (with http(s):// and optionally port)</label>
<input id="homeserver-url" v-model="$parent.notification.homeserverUrl" type="text" class="form-control" :required="true">
<label for="internal-room-id" class="form-label">Internal Room Id</label>
<input id="internal-room-id" v-model="$parent.notification.internalRoomId" type="text" class="form-control" required="true">
<label for="access-token" class="form-label">Access Token</label>
<HiddenInput id="access-token" v-model="$parent.notification.accessToken" :required="true" autocomplete="one-time-code" :maxlength="500"></HiddenInput>
</div>
<p style="margin-top: 8px;">
You can find the internal room ID by looking in the advanced section if your Matrix client. It should look like !QMdRCpUIfLwsfjxye6:home.server.<br/>
It is highly recommended you create a new user and do not use your Matrix user's access token as it will allow full access to the matrix user. You can get the access token by running curl -XPOST -d '{"type":"m.login.password", "identifier": {"user":"botusername", "type": "m.id.user"}, "password":"passwordforuser"}' "https://home.server.url/_matrix/client/r0/login".
</p>
</template>
<script>
import HiddenInput from "../HiddenInput.vue";
export default {
components: {
HiddenInput,
},
}
</script>

View file

@ -15,6 +15,7 @@ import Apprise from "./Apprise.vue";
import Pushbullet from "./Pushbullet.vue"; import Pushbullet from "./Pushbullet.vue";
import Line from "./Line.vue"; import Line from "./Line.vue";
import Mattermost from "./Mattermost.vue"; import Mattermost from "./Mattermost.vue";
import Matrix from "./Matrix.vue";
/** /**
* Manage all notification form. * Manage all notification form.
@ -38,7 +39,8 @@ const NotificationFormList = {
"apprise": Apprise, "apprise": Apprise,
"pushbullet": Pushbullet, "pushbullet": Pushbullet,
"line": Line, "line": Line,
"mattermost": Mattermost "mattermost": Mattermost,
"matrix": Matrix
} }
export default NotificationFormList export default NotificationFormList

View file

@ -195,4 +195,5 @@ export default {
"pushbullet": "Pushbullet", "pushbullet": "Pushbullet",
"line": "Line Messenger", "line": "Line Messenger",
"mattermost": "Mattermost", "mattermost": "Mattermost",
"matrix": "Matrix",
}; };