-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMessaging.ts
34 lines (23 loc) · 1.05 KB
/
Messaging.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Settings } from './Settings';
import { MatrixClient } from "matrix-bot-sdk";
export class Messaging {
static client: MatrixClient;
static async initialize() {
const sdk = require("matrix-bot-sdk");
const MatrixClient = sdk.MatrixClient;
const SimpleFsStorageProvider = sdk.SimpleFsStorageProvider;
const AutojoinRoomsMixin = sdk.AutojoinRoomsMixin;
const homeserverUrl = "https://matrix.org"; // make sure to update this with your url
const storage = new SimpleFsStorageProvider(`${Settings.bot_path}/bot.json`);
this.client = new MatrixClient(homeserverUrl, Settings.matrix_accessToken, storage);
AutojoinRoomsMixin.setupOnClient(this.client);
this.client.start().then((x: MatrixClient) => {
console.log("Matrix client initiated");
})
}
static async sendMessage(message: string) {
this.client.sendHtmlText(Settings.room_id, message).catch(err => {
this.initialize();
});
}
}