-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (41 loc) · 1.26 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const core = require('@actions/core');
const sdk = require('matrix-js-sdk');
const md = require('markdown-it')();
try {
const homeserver = core.getInput('homeserver');
const channel = core.getInput('channel');
const token = core.getInput('token');
const message = core.getInput('message');
const messagetype = core.getInput('messagetype');
// Debug output
core.info(`homeserver: ${homeserver}`);
core.info(`channel: ${channel}`);
core.info(`token: ${token}`);
core.info(`message: ${message}`);
core.info(`messagetype: ${messagetype}`);
// Create client object
const client = sdk.createClient({
baseUrl: `https://${homeserver}`,
accessToken: token,
});
// Join channel (if we are already in the channel this does nothing)
client.joinRoom(channel).then(() => {
core.info('Joined channel');
});
// render markdown in message
const processedMessage = md.render(message);
// Send message
const content = {
msgtype: messagetype,
format: 'org.matrix.custom.html',
body: message,
formatted_body: processedMessage,
};
client.sendEvent(channel, 'm.room.message', content, '').then(() => {
// message sent successfully
}).catch((err) => {
core.error(err);
});
} catch (error) {
core.setFailed(error.message);
}