@vanzxy/baileys 1.5.3 → 1.5.4
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/lib/Utils/MessageBuilder.js +89 -5
- package/package.json +1 -1
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
const MESSAGE_BUILDER_VERSION = '4.9';
|
|
48
48
|
|
|
49
49
|
import { generateWAMessageFromContent, prepareWAMessageMedia } from './messages.js';
|
|
50
|
+
import { generateMessageIDV2 } from './generics.js';
|
|
50
51
|
import { botMetadataSignature, botMetadataCertificate } from './rich-message-utils.js';
|
|
51
52
|
import crypto from 'crypto';
|
|
52
53
|
import { PassThrough, Readable } from 'stream';
|
|
@@ -293,15 +294,19 @@ class Toolkit {
|
|
|
293
294
|
return await waitAllPromises(input);
|
|
294
295
|
}
|
|
295
296
|
|
|
296
|
-
/** Fetch `url` into a Buffer. @param {boolean} [silent] Return an empty Buffer instead of throwing on failure. */
|
|
297
|
-
static async fetchBuffer(url, options = {}, { silent = true } = {}) {
|
|
297
|
+
/** Fetch `url` into a Buffer. @param {boolean} [silent] Return an empty Buffer instead of throwing on failure. @param {number} [timeout] Abort after this many ms (default 15s) instead of hanging indefinitely on a dead/slow host. */
|
|
298
|
+
static async fetchBuffer(url, options = {}, { silent = true, timeout = 15000 } = {}) {
|
|
299
|
+
const controller = new AbortController();
|
|
300
|
+
const timer = setTimeout(() => controller.abort(), timeout);
|
|
298
301
|
try {
|
|
299
|
-
let response = await fetch(url, options);
|
|
302
|
+
let response = await fetch(url, { ...options, signal: options.signal ?? controller.signal });
|
|
300
303
|
if (!response.ok) throw Error(`HTTP ${response.status}`);
|
|
301
304
|
return Buffer.from(await response.arrayBuffer());
|
|
302
305
|
} catch (error) {
|
|
303
306
|
if (silent) return Buffer.alloc(0);
|
|
304
307
|
throw error;
|
|
308
|
+
} finally {
|
|
309
|
+
clearTimeout(timer);
|
|
305
310
|
}
|
|
306
311
|
}
|
|
307
312
|
|
|
@@ -1599,6 +1604,10 @@ class AIRich extends BaseBuilder {
|
|
|
1599
1604
|
this._responseId = null;
|
|
1600
1605
|
this._botResponseId = null;
|
|
1601
1606
|
|
|
1607
|
+
// Vanz@Add --- set by send()/sendEdit() after every relay so a follow-up sendEdit(), called
|
|
1608
|
+
// with no args, knows which jid/message id to patch in place (matches temen's v4.7 API).
|
|
1609
|
+
this._lastMessageKey = null;
|
|
1610
|
+
|
|
1602
1611
|
// Vanz@Add (v4.9.1) --- { id, insertAt } support for every add*()/set*() call, without
|
|
1603
1612
|
// touching each method's own body/signature. Every add*() call ends up pushing 0-N items
|
|
1604
1613
|
// onto _submessages and 0-N onto _sections (some push to both, some to just one — e.g.
|
|
@@ -2741,7 +2750,7 @@ class AIRich extends BaseBuilder {
|
|
|
2741
2750
|
// the two calls expect different option shapes, so the fallback now only forwards `quoted`
|
|
2742
2751
|
// (the one option that clearly applies to both) instead of blindly spreading everything.
|
|
2743
2752
|
/** Build and send this AI-rich message. @param {string} jid Destination chat/group jid. @param {boolean} [skipImageFallback] Skip auto-resending inline images as a plain imageMessage. */
|
|
2744
|
-
async send(jid, { forwarded, notification, includesUnifiedResponse, includesSubmessages, skipImageFallback = false, quoted, ...options } = {}) {
|
|
2753
|
+
async send(jid, { forwarded, notification, includesUnifiedResponse, includesSubmessages, skipImageFallback = false, quoted, messageId, ...options } = {}) {
|
|
2745
2754
|
const msg = await this.build({ forwarded, notification, includesUnifiedResponse, includesSubmessages, quoted, ...options });
|
|
2746
2755
|
|
|
2747
2756
|
if (!skipImageFallback && this._inlineImages.length) {
|
|
@@ -2755,7 +2764,82 @@ class AIRich extends BaseBuilder {
|
|
|
2755
2764
|
}
|
|
2756
2765
|
}
|
|
2757
2766
|
|
|
2758
|
-
|
|
2767
|
+
// Vanz@Add --- pin our own messageId (instead of letting relayMessage mint one internally)
|
|
2768
|
+
// so we know exactly which id was sent, and stash it as _lastMessageKey. That's what lets
|
|
2769
|
+
// sendEdit() be called with no args afterwards and still know which message to patch.
|
|
2770
|
+
messageId = messageId || generateMessageIDV2();
|
|
2771
|
+
|
|
2772
|
+
await this.#client.relayMessage(jid, msg, { messageId, ...options });
|
|
2773
|
+
|
|
2774
|
+
this._lastMessageKey = { remoteJid: jid, fromMe: true, id: messageId };
|
|
2775
|
+
|
|
2776
|
+
return { key: this._lastMessageKey, message: msg };
|
|
2777
|
+
}
|
|
2778
|
+
|
|
2779
|
+
/**
|
|
2780
|
+
* Build a `protocolMessage` (type EDIT) that patches an already-sent AIRich message in place.
|
|
2781
|
+
* @param {string} targetJid Chat the original message lives in.
|
|
2782
|
+
* @param {string} targetId `key.id` of the original message (the id `send()`/`sendEdit()` returned).
|
|
2783
|
+
* @param {object} [opts] Pass `{ msg }` to reuse an already-built content object instead of rebuilding via build().
|
|
2784
|
+
*/
|
|
2785
|
+
async buildEdit(targetJid, targetId, { msg, messageId, ...options } = {}) {
|
|
2786
|
+
const editedMessage = msg || (await this.build({ ...options }));
|
|
2787
|
+
|
|
2788
|
+
if (!editedMessage) {
|
|
2789
|
+
throw new Error('buildEdit: no message content to edit (build() returned nothing)');
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
return generateWAMessageFromContent(
|
|
2793
|
+
targetJid,
|
|
2794
|
+
{
|
|
2795
|
+
protocolMessage: {
|
|
2796
|
+
key: {
|
|
2797
|
+
remoteJid: targetJid,
|
|
2798
|
+
fromMe: true,
|
|
2799
|
+
id: targetId,
|
|
2800
|
+
},
|
|
2801
|
+
type: 14, // MESSAGE_EDIT
|
|
2802
|
+
editedMessage,
|
|
2803
|
+
},
|
|
2804
|
+
},
|
|
2805
|
+
{ messageId: messageId || generateMessageIDV2(), ...options }
|
|
2806
|
+
);
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
/**
|
|
2810
|
+
* Rebuild this AIRich message's current content and patch it into an already-sent message in place
|
|
2811
|
+
* (WA edits the bubble instead of showing a new one). With no args, edits the message from the last
|
|
2812
|
+
* send()/sendEdit() call — that's the flow `.addX(...); await rich.sendEdit();` relies on.
|
|
2813
|
+
* @param {string} [jid] Defaults to the jid from the last send()/sendEdit().
|
|
2814
|
+
* @param {string} [id] Defaults to the message id from the last send()/sendEdit().
|
|
2815
|
+
*/
|
|
2816
|
+
async sendEdit(jid, id, { msg, messageId, additionalNodes = [], ...options } = {}) {
|
|
2817
|
+
jid = jid ?? this._lastMessageKey?.remoteJid;
|
|
2818
|
+
id = id ?? this._lastMessageKey?.id;
|
|
2819
|
+
|
|
2820
|
+
if (!jid) {
|
|
2821
|
+
throw new Error('sendEdit: no jid — pass one explicitly, or call send() first');
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
if (!id) {
|
|
2825
|
+
throw new Error('sendEdit: no message id — pass one explicitly, or call send() first');
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
const msgEdit = await this.buildEdit(jid, id, {
|
|
2829
|
+
msg,
|
|
2830
|
+
messageId: messageId || generateMessageIDV2(),
|
|
2831
|
+
...options,
|
|
2832
|
+
});
|
|
2833
|
+
|
|
2834
|
+
await this.#client.relayMessage(jid, msgEdit.message, {
|
|
2835
|
+
messageId: msgEdit.key.id,
|
|
2836
|
+
additionalNodes,
|
|
2837
|
+
});
|
|
2838
|
+
|
|
2839
|
+
// Vanz@Note --- deliberately NOT overwriting _lastMessageKey with msgEdit.key here: the
|
|
2840
|
+
// protocolMessage envelope has its own id, but the message the user actually sees (and the
|
|
2841
|
+
// one future sendEdit() calls need to keep patching) is still `id`/`jid` above.
|
|
2842
|
+
return msgEdit;
|
|
2759
2843
|
}
|
|
2760
2844
|
|
|
2761
2845
|
/** Tokenize `code` into `{ type, value }` spans for syntax highlighting. Covers JS/TS/Python/Java and more; unsupported languages fall back to a single plain-text token. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanzxy/baileys",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Enhanced Baileys fork by Vanzxy — based on @itsliaaa/baileys + @whiskeysockets/baileys with fixes for audio group status and clean media without newsletter button.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./lib/index.js",
|