Search... Ctrl + K

Get room state by type and state_key (matrix)
One script reply has been approved by the moderators Verified

Created by jaller94 113 days ago Used 18 times 1 Point

Requests the content of a room state event. This does not return the entire room state. Parameters are the room (alias or id), the event type and an optional state key.

No comments yet

Points: 0
deno
One script reply has been approved by the moderators
Ap­pro­ved
import * as wmill from "https://deno.land/x/windmill@v1.35.0/mod.ts";

export async function main(
  matrix_res: wmill.Resource<"matrix">,
  room_id: string,
  type: string,
  state_key?: string,
) {
  let url = `${matrix_res.baseUrl}/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/state/${encodeURIComponent(type)}/`;
  if (state_key) {
    url += encodeURIComponent(state_key);
  }
  const resp = await fetch(url, {
    headers: {
      "Authorization": `Bearer ${matrix_res.token}`,
    },
  });
  if (!resp.ok) {
    throw Error(`Failed to read room state: Error HTTP${resp.status}`);
  }
  return {
    content: await resp.json(),
  };
}

Submitted by jaller94 63 days ago

Edited 61 days ago

No comments yet