@im-more/dsh-dingtalk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/cordis.patch.yml +11 -0
- package/lib/index.js +2765 -0
- package/lib/index.js.map +1 -0
- package/lib/types/api/alitrip.d.ts +397 -0
- package/lib/types/api/alitrip.d.ts.map +1 -0
- package/lib/types/api/alitrip.js +21 -0
- package/lib/types/api/alitrip.js.map +1 -0
- package/lib/types/api/attendance.d.ts +63 -0
- package/lib/types/api/attendance.d.ts.map +1 -0
- package/lib/types/api/attendance.js +8 -0
- package/lib/types/api/attendance.js.map +1 -0
- package/lib/types/api/badge.d.ts +233 -0
- package/lib/types/api/badge.d.ts.map +1 -0
- package/lib/types/api/badge.js +19 -0
- package/lib/types/api/badge.js.map +1 -0
- package/lib/types/api/blackboard.d.ts +17 -0
- package/lib/types/api/blackboard.d.ts.map +1 -0
- package/lib/types/api/blackboard.js +6 -0
- package/lib/types/api/blackboard.js.map +1 -0
- package/lib/types/api/calendar.d.ts +621 -0
- package/lib/types/api/calendar.d.ts.map +1 -0
- package/lib/types/api/calendar.js +57 -0
- package/lib/types/api/calendar.js.map +1 -0
- package/lib/types/api/card.d.ts +185 -0
- package/lib/types/api/card.d.ts.map +1 -0
- package/lib/types/api/card.js +13 -0
- package/lib/types/api/card.js.map +1 -0
- package/lib/types/api/conference.d.ts +404 -0
- package/lib/types/api/conference.d.ts.map +1 -0
- package/lib/types/api/conference.js +60 -0
- package/lib/types/api/conference.js.map +1 -0
- package/lib/types/api/connector.d.ts +79 -0
- package/lib/types/api/connector.d.ts.map +1 -0
- package/lib/types/api/connector.js +8 -0
- package/lib/types/api/connector.js.map +1 -0
- package/lib/types/api/contact.d.ts +40 -0
- package/lib/types/api/contact.d.ts.map +1 -0
- package/lib/types/api/contact.js +9 -0
- package/lib/types/api/contact.js.map +1 -0
- package/lib/types/api/convFile.d.ts +135 -0
- package/lib/types/api/convFile.d.ts.map +1 -0
- package/lib/types/api/convFile.js +9 -0
- package/lib/types/api/convFile.js.map +1 -0
- package/lib/types/api/crm.d.ts +662 -0
- package/lib/types/api/crm.d.ts.map +1 -0
- package/lib/types/api/crm.js +59 -0
- package/lib/types/api/crm.js.map +1 -0
- package/lib/types/api/customerService.d.ts +128 -0
- package/lib/types/api/customerService.d.ts.map +1 -0
- package/lib/types/api/customerService.js +13 -0
- package/lib/types/api/customerService.js.map +1 -0
- package/lib/types/api/datacenter.d.ts +506 -0
- package/lib/types/api/datacenter.d.ts.map +1 -0
- package/lib/types/api/datacenter.js +61 -0
- package/lib/types/api/datacenter.js.map +1 -0
- package/lib/types/api/devicemng.d.ts +161 -0
- package/lib/types/api/devicemng.d.ts.map +1 -0
- package/lib/types/api/devicemng.js +20 -0
- package/lib/types/api/devicemng.js.map +1 -0
- package/lib/types/api/diot.d.ts +13 -0
- package/lib/types/api/diot.d.ts.map +1 -0
- package/lib/types/api/diot.js +4 -0
- package/lib/types/api/diot.js.map +1 -0
- package/lib/types/api/doc.d.ts +141 -0
- package/lib/types/api/doc.d.ts.map +1 -0
- package/lib/types/api/doc.js +27 -0
- package/lib/types/api/doc.js.map +1 -0
- package/lib/types/api/drive.d.ts +88 -0
- package/lib/types/api/drive.d.ts.map +1 -0
- package/lib/types/api/drive.js +11 -0
- package/lib/types/api/drive.js.map +1 -0
- package/lib/types/api/edu.d.ts +23 -0
- package/lib/types/api/edu.d.ts.map +1 -0
- package/lib/types/api/edu.js +4 -0
- package/lib/types/api/edu.js.map +1 -0
- package/lib/types/api/esign.d.ts +34 -0
- package/lib/types/api/esign.d.ts.map +1 -0
- package/lib/types/api/esign.js +7 -0
- package/lib/types/api/esign.js.map +1 -0
- package/lib/types/api/exclusive.d.ts +304 -0
- package/lib/types/api/exclusive.d.ts.map +1 -0
- package/lib/types/api/exclusive.js +27 -0
- package/lib/types/api/exclusive.js.map +1 -0
- package/lib/types/api/h3yun.d.ts +438 -0
- package/lib/types/api/h3yun.d.ts.map +1 -0
- package/lib/types/api/h3yun.js +33 -0
- package/lib/types/api/h3yun.js.map +1 -0
- package/lib/types/api/hrm.d.ts +215 -0
- package/lib/types/api/hrm.d.ts.map +1 -0
- package/lib/types/api/hrm.js +20 -0
- package/lib/types/api/hrm.js.map +1 -0
- package/lib/types/api/im.d.ts +773 -0
- package/lib/types/api/im.d.ts.map +1 -0
- package/lib/types/api/im.js +72 -0
- package/lib/types/api/im.js.map +1 -0
- package/lib/types/api/industry.d.ts +118 -0
- package/lib/types/api/industry.d.ts.map +1 -0
- package/lib/types/api/industry.js +14 -0
- package/lib/types/api/industry.js.map +1 -0
- package/lib/types/api/jzcrm.d.ts +255 -0
- package/lib/types/api/jzcrm.d.ts.map +1 -0
- package/lib/types/api/jzcrm.js +18 -0
- package/lib/types/api/jzcrm.js.map +1 -0
- package/lib/types/api/link.d.ts +73 -0
- package/lib/types/api/link.d.ts.map +1 -0
- package/lib/types/api/link.js +9 -0
- package/lib/types/api/link.js.map +1 -0
- package/lib/types/api/live.d.ts +132 -0
- package/lib/types/api/live.d.ts.map +1 -0
- package/lib/types/api/live.js +13 -0
- package/lib/types/api/live.js.map +1 -0
- package/lib/types/api/microApp.d.ts +240 -0
- package/lib/types/api/microApp.d.ts.map +1 -0
- package/lib/types/api/microApp.js +29 -0
- package/lib/types/api/microApp.js.map +1 -0
- package/lib/types/api/oapi.d.ts +3362 -0
- package/lib/types/api/oapi.d.ts.map +1 -0
- package/lib/types/api/oapi.js +247 -0
- package/lib/types/api/oapi.js.map +1 -0
- package/lib/types/api/oauth2.d.ts +115 -0
- package/lib/types/api/oauth2.d.ts.map +1 -0
- package/lib/types/api/oauth2.js +12 -0
- package/lib/types/api/oauth2.js.map +1 -0
- package/lib/types/api/pedia.d.ts +186 -0
- package/lib/types/api/pedia.d.ts.map +1 -0
- package/lib/types/api/pedia.js +13 -0
- package/lib/types/api/pedia.js.map +1 -0
- package/lib/types/api/project.d.ts +1119 -0
- package/lib/types/api/project.d.ts.map +1 -0
- package/lib/types/api/project.js +135 -0
- package/lib/types/api/project.js.map +1 -0
- package/lib/types/api/resident.d.ts +107 -0
- package/lib/types/api/resident.d.ts.map +1 -0
- package/lib/types/api/resident.js +10 -0
- package/lib/types/api/resident.js.map +1 -0
- package/lib/types/api/robot.d.ts +256 -0
- package/lib/types/api/robot.d.ts.map +1 -0
- package/lib/types/api/robot.js +21 -0
- package/lib/types/api/robot.js.map +1 -0
- package/lib/types/api/rooms.d.ts +256 -0
- package/lib/types/api/rooms.d.ts.map +1 -0
- package/lib/types/api/rooms.js +23 -0
- package/lib/types/api/rooms.js.map +1 -0
- package/lib/types/api/serviceGroup.d.ts +176 -0
- package/lib/types/api/serviceGroup.d.ts.map +1 -0
- package/lib/types/api/serviceGroup.js +15 -0
- package/lib/types/api/serviceGroup.js.map +1 -0
- package/lib/types/api/storage.d.ts +1241 -0
- package/lib/types/api/storage.d.ts.map +1 -0
- package/lib/types/api/storage.js +128 -0
- package/lib/types/api/storage.js.map +1 -0
- package/lib/types/api/swform.d.ts +71 -0
- package/lib/types/api/swform.d.ts.map +1 -0
- package/lib/types/api/swform.js +8 -0
- package/lib/types/api/swform.js.map +1 -0
- package/lib/types/api/todo.d.ts +169 -0
- package/lib/types/api/todo.d.ts.map +1 -0
- package/lib/types/api/todo.js +16 -0
- package/lib/types/api/todo.js.map +1 -0
- package/lib/types/api/wiki.d.ts +195 -0
- package/lib/types/api/wiki.d.ts.map +1 -0
- package/lib/types/api/wiki.js +11 -0
- package/lib/types/api/wiki.js.map +1 -0
- package/lib/types/api/workbench.d.ts +46 -0
- package/lib/types/api/workbench.d.ts.map +1 -0
- package/lib/types/api/workbench.js +14 -0
- package/lib/types/api/workbench.js.map +1 -0
- package/lib/types/api/yida.d.ts +1838 -0
- package/lib/types/api/yida.d.ts.map +1 -0
- package/lib/types/api/yida.js +103 -0
- package/lib/types/api/yida.js.map +1 -0
- package/lib/types/bot.d.ts +62 -0
- package/lib/types/bot.d.ts.map +1 -0
- package/lib/types/bot.js +134 -0
- package/lib/types/bot.js.map +1 -0
- package/lib/types/config.d.ts +47 -0
- package/lib/types/config.d.ts.map +1 -0
- package/lib/types/config.js +53 -0
- package/lib/types/config.js.map +1 -0
- package/lib/types/decode.d.ts +36 -0
- package/lib/types/decode.d.ts.map +1 -0
- package/lib/types/decode.js +200 -0
- package/lib/types/decode.js.map +1 -0
- package/lib/types/errors.d.ts +77 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +249 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/index.d.ts +22 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +22 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/internal.d.ts +15 -0
- package/lib/types/internal.d.ts.map +1 -0
- package/lib/types/internal.js +57 -0
- package/lib/types/internal.js.map +1 -0
- package/lib/types/media.d.ts +57 -0
- package/lib/types/media.d.ts.map +1 -0
- package/lib/types/media.js +99 -0
- package/lib/types/media.js.map +1 -0
- package/lib/types/modes/markdown.d.ts +12 -0
- package/lib/types/modes/markdown.d.ts.map +1 -0
- package/lib/types/modes/markdown.js +148 -0
- package/lib/types/modes/markdown.js.map +1 -0
- package/lib/types/modes/shared.d.ts +183 -0
- package/lib/types/modes/shared.d.ts.map +1 -0
- package/lib/types/modes/shared.js +358 -0
- package/lib/types/modes/shared.js.map +1 -0
- package/lib/types/request.d.ts +63 -0
- package/lib/types/request.d.ts.map +1 -0
- package/lib/types/request.js +182 -0
- package/lib/types/request.js.map +1 -0
- package/lib/types/send.d.ts +38 -0
- package/lib/types/send.d.ts.map +1 -0
- package/lib/types/send.js +128 -0
- package/lib/types/send.js.map +1 -0
- package/lib/types/token.d.ts +32 -0
- package/lib/types/token.d.ts.map +1 -0
- package/lib/types/token.js +62 -0
- package/lib/types/token.js.map +1 -0
- package/lib/types/transport/stream.d.ts +89 -0
- package/lib/types/transport/stream.d.ts.map +1 -0
- package/lib/types/transport/stream.js +345 -0
- package/lib/types/transport/stream.js.map +1 -0
- package/lib/types/transport/webhook.d.ts +54 -0
- package/lib/types/transport/webhook.d.ts.map +1 -0
- package/lib/types/transport/webhook.js +159 -0
- package/lib/types/transport/webhook.js.map +1 -0
- package/lib/types/types/index.d.ts +150 -0
- package/lib/types/types/index.d.ts.map +1 -0
- package/lib/types/types/index.js +43 -0
- package/lib/types/types/index.js.map +1 -0
- package/package.json +61 -3
- package/src/api/.eslintrc.yml +2 -0
- package/src/api/alitrip.ts +467 -0
- package/src/api/attendance.ts +81 -0
- package/src/api/badge.ts +285 -0
- package/src/api/blackboard.ts +28 -0
- package/src/api/calendar.ts +817 -0
- package/src/api/card.ts +215 -0
- package/src/api/conference.ts +561 -0
- package/src/api/connector.ts +97 -0
- package/src/api/contact.ts +56 -0
- package/src/api/convFile.ts +166 -0
- package/src/api/crm.ts +830 -0
- package/src/api/customerService.ts +156 -0
- package/src/api/datacenter.ts +672 -0
- package/src/api/devicemng.ts +202 -0
- package/src/api/diot.ts +19 -0
- package/src/api/doc.ts +232 -0
- package/src/api/drive.ts +109 -0
- package/src/api/edu.ts +30 -0
- package/src/api/esign.ts +44 -0
- package/src/api/exclusive.ts +372 -0
- package/src/api/h3yun.ts +537 -0
- package/src/api/hrm.ts +272 -0
- package/src/api/im.ts +978 -0
- package/src/api/industry.ts +153 -0
- package/src/api/jzcrm.ts +304 -0
- package/src/api/link.ts +94 -0
- package/src/api/live.ts +162 -0
- package/src/api/microApp.ts +309 -0
- package/src/api/oapi.ts +4083 -0
- package/src/api/oauth2.ts +146 -0
- package/src/api/pedia.ts +222 -0
- package/src/api/project.ts +1519 -0
- package/src/api/resident.ts +133 -0
- package/src/api/robot.ts +326 -0
- package/src/api/rooms.ts +334 -0
- package/src/api/serviceGroup.ts +216 -0
- package/src/api/storage.ts +1701 -0
- package/src/api/swform.ts +94 -0
- package/src/api/todo.ts +220 -0
- package/src/api/wiki.ts +231 -0
- package/src/api/workbench.ts +73 -0
- package/src/api/yida.ts +2165 -0
- package/src/bot.ts +211 -0
- package/src/config.ts +88 -0
- package/src/decode.ts +250 -0
- package/src/errors.ts +282 -0
- package/src/index.ts +82 -0
- package/src/internal.ts +60 -0
- package/src/media.ts +149 -0
- package/src/modes/markdown.ts +173 -0
- package/src/modes/shared.ts +473 -0
- package/src/request.ts +262 -0
- package/src/send.ts +195 -0
- package/src/token.ts +72 -0
- package/src/transport/stream.ts +436 -0
- package/src/transport/webhook.ts +198 -0
- package/src/types/index.ts +165 -0
- package/README.md +0 -3
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream Mode transport (`protocol: 'ws'`).
|
|
3
|
+
*
|
|
4
|
+
* The adapter registers a fresh connection before every dial: the platform's ticket is single-use and expires within 90
|
|
5
|
+
* seconds, so it can never be cached. The loop dials again forever — `ws.retryTimes` is a fast-retry budget, not a
|
|
6
|
+
* give-up count — and only a credential refusal stops it.
|
|
7
|
+
*
|
|
8
|
+
* A callback frame is acknowledged only after `bot.receive` accepted the message (`Bot.receive` waits for the intake
|
|
9
|
+
* listeners), so an acknowledgement always means the message is stored. Robot messages are fire-and-forget: the platform
|
|
10
|
+
* does not redeliver an acknowledged frame.
|
|
11
|
+
*/
|
|
12
|
+
import { Status } from '@deepseek-ai/cordis-plugin-im-core';
|
|
13
|
+
import { decodeMessage } from "../decode.js";
|
|
14
|
+
import { isAuthRefusal, isCredentialRefusal } from "../errors.js";
|
|
15
|
+
import { invoke } from "../request.js";
|
|
16
|
+
/** The one topic this adapter subscribes to. */
|
|
17
|
+
export const CALLBACK_TOPIC = '/v1.0/im/bot/messages/get';
|
|
18
|
+
/** System topics the protocol defines. */
|
|
19
|
+
const PING_TOPIC = 'ping';
|
|
20
|
+
const DISCONNECT_TOPIC = 'disconnect';
|
|
21
|
+
/**
|
|
22
|
+
* The `ua` of the connection registration (`name-sdk-lang/version`). Keep the version in step with `package.json`.
|
|
23
|
+
*/
|
|
24
|
+
export const CLIENT_USER_AGENT = 'dsh-im-more/dingtalk/0.1.0';
|
|
25
|
+
/** Waitable sleep that resolves early on abort. */
|
|
26
|
+
function sleep(ms, signal) {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
if (signal.aborted) {
|
|
29
|
+
resolve();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const timer = setTimeout(() => {
|
|
33
|
+
signal.removeEventListener('abort', onAbort);
|
|
34
|
+
resolve();
|
|
35
|
+
}, ms);
|
|
36
|
+
const onAbort = () => {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
resolve();
|
|
39
|
+
};
|
|
40
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** Message of any caught value, for a log line. */
|
|
44
|
+
function messageOf(error) {
|
|
45
|
+
return error instanceof Error ? error.message : String(error);
|
|
46
|
+
}
|
|
47
|
+
/** The Stream Mode client of one bot. */
|
|
48
|
+
export class DingtalkStream {
|
|
49
|
+
bot;
|
|
50
|
+
controller;
|
|
51
|
+
running;
|
|
52
|
+
socket;
|
|
53
|
+
/** Set by a `disconnect` frame: the redial follows at once instead of waiting out the retry interval. */
|
|
54
|
+
redialImmediately = false;
|
|
55
|
+
constructor(bot) {
|
|
56
|
+
this.bot = bot;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Start the reconnect loop.
|
|
60
|
+
*
|
|
61
|
+
* Returning before the first dial is deliberate: `Bot.start` awaits `connect()`, and waiting here would hold plugin
|
|
62
|
+
* initialization for as long as the platform is unreachable.
|
|
63
|
+
*/
|
|
64
|
+
async start() {
|
|
65
|
+
this.controller = new AbortController();
|
|
66
|
+
this.running = this.loop(this.controller.signal);
|
|
67
|
+
}
|
|
68
|
+
/** Stop the loop and wait for it to unwind. */
|
|
69
|
+
async stop() {
|
|
70
|
+
this.controller?.abort();
|
|
71
|
+
this.controller = undefined;
|
|
72
|
+
this.closeSocket();
|
|
73
|
+
await this.running?.catch(() => undefined);
|
|
74
|
+
this.running = undefined;
|
|
75
|
+
}
|
|
76
|
+
async loop(signal) {
|
|
77
|
+
let failures = 0;
|
|
78
|
+
let authFailures = 0;
|
|
79
|
+
while (!signal.aborted) {
|
|
80
|
+
try {
|
|
81
|
+
const url = await this.openUrl(signal);
|
|
82
|
+
const socket = await this.dial(url, signal);
|
|
83
|
+
this.socket = socket;
|
|
84
|
+
this.bot.online();
|
|
85
|
+
failures = 0;
|
|
86
|
+
authFailures = 0;
|
|
87
|
+
await this.accept(socket, signal);
|
|
88
|
+
this.socket = undefined;
|
|
89
|
+
if (signal.aborted)
|
|
90
|
+
return;
|
|
91
|
+
this.bot.ctx.logger.warn('dingtalk: the Stream Mode connection closed; reconnecting');
|
|
92
|
+
this.bot.status = Status.RECONNECT;
|
|
93
|
+
if (this.redialImmediately) {
|
|
94
|
+
this.redialImmediately = false;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
await sleep(this.intervalOf(failures), signal);
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (signal.aborted)
|
|
101
|
+
return;
|
|
102
|
+
if (isCredentialRefusal(error)) {
|
|
103
|
+
// A rejected client id or secret cannot be fixed by reconnecting: report it and stop until the profile is
|
|
104
|
+
// edited.
|
|
105
|
+
this.bot.ctx.logger.error('dingtalk: %s', messageOf(error));
|
|
106
|
+
this.bot.offline(error);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
authFailures = isAuthRefusal(error) ? authFailures + 1 : 0;
|
|
110
|
+
failures += 1;
|
|
111
|
+
this.bot.ctx.logger.warn('dingtalk: %s; reconnecting', messageOf(error));
|
|
112
|
+
this.bot.status = Status.RECONNECT;
|
|
113
|
+
if (authFailures >= this.bot.config.ws.retryTimes) {
|
|
114
|
+
this.bot.ctx.logger.error('dingtalk: %s consecutive authentication refusals; check appkey and secret, then restart the bot', String(authFailures));
|
|
115
|
+
this.bot.offline(error);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
await sleep(this.intervalOf(failures), signal);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/** Delay before the next dial: the fast interval while the failure budget lasts, the lazy one after it. */
|
|
123
|
+
intervalOf(failures) {
|
|
124
|
+
const { ws } = this.bot.config;
|
|
125
|
+
return failures < ws.retryTimes ? ws.retryInterval : ws.retryLazy;
|
|
126
|
+
}
|
|
127
|
+
/** Register one connection and give back the socket URL its single-use ticket belongs to. */
|
|
128
|
+
async openUrl(signal) {
|
|
129
|
+
const answer = await invoke(this.bot, 'api', 'POST', '/v1.0/gateway/connections/open', {
|
|
130
|
+
data: {
|
|
131
|
+
clientId: this.bot.config.appkey,
|
|
132
|
+
clientSecret: this.bot.config.secret,
|
|
133
|
+
subscriptions: [{ type: 'CALLBACK', topic: CALLBACK_TOPIC }],
|
|
134
|
+
ua: CLIENT_USER_AGENT,
|
|
135
|
+
},
|
|
136
|
+
signal,
|
|
137
|
+
});
|
|
138
|
+
if (!answer.endpoint || !answer.ticket) {
|
|
139
|
+
throw new Error('dingtalk: gateway/connections/open answered without an endpoint and ticket');
|
|
140
|
+
}
|
|
141
|
+
return `${answer.endpoint}?ticket=${encodeURIComponent(answer.ticket)}`;
|
|
142
|
+
}
|
|
143
|
+
/** Dial the connection URL and resolve once the socket is open. */
|
|
144
|
+
dial(url, signal) {
|
|
145
|
+
const socket = this.bot.ctx.http.ws(url);
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const cleanup = () => {
|
|
148
|
+
socket.removeEventListener('open', onOpen);
|
|
149
|
+
socket.removeEventListener('error', onError);
|
|
150
|
+
socket.removeEventListener('close', onClose);
|
|
151
|
+
signal.removeEventListener('abort', onAbort);
|
|
152
|
+
};
|
|
153
|
+
const onOpen = () => {
|
|
154
|
+
cleanup();
|
|
155
|
+
resolve(socket);
|
|
156
|
+
};
|
|
157
|
+
const onError = (event) => {
|
|
158
|
+
cleanup();
|
|
159
|
+
reject(new Error(`dingtalk: WebSocket error${event.message === undefined ? '' : `: ${event.message}`}`));
|
|
160
|
+
};
|
|
161
|
+
const onClose = (event) => {
|
|
162
|
+
cleanup();
|
|
163
|
+
reject(new Error(`dingtalk: WebSocket closed before opening (code ${String(event.code)})`));
|
|
164
|
+
};
|
|
165
|
+
const onAbort = () => {
|
|
166
|
+
cleanup();
|
|
167
|
+
reject(signal.reason ?? new Error('dingtalk: adapter stopped'));
|
|
168
|
+
};
|
|
169
|
+
if (signal.aborted) {
|
|
170
|
+
onAbort();
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
socket.addEventListener('open', onOpen);
|
|
174
|
+
socket.addEventListener('error', onError);
|
|
175
|
+
socket.addEventListener('close', onClose);
|
|
176
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
/** Serve one open connection until it closes. */
|
|
180
|
+
async accept(socket, signal) {
|
|
181
|
+
const closed = new Promise((resolve) => {
|
|
182
|
+
socket.addEventListener('close', () => {
|
|
183
|
+
resolve();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
socket.addEventListener('message', (event) => {
|
|
187
|
+
this.handleFrame(socket, String(event.data));
|
|
188
|
+
});
|
|
189
|
+
const onAbort = () => {
|
|
190
|
+
this.closeSocket();
|
|
191
|
+
};
|
|
192
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
193
|
+
try {
|
|
194
|
+
await closed;
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
signal.removeEventListener('abort', onAbort);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/** Dispatch one received frame: a system notice, a callback, or a topic this adapter does not subscribe to. */
|
|
201
|
+
handleFrame(socket, text) {
|
|
202
|
+
let frame;
|
|
203
|
+
try {
|
|
204
|
+
frame = JSON.parse(text);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
this.bot.ctx.logger.warn('dingtalk: cannot parse a Stream frame: %s', messageOf(error));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
if (typeof frame !== 'object' || frame === null)
|
|
211
|
+
return;
|
|
212
|
+
const topic = frame.headers?.topic;
|
|
213
|
+
if (frame.type === 'SYSTEM' && topic === PING_TOPIC) {
|
|
214
|
+
this.acknowledge(socket, frame, {
|
|
215
|
+
code: 200,
|
|
216
|
+
message: 'OK',
|
|
217
|
+
data: opaqueEcho(frame.data),
|
|
218
|
+
});
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (frame.type === 'SYSTEM' && topic === DISCONNECT_TOPIC) {
|
|
222
|
+
// The platform closes the TCP connection ten seconds after this notice; closing now trades that window for one
|
|
223
|
+
// handshake.
|
|
224
|
+
this.bot.ctx.logger.info('dingtalk: the platform announced the connection expiry; redialing');
|
|
225
|
+
this.redialImmediately = true;
|
|
226
|
+
this.closeSocket();
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (frame.type === 'SYSTEM') {
|
|
230
|
+
// `CONNECTED`/`REGISTERED`-style notices need no answer; the set of topics is not documented.
|
|
231
|
+
this.bot.ctx.logger.debug('dingtalk: ignored a system frame of topic "%s"', topic ?? 'unknown');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (frame.type === 'CALLBACK' && topic === CALLBACK_TOPIC) {
|
|
235
|
+
void this.deliver(socket, frame);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
this.bot.ctx.logger.debug('dingtalk: ignored a frame of type "%s" and topic "%s"', frame.type ?? 'unknown', topic ?? 'unknown');
|
|
239
|
+
this.acknowledge(socket, frame, {
|
|
240
|
+
code: 404,
|
|
241
|
+
message: 'topic not supported',
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Hand one callback frame to intake, then acknowledge it.
|
|
246
|
+
*
|
|
247
|
+
* The acknowledgement goes out after `receive` resolved: the host stores a message before `receive` returns, so an
|
|
248
|
+
* acknowledged frame is a stored message. A failed intake is only logged, because no acknowledgement means the
|
|
249
|
+
* platform will not redeliver anyway (robot messages are fire-and-forget).
|
|
250
|
+
*/
|
|
251
|
+
async deliver(socket, frame) {
|
|
252
|
+
let body;
|
|
253
|
+
try {
|
|
254
|
+
body = JSON.parse(frame.data ?? '');
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
this.bot.ctx.logger.error('dingtalk: cannot parse a callback body: %s', messageOf(error));
|
|
258
|
+
this.acknowledge(socket, frame, { code: 500, message: 'internal error' });
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
let session;
|
|
262
|
+
try {
|
|
263
|
+
session = decodeMessage(this.bot, body);
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
this.bot.ctx.logger.error('dingtalk: cannot decode a callback: %s', messageOf(error));
|
|
267
|
+
this.acknowledge(socket, frame, { code: 500, message: 'internal error' });
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (session === undefined) {
|
|
271
|
+
// A quota failure or an unsupported msgtype: the frame was handled, there is just nothing to store.
|
|
272
|
+
this.acknowledge(socket, frame, {
|
|
273
|
+
code: 200,
|
|
274
|
+
message: 'OK',
|
|
275
|
+
data: '{"response":null}',
|
|
276
|
+
});
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
await this.bot.receive(session);
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
this.bot.ctx.logger.error('dingtalk: intake failed: %s', messageOf(error));
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
this.acknowledge(socket, frame, {
|
|
287
|
+
code: 200,
|
|
288
|
+
message: 'OK',
|
|
289
|
+
data: '{"response":null}',
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/** Send one acknowledgement; a socket that already closed cannot carry it, which is only logged. */
|
|
293
|
+
acknowledge(socket, frame, body) {
|
|
294
|
+
const ack = {
|
|
295
|
+
code: body.code,
|
|
296
|
+
headers: {
|
|
297
|
+
...(frame.headers?.messageId === undefined
|
|
298
|
+
? {}
|
|
299
|
+
: { messageId: frame.headers.messageId }),
|
|
300
|
+
contentType: 'application/json',
|
|
301
|
+
},
|
|
302
|
+
message: body.message,
|
|
303
|
+
...(body.data === undefined ? {} : { data: body.data }),
|
|
304
|
+
};
|
|
305
|
+
try {
|
|
306
|
+
socket.send(JSON.stringify(ack));
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
this.bot.ctx.logger.warn('dingtalk: could not acknowledge a frame: %s', messageOf(error));
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
closeSocket() {
|
|
313
|
+
const socket = this.socket;
|
|
314
|
+
this.socket = undefined;
|
|
315
|
+
try {
|
|
316
|
+
socket?.close(1000, 'adapter stopped');
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
// The socket is already closed or closing; nothing left to release.
|
|
320
|
+
error;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The acknowledgement body of a `ping`: the frame's `opaque` value echoed back.
|
|
326
|
+
*
|
|
327
|
+
* @param data - the frame's JSON-string `data`, expected to carry `opaque`.
|
|
328
|
+
* @returns a JSON string carrying the same `opaque`, or the original string when it cannot be read.
|
|
329
|
+
*/
|
|
330
|
+
function opaqueEcho(data) {
|
|
331
|
+
if (data === undefined)
|
|
332
|
+
return '{"opaque":null}';
|
|
333
|
+
try {
|
|
334
|
+
const parsed = JSON.parse(data);
|
|
335
|
+
if (typeof parsed === 'object' && parsed !== null && 'opaque' in parsed) {
|
|
336
|
+
return JSON.stringify({ opaque: parsed.opaque });
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
catch (error) {
|
|
340
|
+
// Not JSON: the frame cannot be echoed structurally; the raw string is the closest answer.
|
|
341
|
+
error;
|
|
342
|
+
}
|
|
343
|
+
return data;
|
|
344
|
+
}
|
|
345
|
+
//# sourceMappingURL=stream.js.map
|
|
@@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C;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,2FAA2F;QAC3F,KAAK,CAAA;IACP,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP callback transport (`protocol: 'http'`).
|
|
3
|
+
*
|
|
4
|
+
* The platform posts bot messages to a URL configured in the developer console; the adapter registers that path on the
|
|
5
|
+
* profile's `webServer` and verifies the request with the platform's own `secret`
|
|
6
|
+
* (`Base64(HMAC-SHA256(key = secret, message = timestamp + "\n" + secret))`).
|
|
7
|
+
*
|
|
8
|
+
* The handler answers `200` once the message is stored and `500` when intake failed, so a retrying platform can resend;
|
|
9
|
+
* every refusal is answered before any work is done.
|
|
10
|
+
*/
|
|
11
|
+
import type { DingtalkBot } from '../bot.ts';
|
|
12
|
+
/** How far a request's `timestamp` may be from now; the platform documents an hour. */
|
|
13
|
+
export declare const TIMESTAMP_WINDOW_MS: number;
|
|
14
|
+
/**
|
|
15
|
+
* The `sign` header value of one request.
|
|
16
|
+
*
|
|
17
|
+
* @param secret - the application Client Secret.
|
|
18
|
+
* @param timestamp - the request's `timestamp` header.
|
|
19
|
+
* @returns the base64 HMAC-SHA256 of `timestamp + "\n" + secret`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function signOf(secret: string, timestamp: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Compare two signatures without leaking where they differ.
|
|
24
|
+
*
|
|
25
|
+
* @param expected - the signature computed from the headers.
|
|
26
|
+
* @param received - the signature the request carried.
|
|
27
|
+
* @returns whether they are equal.
|
|
28
|
+
*/
|
|
29
|
+
export declare function matchesSign(expected: string, received: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The HTTP callback transport.
|
|
32
|
+
*
|
|
33
|
+
* The route is anonymous at the Web server layer and authenticated by the platform's signature, so a profile without
|
|
34
|
+
* `webServer` fails loudly instead of silently receiving nothing.
|
|
35
|
+
*/
|
|
36
|
+
export declare class DingtalkWebhook {
|
|
37
|
+
private readonly bot;
|
|
38
|
+
private dispose;
|
|
39
|
+
constructor(bot: DingtalkBot);
|
|
40
|
+
/** Register the route over the profile's `webServer`. */
|
|
41
|
+
start(): Promise<void>;
|
|
42
|
+
/** Release the route. */
|
|
43
|
+
stop(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Log a fatal start failure before the caller throws it, because `Bot.start` only stores a connect failure on
|
|
46
|
+
* `bot.error`.
|
|
47
|
+
*
|
|
48
|
+
* @param message - error text that also names the corrective action.
|
|
49
|
+
* @returns the error for the caller to throw.
|
|
50
|
+
*/
|
|
51
|
+
private failStart;
|
|
52
|
+
private handle;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../../src/transport/webhook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAkB5C,uFAAuF;AACvF,eAAO,MAAM,mBAAmB,QAAkB,CAAA;AAElD;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAIhE;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKvE;AAkCD;;;;;GAKG;AACH,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,OAAO,CAA0B;gBAEZ,GAAG,EAAE,WAAW;IAE7C,yDAAyD;IACnD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAmB5B,yBAAyB;IACnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;YAKH,MAAM;CAuDrB"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP callback transport (`protocol: 'http'`).
|
|
3
|
+
*
|
|
4
|
+
* The platform posts bot messages to a URL configured in the developer console; the adapter registers that path on the
|
|
5
|
+
* profile's `webServer` and verifies the request with the platform's own `secret`
|
|
6
|
+
* (`Base64(HMAC-SHA256(key = secret, message = timestamp + "\n" + secret))`).
|
|
7
|
+
*
|
|
8
|
+
* The handler answers `200` once the message is stored and `500` when intake failed, so a retrying platform can resend;
|
|
9
|
+
* every refusal is answered before any work is done.
|
|
10
|
+
*/
|
|
11
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
12
|
+
import { routePath } from "../config.js";
|
|
13
|
+
import { decodeMessage } from "../decode.js";
|
|
14
|
+
/** How far a request's `timestamp` may be from now; the platform documents an hour. */
|
|
15
|
+
export const TIMESTAMP_WINDOW_MS = 60 * 60 * 1_000;
|
|
16
|
+
/**
|
|
17
|
+
* The `sign` header value of one request.
|
|
18
|
+
*
|
|
19
|
+
* @param secret - the application Client Secret.
|
|
20
|
+
* @param timestamp - the request's `timestamp` header.
|
|
21
|
+
* @returns the base64 HMAC-SHA256 of `timestamp + "\n" + secret`.
|
|
22
|
+
*/
|
|
23
|
+
export function signOf(secret, timestamp) {
|
|
24
|
+
return createHmac('sha256', secret)
|
|
25
|
+
.update(`${timestamp}\n${secret}`)
|
|
26
|
+
.digest('base64');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compare two signatures without leaking where they differ.
|
|
30
|
+
*
|
|
31
|
+
* @param expected - the signature computed from the headers.
|
|
32
|
+
* @param received - the signature the request carried.
|
|
33
|
+
* @returns whether they are equal.
|
|
34
|
+
*/
|
|
35
|
+
export function matchesSign(expected, received) {
|
|
36
|
+
const left = Buffer.from(expected, 'utf8');
|
|
37
|
+
const right = Buffer.from(received, 'utf8');
|
|
38
|
+
if (left.length !== right.length)
|
|
39
|
+
return false;
|
|
40
|
+
return timingSafeEqual(left, right);
|
|
41
|
+
}
|
|
42
|
+
/** One header of an inbound request, when it arrived exactly once. */
|
|
43
|
+
function headerOf(request, name) {
|
|
44
|
+
const value = request.headers[name];
|
|
45
|
+
return typeof value === 'string' ? value : undefined;
|
|
46
|
+
}
|
|
47
|
+
/** Read a request body to its end. The adapter imposes no size limit of its own. */
|
|
48
|
+
async function readBody(request) {
|
|
49
|
+
const chunks = [];
|
|
50
|
+
for await (const chunk of request) {
|
|
51
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
52
|
+
}
|
|
53
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
54
|
+
}
|
|
55
|
+
/** Write one bodiless answer. */
|
|
56
|
+
function writeStatus(response, status, headers = {}) {
|
|
57
|
+
response.writeHead(status, headers);
|
|
58
|
+
response.end();
|
|
59
|
+
}
|
|
60
|
+
/** Message of any caught value, for a log line. */
|
|
61
|
+
function messageOf(error) {
|
|
62
|
+
return error instanceof Error ? error.message : String(error);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The HTTP callback transport.
|
|
66
|
+
*
|
|
67
|
+
* The route is anonymous at the Web server layer and authenticated by the platform's signature, so a profile without
|
|
68
|
+
* `webServer` fails loudly instead of silently receiving nothing.
|
|
69
|
+
*/
|
|
70
|
+
export class DingtalkWebhook {
|
|
71
|
+
bot;
|
|
72
|
+
dispose;
|
|
73
|
+
constructor(bot) {
|
|
74
|
+
this.bot = bot;
|
|
75
|
+
}
|
|
76
|
+
/** Register the route over the profile's `webServer`. */
|
|
77
|
+
async start() {
|
|
78
|
+
const webServer = this.bot.ctx.get('webServer');
|
|
79
|
+
if (webServer === undefined) {
|
|
80
|
+
throw this.failStart('dingtalk: protocol "http" needs a profile-provided webServer; use protocol "ws" instead');
|
|
81
|
+
}
|
|
82
|
+
// A profile that cannot mint a token cannot answer a callback either, so the failure surfaces at start rather than
|
|
83
|
+
// on the first incoming message.
|
|
84
|
+
await this.bot.tokens.get();
|
|
85
|
+
this.dispose = webServer.register({
|
|
86
|
+
kind: 'exact',
|
|
87
|
+
path: routePath(this.bot.config.path),
|
|
88
|
+
auth: 'anonymous',
|
|
89
|
+
handler: (request, response) => this.handle(request, response),
|
|
90
|
+
});
|
|
91
|
+
this.bot.online();
|
|
92
|
+
}
|
|
93
|
+
/** Release the route. */
|
|
94
|
+
async stop() {
|
|
95
|
+
this.dispose?.();
|
|
96
|
+
this.dispose = undefined;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Log a fatal start failure before the caller throws it, because `Bot.start` only stores a connect failure on
|
|
100
|
+
* `bot.error`.
|
|
101
|
+
*
|
|
102
|
+
* @param message - error text that also names the corrective action.
|
|
103
|
+
* @returns the error for the caller to throw.
|
|
104
|
+
*/
|
|
105
|
+
failStart(message) {
|
|
106
|
+
this.bot.ctx.logger.error(message);
|
|
107
|
+
return new Error(message);
|
|
108
|
+
}
|
|
109
|
+
async handle(request, response) {
|
|
110
|
+
try {
|
|
111
|
+
if (request.method !== 'POST') {
|
|
112
|
+
writeStatus(response, 405, { allow: 'POST' });
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const timestamp = headerOf(request, 'timestamp');
|
|
116
|
+
const sign = headerOf(request, 'sign');
|
|
117
|
+
if (timestamp === undefined || sign === undefined) {
|
|
118
|
+
writeStatus(response, 401);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const sentAt = Number(timestamp);
|
|
122
|
+
if (!Number.isFinite(sentAt) ||
|
|
123
|
+
Math.abs(Date.now() - sentAt) > TIMESTAMP_WINDOW_MS) {
|
|
124
|
+
writeStatus(response, 401);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const body = await readBody(request);
|
|
128
|
+
let parsed;
|
|
129
|
+
try {
|
|
130
|
+
parsed = JSON.parse(body);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
this.bot.ctx.logger.warn('dingtalk: cannot parse a callback request: %s', messageOf(error));
|
|
134
|
+
writeStatus(response, 400);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
138
|
+
writeStatus(response, 400);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!matchesSign(signOf(this.bot.config.secret, timestamp), sign)) {
|
|
142
|
+
writeStatus(response, 401);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const session = decodeMessage(this.bot, parsed);
|
|
146
|
+
if (session !== undefined)
|
|
147
|
+
await this.bot.receive(session);
|
|
148
|
+
writeStatus(response, 200);
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
this.bot.ctx.logger.warn('dingtalk: HTTP callback delivery failed: %s', messageOf(error));
|
|
152
|
+
if (!response.headersSent)
|
|
153
|
+
writeStatus(response, 500);
|
|
154
|
+
else
|
|
155
|
+
response.end();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../../src/transport/webhook.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAGzD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAgB5C,uFAAuF;AACvF,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAA;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CAAC,MAAc,EAAE,SAAiB;IACtD,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC;SAChC,MAAM,CAAC,GAAG,SAAS,KAAK,MAAM,EAAE,CAAC;SACjC,MAAM,CAAC,QAAQ,CAAC,CAAA;AACrB,CAAC;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