1
Get entire room state
One script reply has been approved by the moderators Verified

Given a room, this returns an array of all current state events.

Created by jaller94 597 days ago Viewed 2453 times
0
Submitted by jaller94 Deno
Verified 547 days ago
1
type Matrix = {
2
  baseUrl: string;
3
  token: string;
4
};
5
export async function main(matrix_res: Matrix, room_id: string) {
6
  const url = `${
7
    matrix_res.baseUrl
8
  }/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/state`;
9
  const resp = await fetch(url, {
10
    headers: {
11
      Authorization: `Bearer ${matrix_res.token}`,
12
    },
13
  });
14
  if (!resp.ok) {
15
    throw Error(`Failed to read room state: Error HTTP${resp.status}`);
16
  }
17
  return {
18
    events: await resp.json(),
19
  };
20
}
21