1
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 179 days ago Viewed 355 times
0
Submitted by nextcloud Bun
Verified 9 days ago
1
import * as wmill from "windmill-client";
2
import createClient, { type Middleware } from "openapi-fetch";
3

4
type Nextcloud = {
5
  baseUrl: string,
6
  password: string,
7
  username: string
8
};
9

10
export async function main(
11
  ncResource: Nextcloud,
12

13
  userId: string | null = null,
14

15
  talkRoomToken: string,
16

17
  message: string,
18

19
  useAppApiAuth: boolean = false,
20
) {
21

22
  const client = createClient<paths>({ baseUrl: ncResource.baseUrl });
23
  const authMiddleware: Middleware = {
24
    async onRequest({ request, options }) {
25
      // fetch token, if it doesn’t exist
26
      // add Authorization header to every request
27
      request.headers.set("Authorization", `Basic ${btoa((userId || ncResource.username) + ':' + ncResource.password)}`);
28
      if (useAppApiAuth) {
29
        request.headers.set("AA-VERSION", "2.3.0",);
30
        request.headers.set("EX-APP-ID", "flow",);
31
        request.headers.set("EX-APP-VERSION", "1.0.1",);
32
        request.headers.set("AUTHORIZATION-APP-API", btoa(
33
          `${userId || ncResource.username}:${ncResource.password}`,
34
        ));
35
      }
36
      return request;
37
    },
38
  };
39
  client.use(authMiddleware);
40

41
  const {
42
    data, // only present if 2XX response
43
    error, // only present if 4XX or 5XX response
44
  } = await client.POST("/ocs/v2.php/apps/spreed/api/{apiVersion}/chat/{token}", {
45
    params: {
46
      header: {
47
        "OCS-APIRequest": true,
48
      },
49
      query: {
50
        format: "json",
51
      },
52
      path: {
53
        apiVersion: "v1",
54
        token: talkRoomToken,
55
      },
56

57
    },
58
    body: {
59
      message: message,
60
    },
61
  });
62
}
Other submissions