-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (53 loc) · 1.49 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict'
// Inputs
const roomAlias = process.env.m_room_alias
const username = process.env.m_username
const password = process.env.m_password
if (!roomAlias || !username || !password) {
console.log('Credentials not set. Exiting.')
process.exit(1)
}
// Import the Matrix JS SDK
const sdk = require('matrix-js-sdk')
const App = {
client: null,
bootstrap: async function bootstrap() {
this.client = sdk.createClient({
baseUrl: 'https://matrix.org'
// We won't pass auth parameters here
})
try {
await this.login()
await this.join()
await this.send()
await this.stop()
} catch (err) {
console.error(`${err.errcode} - ${err.httpStatus}`)
if (this.client) this.client.stopClient()
process.exit(1)
}
},
login: function login() {
// Instead, we will log in using password
return this.client.login('m.login.password', {
user: username,
password: password
})
},
join: function join() {
// Use client.joinRoom(roomAlias, opts)
},
send: function sendGreeting() {
// Use client.sendMessage(roomAlias, content)
},
recv: function recvGreeting() {
// Use client.on('Room.timeline', (e) => {})
},
stop: function stop() {
this.client.stopClient()
console.log("I'm done. Bye.")
process.exit(0)
}
}
// Launch
App.bootstrap()