@xmanrui/dsh-im 2.1.0 → 2.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/README.en.md +25 -8
- package/README.md +25 -8
- package/lib/client.js +142 -9
- package/lib/index.js +195 -175
- package/package.json +1 -1
- package/plugin-src/client/channels/whatsapp/index.js +1 -1
- package/plugin-src/client/i18n.js +5 -1
- package/plugin-src/client/index.js +72 -11
- package/plugin-src/client/loopback-recovery.js +75 -0
- package/plugin-src/client/styles.js +10 -0
- package/plugin-src/host/channels/shared/rpc.mjs +11 -0
- package/plugin-src/host/channels/weixin/production.mjs +5 -2
- package/src/channels/dingtalk/dingtalk-bridge.mjs +4 -2
- package/src/channels/feishu/feishu-cards.mjs +6 -2
- package/src/channels/qq/qq-bridge.mjs +4 -2
- package/src/channels/shared/harness-client.mjs +26 -2
- package/src/channels/shared/i18n-en/feishu.mjs +2 -3
- package/src/channels/shared/i18n-en/shared-a.mjs +8 -0
- package/src/channels/shared/i18n-en/shared-b.mjs +39 -0
- package/src/channels/shared/model-command.mjs +356 -27
- package/src/channels/shared/text-harness-bridge.mjs +4 -2
- package/src/channels/wecom/wecom-bridge.mjs +4 -2
- package/src/channels/weixin/weixin-api.mjs +2 -1
- package/src/channels/weixin/weixin-bridge.mjs +6 -3
- package/src/channels/weixin/weixin-runtime.mjs +2 -2
- package/src/channels/whatsapp/whatsapp-runtime.mjs +27 -6
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
1
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
areJidsSameUser,
|
|
@@ -217,9 +217,9 @@ export function normalizeWhatsappMessage(message, accountJid, {
|
|
|
217
217
|
const fromMe = message.key.fromMe === true;
|
|
218
218
|
const selfChat = fromMe && !group
|
|
219
219
|
&& [remoteJid, alternateRemoteJid].some((jid) => jid && areJidsSameUser(jid, accountJid));
|
|
220
|
-
if (fromMe && !selfChat) return null;
|
|
221
|
-
const senderJid =
|
|
222
|
-
const senderAlternateJid = group ? message.key.participantAlt : alternateRemoteJid;
|
|
220
|
+
if (fromMe && !selfChat && !group) return null;
|
|
221
|
+
const senderJid = fromMe ? accountJid : group ? message.key.participant : remoteJid;
|
|
222
|
+
const senderAlternateJid = group && !fromMe ? message.key.participantAlt : alternateRemoteJid;
|
|
223
223
|
if (typeof senderJid !== 'string' || !senderJid) return null;
|
|
224
224
|
const viewOnce = hasViewOnceWrapper(message.message);
|
|
225
225
|
const content = normalizeMessageContent(message.message);
|
|
@@ -241,7 +241,7 @@ export function normalizeWhatsappMessage(message, accountJid, {
|
|
|
241
241
|
content: messageText(content),
|
|
242
242
|
images: image ? [image] : [],
|
|
243
243
|
files: file ? [file] : [],
|
|
244
|
-
addressed: !group || mentioned || replyToSelf,
|
|
244
|
+
addressed: !group || fromMe || mentioned || replyToSelf,
|
|
245
245
|
selfChat,
|
|
246
246
|
replyTarget: { jid: remoteJid, quoted: message, selfChat },
|
|
247
247
|
};
|
|
@@ -272,6 +272,14 @@ class RecentWhatsappOutboundIds {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
remember(id) {
|
|
275
|
+
this.#store(id);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
reserve(id) {
|
|
279
|
+
this.#store(id);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
#store(id) {
|
|
275
283
|
if (typeof id !== 'string' || !id) return;
|
|
276
284
|
this.#purge();
|
|
277
285
|
this.#ids.set(id, Date.now() + 5 * 60_000);
|
|
@@ -360,10 +368,23 @@ export class WhatsappBotClient {
|
|
|
360
368
|
await this.#stopTyping(target.jid);
|
|
361
369
|
const providerMessageIds = [];
|
|
362
370
|
for (const [index, chunk] of splitMessageText(text, 4_000).entries()) {
|
|
371
|
+
const messageId = randomBytes(10).toString('hex').toUpperCase();
|
|
372
|
+
const options = {
|
|
373
|
+
...(index === 0 && target.quoted ? { quoted: target.quoted } : {}),
|
|
374
|
+
messageId,
|
|
375
|
+
};
|
|
376
|
+
// Linked-account group messages are valid inbound prompts in open mode.
|
|
377
|
+
// Reserve our own id before dispatch so an early local echo cannot loop
|
|
378
|
+
// back through the bridge as another owner-authored group prompt.
|
|
379
|
+
if (typeof this.#outboundIds.reserve === 'function') {
|
|
380
|
+
this.#outboundIds.reserve(messageId);
|
|
381
|
+
} else {
|
|
382
|
+
this.#outboundIds.remember(messageId);
|
|
383
|
+
}
|
|
363
384
|
const result = await this.#socket.sendMessage(
|
|
364
385
|
target.jid,
|
|
365
386
|
{ text: chunk },
|
|
366
|
-
|
|
387
|
+
options,
|
|
367
388
|
);
|
|
368
389
|
this.#outboundIds.remember(result?.key?.id);
|
|
369
390
|
if (typeof result?.key?.id === 'string' && result.key.id) {
|