ylib-wecom-openclaw-plugin 2026.4.29
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/README.md +596 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +99 -0
- package/dist/src/accounts.d.ts +57 -0
- package/dist/src/accounts.js +247 -0
- package/dist/src/agent/api-client.d.ts +95 -0
- package/dist/src/agent/api-client.js +425 -0
- package/dist/src/agent/handler.d.ts +64 -0
- package/dist/src/agent/handler.js +731 -0
- package/dist/src/agent/index.d.ts +5 -0
- package/dist/src/agent/index.js +21 -0
- package/dist/src/agent/webhook.d.ts +25 -0
- package/dist/src/agent/webhook.js +294 -0
- package/dist/src/agent/xml.d.ts +21 -0
- package/dist/src/agent/xml.js +43 -0
- package/dist/src/channel.d.ts +5 -0
- package/dist/src/channel.js +815 -0
- package/dist/src/chat-queue.d.ts +31 -0
- package/dist/src/chat-queue.js +53 -0
- package/dist/src/config-schema.d.ts +587 -0
- package/dist/src/config-schema.js +146 -0
- package/dist/src/const.d.ts +128 -0
- package/dist/src/const.js +168 -0
- package/dist/src/dm-policy.d.ts +29 -0
- package/dist/src/dm-policy.js +146 -0
- package/dist/src/dynamic-agent.d.ts +37 -0
- package/dist/src/dynamic-agent.js +67 -0
- package/dist/src/dynamic-routing.d.ts +65 -0
- package/dist/src/dynamic-routing.js +62 -0
- package/dist/src/endpoint-dispatch.d.ts +54 -0
- package/dist/src/endpoint-dispatch.js +967 -0
- package/dist/src/endpoint-event-adapter.d.ts +15 -0
- package/dist/src/endpoint-event-adapter.js +427 -0
- package/dist/src/group-policy.d.ts +30 -0
- package/dist/src/group-policy.js +126 -0
- package/dist/src/http.d.ts +27 -0
- package/dist/src/http.js +168 -0
- package/dist/src/im-runtime-telemetry.d.ts +25 -0
- package/dist/src/im-runtime-telemetry.js +68 -0
- package/dist/src/interface.d.ts +192 -0
- package/dist/src/interface.js +5 -0
- package/dist/src/markdown-chunk.d.ts +1 -0
- package/dist/src/markdown-chunk.js +396 -0
- package/dist/src/mcp/index.d.ts +6 -0
- package/dist/src/mcp/index.js +28 -0
- package/dist/src/mcp/interceptors/biz-error.d.ts +11 -0
- package/dist/src/mcp/interceptors/biz-error.js +73 -0
- package/dist/src/mcp/interceptors/doc-auth-error.d.ts +10 -0
- package/dist/src/mcp/interceptors/doc-auth-error.js +235 -0
- package/dist/src/mcp/interceptors/index.d.ts +35 -0
- package/dist/src/mcp/interceptors/index.js +143 -0
- package/dist/src/mcp/interceptors/msg-media.d.ts +11 -0
- package/dist/src/mcp/interceptors/msg-media.js +201 -0
- package/dist/src/mcp/interceptors/smartpage-create.d.ts +30 -0
- package/dist/src/mcp/interceptors/smartpage-create.js +252 -0
- package/dist/src/mcp/interceptors/smartpage-export.d.ts +17 -0
- package/dist/src/mcp/interceptors/smartpage-export.js +135 -0
- package/dist/src/mcp/interceptors/smartsheet-upload.d.ts +22 -0
- package/dist/src/mcp/interceptors/smartsheet-upload.js +388 -0
- package/dist/src/mcp/interceptors/types.d.ts +64 -0
- package/dist/src/mcp/interceptors/types.js +8 -0
- package/dist/src/mcp/schema.d.ts +11 -0
- package/dist/src/mcp/schema.js +115 -0
- package/dist/src/mcp/tool.d.ts +63 -0
- package/dist/src/mcp/tool.js +318 -0
- package/dist/src/mcp/transport.d.ts +94 -0
- package/dist/src/mcp/transport.js +702 -0
- package/dist/src/media-handler.d.ts +55 -0
- package/dist/src/media-handler.js +306 -0
- package/dist/src/media-uploader.d.ts +142 -0
- package/dist/src/media-uploader.js +446 -0
- package/dist/src/message-parser.d.ts +104 -0
- package/dist/src/message-parser.js +232 -0
- package/dist/src/message-sender.d.ts +54 -0
- package/dist/src/message-sender.js +210 -0
- package/dist/src/monitor.d.ts +69 -0
- package/dist/src/monitor.js +1846 -0
- package/dist/src/onboarding.d.ts +8 -0
- package/dist/src/onboarding.js +248 -0
- package/dist/src/openclaw-compat.d.ts +148 -0
- package/dist/src/openclaw-compat.js +839 -0
- package/dist/src/proactive-markdown-send.d.ts +14 -0
- package/dist/src/proactive-markdown-send.js +205 -0
- package/dist/src/reqid-store.d.ts +23 -0
- package/dist/src/reqid-store.js +136 -0
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/runtime.js +7 -0
- package/dist/src/shared/command-auth.d.ts +23 -0
- package/dist/src/shared/command-auth.js +112 -0
- package/dist/src/shared/xml-parser.d.ts +46 -0
- package/dist/src/shared/xml-parser.js +228 -0
- package/dist/src/state-dir-resolve.d.ts +2 -0
- package/dist/src/state-dir-resolve.js +33 -0
- package/dist/src/state-manager.d.ts +115 -0
- package/dist/src/state-manager.js +413 -0
- package/dist/src/target.d.ts +35 -0
- package/dist/src/target.js +71 -0
- package/dist/src/template-card-manager.d.ts +55 -0
- package/dist/src/template-card-manager.js +316 -0
- package/dist/src/template-card-parser.d.ts +37 -0
- package/dist/src/template-card-parser.js +672 -0
- package/dist/src/timeout.d.ts +20 -0
- package/dist/src/timeout.js +57 -0
- package/dist/src/types/account.d.ts +29 -0
- package/dist/src/types/account.js +5 -0
- package/dist/src/types/config.d.ts +98 -0
- package/dist/src/types/config.js +8 -0
- package/dist/src/types/constants.d.ts +42 -0
- package/dist/src/types/constants.js +45 -0
- package/dist/src/types/index.d.ts +7 -0
- package/dist/src/types/index.js +17 -0
- package/dist/src/types/message.d.ts +238 -0
- package/dist/src/types/message.js +6 -0
- package/dist/src/utils.d.ts +148 -0
- package/dist/src/utils.js +92 -0
- package/dist/src/version.d.ts +2 -0
- package/dist/src/version.js +28 -0
- package/dist/src/webhook/command-auth.d.ts +47 -0
- package/dist/src/webhook/command-auth.js +137 -0
- package/dist/src/webhook/gateway.d.ts +36 -0
- package/dist/src/webhook/gateway.js +297 -0
- package/dist/src/webhook/handler.d.ts +19 -0
- package/dist/src/webhook/handler.js +481 -0
- package/dist/src/webhook/helpers.d.ts +157 -0
- package/dist/src/webhook/helpers.js +936 -0
- package/dist/src/webhook/http.d.ts +27 -0
- package/dist/src/webhook/http.js +168 -0
- package/dist/src/webhook/index.d.ts +11 -0
- package/dist/src/webhook/index.js +43 -0
- package/dist/src/webhook/media.d.ts +30 -0
- package/dist/src/webhook/media.js +152 -0
- package/dist/src/webhook/monitor.d.ts +59 -0
- package/dist/src/webhook/monitor.js +1672 -0
- package/dist/src/webhook/state.d.ts +220 -0
- package/dist/src/webhook/state.js +568 -0
- package/dist/src/webhook/target.d.ts +41 -0
- package/dist/src/webhook/target.js +165 -0
- package/dist/src/webhook/types.d.ts +348 -0
- package/dist/src/webhook/types.js +36 -0
- package/dist/src/webhook/video-frame.d.ts +13 -0
- package/dist/src/webhook/video-frame.js +108 -0
- package/openclaw.plugin.json +19 -0
- package/package.json +96 -0
- package/schema.json +534 -0
- package/scripts/generate-schema.mjs +33 -0
- package/skills/wecom-contact/SKILL.md +162 -0
- package/skills/wecom-doc/SKILL.md +162 -0
- package/skills/wecom-doc/references/create-doc.md +56 -0
- package/skills/wecom-doc/references/edit-doc-content.md +68 -0
- package/skills/wecom-doc/references/get-doc-content.md +88 -0
- package/skills/wecom-doc/references/smartpage-create.md +125 -0
- package/skills/wecom-doc/references/smartpage-export.md +160 -0
- package/skills/wecom-meeting/SKILL.md +441 -0
- package/skills/wecom-meeting/references/example-full.md +30 -0
- package/skills/wecom-meeting/references/example-reminder.md +46 -0
- package/skills/wecom-meeting/references/example-security.md +22 -0
- package/skills/wecom-meeting/references/response-get-meeting-info.md +148 -0
- package/skills/wecom-msg/SKILL.md +157 -0
- package/skills/wecom-msg/references/api-get-messages.md +93 -0
- package/skills/wecom-msg/references/api-get-msg-chat-list.md +58 -0
- package/skills/wecom-msg/references/api-get-msg-media.md +44 -0
- package/skills/wecom-msg/references/api-send-message.md +39 -0
- package/skills/wecom-preflight/SKILL.md +141 -0
- package/skills/wecom-schedule/SKILL.md +161 -0
- package/skills/wecom-schedule/references/api-check-availability.md +56 -0
- package/skills/wecom-schedule/references/api-create-schedule.md +38 -0
- package/skills/wecom-schedule/references/api-get-schedule-detail.md +81 -0
- package/skills/wecom-schedule/references/api-update-schedule.md +32 -0
- package/skills/wecom-schedule/references/ref-reminders.md +24 -0
- package/skills/wecom-send-media/SKILL.md +68 -0
- package/skills/wecom-send-template-card/SKILL.md +157 -0
- package/skills/wecom-send-template-card/references/api-template-card-types.md +358 -0
- package/skills/wecom-smartsheet/SKILL.md +164 -0
- package/skills/wecom-smartsheet/references/smartsheet-cell-value-formats.md +163 -0
- package/skills/wecom-smartsheet/references/smartsheet-field-types.md +44 -0
- package/skills/wecom-smartsheet/references/smartsheet-get-records.md +96 -0
- package/skills/wecom-smartsheet/references/webhook-examples.md +185 -0
- package/skills/wecom-smartsheet/references/webhook-fallback.md +184 -0
- package/skills/wecom-todo/SKILL.md +392 -0
- package/skills/wecom-todo/examples/workflows.md +163 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { WSClient } from "@wecom/aibot-node-sdk";
|
|
2
|
+
import type { RuntimeEnv } from "ylib-openclaw/plugin-sdk";
|
|
3
|
+
export declare function sendWeComMarkdownMessageChunks(params: {
|
|
4
|
+
wsClient: WSClient;
|
|
5
|
+
chatId: string;
|
|
6
|
+
text: string;
|
|
7
|
+
runtime?: RuntimeEnv;
|
|
8
|
+
accountId?: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
messageId: string;
|
|
13
|
+
chunkCount: number;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.sendWeComMarkdownMessageChunks = void 0;
|
|
40
|
+
var const_js_1 = require("./const.js");
|
|
41
|
+
var im_runtime_telemetry_js_1 = require("./im-runtime-telemetry.js");
|
|
42
|
+
var markdown_chunk_js_1 = require("./markdown-chunk.js");
|
|
43
|
+
var timeout_js_1 = require("./timeout.js");
|
|
44
|
+
var IS_TEST_ENV = process.env.VITEST === "true" || process.env.NODE_ENV === "test";
|
|
45
|
+
var INTER_CHUNK_DELAY_MIN_MS = IS_TEST_ENV ? 0 : 200;
|
|
46
|
+
var INTER_CHUNK_DELAY_MAX_MS = IS_TEST_ENV ? 0 : 500;
|
|
47
|
+
var RATE_LIMIT_BACKOFF_MS = IS_TEST_ENV ? [0, 0, 0] : [500, 1000, 2000];
|
|
48
|
+
function sleep(ms) {
|
|
49
|
+
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
|
|
50
|
+
}
|
|
51
|
+
function randomIntInclusive(min, max) {
|
|
52
|
+
if (max <= min)
|
|
53
|
+
return min;
|
|
54
|
+
return min + Math.floor(Math.random() * (max - min + 1));
|
|
55
|
+
}
|
|
56
|
+
function maybeDelayBetweenChunks() {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
+
var ms;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
if (INTER_CHUNK_DELAY_MAX_MS <= 0)
|
|
63
|
+
return [2 /*return*/];
|
|
64
|
+
ms = randomIntInclusive(INTER_CHUNK_DELAY_MIN_MS, INTER_CHUNK_DELAY_MAX_MS);
|
|
65
|
+
if (!(ms > 0)) return [3 /*break*/, 2];
|
|
66
|
+
return [4 /*yield*/, sleep(ms)];
|
|
67
|
+
case 1:
|
|
68
|
+
_a.sent();
|
|
69
|
+
_a.label = 2;
|
|
70
|
+
case 2: return [2 /*return*/];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function isRateLimitedError(err) {
|
|
76
|
+
var raw = err instanceof Error
|
|
77
|
+
? err.name + " " + err.message
|
|
78
|
+
: typeof err === "object" && err
|
|
79
|
+
? JSON.stringify(err)
|
|
80
|
+
: String(err);
|
|
81
|
+
var msg = raw.toLowerCase();
|
|
82
|
+
return (msg.includes("429") ||
|
|
83
|
+
msg.includes("rate limit") ||
|
|
84
|
+
msg.includes("too many") ||
|
|
85
|
+
msg.includes("freq out of limit") ||
|
|
86
|
+
msg.includes("ret=-19") ||
|
|
87
|
+
msg.includes("errcode=-19") ||
|
|
88
|
+
msg.includes("errcode 45009") ||
|
|
89
|
+
msg.includes("errcode=45009"));
|
|
90
|
+
}
|
|
91
|
+
function buildChunks(text) {
|
|
92
|
+
var chunks = markdown_chunk_js_1.splitMarkdownIntoSafeChunks(text, const_js_1.TEXT_CHUNK_LIMIT);
|
|
93
|
+
return chunks.length > 0 ? chunks : [""];
|
|
94
|
+
}
|
|
95
|
+
function sendWeComMarkdownMessageChunks(params) {
|
|
96
|
+
var _a, _b, _c, _d, _e, _f;
|
|
97
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
98
|
+
var wsClient, chatId, runtime, accountId, label, timeoutMs, chunks, lastReqId, _loop_1, i;
|
|
99
|
+
var _this = this;
|
|
100
|
+
return __generator(this, function (_g) {
|
|
101
|
+
switch (_g.label) {
|
|
102
|
+
case 0:
|
|
103
|
+
wsClient = params.wsClient, chatId = params.chatId, runtime = params.runtime, accountId = params.accountId;
|
|
104
|
+
label = params.label || "sendWeComMarkdownMessageChunks";
|
|
105
|
+
timeoutMs = (_a = params.timeoutMs) !== null && _a !== void 0 ? _a : const_js_1.REPLY_SEND_TIMEOUT_MS;
|
|
106
|
+
chunks = buildChunks(params.text || "当前没有可展示的回复内容");
|
|
107
|
+
lastReqId = "wecom-" + Date.now();
|
|
108
|
+
_loop_1 = function (i) {
|
|
109
|
+
var chunk, sendOnce, err_1, retried, retryIndex, delayMs, retryErr_1;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0:
|
|
113
|
+
chunk = (_b = chunks[i]) !== null && _b !== void 0 ? _b : "";
|
|
114
|
+
sendOnce = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
115
|
+
var result;
|
|
116
|
+
var _a, _b;
|
|
117
|
+
return __generator(this, function (_c) {
|
|
118
|
+
switch (_c.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, timeout_js_1.withTimeout(wsClient.sendMessage(chatId, {
|
|
120
|
+
msgtype: "markdown",
|
|
121
|
+
markdown: { content: chunk }
|
|
122
|
+
}), timeoutMs, label + " timed out chunk=" + (i + 1) + "/" + chunks.length)];
|
|
123
|
+
case 1:
|
|
124
|
+
result = _c.sent();
|
|
125
|
+
lastReqId = (_b = (_a = result === null || result === void 0 ? void 0 : result.headers) === null || _a === void 0 ? void 0 : _a.req_id) !== null && _b !== void 0 ? _b : lastReqId;
|
|
126
|
+
return [2 /*return*/];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}); };
|
|
130
|
+
_a.label = 1;
|
|
131
|
+
case 1:
|
|
132
|
+
_a.trys.push([1, 3, , 11]);
|
|
133
|
+
return [4 /*yield*/, sendOnce()];
|
|
134
|
+
case 2:
|
|
135
|
+
_a.sent();
|
|
136
|
+
return [3 /*break*/, 11];
|
|
137
|
+
case 3:
|
|
138
|
+
err_1 = _a.sent();
|
|
139
|
+
if (!isRateLimitedError(err_1)) {
|
|
140
|
+
(_c = runtime === null || runtime === void 0 ? void 0 : runtime.error) === null || _c === void 0 ? void 0 : _c.call(runtime, "[wecom] " + label + ": failed chatId=" + chatId + " chunk=" + (i + 1) + "/" + chunks.length + " err=" + String(err_1));
|
|
141
|
+
throw err_1;
|
|
142
|
+
}
|
|
143
|
+
retried = false;
|
|
144
|
+
retryIndex = 0;
|
|
145
|
+
_a.label = 4;
|
|
146
|
+
case 4:
|
|
147
|
+
if (!(retryIndex < RATE_LIMIT_BACKOFF_MS.length)) return [3 /*break*/, 10];
|
|
148
|
+
delayMs = (_d = RATE_LIMIT_BACKOFF_MS[retryIndex]) !== null && _d !== void 0 ? _d : 0;
|
|
149
|
+
(_e = runtime === null || runtime === void 0 ? void 0 : runtime.log) === null || _e === void 0 ? void 0 : _e.call(runtime, "[wecom] " + label + ": rate limited, retry=" + (retryIndex + 1) + "/" + RATE_LIMIT_BACKOFF_MS.length + " chatId=" + chatId + " delay=" + delayMs + "ms");
|
|
150
|
+
if (!(delayMs > 0)) return [3 /*break*/, 6];
|
|
151
|
+
return [4 /*yield*/, sleep(delayMs)];
|
|
152
|
+
case 5:
|
|
153
|
+
_a.sent();
|
|
154
|
+
_a.label = 6;
|
|
155
|
+
case 6:
|
|
156
|
+
_a.trys.push([6, 8, , 9]);
|
|
157
|
+
return [4 /*yield*/, sendOnce()];
|
|
158
|
+
case 7:
|
|
159
|
+
_a.sent();
|
|
160
|
+
retried = true;
|
|
161
|
+
return [3 /*break*/, 10];
|
|
162
|
+
case 8:
|
|
163
|
+
retryErr_1 = _a.sent();
|
|
164
|
+
if (!isRateLimitedError(retryErr_1)) {
|
|
165
|
+
(_f = runtime === null || runtime === void 0 ? void 0 : runtime.error) === null || _f === void 0 ? void 0 : _f.call(runtime, "[wecom] " + label + ": retry failed chatId=" + chatId + " chunk=" + (i + 1) + "/" + chunks.length + " err=" + String(retryErr_1));
|
|
166
|
+
throw retryErr_1;
|
|
167
|
+
}
|
|
168
|
+
return [3 /*break*/, 9];
|
|
169
|
+
case 9:
|
|
170
|
+
retryIndex++;
|
|
171
|
+
return [3 /*break*/, 4];
|
|
172
|
+
case 10:
|
|
173
|
+
if (!retried)
|
|
174
|
+
throw err_1;
|
|
175
|
+
return [3 /*break*/, 11];
|
|
176
|
+
case 11:
|
|
177
|
+
if (accountId) {
|
|
178
|
+
im_runtime_telemetry_js_1.imRuntimeRecordChannelActivity("wecom", accountId, "outbound");
|
|
179
|
+
}
|
|
180
|
+
if (!(i < chunks.length - 1)) return [3 /*break*/, 13];
|
|
181
|
+
return [4 /*yield*/, maybeDelayBetweenChunks()];
|
|
182
|
+
case 12:
|
|
183
|
+
_a.sent();
|
|
184
|
+
_a.label = 13;
|
|
185
|
+
case 13: return [2 /*return*/];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
i = 0;
|
|
190
|
+
_g.label = 1;
|
|
191
|
+
case 1:
|
|
192
|
+
if (!(i < chunks.length)) return [3 /*break*/, 4];
|
|
193
|
+
return [5 /*yield**/, _loop_1(i)];
|
|
194
|
+
case 2:
|
|
195
|
+
_g.sent();
|
|
196
|
+
_g.label = 3;
|
|
197
|
+
case 3:
|
|
198
|
+
i++;
|
|
199
|
+
return [3 /*break*/, 1];
|
|
200
|
+
case 4: return [2 /*return*/, { messageId: lastReqId, chunkCount: chunks.length }];
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
exports.sendWeComMarkdownMessageChunks = sendWeComMarkdownMessageChunks;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Store 配置 */
|
|
2
|
+
interface ReqIdStoreOptions {
|
|
3
|
+
/** TTL 毫秒数,超时的 reqId 视为过期(默认 7 天) */
|
|
4
|
+
ttlMs?: number;
|
|
5
|
+
/** 内存最大条目数(默认 200) */
|
|
6
|
+
memoryMaxSize?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface PersistentReqIdStore {
|
|
9
|
+
/** 设置 chatId 对应的 reqId(仅写入内存) */
|
|
10
|
+
set(chatId: string, reqId: string): void;
|
|
11
|
+
/** 获取 chatId 对应的 reqId(仅内存) */
|
|
12
|
+
get(chatId: string): Promise<string | undefined>;
|
|
13
|
+
/** 同步获取 chatId 对应的 reqId(仅内存) */
|
|
14
|
+
getSync(chatId: string): string | undefined;
|
|
15
|
+
/** 删除 chatId 对应的 reqId */
|
|
16
|
+
delete(chatId: string): void;
|
|
17
|
+
/** 清空内存缓存 */
|
|
18
|
+
clearMemory(): void;
|
|
19
|
+
/** 返回内存中的条目数 */
|
|
20
|
+
memorySize(): number;
|
|
21
|
+
}
|
|
22
|
+
export declare function createPersistentReqIdStore(accountId: string, options?: ReqIdStoreOptions): PersistentReqIdStore;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================================
|
|
3
|
+
// 类型定义
|
|
4
|
+
// ============================================================================
|
|
5
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
6
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
7
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
8
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
9
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
10
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
15
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
16
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
17
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
18
|
+
function step(op) {
|
|
19
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
20
|
+
while (_) try {
|
|
21
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
22
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
23
|
+
switch (op[0]) {
|
|
24
|
+
case 0: case 1: t = op; break;
|
|
25
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
26
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
27
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
28
|
+
default:
|
|
29
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
30
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
31
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
32
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
33
|
+
if (t[2]) _.ops.pop();
|
|
34
|
+
_.trys.pop(); continue;
|
|
35
|
+
}
|
|
36
|
+
op = body.call(thisArg, _);
|
|
37
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
38
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
42
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
43
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
44
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
45
|
+
r[k] = a[j];
|
|
46
|
+
return r;
|
|
47
|
+
};
|
|
48
|
+
exports.__esModule = true;
|
|
49
|
+
exports.createPersistentReqIdStore = void 0;
|
|
50
|
+
// ============================================================================
|
|
51
|
+
// 常量
|
|
52
|
+
// ============================================================================
|
|
53
|
+
var DEFAULT_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 天
|
|
54
|
+
var DEFAULT_MEMORY_MAX_SIZE = 200;
|
|
55
|
+
// ============================================================================
|
|
56
|
+
// 核心实现
|
|
57
|
+
// ============================================================================
|
|
58
|
+
function createPersistentReqIdStore(accountId, options) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
var ttlMs = (_a = options === null || options === void 0 ? void 0 : options.ttlMs) !== null && _a !== void 0 ? _a : DEFAULT_TTL_MS;
|
|
61
|
+
var memoryMaxSize = (_b = options === null || options === void 0 ? void 0 : options.memoryMaxSize) !== null && _b !== void 0 ? _b : DEFAULT_MEMORY_MAX_SIZE;
|
|
62
|
+
// 内存层:chatId → ReqIdEntry
|
|
63
|
+
var memory = new Map();
|
|
64
|
+
// ========== 内部辅助函数 ==========
|
|
65
|
+
/** 检查条目是否过期 */
|
|
66
|
+
function isExpired(entry, now) {
|
|
67
|
+
return ttlMs > 0 && now - entry.ts >= ttlMs;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 内存容量控制:淘汰最旧的条目。
|
|
71
|
+
* 利用 Map 的插入顺序 + touch(先 delete 再 set) 实现类 LRU 效果。
|
|
72
|
+
*/
|
|
73
|
+
function pruneMemory() {
|
|
74
|
+
if (memory.size <= memoryMaxSize)
|
|
75
|
+
return;
|
|
76
|
+
var sorted = __spreadArrays(memory.entries()).sort(function (a, b) { return a[1].ts - b[1].ts; });
|
|
77
|
+
var toRemove = sorted.slice(0, memory.size - memoryMaxSize);
|
|
78
|
+
for (var _i = 0, toRemove_1 = toRemove; _i < toRemove_1.length; _i++) {
|
|
79
|
+
var key = toRemove_1[_i][0];
|
|
80
|
+
memory["delete"](key);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// ========== 公开 API ==========
|
|
84
|
+
function set(chatId, reqId) {
|
|
85
|
+
var entry = { reqId: reqId, ts: Date.now() };
|
|
86
|
+
// touch:先删再设,保持 Map 插入顺序(类 LRU)
|
|
87
|
+
memory["delete"](chatId);
|
|
88
|
+
memory.set(chatId, entry);
|
|
89
|
+
pruneMemory();
|
|
90
|
+
}
|
|
91
|
+
function get(chatId) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
93
|
+
var now, memEntry;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
now = Date.now();
|
|
96
|
+
memEntry = memory.get(chatId);
|
|
97
|
+
if (memEntry && !isExpired(memEntry, now)) {
|
|
98
|
+
return [2 /*return*/, memEntry.reqId];
|
|
99
|
+
}
|
|
100
|
+
if (memEntry) {
|
|
101
|
+
memory["delete"](chatId); // 过期则删除
|
|
102
|
+
}
|
|
103
|
+
return [2 /*return*/, undefined];
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function getSync(chatId) {
|
|
108
|
+
var now = Date.now();
|
|
109
|
+
var entry = memory.get(chatId);
|
|
110
|
+
if (entry && !isExpired(entry, now)) {
|
|
111
|
+
return entry.reqId;
|
|
112
|
+
}
|
|
113
|
+
if (entry) {
|
|
114
|
+
memory["delete"](chatId);
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
function del(chatId) {
|
|
119
|
+
memory["delete"](chatId);
|
|
120
|
+
}
|
|
121
|
+
function clearMemory() {
|
|
122
|
+
memory.clear();
|
|
123
|
+
}
|
|
124
|
+
function memorySize() {
|
|
125
|
+
return memory.size;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
set: set,
|
|
129
|
+
get: get,
|
|
130
|
+
getSync: getSync,
|
|
131
|
+
"delete": del,
|
|
132
|
+
clearMemory: clearMemory,
|
|
133
|
+
memorySize: memorySize
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
exports.createPersistentReqIdStore = createPersistentReqIdStore;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
exports.__esModule = true;
|
|
3
|
+
exports.getWeComRuntime = exports.setWeComRuntime = void 0;
|
|
4
|
+
var plugin_sdk_1 = require("ylib-openclaw/plugin-sdk");
|
|
5
|
+
var _a = plugin_sdk_1.createPluginRuntimeStore("WeCom runtime not initialized"), setWeComRuntime = _a.setRuntime, getWeComRuntime = _a.getRuntime;
|
|
6
|
+
exports.setWeComRuntime = setWeComRuntime;
|
|
7
|
+
exports.getWeComRuntime = getWeComRuntime;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { OpenClawConfig, PluginRuntime } from "ylib-openclaw/plugin-sdk";
|
|
2
|
+
import type { WecomAgentConfig, WecomBotConfig } from "../types/index.js";
|
|
3
|
+
declare type WecomCommandAuthAccountConfig = Pick<WecomBotConfig, "dmPolicy" | "allowFrom"> | Pick<WecomAgentConfig, "dmPolicy" | "allowFrom">;
|
|
4
|
+
export declare function resolveWecomCommandAuthorization(params: {
|
|
5
|
+
core: PluginRuntime;
|
|
6
|
+
cfg: OpenClawConfig;
|
|
7
|
+
accountConfig: WecomCommandAuthAccountConfig;
|
|
8
|
+
rawBody: string;
|
|
9
|
+
senderUserId: string;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
shouldComputeAuth: boolean;
|
|
12
|
+
dmPolicy: "pairing" | "allowlist" | "open" | "disabled";
|
|
13
|
+
senderAllowed: boolean;
|
|
14
|
+
authorizerConfigured: boolean;
|
|
15
|
+
commandAuthorized: boolean | undefined;
|
|
16
|
+
effectiveAllowFrom: string[];
|
|
17
|
+
}>;
|
|
18
|
+
export declare function buildWecomUnauthorizedCommandPrompt(params: {
|
|
19
|
+
senderUserId: string;
|
|
20
|
+
dmPolicy: "pairing" | "allowlist" | "open" | "disabled";
|
|
21
|
+
scope: "bot" | "agent";
|
|
22
|
+
}): string;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.__esModule = true;
|
|
39
|
+
exports.buildWecomUnauthorizedCommandPrompt = exports.resolveWecomCommandAuthorization = void 0;
|
|
40
|
+
function normalizeWecomAllowFromEntry(raw) {
|
|
41
|
+
return raw
|
|
42
|
+
.trim()
|
|
43
|
+
.toLowerCase()
|
|
44
|
+
.replace(/^wecom:/, "")
|
|
45
|
+
.replace(/^user:/, "")
|
|
46
|
+
.replace(/^userid:/, "");
|
|
47
|
+
}
|
|
48
|
+
function isWecomSenderAllowed(senderUserId, allowFrom) {
|
|
49
|
+
var list = allowFrom.map(function (entry) { return normalizeWecomAllowFromEntry(entry); }).filter(Boolean);
|
|
50
|
+
if (list.includes("*"))
|
|
51
|
+
return true;
|
|
52
|
+
var normalizedSender = normalizeWecomAllowFromEntry(senderUserId);
|
|
53
|
+
if (!normalizedSender)
|
|
54
|
+
return false;
|
|
55
|
+
return list.includes(normalizedSender);
|
|
56
|
+
}
|
|
57
|
+
function resolveWecomCommandAuthorization(params) {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var core, cfg, accountConfig, rawBody, senderUserId, dmPolicy, configAllowFrom, shouldComputeAuth, effectiveAllowFrom, senderAllowed, allowAllConfigured, authorizerConfigured, useAccessGroups, commandAuthorized;
|
|
61
|
+
return __generator(this, function (_d) {
|
|
62
|
+
core = params.core, cfg = params.cfg, accountConfig = params.accountConfig, rawBody = params.rawBody, senderUserId = params.senderUserId;
|
|
63
|
+
dmPolicy = ((_a = accountConfig.dmPolicy) !== null && _a !== void 0 ? _a : "pairing");
|
|
64
|
+
configAllowFrom = ((_b = accountConfig.allowFrom) !== null && _b !== void 0 ? _b : []).map(function (v) { return String(v); });
|
|
65
|
+
shouldComputeAuth = core.channel.commands.shouldComputeCommandAuthorized(rawBody, cfg);
|
|
66
|
+
effectiveAllowFrom = dmPolicy === "open" ? ["*"] : configAllowFrom;
|
|
67
|
+
senderAllowed = isWecomSenderAllowed(senderUserId, effectiveAllowFrom);
|
|
68
|
+
allowAllConfigured = effectiveAllowFrom.some(function (entry) { return normalizeWecomAllowFromEntry(entry) === "*"; });
|
|
69
|
+
authorizerConfigured = allowAllConfigured || effectiveAllowFrom.length > 0;
|
|
70
|
+
useAccessGroups = ((_c = cfg.commands) === null || _c === void 0 ? void 0 : _c.useAccessGroups) !== false;
|
|
71
|
+
commandAuthorized = shouldComputeAuth
|
|
72
|
+
? core.channel.commands.resolveCommandAuthorizedFromAuthorizers({
|
|
73
|
+
useAccessGroups: useAccessGroups,
|
|
74
|
+
authorizers: [{ configured: authorizerConfigured, allowed: senderAllowed }]
|
|
75
|
+
})
|
|
76
|
+
: undefined;
|
|
77
|
+
return [2 /*return*/, {
|
|
78
|
+
shouldComputeAuth: shouldComputeAuth,
|
|
79
|
+
dmPolicy: dmPolicy,
|
|
80
|
+
senderAllowed: senderAllowed,
|
|
81
|
+
authorizerConfigured: authorizerConfigured,
|
|
82
|
+
commandAuthorized: commandAuthorized,
|
|
83
|
+
effectiveAllowFrom: effectiveAllowFrom
|
|
84
|
+
}];
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
exports.resolveWecomCommandAuthorization = resolveWecomCommandAuthorization;
|
|
89
|
+
function buildWecomUnauthorizedCommandPrompt(params) {
|
|
90
|
+
var user = params.senderUserId || "unknown";
|
|
91
|
+
var policy = params.dmPolicy;
|
|
92
|
+
var scopeLabel = params.scope === "bot" ? "Bot(智能机器人)" : "Agent(自建应用)";
|
|
93
|
+
var dmPrefix = params.scope === "bot" ? "channels.wecom.bot" : "channels.wecom.agent";
|
|
94
|
+
var allowCmd = function (value) { return "openclaw config set " + dmPrefix + ".allowFrom '" + value + "'"; };
|
|
95
|
+
var policyCmd = function (value) { return "openclaw config set " + dmPrefix + ".dmPolicy \"" + value + "\""; };
|
|
96
|
+
if (policy === "disabled") {
|
|
97
|
+
return [
|
|
98
|
+
"\u65E0\u6743\u9650\u6267\u884C\u547D\u4EE4\uFF08" + scopeLabel + " \u5DF2\u7981\u7528\uFF1AdmPolicy=disabled\uFF09",
|
|
99
|
+
"\u89E6\u53D1\u8005\uFF1A" + user,
|
|
100
|
+
"\u7BA1\u7406\u5458\uFF1A" + policyCmd("open") + "\uFF08\u5168\u653E\u5F00\uFF09\u6216 " + policyCmd("allowlist") + "\uFF08\u767D\u540D\u5355\uFF09",
|
|
101
|
+
].join("\n");
|
|
102
|
+
}
|
|
103
|
+
// WeCom 不支持 pairing CLI,因此这里统一给出“open / allowlist”两种明确的配置指令
|
|
104
|
+
return [
|
|
105
|
+
"\u65E0\u6743\u9650\u6267\u884C\u547D\u4EE4\uFF08\u5165\u53E3\uFF1A" + scopeLabel + "\uFF0Cuserid\uFF1A" + user + "\uFF09",
|
|
106
|
+
"\u7BA1\u7406\u5458\u5168\u653E\u5F00\uFF1A" + policyCmd("open"),
|
|
107
|
+
"\u7BA1\u7406\u5458\u653E\u884C\u8BE5\u7528\u6237\uFF1A" + policyCmd("allowlist"),
|
|
108
|
+
"\u7136\u540E\u8BBE\u7F6E\u767D\u540D\u5355\uFF1A" + allowCmd(JSON.stringify([user])),
|
|
109
|
+
"\u5982\u679C\u4ECD\u88AB\u62E6\u622A\uFF1A\u68C0\u67E5 commands.useAccessGroups/\u8BBF\u95EE\u7EC4",
|
|
110
|
+
].join("\n");
|
|
111
|
+
}
|
|
112
|
+
exports.buildWecomUnauthorizedCommandPrompt = buildWecomUnauthorizedCommandPrompt;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WeCom XML 解析器
|
|
3
|
+
* 用于 Agent 模式解析 XML 格式消息
|
|
4
|
+
*/
|
|
5
|
+
import type { WecomAgentInboundMessage } from "../types/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* 解析 XML 字符串为消息对象
|
|
8
|
+
*/
|
|
9
|
+
export declare function parseXml(xml: string): WecomAgentInboundMessage;
|
|
10
|
+
/**
|
|
11
|
+
* 从 XML 中提取消息类型
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractMsgType(msg: WecomAgentInboundMessage): string;
|
|
14
|
+
/**
|
|
15
|
+
* 从 XML 中提取发送者 ID
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractFromUser(msg: WecomAgentInboundMessage): string;
|
|
18
|
+
/**
|
|
19
|
+
* 从 XML 中提取文件名(主要用于 file 消息)
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractFileName(msg: WecomAgentInboundMessage): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* 从 XML 中提取接收者 ID (CorpID)
|
|
24
|
+
*/
|
|
25
|
+
export declare function extractToUser(msg: WecomAgentInboundMessage): string;
|
|
26
|
+
/**
|
|
27
|
+
* 从 XML 中提取群聊 ID
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractChatId(msg: WecomAgentInboundMessage): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* 从 XML 中提取 AgentID(兼容 AgentID/agentid 等大小写)
|
|
32
|
+
*/
|
|
33
|
+
export declare function extractAgentId(msg: WecomAgentInboundMessage): string | number | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* 从 XML 中提取消息内容
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractContent(msg: WecomAgentInboundMessage): string;
|
|
38
|
+
/**
|
|
39
|
+
* 从 XML 中提取媒体 ID (Image, Voice, Video)
|
|
40
|
+
* 根据官方文档,MediaId 在 Agent 回调中直接位于根节点
|
|
41
|
+
*/
|
|
42
|
+
export declare function extractMediaId(msg: WecomAgentInboundMessage): string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* 从 XML 中提取 MsgId(用于去重)
|
|
45
|
+
*/
|
|
46
|
+
export declare function extractMsgId(msg: WecomAgentInboundMessage): string | undefined;
|