@vrs-soft/wecom-aibot-mcp 2.4.24 → 2.4.25
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/config-wizard.js +53 -8
- package/package.json +1 -1
package/dist/config-wizard.js
CHANGED
|
@@ -1450,25 +1450,70 @@ export async function runConfigWizard() {
|
|
|
1450
1450
|
docMcpUrl = currentDocUrl;
|
|
1451
1451
|
console.log('[config] 保持原文档 MCP URL');
|
|
1452
1452
|
}
|
|
1453
|
-
//
|
|
1453
|
+
// 第六步:目标用户(默认联系人)
|
|
1454
|
+
// 修改场景:询问是否要重新识别;选 Y 则连接 bot 等待用户消息(与 --add 一致);选 N 保持原值
|
|
1455
|
+
let targetUserId = targetRobot?.targetUserId || '';
|
|
1456
|
+
if (targetRobot) {
|
|
1457
|
+
console.log(`\n当前默认联系人(targetUserId): ${targetUserId || '(未设置)'}`);
|
|
1458
|
+
const changeContact = await question(rl, '是否重新识别?(y/N): ');
|
|
1459
|
+
if (changeContact.toLowerCase() === 'y') {
|
|
1460
|
+
// 临时连接 bot 等待用户消息以识别 userid
|
|
1461
|
+
console.log('\n[config] 正在连接企业微信验证凭证...');
|
|
1462
|
+
const { initClient } = await import('./client.js');
|
|
1463
|
+
const tmpClient = initClient(botId, secret, 'placeholder', 'config-detect');
|
|
1464
|
+
// 等待连接(最多10秒)
|
|
1465
|
+
const connected = await new Promise((resolve) => {
|
|
1466
|
+
const start = Date.now();
|
|
1467
|
+
const iv = setInterval(() => {
|
|
1468
|
+
if (tmpClient.isConnected()) {
|
|
1469
|
+
clearInterval(iv);
|
|
1470
|
+
resolve(true);
|
|
1471
|
+
}
|
|
1472
|
+
else if (Date.now() - start > 10000) {
|
|
1473
|
+
clearInterval(iv);
|
|
1474
|
+
resolve(false);
|
|
1475
|
+
}
|
|
1476
|
+
}, 500);
|
|
1477
|
+
});
|
|
1478
|
+
if (!connected) {
|
|
1479
|
+
console.log('[config] ❌ 连接失败(Bot ID/Secret 可能有误),保持原默认联系人');
|
|
1480
|
+
tmpClient.disconnect();
|
|
1481
|
+
}
|
|
1482
|
+
else {
|
|
1483
|
+
const detectedUserId = await detectUserIdFromMessage(tmpClient, 180);
|
|
1484
|
+
tmpClient.disconnect();
|
|
1485
|
+
if (detectedUserId) {
|
|
1486
|
+
targetUserId = detectedUserId;
|
|
1487
|
+
console.log(`[config] ✅ 默认联系人已更新: ${targetUserId}`);
|
|
1488
|
+
}
|
|
1489
|
+
else {
|
|
1490
|
+
console.log('[config] 未识别到用户消息,保持原默认联系人');
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
else {
|
|
1495
|
+
console.log('[config] 保持原默认联系人');
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
// 第七步:确认
|
|
1454
1499
|
console.log('\n─────────────────────────────────────');
|
|
1455
1500
|
console.log('配置确认:');
|
|
1456
|
-
console.log(` 机器人名称:
|
|
1457
|
-
console.log(` Bot ID:
|
|
1458
|
-
console.log(` Secret:
|
|
1459
|
-
console.log(` 文档 MCP:
|
|
1460
|
-
console.log(`
|
|
1501
|
+
console.log(` 机器人名称: ${robotName}`);
|
|
1502
|
+
console.log(` Bot ID: ${botId}`);
|
|
1503
|
+
console.log(` Secret: ${secret.slice(0, 8)}...${secret.slice(-4)}`);
|
|
1504
|
+
console.log(` 文档 MCP: ${docMcpUrl ? '✅ 已配置' : '(未配置)'}`);
|
|
1505
|
+
console.log(` 默认联系人: ${targetUserId || '(将通过消息自动识别)'}`);
|
|
1461
1506
|
console.log('─────────────────────────────────────\n');
|
|
1462
1507
|
const confirm = await question(rl, '确认配置?(Y/n): ');
|
|
1463
1508
|
if (confirm.toLowerCase() === 'n') {
|
|
1464
1509
|
console.log('[config] 配置已取消');
|
|
1465
1510
|
process.exit(0);
|
|
1466
1511
|
}
|
|
1467
|
-
//
|
|
1512
|
+
// 返回最终配置
|
|
1468
1513
|
const config = {
|
|
1469
1514
|
botId,
|
|
1470
1515
|
secret,
|
|
1471
|
-
targetUserId
|
|
1516
|
+
targetUserId, // 修改时保留 / 已变更,新建时为空(稍后识别)
|
|
1472
1517
|
nameTag: robotName,
|
|
1473
1518
|
...(docMcpUrl ? { doc_mcp_url: docMcpUrl } : {}),
|
|
1474
1519
|
};
|