|
|
@ -1,6 +1,7 @@
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const NotificationProvider = require("./notification-provider");
|
|
|
|
const axios = require("axios");
|
|
|
|
const axios = require("axios");
|
|
|
|
const Crypto = require('crypto')
|
|
|
|
const Crypto = require("crypto");
|
|
|
|
|
|
|
|
const { debug } = require("../../src/util");
|
|
|
|
|
|
|
|
|
|
|
|
class Matrix extends NotificationProvider {
|
|
|
|
class Matrix extends NotificationProvider {
|
|
|
|
name = "matrix";
|
|
|
|
name = "matrix";
|
|
|
@ -9,14 +10,18 @@ class Matrix extends NotificationProvider {
|
|
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
|
|
|
|
|
|
|
|
const size = 20;
|
|
|
|
const size = 20;
|
|
|
|
const randomString = Crypto
|
|
|
|
const randomString = encodeURIComponent(
|
|
|
|
.randomBytes(size)
|
|
|
|
Crypto
|
|
|
|
.toString('base64')
|
|
|
|
.randomBytes(size)
|
|
|
|
.slice(0, size);
|
|
|
|
.toString("base64")
|
|
|
|
const roomId = notification
|
|
|
|
.slice(0, size)
|
|
|
|
.internalRoomId
|
|
|
|
);
|
|
|
|
.replaceAll(":", "%3A")
|
|
|
|
|
|
|
|
.replaceAll("!", "%21");
|
|
|
|
debug("Random String: " + randomString);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const roomId = encodeURIComponent(notification.internalRoomId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
debug("Matrix Room ID: " + roomId);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
let config = {
|
|
|
|
let config = {
|
|
|
@ -29,7 +34,7 @@ class Matrix extends NotificationProvider {
|
|
|
|
"body": msg
|
|
|
|
"body": msg
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await axios.put(`${notification.homeserverUrl}/_matrix/client/r0/rooms/${roomId}/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;
|
|
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|
this.throwGeneralAxiosError(error);
|
|
|
|