1
Leave room
One script reply has been approved by the moderators Verified

Leaves a Matrix room.

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