omp-wechat 1.2.0 → 1.2.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 +25 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1322,7 +1322,7 @@ function saveSyncBuf(buf) {
|
|
|
1322
1322
|
mkdirSync2(STATE_DIR, { recursive: true });
|
|
1323
1323
|
writeFileSync(SYNC_BUF_FILE, buf);
|
|
1324
1324
|
}
|
|
1325
|
-
function extractInboundText(msg) {
|
|
1325
|
+
function extractInboundText(msg, includeImagePlaceholder = true) {
|
|
1326
1326
|
const items = msg.item_list ?? [];
|
|
1327
1327
|
const parts = [];
|
|
1328
1328
|
let imgCount = 0;
|
|
@@ -1346,9 +1346,9 @@ function extractInboundText(msg) {
|
|
|
1346
1346
|
break;
|
|
1347
1347
|
}
|
|
1348
1348
|
}
|
|
1349
|
-
if (imgCount > 0 && parts.length === 0) {
|
|
1349
|
+
if (includeImagePlaceholder && imgCount > 0 && parts.length === 0) {
|
|
1350
1350
|
parts.push(`(user sent ${imgCount} image${imgCount > 1 ? "s" : ""})`);
|
|
1351
|
-
} else if (imgCount > 0) {
|
|
1351
|
+
} else if (includeImagePlaceholder && imgCount > 0) {
|
|
1352
1352
|
parts.push(`(+${imgCount} image${imgCount > 1 ? "s" : ""})`);
|
|
1353
1353
|
}
|
|
1354
1354
|
return parts.join(`
|
|
@@ -2357,34 +2357,42 @@ class WeChatBridge {
|
|
|
2357
2357
|
if (result.action === "pair") {
|
|
2358
2358
|
if (contextToken) {
|
|
2359
2359
|
const lead = result.isResend ? "Still waiting for pairing" : "Pairing required";
|
|
2360
|
-
const
|
|
2361
|
-
await sendMessage(creds, senderId,
|
|
2360
|
+
const text = `${lead} \u2014 approve in OMP with: /wechat pair ${result.code}`;
|
|
2361
|
+
await sendMessage(creds, senderId, text, contextToken).catch((err) => {
|
|
2362
2362
|
logger.warn("Pairing reply send failed:", err);
|
|
2363
2363
|
});
|
|
2364
2364
|
}
|
|
2365
2365
|
return;
|
|
2366
2366
|
}
|
|
2367
|
-
|
|
2368
|
-
if (!text)
|
|
2367
|
+
if (!(msg.item_list ?? []).length)
|
|
2369
2368
|
return;
|
|
2370
|
-
const
|
|
2369
|
+
const rawText = (msg.item_list ?? []).filter((item) => item.type === 1).map((item) => item.text_item?.text ?? "").filter(Boolean).join(`
|
|
2370
|
+
`);
|
|
2371
|
+
const hasImages = (msg.item_list ?? []).some((item) => item.type === 2);
|
|
2372
|
+
const dedupKey = makeDedupKey(senderId, msg.create_time_ms, rawText || "(image)");
|
|
2371
2373
|
if (dedupKey && isDuplicate(dedupKey)) {
|
|
2372
|
-
logger.info(`[${senderId}] Skipping duplicate message: ${
|
|
2374
|
+
logger.info(`[${senderId}] Skipping duplicate message: ${(rawText || "(image)").slice(0, 80)}`);
|
|
2373
2375
|
return;
|
|
2374
2376
|
}
|
|
2375
2377
|
const config = loadConfig();
|
|
2376
|
-
logger.info(`[${senderId}] Inbound (ts=${msg.create_time_ms ?? "n/a"}): ${
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2378
|
+
logger.info(`[${senderId}] Inbound (ts=${msg.create_time_ms ?? "n/a"}): ${(rawText || "(image)").slice(0, 80)}`);
|
|
2379
|
+
if (rawText) {
|
|
2380
|
+
const invocation = this.commands.tryParse(rawText);
|
|
2381
|
+
if (invocation) {
|
|
2382
|
+
const reply = await invocation.execute({ pool: this.pool, config, chatId: senderId }).catch((err) => `Command failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
2383
|
+
await sendMessage(creds, senderId, reply, contextToken).catch((err) => {
|
|
2384
|
+
logger.warn(`[${senderId}] Command reply send failed:`, err);
|
|
2385
|
+
});
|
|
2386
|
+
return;
|
|
2387
|
+
}
|
|
2384
2388
|
}
|
|
2385
2389
|
await sendTyping(creds, senderId, 1).catch(() => {});
|
|
2386
2390
|
try {
|
|
2387
2391
|
const session = await this.pool.ensure(senderId, contextToken, config);
|
|
2392
|
+
const hasVision = session.supportsVision();
|
|
2393
|
+
const text = extractInboundText(msg, !hasVision);
|
|
2394
|
+
if (!text && !hasImages)
|
|
2395
|
+
return;
|
|
2388
2396
|
const images = await this.downloadImages(creds, msg, senderId);
|
|
2389
2397
|
await session.prompt(text, images);
|
|
2390
2398
|
} catch (err) {
|