Edits history of script submission #22459 for ' Get room state by type and state_key (matrix)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    type Matrix = {
      baseUrl: string;
      token: string;
    };
    export async function main(
      matrix_res: 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 hugo989 7 days ago