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