1 | |
2 |
|
3 | type Matrix = { |
4 | baseUrl: string; |
5 | token: string; |
6 | }; |
7 | export async function main(matrix_res: Matrix, room: string) { |
8 | if (!matrix_res.token) { |
9 | throw Error("Joining a room requires an access token."); |
10 | } |
11 | const resp = await fetch( |
12 | `${matrix_res.baseUrl}/_matrix/client/v3/join/${encodeURIComponent(room)}`, |
13 | { |
14 | method: "POST", |
15 | headers: { |
16 | Authorization: `Bearer ${matrix_res.token}`, |
17 | }, |
18 | }, |
19 | ); |
20 | if (!resp.ok) { |
21 | throw Error(`Failed to join room: Error HTTP${resp.status}`); |
22 | } |
23 | } |
24 |
|