@vanzxy/baileys 1.6.2 → 1.6.3
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 +42 -6
- package/package.json +1 -1
|
@@ -704,19 +704,44 @@ class Button extends BaseBuilder {
|
|
|
704
704
|
// error-prone (dangling ids, ordering), so this accepts a plain nested tree instead —
|
|
705
705
|
// { component, ...props, children: [...] } / { component, ...props, child: {...} } — and
|
|
706
706
|
// flattens it into that array itself, auto-assigning ids.
|
|
707
|
-
|
|
707
|
+
//
|
|
708
|
+
// Vanz@Fix 26-08-26 (v2) --- Modal is a different shape: `trigger`/`content` point to a
|
|
709
|
+
// SIBLING node by id (e.g. the Button that opens it), not a fresh child — captured traffic
|
|
710
|
+
// confirmed `{ trigger: "<id of an existing Button node>", content: "<id of its body>" }`.
|
|
711
|
+
// Nesting it as a plain `child`/`children` would duplicate the trigger node. So:
|
|
712
|
+
// - any prop whose value is `{ component: ..., ... }` is now auto-flattened as a nested
|
|
713
|
+
// node too (not just `child`/`children`) — covers Modal.content directly.
|
|
714
|
+
// - a node can carry a builder-only `ref: 'name'` tag; another prop can then point back
|
|
715
|
+
// at it with `{ $ref: 'name' }`, resolved to that node's real id after the whole tree
|
|
716
|
+
// is walked (order-independent). `ref` itself is stripped and never reaches the wire.
|
|
717
|
+
#flattenBloks(tree, out, ctx = { n: 0, refs: new Map(), pending: [] }, id = 'root') {
|
|
708
718
|
if (!tree || typeof tree !== 'object') throw new TypeError('setBloksWidget: every node needs a "component" type');
|
|
709
|
-
const { component, children, child, ...
|
|
719
|
+
const { component, children, child, ref, ...rest } = tree;
|
|
710
720
|
if (typeof component !== 'string' || !component) throw new TypeError('setBloksWidget: every node needs a "component" type');
|
|
711
721
|
|
|
712
|
-
const
|
|
722
|
+
const isTreeNode = (v) => v && typeof v === 'object' && !Array.isArray(v) && typeof v.component === 'string';
|
|
723
|
+
const isRefMarker = (v) => v && typeof v === 'object' && !Array.isArray(v) && typeof v.$ref === 'string' && Object.keys(v).length === 1;
|
|
724
|
+
|
|
725
|
+
const node = { id, component };
|
|
726
|
+
for (const [k, v] of Object.entries(rest)) {
|
|
727
|
+
if (isRefMarker(v)) {
|
|
728
|
+
node[k] = null; // resolved once the full tree (and its `ref` tags) has been walked
|
|
729
|
+
ctx.pending.push({ node, key: k, refName: v.$ref });
|
|
730
|
+
} else if (isTreeNode(v)) {
|
|
731
|
+
node[k] = this.#flattenBloks(v, out, ctx, `n${ctx.n++}`);
|
|
732
|
+
} else {
|
|
733
|
+
node[k] = v;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
713
736
|
|
|
714
737
|
if (Array.isArray(children)) {
|
|
715
|
-
node.children = children.map((c) => this.#flattenBloks(c, out,
|
|
738
|
+
node.children = children.map((c) => this.#flattenBloks(c, out, ctx, `n${ctx.n++}`));
|
|
716
739
|
} else if (child) {
|
|
717
|
-
node.child = this.#flattenBloks(child, out,
|
|
740
|
+
node.child = this.#flattenBloks(child, out, ctx, `n${ctx.n++}`);
|
|
718
741
|
}
|
|
719
742
|
|
|
743
|
+
if (ref) ctx.refs.set(ref, id);
|
|
744
|
+
|
|
720
745
|
out.push(node);
|
|
721
746
|
return id;
|
|
722
747
|
}
|
|
@@ -725,12 +750,23 @@ class Button extends BaseBuilder {
|
|
|
725
750
|
* Set a Bloks/A2UI native widget (`bloksWidget`, `type: "im_a2ui"`) — a real interactive
|
|
726
751
|
* screen (images, video, checkboxes, text fields, buttons that fire an `action`), not a
|
|
727
752
|
* static card. Pass a nested tree; ids are assigned automatically.
|
|
753
|
+
*
|
|
754
|
+
* For components that reference a SIBLING node instead of nesting one — currently just
|
|
755
|
+
* `Modal.trigger` — tag the source node with `ref: 'someName'` and point at it with
|
|
756
|
+
* `{ $ref: 'someName' }`. Everything else (including `Modal.content`) can just be nested
|
|
757
|
+
* directly, no special key needed.
|
|
728
758
|
* @param {Record<string, any>} tree Root node, e.g. `{ component: 'Column', children: [...] }`.
|
|
729
759
|
* @param {{uuid?: string, catalogId?: string, surfaceId?: string, version?: string}} [options]
|
|
730
760
|
*/
|
|
731
761
|
setBloksWidget(tree, { uuid = crypto.randomUUID(), catalogId = 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json', surfaceId, version = 'v0.9' } = {}) {
|
|
732
762
|
const components = [];
|
|
733
|
-
|
|
763
|
+
const ctx = { n: 0, refs: new Map(), pending: [] };
|
|
764
|
+
this.#flattenBloks(tree, components, ctx);
|
|
765
|
+
for (const { node, key, refName } of ctx.pending) {
|
|
766
|
+
const resolved = ctx.refs.get(refName);
|
|
767
|
+
if (!resolved) throw new Error(`setBloksWidget: ref "${refName}" (used on "${key}") was never declared with ref: "${refName}" on any node`);
|
|
768
|
+
node[key] = resolved;
|
|
769
|
+
}
|
|
734
770
|
|
|
735
771
|
this._bloksWidget = {
|
|
736
772
|
uuid,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanzxy/baileys",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.3",
|
|
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",
|