1 | import * as wmill from "npm:windmill-client@1"; |
2 | import * as tb from "https://raw.githubusercontent.com/marcelklehr/nextcloud-client-deno/6f973bfdcaed0d8b4f35b6cf5d0368d8bec73ed4/talk/index.ts"; |
3 |
|
4 | export async function main( |
5 | nextcloudResource: string, |
6 | userId: string | null = null, |
7 | talkRoomToken: string, |
8 | message: string, |
9 | useAppApiAuth: boolean = false, |
10 | ) { |
11 | const ncResource = await wmill.getResource( |
12 | nextcloudResource, |
13 | ); |
14 | const config = new tb.Configuration({ |
15 | username: userId || ncResource.username, |
16 | password: ncResource.password, |
17 | basePath: ncResource.baseUrl, |
18 | middleware: [{ |
19 | async pre(context) { |
20 | if (!context.url.includes("?")) { |
21 | context.url += "?"; |
22 | } else { |
23 | context.url += "&"; |
24 | } |
25 | context.url += "format=json"; |
26 | return context; |
27 | }, |
28 | }], |
29 | ...(useAppApiAuth && ({ |
30 | headers: { |
31 | "AA-VERSION": "2.3.0", |
32 | "EX-APP-ID": "flow", |
33 | "EX-APP-VERSION": "1.0.0", |
34 | "AUTHORIZATION-APP-API": btoa( |
35 | `${userId || ncResource.username}:${ncResource.password}`, |
36 | ), |
37 | }, |
38 | })), |
39 | }); |
40 | const api = new tb.ChatApi(config); |
41 |
|
42 | const res = await api.chatSendMessageRaw({ |
43 | apiVersion: "v1", |
44 | message, |
45 | oCSAPIRequest: true, |
46 | token: talkRoomToken, |
47 | }); |
48 | return await res.raw.json(); |
49 | } |
50 |
|