Given a room, this returns an array of all current state events.
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