@henryxiaoyang/wechat-access-unqclawed 1.0.12 → 1.0.13

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.
Files changed (2) hide show
  1. package/index.ts +54 -50
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -199,63 +199,67 @@ const tencentAccessPlugin = {
199
199
  }
200
200
  } catch { /* non-fatal */ }
201
201
 
202
- // 7. 生成企微客服链接,等待设备绑定
203
- const OPEN_KFID = "wkzLlJLAAAfbxEV3ZcS-lHZxkaKmpejQ";
204
- runtime.log("\n[wechat-access] 生成企微客服链接...");
205
- const linkResult = await api.generateContactLink(OPEN_KFID);
206
- let deviceBound = false;
207
-
208
- if (!linkResult.success) {
209
- runtime.log(`[wechat-access] 生成链接失败: ${linkResult.message ?? "未知错误"}(跳过设备绑定)`);
210
- } else {
211
- const linkData = linkResult.data as Record<string, unknown>;
212
- const contactUrl =
213
- (nested(linkData, "url") as string) ||
214
- (nested(linkData, "data", "url") as string) ||
215
- "";
216
-
217
- if (!contactUrl) {
218
- runtime.log("[wechat-access] 返回数据中没有 URL(跳过设备绑定)");
202
+ // 7. 生成企微客服链接,等待设备绑定(非致命,token 已拿到)
203
+ try {
204
+ const OPEN_KFID = "wkzLlJLAAAfbxEV3ZcS-lHZxkaKmpejQ";
205
+ runtime.log("\n[wechat-access] 生成企微客服链接...");
206
+ const linkResult = await api.generateContactLink(OPEN_KFID);
207
+
208
+ if (!linkResult.success) {
209
+ runtime.log(`[wechat-access] 生成链接失败: ${linkResult.message ?? "未知错误"}(跳过设备绑定)`);
219
210
  } else {
220
- runtime.log("=".repeat(60));
221
- runtime.log(" 用微信扫描下方二维码,进入客服对话完成设备绑定");
222
- runtime.log("=".repeat(60));
211
+ const linkData = linkResult.data as Record<string, unknown>;
212
+ const contactUrl =
213
+ (nested(linkData, "url") as string) ||
214
+ (nested(linkData, "data", "url") as string) ||
215
+ "";
223
216
 
224
- try {
225
- const qrterm = await import("qrcode-terminal");
226
- const generate = qrterm.default?.generate ?? qrterm.generate;
227
- generate(contactUrl, { small: true }, (qrcode: string) => {
228
- runtime.log("\n" + qrcode);
229
- });
230
- } catch {
231
- runtime.log("(qrcode-terminal 不可用)");
232
- }
233
- runtime.log(`\n或手动打开: ${contactUrl}\n`);
217
+ if (!contactUrl) {
218
+ runtime.log("[wechat-access] 返回数据中没有 URL(跳过设备绑定)");
219
+ } else {
220
+ runtime.log("=".repeat(60));
221
+ runtime.log(" 用微信扫描下方二维码,进入客服对话完成设备绑定");
222
+ runtime.log("=".repeat(60));
234
223
 
235
- // 轮询等待绑定
236
- runtime.log("[wechat-access] 等待微信扫码绑定 (超时 5 分钟)...");
237
- const bindDeadline = Date.now() + 300_000;
238
- while (Date.now() < bindDeadline) {
239
- await new Promise((r) => setTimeout(r, 2000));
240
224
  try {
241
- const status = await api.queryDeviceByGuid();
242
- if (status.success) {
243
- const sd = status.data as Record<string, unknown>;
244
- const nick =
245
- (nested(sd, "nickname") as string) ||
246
- (nested(sd, "data", "nickname") as string);
247
- if (nick) {
248
- runtime.log(`[wechat-access] 设备绑定成功! 微信昵称: ${nick}`);
249
- deviceBound = true;
250
- break;
225
+ const qrterm = await import("qrcode-terminal");
226
+ const generate = qrterm.default?.generate ?? qrterm.generate;
227
+ generate(contactUrl, { small: true }, (qrcode: string) => {
228
+ runtime.log("\n" + qrcode);
229
+ });
230
+ } catch {
231
+ runtime.log("(qrcode-terminal 不可用)");
232
+ }
233
+ runtime.log(`\n或手动打开: ${contactUrl}\n`);
234
+
235
+ // 轮询等待绑定
236
+ runtime.log("[wechat-access] 等待微信扫码绑定 (超时 5 分钟)...");
237
+ const bindDeadline = Date.now() + 300_000;
238
+ let deviceBound = false;
239
+ while (Date.now() < bindDeadline) {
240
+ await new Promise((r) => setTimeout(r, 2000));
241
+ try {
242
+ const status = await api.queryDeviceByGuid();
243
+ if (status.success) {
244
+ const sd = status.data as Record<string, unknown>;
245
+ const nick =
246
+ (nested(sd, "nickname") as string) ||
247
+ (nested(sd, "data", "nickname") as string);
248
+ if (nick) {
249
+ runtime.log(`[wechat-access] 设备绑定成功! 微信昵称: ${nick}`);
250
+ deviceBound = true;
251
+ break;
252
+ }
251
253
  }
252
- }
253
- } catch { /* continue polling */ }
254
- }
255
- if (!deviceBound) {
256
- runtime.log("[wechat-access] 设备绑定超时,可稍后重新执行 channels login");
254
+ } catch { /* continue polling */ }
255
+ }
256
+ if (!deviceBound) {
257
+ runtime.log("[wechat-access] 设备绑定超时,可稍后重新执行 channels login");
258
+ }
257
259
  }
258
260
  }
261
+ } catch (e) {
262
+ runtime.log(`[wechat-access] 设备绑定失败(非致命): ${e instanceof Error ? e.message : String(e)}`);
259
263
  }
260
264
 
261
265
  // 写入 openclaw.json(统一存储)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryxiaoyang/wechat-access-unqclawed",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "description": "OpenClaw 微信通路插件 — 扫码登录 + AGP WebSocket 双向通信",
6
6
  "author": "HenryXiaoYang",