1 | |
2 |
|
3 | |
4 | * Set the topic of a Matrix room. A topic is a short message detailing what is currently being discussed in the room. |
5 | * |
6 | * HTTP endpoint: https://spec.matrix.org/v1.5/client-server-api/#put_matrixclientv3roomsroomidstateeventtypestatekey |
7 | * |
8 | * State event description: https://spec.matrix.org/v1.5/client-server-api/#mroomtopic |
9 | */ |
10 | type Matrix = { |
11 | baseUrl: string; |
12 | token: string; |
13 | }; |
14 | export async function main( |
15 | matrix_res: Matrix, |
16 | room_id: string, |
17 | topic: string = "", |
18 | ) { |
19 | const url = `${ |
20 | matrix_res.baseUrl |
21 | }/_matrix/client/v3/rooms/${encodeURIComponent(room_id)}/state/m.room.topic/`; |
22 | const resp = await fetch(url, { |
23 | method: "PUT", |
24 | headers: { |
25 | Authorization: `Bearer ${matrix_res.token}`, |
26 | "Content-Type": "application/json", |
27 | }, |
28 | body: JSON.stringify({ |
29 | topic, |
30 | }), |
31 | }); |
32 | if (!resp.ok) { |
33 | throw Error(`Failed to set room topic: Error HTTP${resp.status}`); |
34 | } |
35 | return await resp.json(); |
36 | } |
37 |
|