@agent-wechat/wechat 0.3.1 → 0.4.1
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/dist/index.js +140 -163
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -1106,6 +1106,18 @@ function resolveWeChatAccount(cfg, accountId) {
|
|
|
1106
1106
|
};
|
|
1107
1107
|
}
|
|
1108
1108
|
|
|
1109
|
+
// src/runtime.ts
|
|
1110
|
+
var runtime = null;
|
|
1111
|
+
function setWeChatRuntime(next) {
|
|
1112
|
+
runtime = next;
|
|
1113
|
+
}
|
|
1114
|
+
function getWeChatRuntime() {
|
|
1115
|
+
if (!runtime) {
|
|
1116
|
+
throw new Error("WeChat runtime not initialized");
|
|
1117
|
+
}
|
|
1118
|
+
return runtime;
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1109
1121
|
// ../shared/dist/client.js
|
|
1110
1122
|
function normalizeUrl(base) {
|
|
1111
1123
|
const url = base.startsWith("http") ? base : `http://${base}`;
|
|
@@ -5486,20 +5498,6 @@ var agentConfigSchema = external_exports.object({
|
|
|
5486
5498
|
|
|
5487
5499
|
// src/monitor.ts
|
|
5488
5500
|
import { createReplyPrefixOptions } from "openclaw/plugin-sdk";
|
|
5489
|
-
|
|
5490
|
-
// src/runtime.ts
|
|
5491
|
-
var runtime = null;
|
|
5492
|
-
function setWeChatRuntime(next) {
|
|
5493
|
-
runtime = next;
|
|
5494
|
-
}
|
|
5495
|
-
function getWeChatRuntime() {
|
|
5496
|
-
if (!runtime) {
|
|
5497
|
-
throw new Error("WeChat runtime not initialized");
|
|
5498
|
-
}
|
|
5499
|
-
return runtime;
|
|
5500
|
-
}
|
|
5501
|
-
|
|
5502
|
-
// src/monitor.ts
|
|
5503
5501
|
var MEDIA_TYPES = /* @__PURE__ */ new Set([3, 34]);
|
|
5504
5502
|
var HISTORY_CONTEXT_MARKER = "[Chat messages since your last reply - for context]";
|
|
5505
5503
|
var CURRENT_MESSAGE_MARKER = "[Current message - respond to this]";
|
|
@@ -5553,7 +5551,7 @@ function enqueueWeChatSystemEvent(text, contextKey) {
|
|
|
5553
5551
|
}
|
|
5554
5552
|
}
|
|
5555
5553
|
async function startWeChatMonitor(opts) {
|
|
5556
|
-
const { account, abortSignal,
|
|
5554
|
+
const { account, abortSignal, setStatus, log } = opts;
|
|
5557
5555
|
const client = new WeChatClient({ baseUrl: account.serverUrl, token: account.token });
|
|
5558
5556
|
const lastSeenId = /* @__PURE__ */ new Map();
|
|
5559
5557
|
let lastAuthCheck = 0;
|
|
@@ -5581,11 +5579,11 @@ async function startWeChatMonitor(opts) {
|
|
|
5581
5579
|
authStatus: auth.status
|
|
5582
5580
|
});
|
|
5583
5581
|
if (prevStatus === "logged_in" && !isLinked) {
|
|
5584
|
-
const msg = auth.status === "app_not_running" ? "[WeChat] Application stopped. It will restart automatically \u2014
|
|
5582
|
+
const msg = auth.status === "app_not_running" ? "[WeChat] Application stopped. It will restart automatically \u2014 credentials may be cached, so you can try reconnecting using the wechat_login tool." : "[WeChat] Session ended. You can try reconnecting using the wechat_login tool \u2014 if credentials are cached, login may complete automatically.";
|
|
5585
5583
|
enqueueWeChatSystemEvent(msg, "wechat:auth_lost");
|
|
5586
5584
|
} else if (prevStatus === void 0 && !isLinked) {
|
|
5587
5585
|
enqueueWeChatSystemEvent(
|
|
5588
|
-
"[WeChat] Not logged in. Use the wechat_login tool to authenticate.",
|
|
5586
|
+
"[WeChat] Not logged in. Use the wechat_login tool to authenticate \u2014 if credentials are cached from a previous session, login may complete automatically.",
|
|
5589
5587
|
"wechat:auth_required"
|
|
5590
5588
|
);
|
|
5591
5589
|
}
|
|
@@ -6303,24 +6301,26 @@ function readOrGenerateToken() {
|
|
|
6303
6301
|
return token;
|
|
6304
6302
|
}
|
|
6305
6303
|
var wechatOnboardingAdapter = {
|
|
6306
|
-
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
if (!account
|
|
6304
|
+
channel: "wechat",
|
|
6305
|
+
getStatus: async ({ cfg }) => {
|
|
6306
|
+
const account = resolveWeChatAccount(cfg);
|
|
6307
|
+
if (!account?.serverUrl) {
|
|
6310
6308
|
return {
|
|
6309
|
+
channel: "wechat",
|
|
6311
6310
|
configured: false,
|
|
6312
|
-
|
|
6311
|
+
statusLines: ["Not configured. Run: openclaw channels setup wechat"]
|
|
6313
6312
|
};
|
|
6314
6313
|
}
|
|
6315
6314
|
const client = new WeChatClient({ baseUrl: account.serverUrl, token: account.token });
|
|
6316
|
-
const
|
|
6315
|
+
const statusLines = [];
|
|
6317
6316
|
try {
|
|
6318
6317
|
await client.status();
|
|
6319
|
-
|
|
6318
|
+
statusLines.push(`Connected to ${account.serverUrl}`);
|
|
6320
6319
|
} catch {
|
|
6321
6320
|
return {
|
|
6321
|
+
channel: "wechat",
|
|
6322
6322
|
configured: true,
|
|
6323
|
-
|
|
6323
|
+
statusLines: [
|
|
6324
6324
|
`Server URL: ${account.serverUrl}`,
|
|
6325
6325
|
"Cannot reach server \u2014 is the agent-wechat container running?"
|
|
6326
6326
|
]
|
|
@@ -6329,45 +6329,44 @@ var wechatOnboardingAdapter = {
|
|
|
6329
6329
|
try {
|
|
6330
6330
|
const auth = await client.authStatus();
|
|
6331
6331
|
if (auth.status === "logged_in") {
|
|
6332
|
-
|
|
6332
|
+
statusLines.push(
|
|
6333
6333
|
`Logged in${auth.loggedInUser ? ` as ${auth.loggedInUser}` : ""}`
|
|
6334
6334
|
);
|
|
6335
6335
|
} else {
|
|
6336
|
-
|
|
6336
|
+
statusLines.push("Not logged in. Run: openclaw channels login --channel wechat");
|
|
6337
6337
|
}
|
|
6338
6338
|
} catch {
|
|
6339
|
-
|
|
6339
|
+
statusLines.push("Could not check auth status");
|
|
6340
6340
|
}
|
|
6341
|
-
|
|
6341
|
+
statusLines.push(`DM policy: ${account.dmPolicy}`);
|
|
6342
6342
|
if (account.allowFrom.length > 0) {
|
|
6343
|
-
|
|
6343
|
+
statusLines.push(`Allowed senders: ${account.allowFrom.join(", ")}`);
|
|
6344
6344
|
}
|
|
6345
|
-
|
|
6346
|
-
return { configured: true,
|
|
6345
|
+
statusLines.push(`Group policy: ${account.groupPolicy}`);
|
|
6346
|
+
return { channel: "wechat", configured: true, statusLines };
|
|
6347
6347
|
},
|
|
6348
|
-
configure: async ({
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
const existingUrl = cfg?.channels?.wechat?.serverUrl ?? "http://localhost:6174";
|
|
6348
|
+
configure: async ({ prompter, cfg }) => {
|
|
6349
|
+
const wechatCfg = {
|
|
6350
|
+
...cfg?.channels?.wechat ?? {}
|
|
6351
|
+
};
|
|
6352
|
+
const existingUrl = wechatCfg.serverUrl ?? "http://localhost:6174";
|
|
6354
6353
|
const serverUrl = await prompter.text({
|
|
6355
6354
|
message: "Agent-wechat server URL",
|
|
6356
|
-
|
|
6355
|
+
initialValue: existingUrl
|
|
6357
6356
|
});
|
|
6358
|
-
|
|
6359
|
-
const existingToken =
|
|
6357
|
+
wechatCfg.serverUrl = serverUrl;
|
|
6358
|
+
const existingToken = wechatCfg.token ?? "";
|
|
6360
6359
|
const localDefault = existingToken || readOrGenerateToken();
|
|
6361
6360
|
const token = await prompter.text({
|
|
6362
6361
|
message: "Auth token (leave empty to use local token)",
|
|
6363
|
-
|
|
6362
|
+
initialValue: localDefault
|
|
6364
6363
|
});
|
|
6365
|
-
|
|
6364
|
+
wechatCfg.token = token || localDefault;
|
|
6366
6365
|
const client = new WeChatClient({ baseUrl: serverUrl, token: token || void 0 });
|
|
6367
6366
|
try {
|
|
6368
6367
|
await client.status();
|
|
6369
6368
|
} catch {
|
|
6370
|
-
|
|
6369
|
+
wechatCfg.enabled = false;
|
|
6371
6370
|
throw new Error(
|
|
6372
6371
|
`Cannot reach ${serverUrl}. Ensure the agent-wechat container is running.`
|
|
6373
6372
|
);
|
|
@@ -6377,10 +6376,10 @@ var wechatOnboardingAdapter = {
|
|
|
6377
6376
|
if (auth.status !== "logged_in") {
|
|
6378
6377
|
const wantsLink = await prompter.confirm({
|
|
6379
6378
|
message: "WeChat not logged in. Link now?",
|
|
6380
|
-
|
|
6379
|
+
initialValue: true
|
|
6381
6380
|
});
|
|
6382
6381
|
if (wantsLink) {
|
|
6383
|
-
await prompter.note
|
|
6382
|
+
await prompter.note(
|
|
6384
6383
|
"Starting login \u2014 watch for QR code or phone confirmation.",
|
|
6385
6384
|
"WeChat Login"
|
|
6386
6385
|
);
|
|
@@ -6389,52 +6388,37 @@ var wechatOnboardingAdapter = {
|
|
|
6389
6388
|
onEvent: (event) => {
|
|
6390
6389
|
switch (event.type) {
|
|
6391
6390
|
case "status":
|
|
6392
|
-
prompter.
|
|
6391
|
+
prompter.note?.(event.message, "Status");
|
|
6393
6392
|
break;
|
|
6394
6393
|
case "qr":
|
|
6395
|
-
prompter.
|
|
6396
|
-
if (event.qrData) {
|
|
6397
|
-
try {
|
|
6398
|
-
const qrTerminalMod = require_main();
|
|
6399
|
-
const qrInput = event.qrBinaryData ? Buffer.from(event.qrBinaryData).toString("utf-8") : event.qrData;
|
|
6400
|
-
qrTerminalMod.generate(qrInput, { small: true }, (qr) => {
|
|
6401
|
-
prompter.log?.(qr);
|
|
6402
|
-
});
|
|
6403
|
-
} catch {
|
|
6404
|
-
if (event.qrDataUrl) {
|
|
6405
|
-
prompter.log?.("(QR data URL available \u2014 open in browser to scan)");
|
|
6406
|
-
}
|
|
6407
|
-
}
|
|
6408
|
-
}
|
|
6409
|
-
prompter.log?.("\nWaiting for scan...\n");
|
|
6394
|
+
prompter.note?.("Scan QR code with WeChat", "Login");
|
|
6410
6395
|
break;
|
|
6411
6396
|
case "phone_confirm":
|
|
6412
|
-
prompter.
|
|
6413
|
-
|
|
6414
|
-
|
|
6415
|
-
`
|
|
6397
|
+
prompter.note?.(
|
|
6398
|
+
event.message || "Please confirm login on your phone",
|
|
6399
|
+
"Confirm"
|
|
6416
6400
|
);
|
|
6417
6401
|
break;
|
|
6418
6402
|
case "login_success":
|
|
6419
|
-
prompter.
|
|
6403
|
+
prompter.note?.("Login successful!", "Done");
|
|
6420
6404
|
break;
|
|
6421
6405
|
case "login_timeout":
|
|
6422
|
-
prompter.
|
|
6406
|
+
prompter.note?.("Login timed out. Please try again.", "Timeout");
|
|
6423
6407
|
break;
|
|
6424
6408
|
case "error":
|
|
6425
|
-
prompter.
|
|
6426
|
-
Error: ${event.message}`);
|
|
6409
|
+
prompter.note?.(`Error: ${event.message}`, "Error");
|
|
6427
6410
|
break;
|
|
6428
6411
|
}
|
|
6429
6412
|
}
|
|
6430
6413
|
});
|
|
6431
6414
|
} catch (err) {
|
|
6432
|
-
prompter.
|
|
6433
|
-
`Login failed: ${err instanceof Error ? err.message : String(err)}
|
|
6415
|
+
prompter.note?.(
|
|
6416
|
+
`Login failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
6417
|
+
"Error"
|
|
6434
6418
|
);
|
|
6435
6419
|
}
|
|
6436
6420
|
} else {
|
|
6437
|
-
await prompter.note
|
|
6421
|
+
await prompter.note(
|
|
6438
6422
|
"Run `openclaw channels login --channel wechat` later to link.",
|
|
6439
6423
|
"WeChat"
|
|
6440
6424
|
);
|
|
@@ -6444,54 +6428,45 @@ Error: ${event.message}`);
|
|
|
6444
6428
|
}
|
|
6445
6429
|
const dmPolicy = await prompter.select({
|
|
6446
6430
|
message: "DM (direct message) policy",
|
|
6447
|
-
|
|
6431
|
+
options: [
|
|
6448
6432
|
{ label: "Disabled \u2014 ignore all DMs", value: "disabled" },
|
|
6449
|
-
{
|
|
6450
|
-
label: "Allowlist \u2014 only respond to specific senders",
|
|
6451
|
-
value: "allowlist"
|
|
6452
|
-
},
|
|
6433
|
+
{ label: "Allowlist \u2014 only respond to specific senders", value: "allowlist" },
|
|
6453
6434
|
{ label: "Open \u2014 respond to all DMs", value: "open" }
|
|
6454
6435
|
]
|
|
6455
6436
|
});
|
|
6456
|
-
|
|
6437
|
+
wechatCfg.dmPolicy = dmPolicy;
|
|
6457
6438
|
if (dmPolicy === "allowlist") {
|
|
6458
|
-
const
|
|
6459
|
-
message: "Allowed WeChat IDs (wxid_xxx)
|
|
6460
|
-
hint: "Enter wxid values, press Enter after each. Empty line to finish."
|
|
6439
|
+
const raw = await prompter.text({
|
|
6440
|
+
message: "Allowed WeChat IDs (comma-separated wxid_xxx values)"
|
|
6461
6441
|
});
|
|
6462
|
-
|
|
6442
|
+
wechatCfg.allowFrom = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
6463
6443
|
}
|
|
6464
6444
|
const groupPolicy = await prompter.select({
|
|
6465
6445
|
message: "Group chat policy",
|
|
6466
|
-
|
|
6467
|
-
{
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
},
|
|
6471
|
-
{
|
|
6472
|
-
label: "Allowlist \u2014 only respond in specific groups",
|
|
6473
|
-
value: "allowlist"
|
|
6474
|
-
},
|
|
6475
|
-
{
|
|
6476
|
-
label: "Open \u2014 respond in all groups (when mentioned)",
|
|
6477
|
-
value: "open"
|
|
6478
|
-
}
|
|
6446
|
+
options: [
|
|
6447
|
+
{ label: "Disabled \u2014 ignore all group messages", value: "disabled" },
|
|
6448
|
+
{ label: "Allowlist \u2014 only respond in specific groups", value: "allowlist" },
|
|
6449
|
+
{ label: "Open \u2014 respond in all groups (when mentioned)", value: "open" }
|
|
6479
6450
|
]
|
|
6480
6451
|
});
|
|
6481
|
-
|
|
6452
|
+
wechatCfg.groupPolicy = groupPolicy;
|
|
6482
6453
|
if (groupPolicy === "allowlist") {
|
|
6483
|
-
const
|
|
6484
|
-
message: "Allowed group IDs (xxx@chatroom)
|
|
6485
|
-
hint: "Enter chatroom IDs, press Enter after each. Empty line to finish."
|
|
6454
|
+
const raw = await prompter.text({
|
|
6455
|
+
message: "Allowed group IDs (comma-separated xxx@chatroom values)"
|
|
6486
6456
|
});
|
|
6487
|
-
|
|
6457
|
+
wechatCfg.groupAllowFrom = raw.split(",").map((s) => s.trim()).filter(Boolean);
|
|
6488
6458
|
}
|
|
6489
|
-
|
|
6459
|
+
wechatCfg.enabled = true;
|
|
6460
|
+
const newCfg = {
|
|
6461
|
+
...cfg,
|
|
6462
|
+
channels: { ...cfg.channels, wechat: wechatCfg }
|
|
6463
|
+
};
|
|
6464
|
+
return { cfg: newCfg };
|
|
6490
6465
|
}
|
|
6491
6466
|
};
|
|
6492
6467
|
|
|
6493
6468
|
// src/status.ts
|
|
6494
|
-
|
|
6469
|
+
function collectWeChatStatusIssues(accounts) {
|
|
6495
6470
|
const issues = [];
|
|
6496
6471
|
for (const snapshot of accounts) {
|
|
6497
6472
|
if (!snapshot.connected) {
|
|
@@ -6548,7 +6523,8 @@ function createWeChatLoginTool(account) {
|
|
|
6548
6523
|
},
|
|
6549
6524
|
required: ["action"]
|
|
6550
6525
|
},
|
|
6551
|
-
execute: async (_toolCallId,
|
|
6526
|
+
execute: async (_toolCallId, params) => {
|
|
6527
|
+
const args = params;
|
|
6552
6528
|
const action = args.action;
|
|
6553
6529
|
const force = args.force;
|
|
6554
6530
|
const timeoutMs = args.timeoutMs;
|
|
@@ -6671,6 +6647,7 @@ var meta = {
|
|
|
6671
6647
|
label: "WeChat",
|
|
6672
6648
|
selectionLabel: "WeChat (\u5FAE\u4FE1)",
|
|
6673
6649
|
blurb: "WeChat messaging via agent-wechat container.",
|
|
6650
|
+
docsPath: "wechat",
|
|
6674
6651
|
aliases: ["weixin"],
|
|
6675
6652
|
order: 80
|
|
6676
6653
|
};
|
|
@@ -6787,14 +6764,16 @@ var wechatPlugin = {
|
|
|
6787
6764
|
cfg
|
|
6788
6765
|
);
|
|
6789
6766
|
if (!account?.serverUrl) {
|
|
6790
|
-
|
|
6767
|
+
throw new Error("No serverUrl configured");
|
|
6791
6768
|
}
|
|
6792
6769
|
const client = new WeChatClient({ baseUrl: account.serverUrl, token: account.token });
|
|
6793
6770
|
const result = await client.sendMessage({ chatId: to, text });
|
|
6771
|
+
if (!result.success) {
|
|
6772
|
+
throw new Error(result.error ?? "Send failed");
|
|
6773
|
+
}
|
|
6794
6774
|
return {
|
|
6795
6775
|
channel: "wechat",
|
|
6796
|
-
|
|
6797
|
-
error: result.error ?? void 0
|
|
6776
|
+
messageId: `wechat:${to}:${Date.now()}`
|
|
6798
6777
|
};
|
|
6799
6778
|
},
|
|
6800
6779
|
sendMedia: async ({ cfg, to, text, mediaUrl }) => {
|
|
@@ -6802,68 +6781,64 @@ var wechatPlugin = {
|
|
|
6802
6781
|
cfg
|
|
6803
6782
|
);
|
|
6804
6783
|
if (!account?.serverUrl) {
|
|
6805
|
-
|
|
6784
|
+
throw new Error("No serverUrl configured");
|
|
6806
6785
|
}
|
|
6807
6786
|
const client = new WeChatClient({ baseUrl: account.serverUrl, token: account.token });
|
|
6808
6787
|
if (mediaUrl) {
|
|
6809
|
-
|
|
6810
|
-
|
|
6811
|
-
|
|
6812
|
-
|
|
6813
|
-
|
|
6814
|
-
|
|
6815
|
-
|
|
6816
|
-
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6820
|
-
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
webp: "image/webp"
|
|
6833
|
-
};
|
|
6834
|
-
mimeType = extMime[ext] ?? "application/octet-stream";
|
|
6835
|
-
}
|
|
6836
|
-
const isImage = mimeType.startsWith("image/");
|
|
6837
|
-
const result2 = isImage ? await client.sendMessage({
|
|
6838
|
-
chatId: to,
|
|
6839
|
-
text: text || void 0,
|
|
6840
|
-
image: { data: base64, mimeType }
|
|
6841
|
-
}) : await client.sendMessage({
|
|
6842
|
-
chatId: to,
|
|
6843
|
-
text: text || void 0,
|
|
6844
|
-
file: { data: base64, filename }
|
|
6845
|
-
});
|
|
6846
|
-
return {
|
|
6847
|
-
channel: "wechat",
|
|
6848
|
-
ok: result2.success,
|
|
6849
|
-
error: result2.error ?? void 0
|
|
6850
|
-
};
|
|
6851
|
-
} catch (err) {
|
|
6852
|
-
return {
|
|
6853
|
-
channel: "wechat",
|
|
6854
|
-
ok: false,
|
|
6855
|
-
error: `Failed to send media: ${err}`
|
|
6788
|
+
const fsmod = await import("fs/promises");
|
|
6789
|
+
const pathmod = await import("path");
|
|
6790
|
+
let base64;
|
|
6791
|
+
let mimeType;
|
|
6792
|
+
let filename;
|
|
6793
|
+
if (mediaUrl.startsWith("http://") || mediaUrl.startsWith("https://")) {
|
|
6794
|
+
const res = await fetch(mediaUrl);
|
|
6795
|
+
const buffer = await res.arrayBuffer();
|
|
6796
|
+
base64 = Buffer.from(buffer).toString("base64");
|
|
6797
|
+
mimeType = res.headers.get("content-type") ?? "application/octet-stream";
|
|
6798
|
+
const urlPath = new URL(mediaUrl).pathname;
|
|
6799
|
+
filename = pathmod.basename(urlPath) || "file";
|
|
6800
|
+
} else {
|
|
6801
|
+
const buf = await fsmod.readFile(mediaUrl);
|
|
6802
|
+
base64 = buf.toString("base64");
|
|
6803
|
+
filename = pathmod.basename(mediaUrl);
|
|
6804
|
+
const ext = pathmod.extname(mediaUrl).toLowerCase().replace(".", "");
|
|
6805
|
+
const extMime = {
|
|
6806
|
+
png: "image/png",
|
|
6807
|
+
jpg: "image/jpeg",
|
|
6808
|
+
jpeg: "image/jpeg",
|
|
6809
|
+
gif: "image/gif",
|
|
6810
|
+
webp: "image/webp"
|
|
6856
6811
|
};
|
|
6812
|
+
mimeType = extMime[ext] ?? "application/octet-stream";
|
|
6813
|
+
}
|
|
6814
|
+
const isImage = mimeType.startsWith("image/");
|
|
6815
|
+
const result2 = isImage ? await client.sendMessage({
|
|
6816
|
+
chatId: to,
|
|
6817
|
+
text: text || void 0,
|
|
6818
|
+
image: { data: base64, mimeType }
|
|
6819
|
+
}) : await client.sendMessage({
|
|
6820
|
+
chatId: to,
|
|
6821
|
+
text: text || void 0,
|
|
6822
|
+
file: { data: base64, filename }
|
|
6823
|
+
});
|
|
6824
|
+
if (!result2.success) {
|
|
6825
|
+
throw new Error(result2.error ?? "Send media failed");
|
|
6857
6826
|
}
|
|
6827
|
+
return {
|
|
6828
|
+
channel: "wechat",
|
|
6829
|
+
messageId: `wechat:${to}:${Date.now()}`
|
|
6830
|
+
};
|
|
6858
6831
|
}
|
|
6859
6832
|
const result = await client.sendMessage({
|
|
6860
6833
|
chatId: to,
|
|
6861
6834
|
text: text || void 0
|
|
6862
6835
|
});
|
|
6836
|
+
if (!result.success) {
|
|
6837
|
+
throw new Error(result.error ?? "Send failed");
|
|
6838
|
+
}
|
|
6863
6839
|
return {
|
|
6864
6840
|
channel: "wechat",
|
|
6865
|
-
|
|
6866
|
-
error: result.error ?? void 0
|
|
6841
|
+
messageId: `wechat:${to}:${Date.now()}`
|
|
6867
6842
|
};
|
|
6868
6843
|
}
|
|
6869
6844
|
},
|
|
@@ -6882,7 +6857,8 @@ var wechatPlugin = {
|
|
|
6882
6857
|
cfg: ctx.cfg
|
|
6883
6858
|
});
|
|
6884
6859
|
},
|
|
6885
|
-
loginWithQrStart: async ({
|
|
6860
|
+
loginWithQrStart: async ({ accountId, force, timeoutMs }) => {
|
|
6861
|
+
const cfg = getWeChatRuntime().config.loadConfig();
|
|
6886
6862
|
const account = resolveWeChatAccount(
|
|
6887
6863
|
cfg,
|
|
6888
6864
|
accountId ?? void 0
|
|
@@ -6892,7 +6868,7 @@ var wechatPlugin = {
|
|
|
6892
6868
|
}
|
|
6893
6869
|
const client = new WeChatClient({ baseUrl: account.serverUrl, token: account.token });
|
|
6894
6870
|
try {
|
|
6895
|
-
const result = await loginStart(client, accountId, { timeoutMs, force });
|
|
6871
|
+
const result = await loginStart(client, accountId ?? DEFAULT_ACCOUNT_ID2, { timeoutMs, force });
|
|
6896
6872
|
return result;
|
|
6897
6873
|
} catch (err) {
|
|
6898
6874
|
return {
|
|
@@ -6900,7 +6876,8 @@ var wechatPlugin = {
|
|
|
6900
6876
|
};
|
|
6901
6877
|
}
|
|
6902
6878
|
},
|
|
6903
|
-
logoutAccount: async ({
|
|
6879
|
+
logoutAccount: async ({ accountId }) => {
|
|
6880
|
+
const cfg = getWeChatRuntime().config.loadConfig();
|
|
6904
6881
|
const account = resolveWeChatAccount(
|
|
6905
6882
|
cfg,
|
|
6906
6883
|
accountId ?? void 0
|
|
@@ -6915,7 +6892,7 @@ var wechatPlugin = {
|
|
|
6915
6892
|
}
|
|
6916
6893
|
},
|
|
6917
6894
|
loginWithQrWait: async ({ accountId, timeoutMs }) => {
|
|
6918
|
-
const result = await loginWait(accountId, { timeoutMs });
|
|
6895
|
+
const result = await loginWait(accountId ?? DEFAULT_ACCOUNT_ID2, { timeoutMs });
|
|
6919
6896
|
return result;
|
|
6920
6897
|
}
|
|
6921
6898
|
},
|
|
@@ -6999,11 +6976,11 @@ Error: ${event.message}`);
|
|
|
6999
6976
|
collectStatusIssues: collectWeChatStatusIssues
|
|
7000
6977
|
},
|
|
7001
6978
|
// ---- Agent tools adapter ----
|
|
7002
|
-
agentTools: ({ cfg }) => {
|
|
6979
|
+
agentTools: (({ cfg }) => {
|
|
7003
6980
|
const account = resolveWeChatAccount(cfg);
|
|
7004
6981
|
if (!account?.serverUrl) return [];
|
|
7005
6982
|
return [createWeChatLoginTool(account)];
|
|
7006
|
-
},
|
|
6983
|
+
}),
|
|
7007
6984
|
// ---- Directory adapter ----
|
|
7008
6985
|
directory: {
|
|
7009
6986
|
self: async ({ cfg }) => {
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-wechat/wechat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"openclaw.plugin.json"
|
|
8
8
|
],
|
|
9
9
|
"devDependencies": {
|
|
10
|
+
"@types/node": "^22",
|
|
10
11
|
"esbuild": "^0.25.0",
|
|
12
|
+
"openclaw": "^2026.2.22",
|
|
13
|
+
"typescript": "^5.4.5",
|
|
11
14
|
"@agent-wechat/shared": "0.1.0"
|
|
12
15
|
},
|
|
13
16
|
"openclaw": {
|
|
@@ -37,6 +40,7 @@
|
|
|
37
40
|
"directory": "packages/openclaw-extension"
|
|
38
41
|
},
|
|
39
42
|
"scripts": {
|
|
40
|
-
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --external:openclaw"
|
|
43
|
+
"build": "esbuild index.ts --bundle --format=esm --platform=node --outfile=dist/index.js --external:openclaw",
|
|
44
|
+
"typecheck": "tsc --noEmit"
|
|
41
45
|
}
|
|
42
46
|
}
|