@vanzxy/baileys 1.5.0 → 1.5.2
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 +94 -13
- package/package.json +1 -1
|
@@ -2679,24 +2679,105 @@ class AIRich extends BaseBuilder {
|
|
|
2679
2679
|
// the two calls expect different option shapes, so the fallback now only forwards `quoted`
|
|
2680
2680
|
// (the one option that clearly applies to both) instead of blindly spreading everything.
|
|
2681
2681
|
/** 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. */
|
|
2682
|
-
async send(jid, {
|
|
2682
|
+
async send(jid, {
|
|
2683
|
+
forwarded,
|
|
2684
|
+
notification,
|
|
2685
|
+
includesUnifiedResponse,
|
|
2686
|
+
includesSubmessages,
|
|
2687
|
+
skipImageFallback = false,
|
|
2688
|
+
nativeFallback = true,
|
|
2689
|
+
quoted,
|
|
2690
|
+
...options
|
|
2691
|
+
} = {}) {
|
|
2683
2692
|
const msg = await this.build({ forwarded, notification, includesUnifiedResponse, includesSubmessages, quoted, ...options });
|
|
2693
|
+
const sendOptions = quoted ? { quoted } : {};
|
|
2694
|
+
|
|
2695
|
+
// Native fallback is enabled by default because stock/third-party WhatsApp clients
|
|
2696
|
+
// do not reliably render botForwardedMessage.richResponseMessage. The rich payload
|
|
2697
|
+
// remains available through build()/relayMessage(), while send() uses ordinary WA
|
|
2698
|
+
// message types that are known to render immediately.
|
|
2699
|
+
if (nativeFallback) {
|
|
2700
|
+
const sent = [];
|
|
2701
|
+
|
|
2702
|
+
// 1) Send real WhatsApp media first. addImage()/addVideo()/addInlineImage()
|
|
2703
|
+
// already populate this queue with resolved URLs/buffers.
|
|
2704
|
+
if (!skipImageFallback && this._mediaFallbacks.length) {
|
|
2705
|
+
const fallbacks = await waitAllPromises(this._mediaFallbacks);
|
|
2706
|
+
for (const item of fallbacks) {
|
|
2707
|
+
try {
|
|
2708
|
+
const media = Buffer.isBuffer(item.url) ? item.url : { url: item.url };
|
|
2709
|
+
const content = { [item.type]: media };
|
|
2710
|
+
if (item.caption) content.caption = item.caption;
|
|
2711
|
+
if (item.mimetype) content.mimetype = item.mimetype;
|
|
2712
|
+
if (item.fileName) content.fileName = item.fileName;
|
|
2713
|
+
sent.push(await this.#client.sendMessage(jid, content, sendOptions));
|
|
2714
|
+
} catch (err) {
|
|
2715
|
+
this.#client.logger?.warn?.(
|
|
2716
|
+
{ err, url: item.url, type: item.type },
|
|
2717
|
+
'AIRich native media fallback failed'
|
|
2718
|
+
);
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
|
|
2723
|
+
// 2) Convert AIRich submessages into ordinary WhatsApp text. This preserves
|
|
2724
|
+
// every primitive's readable content even when the AI-only rich renderer is absent.
|
|
2725
|
+
const lines = [];
|
|
2726
|
+
for (const sub of await waitAllPromises(this._submessages)) {
|
|
2727
|
+
if (!sub) continue;
|
|
2728
|
+
|
|
2729
|
+
if (typeof sub.messageText === 'string' && sub.messageText.trim()) {
|
|
2730
|
+
const t = sub.messageText.trim();
|
|
2731
|
+
|
|
2732
|
+
// Media primitives already have a native media message above; don't emit
|
|
2733
|
+
// their internal placeholder text as a duplicate.
|
|
2734
|
+
if (
|
|
2735
|
+
t === '[ Video tidak dapat dimuat ]' ||
|
|
2736
|
+
t === '[ Postingan tidak dapat dimuat ]' ||
|
|
2737
|
+
t === '[ Produk tidak dapat dimuat ]' ||
|
|
2738
|
+
t === '[ Sedang diproses... ]'
|
|
2739
|
+
) continue;
|
|
2740
|
+
|
|
2741
|
+
lines.push(t);
|
|
2742
|
+
continue;
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
if (sub.codeMetadata) {
|
|
2746
|
+
const blocks = sub.codeMetadata.codeBlocks ?? [];
|
|
2747
|
+
const code = Array.isArray(blocks)
|
|
2748
|
+
? blocks.map((b) => typeof b === 'string' ? b : (b?.value ?? '')).join('')
|
|
2749
|
+
: String(blocks);
|
|
2750
|
+
lines.push('```' + (sub.codeMetadata.codeLanguage || '') + '\\n' + code + '\\n```');
|
|
2751
|
+
continue;
|
|
2752
|
+
}
|
|
2753
|
+
|
|
2754
|
+
if (sub.tableMetadata?.rows) {
|
|
2755
|
+
const rows = sub.tableMetadata.rows;
|
|
2756
|
+
if (Array.isArray(rows)) {
|
|
2757
|
+
lines.push(rows.map((row) => {
|
|
2758
|
+
const cells = Array.isArray(row) ? row : row?.cells;
|
|
2759
|
+
return Array.isArray(cells)
|
|
2760
|
+
? cells.map((c) => typeof c === 'string' ? c : (c?.text ?? c?.value ?? '')).join(' | ')
|
|
2761
|
+
: String(row);
|
|
2762
|
+
}).join('\\n'));
|
|
2763
|
+
}
|
|
2764
|
+
continue;
|
|
2765
|
+
}
|
|
2684
2766
|
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
for (const item of fallbacks) {
|
|
2688
|
-
try {
|
|
2689
|
-
const media = Buffer.isBuffer(item.url) ? item.url : { url: item.url };
|
|
2690
|
-
const content = { [item.type]: media };
|
|
2691
|
-
if (item.caption) content.caption = item.caption;
|
|
2692
|
-
if (item.mimetype) content.mimetype = item.mimetype;
|
|
2693
|
-
if (item.fileName) content.fileName = item.fileName;
|
|
2694
|
-
await this.#client.sendMessage(jid, content, quoted ? { quoted } : {});
|
|
2695
|
-
} catch (err) {
|
|
2696
|
-
this.#client.logger?.warn?.({ err, url: item.url, type: item.type }, 'AIRich media fallback failed, continuing with rich card');
|
|
2767
|
+
if (sub.latexMetadata?.text) {
|
|
2768
|
+
lines.push(sub.latexMetadata.text);
|
|
2697
2769
|
}
|
|
2698
2770
|
}
|
|
2771
|
+
|
|
2772
|
+
const text = lines.join('\\n\\n').trim();
|
|
2773
|
+
if (text) {
|
|
2774
|
+
sent.push(await this.#client.sendMessage(jid, { text }, sendOptions));
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
if (sent.length) return sent.length === 1 ? sent[0] : sent;
|
|
2699
2778
|
}
|
|
2779
|
+
|
|
2780
|
+
// Explicit compatibility mode: preserve the original AIRich rich payload.
|
|
2700
2781
|
return await this.#client.relayMessage(jid, msg, { ...options });
|
|
2701
2782
|
}
|
|
2702
2783
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanzxy/baileys",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
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",
|