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,815 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
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;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
50
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
51
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
52
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
53
|
+
r[k] = a[j];
|
|
54
|
+
return r;
|
|
55
|
+
};
|
|
56
|
+
exports.__esModule = true;
|
|
57
|
+
exports.wecomPlugin = void 0;
|
|
58
|
+
var openclaw_compat_js_1 = require("./openclaw-compat.js");
|
|
59
|
+
var openclaw_compat_js_2 = require("./openclaw-compat.js");
|
|
60
|
+
var runtime_js_1 = require("./runtime.js");
|
|
61
|
+
var monitor_js_1 = require("./monitor.js");
|
|
62
|
+
var state_manager_js_1 = require("./state-manager.js");
|
|
63
|
+
var onboarding_js_1 = require("./onboarding.js");
|
|
64
|
+
var accounts_js_1 = require("./accounts.js");
|
|
65
|
+
var const_js_1 = require("./const.js");
|
|
66
|
+
var media_uploader_js_1 = require("./media-uploader.js");
|
|
67
|
+
var webhook_js_1 = require("./agent/webhook.js");
|
|
68
|
+
var target_js_1 = require("./target.js");
|
|
69
|
+
var api_client_js_1 = require("./agent/api-client.js");
|
|
70
|
+
var index_js_1 = require("./webhook/index.js");
|
|
71
|
+
var im_runtime_telemetry_js_1 = require("./im-runtime-telemetry.js");
|
|
72
|
+
var markdown_chunk_js_1 = require("./markdown-chunk.js");
|
|
73
|
+
var proactive_markdown_send_js_1 = require("./proactive-markdown-send.js");
|
|
74
|
+
var WECOM_PROBE_CACHE_TTL_MS_DEFAULT = 10 * 60 * 1000;
|
|
75
|
+
var WECOM_PROBE_CACHE_TTL_MS = Math.max(0, Number(process.env.WECOM_PROBE_CACHE_TTL_MS ||
|
|
76
|
+
String(WECOM_PROBE_CACHE_TTL_MS_DEFAULT)) || WECOM_PROBE_CACHE_TTL_MS_DEFAULT);
|
|
77
|
+
var wecomProbeCacheByAccountId = new Map();
|
|
78
|
+
function parseRuntimeBoolFlag(value) {
|
|
79
|
+
var normalized = String(value !== null && value !== void 0 ? value : "")
|
|
80
|
+
.trim()
|
|
81
|
+
.toLowerCase();
|
|
82
|
+
return (normalized === "1" ||
|
|
83
|
+
normalized === "true" ||
|
|
84
|
+
normalized === "yes" ||
|
|
85
|
+
normalized === "on");
|
|
86
|
+
}
|
|
87
|
+
function clearWeComProbeCache(accountId) {
|
|
88
|
+
var normalized = String(accountId || "").trim();
|
|
89
|
+
if (!normalized) {
|
|
90
|
+
wecomProbeCacheByAccountId.clear();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
wecomProbeCacheByAccountId["delete"](normalized);
|
|
94
|
+
}
|
|
95
|
+
function readWeComProbeCache(accountId, forceProbe) {
|
|
96
|
+
var _a;
|
|
97
|
+
if (forceProbe || WECOM_PROBE_CACHE_TTL_MS <= 0)
|
|
98
|
+
return null;
|
|
99
|
+
var normalized = String(accountId || "").trim();
|
|
100
|
+
if (!normalized)
|
|
101
|
+
return null;
|
|
102
|
+
var cache = wecomProbeCacheByAccountId.get(normalized);
|
|
103
|
+
if (!cache)
|
|
104
|
+
return null;
|
|
105
|
+
if (Date.now() - cache.updatedAtMs > WECOM_PROBE_CACHE_TTL_MS) {
|
|
106
|
+
wecomProbeCacheByAccountId["delete"](normalized);
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return __assign(__assign({}, cache.result), { details: __assign(__assign({}, ((_a = cache.result.details) !== null && _a !== void 0 ? _a : {})), { cached: true, cacheUpdatedAtMs: cache.updatedAtMs }) });
|
|
110
|
+
}
|
|
111
|
+
function writeWeComProbeCache(accountId, result) {
|
|
112
|
+
var _a;
|
|
113
|
+
if (WECOM_PROBE_CACHE_TTL_MS <= 0)
|
|
114
|
+
return;
|
|
115
|
+
var normalized = String(accountId || "").trim();
|
|
116
|
+
if (!normalized)
|
|
117
|
+
return;
|
|
118
|
+
wecomProbeCacheByAccountId.set(normalized, {
|
|
119
|
+
result: __assign(__assign({}, result), { details: __assign(__assign({}, ((_a = result.details) !== null && _a !== void 0 ? _a : {})), { cached: false }) }),
|
|
120
|
+
updatedAtMs: Date.now()
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 使用 SDK 的 sendMessage 主动发送企业微信消息
|
|
125
|
+
* 优先 Bot WebSocket,不可用时自动回退到 Agent HTTP API
|
|
126
|
+
*/
|
|
127
|
+
function sendWeComMessage(_a) {
|
|
128
|
+
var to = _a.to, content = _a.content, accountId = _a.accountId, cfg = _a.cfg;
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
var resolvedAccountId, channelPrefix, chatId, wsClient, result, messageId, account, agent, target, outboundChunks, _i, outboundChunks_1, chunk;
|
|
131
|
+
return __generator(this, function (_b) {
|
|
132
|
+
switch (_b.label) {
|
|
133
|
+
case 0:
|
|
134
|
+
resolvedAccountId = accountId !== null && accountId !== void 0 ? accountId : openclaw_compat_js_2.DEFAULT_ACCOUNT_ID;
|
|
135
|
+
channelPrefix = new RegExp("^" + const_js_1.CHANNEL_ID + ":", "i");
|
|
136
|
+
chatId = to.replace(channelPrefix, "");
|
|
137
|
+
wsClient = state_manager_js_1.getWeComWebSocket(resolvedAccountId);
|
|
138
|
+
if (!(wsClient === null || wsClient === void 0 ? void 0 : wsClient.isConnected)) return [3 /*break*/, 2];
|
|
139
|
+
return [4 /*yield*/, proactive_markdown_send_js_1.sendWeComMarkdownMessageChunks({
|
|
140
|
+
wsClient: wsClient,
|
|
141
|
+
chatId: chatId,
|
|
142
|
+
text: content,
|
|
143
|
+
accountId: resolvedAccountId,
|
|
144
|
+
label: "sendWeComMessage"
|
|
145
|
+
})];
|
|
146
|
+
case 1:
|
|
147
|
+
result = _b.sent();
|
|
148
|
+
messageId = result.messageId;
|
|
149
|
+
return [2 /*return*/, { channel: const_js_1.CHANNEL_ID, messageId: messageId, chatId: chatId }];
|
|
150
|
+
case 2:
|
|
151
|
+
// ── 回退到 Agent HTTP API ──
|
|
152
|
+
if (!cfg) {
|
|
153
|
+
throw new Error("WSClient not connected for account " + resolvedAccountId + " and no config available for Agent fallback");
|
|
154
|
+
}
|
|
155
|
+
account = accounts_js_1.resolveWeComAccountMulti({ cfg: cfg, accountId: resolvedAccountId });
|
|
156
|
+
agent = account.agent;
|
|
157
|
+
if (!(agent === null || agent === void 0 ? void 0 : agent.configured)) {
|
|
158
|
+
throw new Error("WSClient not connected for account " + resolvedAccountId + " and Agent mode is not configured. " +
|
|
159
|
+
"Please configure either Bot (botId + secret) or Agent (corpId + corpSecret + agentId) for this account.");
|
|
160
|
+
}
|
|
161
|
+
target = target_js_1.resolveWecomTarget(chatId);
|
|
162
|
+
if (!target) {
|
|
163
|
+
throw new Error("Cannot resolve outbound target from \"" + to + "\"");
|
|
164
|
+
}
|
|
165
|
+
console.log("[wecom-outbound] Bot WS unavailable, sending via Agent HTTP API to " + JSON.stringify(target) + " (accountId=" + resolvedAccountId + ")");
|
|
166
|
+
outboundChunks = markdown_chunk_js_1.splitMarkdownIntoSafeChunks(content || "当前没有可展示的回复内容", const_js_1.TEXT_CHUNK_LIMIT);
|
|
167
|
+
_i = 0, outboundChunks_1 = outboundChunks;
|
|
168
|
+
_b.label = 3;
|
|
169
|
+
case 3:
|
|
170
|
+
if (!(_i < outboundChunks_1.length)) return [3 /*break*/, 6];
|
|
171
|
+
chunk = outboundChunks_1[_i];
|
|
172
|
+
return [4 /*yield*/, api_client_js_1.sendText({
|
|
173
|
+
agent: agent,
|
|
174
|
+
toUser: target.touser,
|
|
175
|
+
toParty: target.toparty,
|
|
176
|
+
toTag: target.totag,
|
|
177
|
+
chatId: target.chatid,
|
|
178
|
+
text: chunk
|
|
179
|
+
})];
|
|
180
|
+
case 4:
|
|
181
|
+
_b.sent();
|
|
182
|
+
im_runtime_telemetry_js_1.imRuntimeRecordChannelActivity("wecom", resolvedAccountId, "outbound");
|
|
183
|
+
_b.label = 5;
|
|
184
|
+
case 5:
|
|
185
|
+
_i++;
|
|
186
|
+
return [3 /*break*/, 3];
|
|
187
|
+
case 6: return [2 /*return*/, {
|
|
188
|
+
channel: const_js_1.CHANNEL_ID,
|
|
189
|
+
messageId: "agent-" + Date.now(),
|
|
190
|
+
chatId: chatId
|
|
191
|
+
}];
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// 企业微信频道元数据
|
|
197
|
+
var meta = {
|
|
198
|
+
id: const_js_1.CHANNEL_ID,
|
|
199
|
+
label: "企业微信",
|
|
200
|
+
selectionLabel: "企业微信 (WeCom)",
|
|
201
|
+
detailLabel: "企业微信智能机器人",
|
|
202
|
+
docsPath: "/channels/" + const_js_1.CHANNEL_ID,
|
|
203
|
+
docsLabel: const_js_1.CHANNEL_ID,
|
|
204
|
+
blurb: "企业微信智能机器人接入插件",
|
|
205
|
+
systemImage: "message.fill"
|
|
206
|
+
};
|
|
207
|
+
exports.wecomPlugin = {
|
|
208
|
+
id: const_js_1.CHANNEL_ID,
|
|
209
|
+
meta: __assign(__assign({}, meta), { quickstartAllowFrom: true }),
|
|
210
|
+
pairing: {
|
|
211
|
+
idLabel: "wecomUserId",
|
|
212
|
+
normalizeAllowEntry: function (entry) { return entry.replace(new RegExp("^(" + const_js_1.CHANNEL_ID + "|user):", "i"), "").trim(); },
|
|
213
|
+
notifyApproval: function (_a) {
|
|
214
|
+
var cfg = _a.cfg, id = _a.id;
|
|
215
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
216
|
+
return __generator(this, function (_b) {
|
|
217
|
+
return [2 /*return*/];
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
setupWizard: onboarding_js_1.wecomSetupWizard,
|
|
223
|
+
setup: onboarding_js_1.wecomSetupAdapter,
|
|
224
|
+
capabilities: {
|
|
225
|
+
chatTypes: ["direct", "group"],
|
|
226
|
+
reactions: false,
|
|
227
|
+
threads: false,
|
|
228
|
+
media: true,
|
|
229
|
+
nativeCommands: false,
|
|
230
|
+
blockStreaming: true
|
|
231
|
+
},
|
|
232
|
+
reload: { configPrefixes: ["channels." + const_js_1.CHANNEL_ID] },
|
|
233
|
+
config: {
|
|
234
|
+
// 多账号:列出所有账户 ID
|
|
235
|
+
listAccountIds: function (cfg) { return accounts_js_1.listWeComAccountIds(cfg); },
|
|
236
|
+
// 多账号:按 accountId 解析账户配置
|
|
237
|
+
resolveAccount: function (cfg, accountId) { return accounts_js_1.resolveWeComAccountMulti({ cfg: cfg, accountId: accountId }); },
|
|
238
|
+
// 多账号:获取默认账户 ID
|
|
239
|
+
defaultAccountId: function (cfg) { return accounts_js_1.resolveDefaultWeComAccountId(cfg); },
|
|
240
|
+
// 多账号:设置账户启用状态
|
|
241
|
+
setAccountEnabled: function (_a) {
|
|
242
|
+
var _b, _c, _d;
|
|
243
|
+
var _e, _f, _g, _h, _j;
|
|
244
|
+
var cfg = _a.cfg, accountId = _a.accountId, enabled = _a.enabled;
|
|
245
|
+
if (!accounts_js_1.hasMultiAccounts(cfg)) {
|
|
246
|
+
// 单账号模式:设置顶层 enabled
|
|
247
|
+
var wecomConfig_1 = ((_f = (_e = cfg.channels) === null || _e === void 0 ? void 0 : _e[const_js_1.CHANNEL_ID]) !== null && _f !== void 0 ? _f : {});
|
|
248
|
+
return __assign(__assign({}, cfg), { channels: __assign(__assign({}, cfg.channels), (_b = {}, _b[const_js_1.CHANNEL_ID] = __assign(__assign({}, wecomConfig_1), { enabled: enabled }), _b)) });
|
|
249
|
+
}
|
|
250
|
+
// 多账号模式:设置 accounts[accountId].enabled
|
|
251
|
+
var wecomConfig = ((_h = (_g = cfg.channels) === null || _g === void 0 ? void 0 : _g[const_js_1.CHANNEL_ID]) !== null && _h !== void 0 ? _h : {});
|
|
252
|
+
return __assign(__assign({}, cfg), { channels: __assign(__assign({}, cfg.channels), (_c = {}, _c[const_js_1.CHANNEL_ID] = __assign(__assign({}, wecomConfig), { accounts: __assign(__assign({}, wecomConfig.accounts), (_d = {}, _d[accountId] = __assign(__assign({}, (_j = wecomConfig.accounts) === null || _j === void 0 ? void 0 : _j[accountId]), { enabled: enabled }), _d)) }), _c)) });
|
|
253
|
+
},
|
|
254
|
+
// 多账号:删除账户
|
|
255
|
+
deleteAccount: function (_a) {
|
|
256
|
+
var _b;
|
|
257
|
+
var _c;
|
|
258
|
+
var cfg = _a.cfg, accountId = _a.accountId;
|
|
259
|
+
if (!accounts_js_1.hasMultiAccounts(cfg)) {
|
|
260
|
+
// 单账号模式:删除整个 wecom 配置
|
|
261
|
+
var next = __assign({}, cfg);
|
|
262
|
+
var nextChannels = __assign({}, cfg.channels);
|
|
263
|
+
delete nextChannels[const_js_1.CHANNEL_ID];
|
|
264
|
+
if (Object.keys(nextChannels).length > 0) {
|
|
265
|
+
next.channels = nextChannels;
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
delete next.channels;
|
|
269
|
+
}
|
|
270
|
+
return next;
|
|
271
|
+
}
|
|
272
|
+
// 删除指定账号
|
|
273
|
+
var wecomConfig = (_c = cfg.channels) === null || _c === void 0 ? void 0 : _c[const_js_1.CHANNEL_ID];
|
|
274
|
+
var accounts = __assign({}, wecomConfig === null || wecomConfig === void 0 ? void 0 : wecomConfig.accounts);
|
|
275
|
+
delete accounts[accountId];
|
|
276
|
+
return __assign(__assign({}, cfg), { channels: __assign(__assign({}, cfg.channels), (_b = {}, _b[const_js_1.CHANNEL_ID] = __assign(__assign({}, wecomConfig), { accounts: Object.keys(accounts).length > 0 ? accounts : undefined }), _b)) });
|
|
277
|
+
},
|
|
278
|
+
// 检查是否已配置(Bot / Agent / botWebhook 凭证之一即可)
|
|
279
|
+
isConfigured: function (account) {
|
|
280
|
+
var _a, _b, _c, _d, _e;
|
|
281
|
+
return Boolean(((_a = account.botId) === null || _a === void 0 ? void 0 : _a.trim()) && ((_b = account.secret) === null || _b === void 0 ? void 0 : _b.trim())) ||
|
|
282
|
+
Boolean((_c = account.agent) === null || _c === void 0 ? void 0 : _c.configured) ||
|
|
283
|
+
Boolean(((_d = account.token) === null || _d === void 0 ? void 0 : _d.trim()) && ((_e = account.encodingAESKey) === null || _e === void 0 ? void 0 : _e.trim()));
|
|
284
|
+
},
|
|
285
|
+
// 描述账户信息
|
|
286
|
+
describeAccount: function (account) {
|
|
287
|
+
var _a, _b, _c, _d;
|
|
288
|
+
return ({
|
|
289
|
+
accountId: account.accountId,
|
|
290
|
+
name: account.name,
|
|
291
|
+
enabled: account.enabled,
|
|
292
|
+
configured: Boolean(((_a = account.botId) === null || _a === void 0 ? void 0 : _a.trim()) && ((_b = account.secret) === null || _b === void 0 ? void 0 : _b.trim())) || Boolean((_c = account.agent) === null || _c === void 0 ? void 0 : _c.configured),
|
|
293
|
+
botId: account.botId,
|
|
294
|
+
websocketUrl: account.websocketUrl,
|
|
295
|
+
agentConfigured: Boolean((_d = account.agent) === null || _d === void 0 ? void 0 : _d.configured)
|
|
296
|
+
});
|
|
297
|
+
},
|
|
298
|
+
// 解析允许来源列表(多账号:按 accountId 解析)
|
|
299
|
+
resolveAllowFrom: function (_a) {
|
|
300
|
+
var _b;
|
|
301
|
+
var cfg = _a.cfg, accountId = _a.accountId;
|
|
302
|
+
var account = accounts_js_1.resolveWeComAccountMulti({ cfg: cfg, accountId: accountId });
|
|
303
|
+
return ((_b = account.config.allowFrom) !== null && _b !== void 0 ? _b : []).map(function (entry) { return String(entry); });
|
|
304
|
+
},
|
|
305
|
+
// 格式化允许来源列表
|
|
306
|
+
formatAllowFrom: function (_a) {
|
|
307
|
+
var allowFrom = _a.allowFrom;
|
|
308
|
+
return allowFrom
|
|
309
|
+
.map(function (entry) { return String(entry).trim(); })
|
|
310
|
+
.filter(Boolean);
|
|
311
|
+
}
|
|
312
|
+
},
|
|
313
|
+
security: {
|
|
314
|
+
resolveDmPolicy: function (_a) {
|
|
315
|
+
var _b;
|
|
316
|
+
var cfg = _a.cfg, accountId = _a.accountId, account = _a.account;
|
|
317
|
+
var result = openclaw_compat_js_1.buildAccountScopedDmSecurityPolicy({
|
|
318
|
+
cfg: cfg,
|
|
319
|
+
channelKey: const_js_1.CHANNEL_ID,
|
|
320
|
+
accountId: accountId,
|
|
321
|
+
fallbackAccountId: account.accountId,
|
|
322
|
+
policy: account.config.dmPolicy,
|
|
323
|
+
allowFrom: (_b = account.config.allowFrom) !== null && _b !== void 0 ? _b : [],
|
|
324
|
+
defaultPolicy: "open",
|
|
325
|
+
policyPathSuffix: "dmPolicy",
|
|
326
|
+
approveHint: openclaw_compat_js_2.formatPairingApproveHint(const_js_1.CHANNEL_ID),
|
|
327
|
+
normalizeEntry: function (raw) { return raw.replace(new RegExp("^" + const_js_1.CHANNEL_ID + ":", "i"), "").trim(); }
|
|
328
|
+
});
|
|
329
|
+
return result;
|
|
330
|
+
},
|
|
331
|
+
collectWarnings: function (_a) {
|
|
332
|
+
var _b, _c, _d, _e, _f, _g;
|
|
333
|
+
var cfg = _a.cfg, accountId = _a.accountId;
|
|
334
|
+
var account = accounts_js_1.resolveWeComAccountMulti({ cfg: cfg, accountId: accountId });
|
|
335
|
+
var warnings = [];
|
|
336
|
+
// 动态构造配置路径(区分单账号 / 多账号)
|
|
337
|
+
var isMulti = accounts_js_1.hasMultiAccounts(cfg);
|
|
338
|
+
var basePath = isMulti && accountId
|
|
339
|
+
? "channels." + const_js_1.CHANNEL_ID + ".accounts." + accountId + "."
|
|
340
|
+
: "channels." + const_js_1.CHANNEL_ID + ".";
|
|
341
|
+
// DM 策略警告
|
|
342
|
+
var dmPolicy = (_b = account.config.dmPolicy) !== null && _b !== void 0 ? _b : "open";
|
|
343
|
+
if (dmPolicy === "open") {
|
|
344
|
+
var hasWildcard = ((_c = account.config.allowFrom) !== null && _c !== void 0 ? _c : []).some(function (entry) { return String(entry).trim() === "*"; });
|
|
345
|
+
if (!hasWildcard) {
|
|
346
|
+
warnings.push("- \u4F01\u4E1A\u5FAE\u4FE1[" + account.accountId + "]\u79C1\u4FE1\uFF1AdmPolicy=\"open\" \u4F46 allowFrom \u672A\u5305\u542B \"*\"\u3002\u4EFB\u4F55\u4EBA\u90FD\u53EF\u4EE5\u53D1\u6D88\u606F\uFF0C\u4F46\u5141\u8BB8\u5217\u8868\u4E3A\u7A7A\u53EF\u80FD\u5BFC\u81F4\u610F\u5916\u884C\u4E3A\u3002\u5EFA\u8BAE\u8BBE\u7F6E " + basePath + "allowFrom=[\"*\"] \u6216\u4F7F\u7528 dmPolicy=\"pairing\"\u3002");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// 群组策略警告
|
|
350
|
+
var defaultGroupPolicy = (_e = (_d = cfg.channels) === null || _d === void 0 ? void 0 : _d.defaults) === null || _e === void 0 ? void 0 : _e.groupPolicy;
|
|
351
|
+
var groupPolicy = (_g = (_f = account.config.groupPolicy) !== null && _f !== void 0 ? _f : defaultGroupPolicy) !== null && _g !== void 0 ? _g : "open";
|
|
352
|
+
if (groupPolicy === "open") {
|
|
353
|
+
warnings.push("- \u4F01\u4E1A\u5FAE\u4FE1[" + account.accountId + "]\u7FA4\u7EC4\uFF1AgroupPolicy=\"open\" \u5141\u8BB8\u6240\u6709\u7FA4\u7EC4\u4E2D\u7684\u6210\u5458\u89E6\u53D1\u3002\u8BBE\u7F6E " + basePath + "groupPolicy=\"allowlist\" + " + basePath + "groupAllowFrom \u6765\u9650\u5236\u7FA4\u7EC4\u3002");
|
|
354
|
+
}
|
|
355
|
+
return warnings;
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
messaging: {
|
|
359
|
+
normalizeTarget: function (target) {
|
|
360
|
+
var trimmed = target.trim();
|
|
361
|
+
if (!trimmed)
|
|
362
|
+
return undefined;
|
|
363
|
+
return trimmed;
|
|
364
|
+
},
|
|
365
|
+
targetResolver: {
|
|
366
|
+
looksLikeId: function (id) {
|
|
367
|
+
var trimmed = id === null || id === void 0 ? void 0 : id.trim();
|
|
368
|
+
return Boolean(trimmed);
|
|
369
|
+
},
|
|
370
|
+
hint: "<userId|groupId>"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
directory: {
|
|
374
|
+
self: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
375
|
+
return [2 /*return*/, null];
|
|
376
|
+
}); }); },
|
|
377
|
+
listPeers: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
378
|
+
return [2 /*return*/, []];
|
|
379
|
+
}); }); },
|
|
380
|
+
listGroups: function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
381
|
+
return [2 /*return*/, []];
|
|
382
|
+
}); }); }
|
|
383
|
+
},
|
|
384
|
+
outbound: {
|
|
385
|
+
deliveryMode: "gateway",
|
|
386
|
+
chunker: function (text, limit) { return runtime_js_1.getWeComRuntime().channel.text.chunkMarkdownText(text, limit); },
|
|
387
|
+
textChunkLimit: const_js_1.TEXT_CHUNK_LIMIT,
|
|
388
|
+
sendText: function (_a) {
|
|
389
|
+
var to = _a.to, text = _a.text, accountId = _a.accountId, cfg = _a.cfg;
|
|
390
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
391
|
+
return __generator(this, function (_b) {
|
|
392
|
+
return [2 /*return*/, sendWeComMessage({ to: to, content: text, accountId: accountId !== null && accountId !== void 0 ? accountId : undefined, cfg: cfg })];
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
},
|
|
396
|
+
sendMedia: function (_a) {
|
|
397
|
+
var to = _a.to, text = _a.text, mediaUrl = _a.mediaUrl, mediaLocalRoots = _a.mediaLocalRoots, accountId = _a.accountId, cfg = _a.cfg;
|
|
398
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
399
|
+
var resolvedAccountId, channelPrefix, chatId, resolvedAccount, wsClient, result, fallbackContent_1, account, agent, target, mediaResponse, buffer, _b, _c, filename, mediaId, err_1, fallbackContent;
|
|
400
|
+
var _d, _e;
|
|
401
|
+
return __generator(this, function (_f) {
|
|
402
|
+
switch (_f.label) {
|
|
403
|
+
case 0:
|
|
404
|
+
resolvedAccountId = accountId !== null && accountId !== void 0 ? accountId : openclaw_compat_js_2.DEFAULT_ACCOUNT_ID;
|
|
405
|
+
channelPrefix = new RegExp("^" + const_js_1.CHANNEL_ID + ":", "i");
|
|
406
|
+
chatId = to.replace(channelPrefix, "");
|
|
407
|
+
resolvedAccount = cfg
|
|
408
|
+
? accounts_js_1.resolveWeComAccountMulti({ cfg: cfg, accountId: resolvedAccountId })
|
|
409
|
+
: undefined;
|
|
410
|
+
// 如果没有 mediaUrl,fallback 为纯文本
|
|
411
|
+
if (!mediaUrl) {
|
|
412
|
+
return [2 /*return*/, sendWeComMessage({ to: to, content: text || "", accountId: resolvedAccountId, cfg: cfg })];
|
|
413
|
+
}
|
|
414
|
+
wsClient = state_manager_js_1.getWeComWebSocket(resolvedAccountId);
|
|
415
|
+
if (!(wsClient === null || wsClient === void 0 ? void 0 : wsClient.isConnected)) return [3 /*break*/, 6];
|
|
416
|
+
return [4 /*yield*/, media_uploader_js_1.uploadAndSendMedia({
|
|
417
|
+
wsClient: wsClient,
|
|
418
|
+
mediaUrl: mediaUrl,
|
|
419
|
+
chatId: chatId,
|
|
420
|
+
mediaLocalRoots: mediaLocalRoots,
|
|
421
|
+
gatewayToken: (_d = resolvedAccount === null || resolvedAccount === void 0 ? void 0 : resolvedAccount.config) === null || _d === void 0 ? void 0 : _d.gatewayToken,
|
|
422
|
+
gatewayBaseUrl: (_e = resolvedAccount === null || resolvedAccount === void 0 ? void 0 : resolvedAccount.config) === null || _e === void 0 ? void 0 : _e.gatewayBaseUrl
|
|
423
|
+
})];
|
|
424
|
+
case 1:
|
|
425
|
+
result = _f.sent();
|
|
426
|
+
if (result.rejected) {
|
|
427
|
+
return [2 /*return*/, sendWeComMessage({ to: to, content: "\u26A0\uFE0F " + result.rejectReason, accountId: resolvedAccountId, cfg: cfg })];
|
|
428
|
+
}
|
|
429
|
+
if (!result.ok) {
|
|
430
|
+
fallbackContent_1 = text
|
|
431
|
+
? text + "\n\uD83D\uDCCE " + mediaUrl
|
|
432
|
+
: "\uD83D\uDCCE " + mediaUrl;
|
|
433
|
+
return [2 /*return*/, sendWeComMessage({ to: to, content: fallbackContent_1, accountId: resolvedAccountId, cfg: cfg })];
|
|
434
|
+
}
|
|
435
|
+
im_runtime_telemetry_js_1.imRuntimeRecordChannelActivity("wecom", resolvedAccountId, "outbound");
|
|
436
|
+
if (!text) return [3 /*break*/, 3];
|
|
437
|
+
return [4 /*yield*/, sendWeComMessage({ to: to, content: text, accountId: resolvedAccountId, cfg: cfg })];
|
|
438
|
+
case 2:
|
|
439
|
+
_f.sent();
|
|
440
|
+
_f.label = 3;
|
|
441
|
+
case 3:
|
|
442
|
+
if (!result.downgradeNote) return [3 /*break*/, 5];
|
|
443
|
+
return [4 /*yield*/, sendWeComMessage({ to: to, content: "\u2139\uFE0F " + result.downgradeNote, accountId: resolvedAccountId, cfg: cfg })];
|
|
444
|
+
case 4:
|
|
445
|
+
_f.sent();
|
|
446
|
+
_f.label = 5;
|
|
447
|
+
case 5: return [2 /*return*/, {
|
|
448
|
+
channel: const_js_1.CHANNEL_ID,
|
|
449
|
+
messageId: result.messageId,
|
|
450
|
+
chatId: chatId
|
|
451
|
+
}];
|
|
452
|
+
case 6:
|
|
453
|
+
// ── 回退到 Agent HTTP API ──
|
|
454
|
+
if (!cfg) {
|
|
455
|
+
throw new Error("WSClient not connected for account " + resolvedAccountId + " and no config available for Agent fallback");
|
|
456
|
+
}
|
|
457
|
+
account = resolvedAccount !== null && resolvedAccount !== void 0 ? resolvedAccount : accounts_js_1.resolveWeComAccountMulti({ cfg: cfg, accountId: resolvedAccountId });
|
|
458
|
+
agent = account.agent;
|
|
459
|
+
if (!(agent === null || agent === void 0 ? void 0 : agent.configured)) {
|
|
460
|
+
throw new Error("WSClient not connected for account " + resolvedAccountId + " and Agent mode is not configured. " +
|
|
461
|
+
"Please configure either Bot (botId + secret) or Agent (corpId + corpSecret + agentId).");
|
|
462
|
+
}
|
|
463
|
+
target = target_js_1.resolveWecomTarget(chatId);
|
|
464
|
+
if (!target) {
|
|
465
|
+
throw new Error("Cannot resolve outbound target from \"" + to + "\"");
|
|
466
|
+
}
|
|
467
|
+
console.log("[wecom-outbound] Bot WS unavailable, sending media via Agent HTTP API to " + JSON.stringify(target));
|
|
468
|
+
_f.label = 7;
|
|
469
|
+
case 7:
|
|
470
|
+
_f.trys.push([7, 15, , 16]);
|
|
471
|
+
return [4 /*yield*/, fetch(mediaUrl)];
|
|
472
|
+
case 8:
|
|
473
|
+
mediaResponse = _f.sent();
|
|
474
|
+
if (!mediaResponse.ok) return [3 /*break*/, 14];
|
|
475
|
+
_c = (_b = Buffer).from;
|
|
476
|
+
return [4 /*yield*/, mediaResponse.arrayBuffer()];
|
|
477
|
+
case 9:
|
|
478
|
+
buffer = _c.apply(_b, [_f.sent()]);
|
|
479
|
+
filename = mediaUrl.split('/').pop() || 'file.bin';
|
|
480
|
+
return [4 /*yield*/, api_client_js_1.uploadMedia({
|
|
481
|
+
agent: agent,
|
|
482
|
+
type: 'file',
|
|
483
|
+
buffer: buffer,
|
|
484
|
+
filename: filename
|
|
485
|
+
})];
|
|
486
|
+
case 10:
|
|
487
|
+
mediaId = _f.sent();
|
|
488
|
+
return [4 /*yield*/, api_client_js_1.sendMedia({
|
|
489
|
+
agent: agent,
|
|
490
|
+
toUser: target.touser,
|
|
491
|
+
toParty: target.toparty,
|
|
492
|
+
toTag: target.totag,
|
|
493
|
+
chatId: target.chatid,
|
|
494
|
+
mediaId: mediaId,
|
|
495
|
+
mediaType: 'file'
|
|
496
|
+
})];
|
|
497
|
+
case 11:
|
|
498
|
+
_f.sent();
|
|
499
|
+
im_runtime_telemetry_js_1.imRuntimeRecordChannelActivity("wecom", resolvedAccountId, "outbound");
|
|
500
|
+
if (!text) return [3 /*break*/, 13];
|
|
501
|
+
return [4 /*yield*/, api_client_js_1.sendText({ agent: agent, toUser: target.touser, toParty: target.toparty, toTag: target.totag, chatId: target.chatid, text: text })];
|
|
502
|
+
case 12:
|
|
503
|
+
_f.sent();
|
|
504
|
+
im_runtime_telemetry_js_1.imRuntimeRecordChannelActivity("wecom", resolvedAccountId, "outbound");
|
|
505
|
+
_f.label = 13;
|
|
506
|
+
case 13: return [2 /*return*/, { channel: const_js_1.CHANNEL_ID, messageId: "agent-media-" + Date.now(), chatId: chatId }];
|
|
507
|
+
case 14: return [3 /*break*/, 16];
|
|
508
|
+
case 15:
|
|
509
|
+
err_1 = _f.sent();
|
|
510
|
+
console.warn("[wecom-outbound] Agent media upload failed, falling back to text:", err_1);
|
|
511
|
+
return [3 /*break*/, 16];
|
|
512
|
+
case 16:
|
|
513
|
+
fallbackContent = text ? text + "\n\uD83D\uDCCE " + mediaUrl : "\uD83D\uDCCE " + mediaUrl;
|
|
514
|
+
return [4 /*yield*/, api_client_js_1.sendText({ agent: agent, toUser: target.touser, toParty: target.toparty, toTag: target.totag, chatId: target.chatid, text: fallbackContent })];
|
|
515
|
+
case 17:
|
|
516
|
+
_f.sent();
|
|
517
|
+
im_runtime_telemetry_js_1.imRuntimeRecordChannelActivity("wecom", resolvedAccountId, "outbound");
|
|
518
|
+
return [2 /*return*/, { channel: const_js_1.CHANNEL_ID, messageId: "agent-" + Date.now(), chatId: chatId }];
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
status: {
|
|
525
|
+
defaultRuntime: {
|
|
526
|
+
accountId: openclaw_compat_js_2.DEFAULT_ACCOUNT_ID,
|
|
527
|
+
running: false,
|
|
528
|
+
lastStartAt: null,
|
|
529
|
+
lastStopAt: null,
|
|
530
|
+
lastError: null
|
|
531
|
+
},
|
|
532
|
+
collectStatusIssues: function (accounts) {
|
|
533
|
+
return accounts.flatMap(function (entry) {
|
|
534
|
+
var _a;
|
|
535
|
+
var accountId = String((_a = entry.accountId) !== null && _a !== void 0 ? _a : openclaw_compat_js_2.DEFAULT_ACCOUNT_ID);
|
|
536
|
+
var enabled = entry.enabled !== false;
|
|
537
|
+
var configured = entry.configured === true;
|
|
538
|
+
if (!enabled) {
|
|
539
|
+
return [];
|
|
540
|
+
}
|
|
541
|
+
var issues = [];
|
|
542
|
+
if (!configured) {
|
|
543
|
+
issues.push({
|
|
544
|
+
channel: const_js_1.CHANNEL_ID,
|
|
545
|
+
accountId: accountId,
|
|
546
|
+
kind: "config",
|
|
547
|
+
message: "企业微信机器人 ID 或 Secret 未配置",
|
|
548
|
+
fix: "Run: openclaw channels add wecom --bot-id <id> --secret <secret>"
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
return issues;
|
|
552
|
+
});
|
|
553
|
+
},
|
|
554
|
+
buildChannelSummary: function (_a) {
|
|
555
|
+
var _b, _c, _d, _e, _f;
|
|
556
|
+
var snapshot = _a.snapshot;
|
|
557
|
+
return ({
|
|
558
|
+
configured: (_b = snapshot.configured) !== null && _b !== void 0 ? _b : false,
|
|
559
|
+
running: (_c = snapshot.running) !== null && _c !== void 0 ? _c : false,
|
|
560
|
+
lastStartAt: (_d = snapshot.lastStartAt) !== null && _d !== void 0 ? _d : null,
|
|
561
|
+
lastStopAt: (_e = snapshot.lastStopAt) !== null && _e !== void 0 ? _e : null,
|
|
562
|
+
lastError: (_f = snapshot.lastError) !== null && _f !== void 0 ? _f : null
|
|
563
|
+
});
|
|
564
|
+
},
|
|
565
|
+
probeAccount: function (_a) {
|
|
566
|
+
var account = _a.account, forceProbe = _a.forceProbe, force_probe = _a.force_probe;
|
|
567
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
568
|
+
var accountId, shouldForceProbe, configured, result_1, cached, wsClient, snapshot, connected, result_2, result;
|
|
569
|
+
var _b, _c;
|
|
570
|
+
return __generator(this, function (_d) {
|
|
571
|
+
accountId = String((account === null || account === void 0 ? void 0 : account.accountId) || openclaw_compat_js_2.DEFAULT_ACCOUNT_ID).trim();
|
|
572
|
+
shouldForceProbe = parseRuntimeBoolFlag(forceProbe != null ? forceProbe : force_probe);
|
|
573
|
+
configured = Boolean(((_b = account === null || account === void 0 ? void 0 : account.botId) === null || _b === void 0 ? void 0 : _b.trim()) && ((_c = account === null || account === void 0 ? void 0 : account.secret) === null || _c === void 0 ? void 0 : _c.trim()));
|
|
574
|
+
if (!configured) {
|
|
575
|
+
result_1 = {
|
|
576
|
+
ok: false,
|
|
577
|
+
error: "wecom websocket account not configured",
|
|
578
|
+
details: { accountId: accountId, source: "wecom_plugin_probe" }
|
|
579
|
+
};
|
|
580
|
+
writeWeComProbeCache(accountId, result_1);
|
|
581
|
+
return [2 /*return*/, result_1];
|
|
582
|
+
}
|
|
583
|
+
cached = readWeComProbeCache(accountId, shouldForceProbe);
|
|
584
|
+
if (cached) {
|
|
585
|
+
return [2 /*return*/, cached];
|
|
586
|
+
}
|
|
587
|
+
wsClient = state_manager_js_1.getWeComWebSocket(accountId);
|
|
588
|
+
snapshot = state_manager_js_1.getWeComConnectionSnapshot(accountId);
|
|
589
|
+
connected = Boolean((wsClient === null || wsClient === void 0 ? void 0 : wsClient.isConnected) || ((snapshot === null || snapshot === void 0 ? void 0 : snapshot.connected) && (snapshot === null || snapshot === void 0 ? void 0 : snapshot.authenticated)));
|
|
590
|
+
if (!connected) {
|
|
591
|
+
result_2 = {
|
|
592
|
+
ok: false,
|
|
593
|
+
error: (snapshot === null || snapshot === void 0 ? void 0 : snapshot.lastError) || "wecom websocket not connected",
|
|
594
|
+
details: {
|
|
595
|
+
accountId: accountId,
|
|
596
|
+
source: "wecom_plugin_probe",
|
|
597
|
+
forceProbe: shouldForceProbe,
|
|
598
|
+
wsConnected: Boolean(wsClient === null || wsClient === void 0 ? void 0 : wsClient.isConnected),
|
|
599
|
+
snapshot: snapshot
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
writeWeComProbeCache(accountId, result_2);
|
|
603
|
+
return [2 /*return*/, result_2];
|
|
604
|
+
}
|
|
605
|
+
result = {
|
|
606
|
+
ok: true,
|
|
607
|
+
status: 200,
|
|
608
|
+
details: {
|
|
609
|
+
accountId: accountId,
|
|
610
|
+
source: "wecom_plugin_probe",
|
|
611
|
+
forceProbe: shouldForceProbe,
|
|
612
|
+
wsConnected: Boolean(wsClient === null || wsClient === void 0 ? void 0 : wsClient.isConnected),
|
|
613
|
+
snapshot: snapshot
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
writeWeComProbeCache(accountId, result);
|
|
617
|
+
return [2 /*return*/, result];
|
|
618
|
+
});
|
|
619
|
+
});
|
|
620
|
+
},
|
|
621
|
+
buildAccountSnapshot: function (_a) {
|
|
622
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
623
|
+
var account = _a.account, runtime = _a.runtime;
|
|
624
|
+
var configured = Boolean(((_b = account.botId) === null || _b === void 0 ? void 0 : _b.trim()) && ((_c = account.secret) === null || _c === void 0 ? void 0 : _c.trim())) || Boolean((_d = account.agent) === null || _d === void 0 ? void 0 : _d.configured);
|
|
625
|
+
return {
|
|
626
|
+
accountId: account.accountId,
|
|
627
|
+
name: account.name,
|
|
628
|
+
enabled: account.enabled,
|
|
629
|
+
configured: configured,
|
|
630
|
+
running: (_e = runtime === null || runtime === void 0 ? void 0 : runtime.running) !== null && _e !== void 0 ? _e : false,
|
|
631
|
+
lastStartAt: (_f = runtime === null || runtime === void 0 ? void 0 : runtime.lastStartAt) !== null && _f !== void 0 ? _f : null,
|
|
632
|
+
lastStopAt: (_g = runtime === null || runtime === void 0 ? void 0 : runtime.lastStopAt) !== null && _g !== void 0 ? _g : null,
|
|
633
|
+
lastError: (_h = runtime === null || runtime === void 0 ? void 0 : runtime.lastError) !== null && _h !== void 0 ? _h : null
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
},
|
|
637
|
+
gateway: {
|
|
638
|
+
startAccount: function (ctx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
639
|
+
var account, connectionMode, agent, isMulti, defaultId, isDefault, paths, _i, paths_1, p, hasBotCredentials, webhookAccount, gatewayCtx_1;
|
|
640
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
641
|
+
return __generator(this, function (_l) {
|
|
642
|
+
switch (_l.label) {
|
|
643
|
+
case 0:
|
|
644
|
+
account = accounts_js_1.resolveWeComAccountMulti({ cfg: ctx.cfg, accountId: ctx.accountId });
|
|
645
|
+
connectionMode = (_a = account.config.connectionMode) !== null && _a !== void 0 ? _a : "websocket";
|
|
646
|
+
(_b = ctx.log) === null || _b === void 0 ? void 0 : _b.info("starting wecom[" + ctx.accountId + "] (name: " + account.name + ", mode: " + connectionMode + ")");
|
|
647
|
+
clearWeComProbeCache(ctx.accountId);
|
|
648
|
+
agent = account.agent;
|
|
649
|
+
if (agent === null || agent === void 0 ? void 0 : agent.configured) {
|
|
650
|
+
isMulti = accounts_js_1.hasMultiAccounts(ctx.cfg);
|
|
651
|
+
defaultId = accounts_js_1.resolveDefaultWeComAccountId(ctx.cfg);
|
|
652
|
+
isDefault = ctx.accountId === defaultId;
|
|
653
|
+
paths = isMulti
|
|
654
|
+
? __spreadArrays([
|
|
655
|
+
const_js_1.WEBHOOK_PATHS.AGENT_PLUGIN + "/" + ctx.accountId,
|
|
656
|
+
const_js_1.WEBHOOK_PATHS.AGENT + "/" + ctx.accountId
|
|
657
|
+
], (isDefault && ctx.accountId !== openclaw_compat_js_2.DEFAULT_ACCOUNT_ID
|
|
658
|
+
? [
|
|
659
|
+
const_js_1.WEBHOOK_PATHS.AGENT_PLUGIN + "/" + openclaw_compat_js_2.DEFAULT_ACCOUNT_ID,
|
|
660
|
+
const_js_1.WEBHOOK_PATHS.AGENT + "/" + openclaw_compat_js_2.DEFAULT_ACCOUNT_ID,
|
|
661
|
+
]
|
|
662
|
+
: []), [
|
|
663
|
+
const_js_1.WEBHOOK_PATHS.AGENT_PLUGIN,
|
|
664
|
+
const_js_1.WEBHOOK_PATHS.AGENT,
|
|
665
|
+
]) : [
|
|
666
|
+
// 单账号模式:同时注册 /default 路径以支持显式指定
|
|
667
|
+
const_js_1.WEBHOOK_PATHS.AGENT_PLUGIN,
|
|
668
|
+
const_js_1.WEBHOOK_PATHS.AGENT,
|
|
669
|
+
const_js_1.WEBHOOK_PATHS.AGENT_PLUGIN + "/" + openclaw_compat_js_2.DEFAULT_ACCOUNT_ID,
|
|
670
|
+
const_js_1.WEBHOOK_PATHS.AGENT + "/" + openclaw_compat_js_2.DEFAULT_ACCOUNT_ID,
|
|
671
|
+
];
|
|
672
|
+
for (_i = 0, paths_1 = paths; _i < paths_1.length; _i++) {
|
|
673
|
+
p = paths_1[_i];
|
|
674
|
+
webhook_js_1.registerAgentWebhookTarget({
|
|
675
|
+
agent: agent,
|
|
676
|
+
config: ctx.cfg,
|
|
677
|
+
runtime: {
|
|
678
|
+
log: ((_c = ctx.log) === null || _c === void 0 ? void 0 : _c.info) ? function (msg) { return ctx.log.info(msg); } : undefined,
|
|
679
|
+
error: ((_d = ctx.log) === null || _d === void 0 ? void 0 : _d.error) ? function (msg) { return ctx.log.error(msg); } : undefined
|
|
680
|
+
},
|
|
681
|
+
path: p
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
(_e = ctx.log) === null || _e === void 0 ? void 0 : _e.info("[" + ctx.accountId + "] wecom agent webhook registered at " + paths.join(", "));
|
|
685
|
+
// 账号生命周期结束时清理
|
|
686
|
+
ctx.abortSignal.addEventListener("abort", function () {
|
|
687
|
+
webhook_js_1.deregisterAgentWebhookTarget(agent.accountId);
|
|
688
|
+
}, { once: true });
|
|
689
|
+
}
|
|
690
|
+
hasBotCredentials = Boolean(((_f = account.botId) === null || _f === void 0 ? void 0 : _f.trim()) && ((_g = account.secret) === null || _g === void 0 ? void 0 : _g.trim()));
|
|
691
|
+
if (!hasBotCredentials) return [3 /*break*/, 1];
|
|
692
|
+
return [2 /*return*/, monitor_js_1.monitorWeComProvider({
|
|
693
|
+
account: account,
|
|
694
|
+
config: ctx.cfg,
|
|
695
|
+
runtime: ctx.runtime,
|
|
696
|
+
abortSignal: ctx.abortSignal,
|
|
697
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- SDK 类型签名在不同版本间存在差异
|
|
698
|
+
setStatus: ctx.setStatus
|
|
699
|
+
})];
|
|
700
|
+
case 1:
|
|
701
|
+
if (!(connectionMode === "webhook")) return [3 /*break*/, 3];
|
|
702
|
+
webhookAccount = __assign(__assign({}, account), { connectionMode: "webhook", token: (_h = account.config.token) !== null && _h !== void 0 ? _h : "", encodingAESKey: (_j = account.config.encodingAESKey) !== null && _j !== void 0 ? _j : "", receiveId: (_k = account.config.receiveId) !== null && _k !== void 0 ? _k : "", welcomeText: account.config.welcomeText });
|
|
703
|
+
gatewayCtx_1 = {
|
|
704
|
+
account: webhookAccount,
|
|
705
|
+
config: ctx.cfg,
|
|
706
|
+
runtime: ctx.runtime,
|
|
707
|
+
abortSignal: ctx.abortSignal,
|
|
708
|
+
setStatus: ctx.setStatus,
|
|
709
|
+
log: ctx.log,
|
|
710
|
+
accountId: ctx.accountId
|
|
711
|
+
};
|
|
712
|
+
index_js_1.startWebhookGateway(gatewayCtx_1);
|
|
713
|
+
// 等待 abortSignal 停止后清理
|
|
714
|
+
return [4 /*yield*/, new Promise(function (resolve) {
|
|
715
|
+
if (ctx.abortSignal.aborted) {
|
|
716
|
+
clearWeComProbeCache(ctx.accountId);
|
|
717
|
+
index_js_1.stopWebhookGateway(gatewayCtx_1);
|
|
718
|
+
resolve();
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
ctx.abortSignal.addEventListener("abort", function () {
|
|
722
|
+
clearWeComProbeCache(ctx.accountId);
|
|
723
|
+
index_js_1.stopWebhookGateway(gatewayCtx_1);
|
|
724
|
+
resolve();
|
|
725
|
+
}, { once: true });
|
|
726
|
+
})];
|
|
727
|
+
case 2:
|
|
728
|
+
// 等待 abortSignal 停止后清理
|
|
729
|
+
_l.sent();
|
|
730
|
+
return [2 /*return*/];
|
|
731
|
+
case 3:
|
|
732
|
+
// Agent-only:无 Bot,等待 abort 信号
|
|
733
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
734
|
+
ctx.abortSignal.addEventListener("abort", function () {
|
|
735
|
+
clearWeComProbeCache(ctx.accountId);
|
|
736
|
+
resolve();
|
|
737
|
+
}, { once: true });
|
|
738
|
+
})];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
}); },
|
|
742
|
+
logoutAccount: function (_a) {
|
|
743
|
+
var cfg = _a.cfg, accountId = _a.accountId;
|
|
744
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
745
|
+
var resolvedAccountId, isMulti, nextCfg, cleared, changed, wecomConfig, nextWecom, nextChannels, wecomConfig, accountCfg, nextAccount, nextAccounts, resolved, loggedOut;
|
|
746
|
+
var _b, _c;
|
|
747
|
+
var _d, _e, _f, _g, _h;
|
|
748
|
+
return __generator(this, function (_j) {
|
|
749
|
+
switch (_j.label) {
|
|
750
|
+
case 0:
|
|
751
|
+
resolvedAccountId = accountId !== null && accountId !== void 0 ? accountId : openclaw_compat_js_2.DEFAULT_ACCOUNT_ID;
|
|
752
|
+
clearWeComProbeCache(resolvedAccountId);
|
|
753
|
+
isMulti = accounts_js_1.hasMultiAccounts(cfg);
|
|
754
|
+
nextCfg = __assign({}, cfg);
|
|
755
|
+
cleared = false;
|
|
756
|
+
changed = false;
|
|
757
|
+
if (!isMulti) {
|
|
758
|
+
wecomConfig = ((_e = (_d = cfg.channels) === null || _d === void 0 ? void 0 : _d[const_js_1.CHANNEL_ID]) !== null && _e !== void 0 ? _e : {});
|
|
759
|
+
nextWecom = __assign({}, wecomConfig);
|
|
760
|
+
if (nextWecom.botId || nextWecom.secret) {
|
|
761
|
+
delete nextWecom.botId;
|
|
762
|
+
delete nextWecom.secret;
|
|
763
|
+
cleared = true;
|
|
764
|
+
changed = true;
|
|
765
|
+
}
|
|
766
|
+
if (changed) {
|
|
767
|
+
if (Object.keys(nextWecom).length > 0) {
|
|
768
|
+
nextCfg.channels = __assign(__assign({}, nextCfg.channels), (_b = {}, _b[const_js_1.CHANNEL_ID] = nextWecom, _b));
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
nextChannels = __assign({}, nextCfg.channels);
|
|
772
|
+
delete nextChannels[const_js_1.CHANNEL_ID];
|
|
773
|
+
if (Object.keys(nextChannels).length > 0) {
|
|
774
|
+
nextCfg.channels = nextChannels;
|
|
775
|
+
}
|
|
776
|
+
else {
|
|
777
|
+
delete nextCfg.channels;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
wecomConfig = ((_g = (_f = cfg.channels) === null || _f === void 0 ? void 0 : _f[const_js_1.CHANNEL_ID]) !== null && _g !== void 0 ? _g : {});
|
|
784
|
+
accountCfg = (_h = wecomConfig.accounts) === null || _h === void 0 ? void 0 : _h[resolvedAccountId];
|
|
785
|
+
if ((accountCfg === null || accountCfg === void 0 ? void 0 : accountCfg.botId) || (accountCfg === null || accountCfg === void 0 ? void 0 : accountCfg.secret)) {
|
|
786
|
+
nextAccount = __assign({}, accountCfg);
|
|
787
|
+
delete nextAccount.botId;
|
|
788
|
+
delete nextAccount.secret;
|
|
789
|
+
cleared = true;
|
|
790
|
+
changed = true;
|
|
791
|
+
nextAccounts = __assign({}, wecomConfig.accounts);
|
|
792
|
+
if (Object.keys(nextAccount).length > 0) {
|
|
793
|
+
nextAccounts[resolvedAccountId] = nextAccount;
|
|
794
|
+
}
|
|
795
|
+
else {
|
|
796
|
+
delete nextAccounts[resolvedAccountId];
|
|
797
|
+
}
|
|
798
|
+
nextCfg = __assign(__assign({}, cfg), { channels: __assign(__assign({}, cfg.channels), (_c = {}, _c[const_js_1.CHANNEL_ID] = __assign(__assign({}, wecomConfig), { accounts: Object.keys(nextAccounts).length > 0 ? nextAccounts : undefined }), _c)) });
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (!changed) return [3 /*break*/, 2];
|
|
802
|
+
return [4 /*yield*/, runtime_js_1.getWeComRuntime().config.writeConfigFile(nextCfg)];
|
|
803
|
+
case 1:
|
|
804
|
+
_j.sent();
|
|
805
|
+
_j.label = 2;
|
|
806
|
+
case 2:
|
|
807
|
+
resolved = accounts_js_1.resolveWeComAccountMulti({ cfg: changed ? nextCfg : cfg, accountId: resolvedAccountId });
|
|
808
|
+
loggedOut = !resolved.botId && !resolved.secret;
|
|
809
|
+
return [2 /*return*/, { cleared: cleared, envToken: false, loggedOut: loggedOut }];
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
};
|