Get entire room state

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

Script matrix Verified

by jaller94 ยท 8/10/2022

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 4 days ago
1
//native
2

3
type Matrix = {
4
  baseUrl: string;
5
  token: string;
6
};
7
export async function main(matrix_res: Matrix, room_id: string) {
8
  const url = `${
9
    matrix_res.baseUrl
10
  }/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/state`;
11
  const resp = await fetch(url, {
12
    headers: {
13
      Authorization: `Bearer ${matrix_res.token}`,
14
    },
15
  });
16
  if (!resp.ok) {
17
    throw Error(`Failed to read room state: Error HTTP${resp.status}`);
18
  }
19
  return {
20
    events: await resp.json(),
21
  };
22
}
23

Other submissions
  • Submitted by jaller94 Deno
    Created 396 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