Nextcloud Talk: Send a message
One script reply has been approved by the moderators Verified

Send a message to a talk room

Created by marcel klehr12 595 days ago Picked 11 times
Submitted by nextcloud Bun
Verified 21 days ago
1
import createClient, { type Middleware } from "openapi-fetch";
2

3
export async function main(
4
  nextcloud: RT.Nextcloud,
5
  talkRoomToken: string,
6
  message: string,
7
) {
8

9
  const client = createClient<paths>({ baseUrl: nextcloud.baseUrl });
10
  const authMiddleware: Middleware = {
11
    async onRequest({ request, options }) {
12
      // fetch token, if it doesn’t exist
13
      // add Authorization header to every request
14
      request.headers.set("Authorization", `Basic ${btoa((nextcloud.userId) + ':' + nextcloud.token)}`);
15
      return request;
16
    },
17
  };
18
  client.use(authMiddleware);
19

20
  const data = await client.POST("/ocs/v2.php/apps/spreed/api/{apiVersion}/chat/{token}", {
21
    params: {
22
      header: {
23
        "OCS-APIRequest": true,
24
      },
25
      query: {
26
        format: "json",
27
      },
28
      path: {
29
        apiVersion: "v1",
30
        token: talkRoomToken,
31
      },
32

33
    },
34
    body: {
35
      message: message,
36
    },
37
  });
38
  return data;
39
}
Other submissions