Edits history of script submission #22456 for ' Leave room (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, roomId: string) {
      if (!matrix_res.token) {
        throw Error("Leaving a room requires an access token.");
      }
      const resp = await fetch(
        `${matrix_res.baseUrl}/_matrix/client/v3/rooms/${encodeURIComponent(
          roomId,
        )}/leave`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${matrix_res.token}`,
          },
        },
      );
      if (!resp.ok) {
        throw Error(`Failed to leave room: Error HTTP${resp.status}`);
      }
    }
    

    Submitted by hugo989 4 days ago