@vanzxy/baileys 1.5.4 โ 1.5.6
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 +170 -1
- package/lib/Utils/MessageBuilder_d.ts +16 -0
- package/package.json +1 -1
|
@@ -44,7 +44,10 @@
|
|
|
44
44
|
|
|
45
45
|
'use strict';
|
|
46
46
|
|
|
47
|
-
const MESSAGE_BUILDER_VERSION = '4.9';
|
|
47
|
+
const MESSAGE_BUILDER_VERSION = '4.9.1';
|
|
48
|
+
// Vanz@Fix 24-08-26: use the exported builder version everywhere; the old
|
|
49
|
+
// verification helper referenced an undeclared `VERSION`, making every AIRich.build() fail.
|
|
50
|
+
|
|
48
51
|
|
|
49
52
|
import { generateWAMessageFromContent, prepareWAMessageMedia } from './messages.js';
|
|
50
53
|
import { generateMessageIDV2 } from './generics.js';
|
|
@@ -1009,6 +1012,106 @@ class Button extends BaseBuilder {
|
|
|
1009
1012
|
return this;
|
|
1010
1013
|
}
|
|
1011
1014
|
|
|
1015
|
+
|
|
1016
|
+
/** Native-flow `card_message` shortcut, matching this fork's prepareNativeFlowButtons(). */
|
|
1017
|
+
addCardMessage(payload = {}) {
|
|
1018
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) throw new TypeError('addCardMessage(payload) requires a plain object');
|
|
1019
|
+
this._buttons.push({ name: 'card_message', buttonParamsJson: JSON.stringify(payload) });
|
|
1020
|
+
return this;
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/** Native-flow `order_details` shortcut. */
|
|
1024
|
+
addOrderDetails(payload = {}) {
|
|
1025
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) throw new TypeError('addOrderDetails(payload) requires a plain object');
|
|
1026
|
+
this._buttons.push({ name: 'order_details', buttonParamsJson: JSON.stringify(payload) });
|
|
1027
|
+
return this;
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/** Native-flow `order_status` shortcut. */
|
|
1031
|
+
addOrderStatus(payload = {}) {
|
|
1032
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) throw new TypeError('addOrderStatus(payload) requires a plain object');
|
|
1033
|
+
this._buttons.push({ name: 'order_status', buttonParamsJson: JSON.stringify(payload) });
|
|
1034
|
+
return this;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
/** Native-flow `payment_status` shortcut. */
|
|
1038
|
+
addPaymentStatus(payload = {}) {
|
|
1039
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) throw new TypeError('addPaymentStatus(payload) requires a plain object');
|
|
1040
|
+
this._buttons.push({ name: 'payment_status', buttonParamsJson: JSON.stringify(payload) });
|
|
1041
|
+
return this;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/** Native-flow `payment_method` shortcut. */
|
|
1045
|
+
addPaymentMethod(payload = {}) {
|
|
1046
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) throw new TypeError('addPaymentMethod(payload) requires a plain object');
|
|
1047
|
+
this._buttons.push({ name: 'payment_method', buttonParamsJson: JSON.stringify(payload) });
|
|
1048
|
+
return this;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/** Native-flow `track_order` shortcut. */
|
|
1052
|
+
addTrackOrder(id, display_text = '๐ Track order') {
|
|
1053
|
+
if (!id) throw new TypeError('addTrackOrder(id) requires a non-empty id');
|
|
1054
|
+
this._buttons.push({ name: 'track_order', buttonParamsJson: JSON.stringify({ id, display_text }) });
|
|
1055
|
+
return this;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/** Native-flow `reorder` shortcut. */
|
|
1059
|
+
addReorder(id, display_text = '๐ Reorder') {
|
|
1060
|
+
if (!id) throw new TypeError('addReorder(id) requires a non-empty id');
|
|
1061
|
+
this._buttons.push({ name: 'reorder', buttonParamsJson: JSON.stringify({ id, display_text }) });
|
|
1062
|
+
return this;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
/** Native-flow `cancel_order` shortcut. */
|
|
1066
|
+
addCancelOrder(id, display_text = 'โ Cancel order') {
|
|
1067
|
+
if (!id) throw new TypeError('addCancelOrder(id) requires a non-empty id');
|
|
1068
|
+
this._buttons.push({ name: 'cancel_order', buttonParamsJson: JSON.stringify({ id, display_text }) });
|
|
1069
|
+
return this;
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/** Native-flow `clear_chat` shortcut. */
|
|
1073
|
+
addClearChat() {
|
|
1074
|
+
this._buttons.push({ name: 'clear_chat', buttonParamsJson: '{}' });
|
|
1075
|
+
return this;
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
/** Native-flow `navigateToScreen` shortcut. */
|
|
1079
|
+
addNavigateToScreen(screen, data = {}) {
|
|
1080
|
+
if (!screen) throw new TypeError('addNavigateToScreen(screen) requires a non-empty screen');
|
|
1081
|
+
this._buttons.push({ name: 'navigateToScreen', buttonParamsJson: JSON.stringify({ screen_name: screen, data }) });
|
|
1082
|
+
return this;
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1085
|
+
/** WhatsApp Flows `flow_action` shortcut. Requires a real registered Flow. */
|
|
1086
|
+
addFlow(flow = {}, display_text = '') {
|
|
1087
|
+
if (typeof flow !== 'object' || flow === null || Array.isArray(flow) || !flow.id) throw new TypeError('addFlow(flow) requires a plain object with flow.id');
|
|
1088
|
+
this._buttons.push({
|
|
1089
|
+
name: 'flow_action',
|
|
1090
|
+
buttonParamsJson: JSON.stringify({
|
|
1091
|
+
flow_message_version: flow.version || '3',
|
|
1092
|
+
flow_id: flow.id,
|
|
1093
|
+
flow_cta: display_text || flow.cta || 'Continue',
|
|
1094
|
+
flow_action: flow.action || 'navigate',
|
|
1095
|
+
flow_action_payload: flow.actionPayload || { screen: flow.screen || 'WELCOME', data: flow.data || {} },
|
|
1096
|
+
}),
|
|
1097
|
+
});
|
|
1098
|
+
return this;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/** Native-flow `voice_call` shortcut. */
|
|
1102
|
+
addVoiceCall(id, display_text = '๐ Voice call') {
|
|
1103
|
+
if (!id) throw new TypeError('addVoiceCall(id) requires a non-empty id');
|
|
1104
|
+
this._buttons.push({ name: 'voice_call', buttonParamsJson: JSON.stringify({ display_text, id }) });
|
|
1105
|
+
return this;
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/** Native-flow `video_call_button` shortcut. */
|
|
1109
|
+
addVideoCall(id, display_text = '๐ฅ Video call') {
|
|
1110
|
+
if (!id) throw new TypeError('addVideoCall(id) requires a non-empty id');
|
|
1111
|
+
this._buttons.push({ name: 'video_call_button', buttonParamsJson: JSON.stringify({ display_text, id }) });
|
|
1112
|
+
return this;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1012
1115
|
// Vanz@Fix (bug 43) --- paramsList documented the schema for these 3 message-level native flow
|
|
1013
1116
|
// params (limited_time_offer / bottom_sheet / tap_target_configuration) but no helper ever wrote
|
|
1014
1117
|
// them into this._params โ only manual setParams() could, with zero validation against the
|
|
@@ -1811,6 +1914,72 @@ class AIRich extends BaseBuilder {
|
|
|
1811
1914
|
}
|
|
1812
1915
|
|
|
1813
1916
|
/** Add a "Sources" strip. @param {string[]|string[][]} sources Flat list of urls, or `[title, url]` pairs. */
|
|
1917
|
+
|
|
1918
|
+
/** Build rich-response citation/link submessages using the same shape as Baileys' `links` content shortcut. */
|
|
1919
|
+
addLinks(links = []) {
|
|
1920
|
+
if (!Array.isArray(links)) throw new TypeError('links must be an array');
|
|
1921
|
+
links.forEach((linkField, index) => {
|
|
1922
|
+
if (!linkField || typeof linkField !== 'object') throw new TypeError('Each link must be an object');
|
|
1923
|
+
const prefix = 'SS_' + index;
|
|
1924
|
+
const url = linkField.url || '';
|
|
1925
|
+
const text = String(linkField.text ?? '');
|
|
1926
|
+
const sources = Array.isArray(linkField.sources) ? linkField.sources.map((sourceField) => ({
|
|
1927
|
+
source_type: 'THIRD_PARTY',
|
|
1928
|
+
source_display_name: sourceField?.displayName || sourceField?.title || 'Source',
|
|
1929
|
+
source_subtitle: sourceField?.subtitle || '',
|
|
1930
|
+
source_url: sourceField?.url || url,
|
|
1931
|
+
})) : [];
|
|
1932
|
+
const entity = {
|
|
1933
|
+
key: prefix,
|
|
1934
|
+
metadata: {
|
|
1935
|
+
reference_id: index + 1,
|
|
1936
|
+
reference_url: url,
|
|
1937
|
+
reference_title: linkField.title || 'Source',
|
|
1938
|
+
reference_display_name: linkField.displayName || linkField.title || 'Source',
|
|
1939
|
+
sources,
|
|
1940
|
+
__typename: 'GenAISearchCitationItem',
|
|
1941
|
+
},
|
|
1942
|
+
};
|
|
1943
|
+
const section = AIRich.newLayout('Single', {
|
|
1944
|
+
text: `${text} {{${prefix}}}${url}{{/${prefix}}}`,
|
|
1945
|
+
inline_entities: [entity],
|
|
1946
|
+
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
1947
|
+
});
|
|
1948
|
+
this._sections.push(section);
|
|
1949
|
+
this._submessages.push({
|
|
1950
|
+
messageType: 2,
|
|
1951
|
+
messageText: `${text} {{${prefix}}}ยน{{/${prefix}}} `,
|
|
1952
|
+
inlineEntities: [entity],
|
|
1953
|
+
});
|
|
1954
|
+
});
|
|
1955
|
+
return this;
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
/** Add a raw rich-response content-items carousel, matching Baileys' `items` field. */
|
|
1959
|
+
addContentItems(items = []) {
|
|
1960
|
+
if (!Array.isArray(items)) throw new TypeError('items must be an array');
|
|
1961
|
+
this._submessages.push({
|
|
1962
|
+
messageType: 9,
|
|
1963
|
+
contentItemsMetadata: { itemsMetadata: items, contentType: 1 },
|
|
1964
|
+
});
|
|
1965
|
+
this._sections.push(AIRich.newLayout('Single', {
|
|
1966
|
+
items,
|
|
1967
|
+
content_type: 1,
|
|
1968
|
+
__typename: 'GenAIContentItemsUXPrimitive',
|
|
1969
|
+
}));
|
|
1970
|
+
return this;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
/** Add Baileys-compatible inline-video marker. WhatsApp's current rich-response helper carries this as a text marker. */
|
|
1974
|
+
addInlineVideo() {
|
|
1975
|
+
this._submessages.push({ messageType: 2, messageText: 'INLINE_VIDEO' });
|
|
1976
|
+
this._sections.push(AIRich.newLayout('Single', {
|
|
1977
|
+
text: 'INLINE_VIDEO',
|
|
1978
|
+
__typename: 'GenAIMarkdownTextUXPrimitive',
|
|
1979
|
+
}));
|
|
1980
|
+
return this;
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1814
1983
|
addSource(sources = [], { resolveUrl = false } = {}) {
|
|
1815
1984
|
if (!(Array.isArray(sources) && (sources.every((item) => typeof item === 'string') || sources.every((item) => Array.isArray(item) && item.every((v) => typeof v === 'string'))))) {
|
|
1816
1985
|
throw new TypeError('Sources must be a string array or an array of string arrays');
|
|
@@ -74,6 +74,19 @@ export class Button extends BaseBuilder {
|
|
|
74
74
|
addTransactionDetails(payload?: Record<string, any>): this;
|
|
75
75
|
/** mpm โ multi-product message. Business-catalog accounts only. */
|
|
76
76
|
addMultiProduct(payload?: Record<string, any>): this;
|
|
77
|
+
addCardMessage(payload?: Record<string, any>): this;
|
|
78
|
+
addOrderDetails(payload?: Record<string, any>): this;
|
|
79
|
+
addOrderStatus(payload?: Record<string, any>): this;
|
|
80
|
+
addPaymentStatus(payload?: Record<string, any>): this;
|
|
81
|
+
addPaymentMethod(payload?: Record<string, any>): this;
|
|
82
|
+
addTrackOrder(id: string, display_text?: string): this;
|
|
83
|
+
addReorder(id: string, display_text?: string): this;
|
|
84
|
+
addCancelOrder(id: string, display_text?: string): this;
|
|
85
|
+
addClearChat(): this;
|
|
86
|
+
addNavigateToScreen(screen: string, data?: Record<string, any>): this;
|
|
87
|
+
addFlow(flow: Record<string, any>, display_text?: string): this;
|
|
88
|
+
addVoiceCall(id: string, display_text?: string): this;
|
|
89
|
+
addVideoCall(id: string, display_text?: string): this;
|
|
77
90
|
setLimitedTimeOffer(params?: LimitedTimeOfferParams): this;
|
|
78
91
|
setBottomSheet(params?: BottomSheetParams): this;
|
|
79
92
|
setTapTargetConfiguration(params?: TapTargetConfigurationParams): this;
|
|
@@ -147,6 +160,9 @@ export class AIRich extends BaseBuilder {
|
|
|
147
160
|
addText(text: string, options?: AddTextOptions): this;
|
|
148
161
|
addCode(language: string, code: string): this;
|
|
149
162
|
addTable(table: string[][], options?: AddTextOptions): this;
|
|
163
|
+
addLinks(links?: Record<string, any>[]): this;
|
|
164
|
+
addContentItems(items?: Record<string, any>[]): this;
|
|
165
|
+
addInlineVideo(): this;
|
|
150
166
|
addSource(sources?: Record<string, any>[], options?: { resolveUrl?: boolean }): this;
|
|
151
167
|
addReels(reelsItems?: Record<string, any>[], options?: { resolveUrl?: boolean }): this;
|
|
152
168
|
addImage(imageUrl: string, options?: { resolveUrl?: boolean }): this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanzxy/baileys",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
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",
|