@jexkcode/baileys 1.1.5 → 1.3.0
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.md +29 -0
- package/lib/Builders/A2UI.d.ts +275 -0
- package/lib/Builders/A2UI.js +422 -0
- package/lib/Socket/index.js +25 -0
- package/lib/Utils/auto-reconnect.d.ts +54 -0
- package/lib/Utils/auto-reconnect.js +214 -0
- package/lib/Utils/chat-export.d.ts +52 -0
- package/lib/Utils/chat-export.js +248 -0
- package/lib/Utils/index.d.ts +7 -0
- package/lib/Utils/index.js +7 -0
- package/lib/Utils/message-search.d.ts +44 -0
- package/lib/Utils/message-search.js +250 -0
- package/lib/Utils/messages.js +90 -1
- package/lib/Utils/mini-app.d.ts +93 -0
- package/lib/Utils/mini-app.js +447 -0
- package/lib/Utils/mock-socket.d.ts +60 -0
- package/lib/Utils/mock-socket.js +253 -0
- package/lib/Utils/rich-message-utils.js +75 -0
- package/lib/Utils/transcribe.d.ts +12 -0
- package/lib/Utils/transcribe.js +107 -0
- package/lib/Utils/username.d.ts +3 -0
- package/lib/Utils/username.js +73 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/** Search and text-extraction helpers for @japofc/baileys message objects. */
|
|
2
|
+
|
|
3
|
+
const WRAPPER_KEYS = [
|
|
4
|
+
'ephemeralMessage',
|
|
5
|
+
'viewOnceMessage',
|
|
6
|
+
'viewOnceMessageV2',
|
|
7
|
+
'viewOnceMessageV2Extension',
|
|
8
|
+
'documentWithCaptionMessage',
|
|
9
|
+
'editedMessage'
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const unwrapMessageContent = (messageOrContent) => {
|
|
13
|
+
let content = messageOrContent?.message ?? messageOrContent;
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < 8 && content && typeof content === 'object'; i++) {
|
|
17
|
+
if (seen.has(content)) break;
|
|
18
|
+
seen.add(content);
|
|
19
|
+
|
|
20
|
+
let next;
|
|
21
|
+
for (const key of WRAPPER_KEYS) {
|
|
22
|
+
next = content?.[key]?.message;
|
|
23
|
+
if (next) break;
|
|
24
|
+
}
|
|
25
|
+
if (!next) break;
|
|
26
|
+
content = next;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return content;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const firstText = (...values) => {
|
|
33
|
+
for (const value of values) {
|
|
34
|
+
if (typeof value === 'string' && value.length > 0) return value;
|
|
35
|
+
}
|
|
36
|
+
return '';
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const combine = (...values) => values.filter((value) => typeof value === 'string' && value.length > 0).join('\n');
|
|
40
|
+
|
|
41
|
+
const messageTimestampToDate = (timestamp) => {
|
|
42
|
+
if (timestamp === undefined || timestamp === null) return null;
|
|
43
|
+
const seconds = typeof timestamp === 'number'
|
|
44
|
+
? timestamp
|
|
45
|
+
: typeof timestamp?.toNumber === 'function'
|
|
46
|
+
? timestamp.toNumber()
|
|
47
|
+
: Number(timestamp);
|
|
48
|
+
return Number.isFinite(seconds) ? new Date(seconds * 1000) : null;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const extractMessageText = (message) => {
|
|
52
|
+
const content = unwrapMessageContent(message);
|
|
53
|
+
if (!content) return '';
|
|
54
|
+
|
|
55
|
+
return firstText(
|
|
56
|
+
content.conversation,
|
|
57
|
+
content.extendedTextMessage?.text,
|
|
58
|
+
content.imageMessage?.caption,
|
|
59
|
+
content.videoMessage?.caption,
|
|
60
|
+
content.documentMessage?.caption,
|
|
61
|
+
content.documentMessage?.fileName,
|
|
62
|
+
content.locationMessage?.name,
|
|
63
|
+
content.locationMessage?.address,
|
|
64
|
+
content.contactMessage?.displayName,
|
|
65
|
+
content.contactsArrayMessage?.displayName,
|
|
66
|
+
content.pollCreationMessage?.name,
|
|
67
|
+
content.pollCreationMessageV2?.name,
|
|
68
|
+
content.pollCreationMessageV3?.name,
|
|
69
|
+
content.pollCreationMessageV4?.name,
|
|
70
|
+
content.pollCreationMessageV5?.name,
|
|
71
|
+
content.pollCreationMessageV6?.name,
|
|
72
|
+
content.groupInviteMessage?.caption,
|
|
73
|
+
content.groupInviteMessage?.groupName,
|
|
74
|
+
content.liveLocationMessage?.caption,
|
|
75
|
+
content.orderMessage?.message,
|
|
76
|
+
content.buttonsMessage?.contentText,
|
|
77
|
+
content.listMessage?.description,
|
|
78
|
+
content.listMessage?.title,
|
|
79
|
+
content.templateMessage?.hydratedTemplate?.hydratedContentText,
|
|
80
|
+
content.interactiveMessage?.body?.text,
|
|
81
|
+
content.interactiveMessage?.header?.title,
|
|
82
|
+
content.requestPaymentMessage?.noteMessage ? extractMessageText({ message: content.requestPaymentMessage.noteMessage }) : '',
|
|
83
|
+
content.productMessage?.product ? combine(content.productMessage.product.title, content.productMessage.product.description) : '',
|
|
84
|
+
content.eventMessage ? combine(content.eventMessage.name, content.eventMessage.description) : ''
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const getMessageType = (message) => {
|
|
89
|
+
const content = unwrapMessageContent(message);
|
|
90
|
+
if (!content) return 'other';
|
|
91
|
+
if (content.conversation || content.extendedTextMessage) return 'text';
|
|
92
|
+
if (content.imageMessage) return 'image';
|
|
93
|
+
if (content.videoMessage) return 'video';
|
|
94
|
+
if (content.documentMessage) return 'document';
|
|
95
|
+
if (content.audioMessage) return 'audio';
|
|
96
|
+
if (content.stickerMessage) return 'sticker';
|
|
97
|
+
if (content.locationMessage || content.liveLocationMessage) return 'location';
|
|
98
|
+
if (content.contactMessage || content.contactsArrayMessage) return 'contact';
|
|
99
|
+
return 'other';
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const passesFilters = (message, options) => {
|
|
103
|
+
if (options.jid && message.key?.remoteJid !== options.jid) return false;
|
|
104
|
+
if (options.fromSender && message.key?.participant !== options.fromSender) return false;
|
|
105
|
+
if (options.fromMe !== undefined && message.key?.fromMe !== options.fromMe) return false;
|
|
106
|
+
|
|
107
|
+
if (options.fromDate || options.toDate) {
|
|
108
|
+
const date = messageTimestampToDate(message.messageTimestamp);
|
|
109
|
+
if (date) {
|
|
110
|
+
if (options.fromDate && date < options.fromDate) return false;
|
|
111
|
+
if (options.toDate && date > options.toDate) return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (options.messageTypes?.length && !options.messageTypes.includes(getMessageType(message))) return false;
|
|
116
|
+
return true;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const calculateRelevance = (query, text, position) => {
|
|
120
|
+
if (position < 0) return 0;
|
|
121
|
+
|
|
122
|
+
const source = String(text);
|
|
123
|
+
const needle = String(query);
|
|
124
|
+
const lowerSource = source.toLowerCase();
|
|
125
|
+
const lowerNeedle = needle.toLowerCase();
|
|
126
|
+
let score = 100;
|
|
127
|
+
|
|
128
|
+
if (lowerSource === lowerNeedle) score += 50;
|
|
129
|
+
if (position === 0) score += 20;
|
|
130
|
+
else if (/\s|[.,!?;:()[\]{}"']/.test(lowerSource[position - 1] ?? '')) score += 10;
|
|
131
|
+
|
|
132
|
+
const after = position + lowerNeedle.length;
|
|
133
|
+
if (after === source.length) score += 10;
|
|
134
|
+
else if (/\s|[.,!?;:()[\]{}"']/.test(lowerSource[after] ?? '')) score += 10;
|
|
135
|
+
|
|
136
|
+
score -= Math.min(position / 10, 20);
|
|
137
|
+
return Math.max(0, score);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** Plain-text substring search with relevance-sorted results. */
|
|
141
|
+
export const searchMessages = (messages, query, options = {}) => {
|
|
142
|
+
const results = [];
|
|
143
|
+
const needle = options.caseSensitive ? String(query) : String(query).toLowerCase();
|
|
144
|
+
if (!needle) return results;
|
|
145
|
+
|
|
146
|
+
for (const message of messages) {
|
|
147
|
+
if (!passesFilters(message, options)) continue;
|
|
148
|
+
|
|
149
|
+
const text = extractMessageText(message);
|
|
150
|
+
if (!text) continue;
|
|
151
|
+
|
|
152
|
+
const haystack = options.caseSensitive ? text : text.toLowerCase();
|
|
153
|
+
const position = haystack.indexOf(needle);
|
|
154
|
+
if (position === -1) continue;
|
|
155
|
+
|
|
156
|
+
results.push({
|
|
157
|
+
message,
|
|
158
|
+
matchedText: text.slice(Math.max(0, position - 20), Math.min(text.length, position + String(query).length + 20)),
|
|
159
|
+
matchPosition: position,
|
|
160
|
+
relevanceScore: calculateRelevance(query, text, position)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
results.sort((a, b) => b.relevanceScore - a.relevanceScore);
|
|
165
|
+
return options.limit ? results.slice(0, options.limit) : results;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/** Regex-based search for bot commands, structured tags, or custom patterns. */
|
|
169
|
+
export const searchMessagesRegex = (messages, pattern, options = {}) => {
|
|
170
|
+
const results = [];
|
|
171
|
+
const flags = pattern.flags.replace(/g/g, '');
|
|
172
|
+
|
|
173
|
+
for (const message of messages) {
|
|
174
|
+
if (!passesFilters(message, options)) continue;
|
|
175
|
+
|
|
176
|
+
const text = extractMessageText(message);
|
|
177
|
+
if (!text) continue;
|
|
178
|
+
|
|
179
|
+
const regex = new RegExp(pattern.source, flags);
|
|
180
|
+
const match = regex.exec(text);
|
|
181
|
+
if (!match) continue;
|
|
182
|
+
|
|
183
|
+
results.push({
|
|
184
|
+
message,
|
|
185
|
+
matchedText: match[0],
|
|
186
|
+
matchPosition: match.index ?? 0,
|
|
187
|
+
relevanceScore: 100
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (options.limit && results.length >= options.limit) break;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return results;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/** Standalone searchable index; feed it messages independently of the main Store. */
|
|
197
|
+
export class MessageSearchManager {
|
|
198
|
+
messages = [];
|
|
199
|
+
messageIndex = new Map();
|
|
200
|
+
|
|
201
|
+
addMessages(messages) {
|
|
202
|
+
for (const message of messages) {
|
|
203
|
+
const id = message.key?.id;
|
|
204
|
+
if (!id || this.messageIndex.has(id)) continue;
|
|
205
|
+
this.messages.push(message);
|
|
206
|
+
this.messageIndex.set(id, message);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
removeMessages(messageIds) {
|
|
211
|
+
const ids = new Set(messageIds);
|
|
212
|
+
this.messages = this.messages.filter((message) => !ids.has(message.key?.id || ''));
|
|
213
|
+
for (const id of ids) this.messageIndex.delete(id);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
clear() {
|
|
217
|
+
this.messages = [];
|
|
218
|
+
this.messageIndex.clear();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
get count() {
|
|
222
|
+
return this.messages.length;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
search(query, options) {
|
|
226
|
+
return searchMessages(this.messages, query, options);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
searchRegex(pattern, options) {
|
|
230
|
+
return searchMessagesRegex(this.messages, pattern, options);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
getByJid(jid) {
|
|
234
|
+
return this.messages.filter((message) => message.key?.remoteJid === jid);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
getBySender(sender) {
|
|
238
|
+
return this.messages.filter((message) => message.key?.participant === sender || message.key?.remoteJid === sender);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
getByType(type) {
|
|
242
|
+
return this.messages.filter((message) => getMessageType(message) === type);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
getById(id) {
|
|
246
|
+
return this.messageIndex.get(id);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export const createMessageSearch = () => new MessageSearchManager();
|
package/lib/Utils/messages.js
CHANGED
|
@@ -9,7 +9,7 @@ import { isLidUser, isPnUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast,
|
|
|
9
9
|
import { sha256 } from './crypto.js';
|
|
10
10
|
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
11
11
|
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getImageProcessingLibrary, getRawMediaUploadData, getStream, toBuffer } from './messages-media.js';
|
|
12
|
-
import { prepareRichResponseMessage } from './rich-message-utils.js';
|
|
12
|
+
import { prepareHtmlRichMessage, prepareRichResponseMessage } from './rich-message-utils.js';
|
|
13
13
|
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
14
14
|
const CONCURRENCY_LIMIT = 15;
|
|
15
15
|
const MIMETYPE_MAP = {
|
|
@@ -435,6 +435,69 @@ const prepareStickerPackMessage = async (message, options) => {
|
|
|
435
435
|
}
|
|
436
436
|
return WAProto.Message.StickerPackMessage.fromObject(obj);
|
|
437
437
|
};
|
|
438
|
+
// JexkCode@Port (from JAPofc/baileys, MIT) - extra native flow shortcuts.
|
|
439
|
+
// Dipakai di dalam nativeFlow: { webview, reminder, cancelReminder, address, location, catalog,
|
|
440
|
+
// products, flow, voiceCall, videoCall, clearChat, screen }. Tombol lain tetap lewat { name, buttonParamsJson }.
|
|
441
|
+
const nativeExtraButton = (button, buttonText, buttonIcon) => {
|
|
442
|
+
const has = (k) => hasOptionalProperty(button, k) && !!button[k];
|
|
443
|
+
if (has('webview') || has('openWebview')) {
|
|
444
|
+
const raw = button.webview ?? button.openWebview;
|
|
445
|
+
const wv = typeof raw === 'string' ? { url: raw } : (raw || {});
|
|
446
|
+
return {
|
|
447
|
+
name: 'open_webview',
|
|
448
|
+
buttonParamsJson: JSON.stringify({
|
|
449
|
+
title: buttonText || wv.title || '🌐 Open',
|
|
450
|
+
link: { url: wv.url, in_app_webview: wv.inAppWebview ?? wv.in_app_webview ?? true }
|
|
451
|
+
})
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
if (has('reminder')) {
|
|
455
|
+
return { name: 'cta_reminder', buttonParamsJson: JSON.stringify({ display_text: buttonText || '⏰ Remind me', id: button.id || button.reminder, icon: buttonIcon }) };
|
|
456
|
+
}
|
|
457
|
+
if (has('cancelReminder')) {
|
|
458
|
+
return { name: 'cta_cancel_reminder', buttonParamsJson: JSON.stringify({ display_text: buttonText || '🔕 Cancel reminder', id: button.id || button.cancelReminder, icon: buttonIcon }) };
|
|
459
|
+
}
|
|
460
|
+
if (has('address')) {
|
|
461
|
+
return { name: 'address_message', buttonParamsJson: JSON.stringify({ display_text: buttonText || '📍 Send address', id: button.id || 'address_message' }) };
|
|
462
|
+
}
|
|
463
|
+
if (hasOptionalProperty(button, 'location') && button.location === true) {
|
|
464
|
+
return { name: 'send_location', buttonParamsJson: JSON.stringify({}) };
|
|
465
|
+
}
|
|
466
|
+
if (has('catalog')) {
|
|
467
|
+
return { name: 'catalog_message', buttonParamsJson: JSON.stringify({ business_phone_number: button.catalog.bizJid || button.catalog, display_text: buttonText || '🛍️ View catalog', id: button.id || 'catalog_message' }) };
|
|
468
|
+
}
|
|
469
|
+
if (has('products')) {
|
|
470
|
+
return { name: 'mpm', buttonParamsJson: JSON.stringify({ business_phone_number: button.bizJid || button.products.bizJid, product_ids: Array.isArray(button.products) ? button.products : button.products.ids }) };
|
|
471
|
+
}
|
|
472
|
+
if (has('flow')) {
|
|
473
|
+
// butuh Flow ID yang sudah dipublish di akun bisnis kamu
|
|
474
|
+
const flow = typeof button.flow === 'string' ? { id: button.flow } : button.flow;
|
|
475
|
+
return {
|
|
476
|
+
name: 'flow',
|
|
477
|
+
buttonParamsJson: JSON.stringify({
|
|
478
|
+
flow_message_version: flow.version || '3',
|
|
479
|
+
flow_token: flow.token || generateMessageIDV2(),
|
|
480
|
+
flow_id: flow.id,
|
|
481
|
+
flow_cta: buttonText || flow.cta || 'Continue',
|
|
482
|
+
flow_action: flow.action || 'navigate',
|
|
483
|
+
flow_action_payload: flow.actionPayload || { screen: flow.screen || 'WELCOME', data: flow.data || {} }
|
|
484
|
+
})
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
if (has('voiceCall')) {
|
|
488
|
+
return { name: 'voice_call', buttonParamsJson: JSON.stringify({ display_text: buttonText || '📞 Voice call', id: button.id || button.voiceCall }) };
|
|
489
|
+
}
|
|
490
|
+
if (has('videoCall')) {
|
|
491
|
+
return { name: 'video_call_button', buttonParamsJson: JSON.stringify({ display_text: buttonText || '🎥 Video call', id: button.id || button.videoCall }) };
|
|
492
|
+
}
|
|
493
|
+
if (hasOptionalProperty(button, 'clearChat') && button.clearChat === true) {
|
|
494
|
+
return { name: 'clear_chat', buttonParamsJson: JSON.stringify({}) };
|
|
495
|
+
}
|
|
496
|
+
if (has('screen')) {
|
|
497
|
+
return { name: 'navigateToScreen', buttonParamsJson: JSON.stringify({ screen_name: button.screen, data: button.data || {} }) };
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
};
|
|
438
501
|
// JexkCode@Update - Add native flow button helper for interactive message
|
|
439
502
|
const prepareNativeFlowButtons = (message) => {
|
|
440
503
|
const buttons = message.nativeFlow;
|
|
@@ -466,6 +529,10 @@ const prepareNativeFlowButtons = (message) => {
|
|
|
466
529
|
buttons: correctedField.map(button => {
|
|
467
530
|
const buttonText = button.text || button.buttonText;
|
|
468
531
|
const buttonIcon = button.icon?.toUpperCase();
|
|
532
|
+
const extraButton = nativeExtraButton(button, buttonText, buttonIcon);
|
|
533
|
+
if (extraButton) {
|
|
534
|
+
return extraButton;
|
|
535
|
+
}
|
|
469
536
|
if (hasOptionalProperty(button, 'id') && !!button.id) {
|
|
470
537
|
return {
|
|
471
538
|
name: 'quick_reply',
|
|
@@ -606,6 +673,9 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
606
673
|
delete message.raw;
|
|
607
674
|
return message;
|
|
608
675
|
}
|
|
676
|
+
else if (hasNonNullishProperty(message, 'html')) {
|
|
677
|
+
m = prepareHtmlRichMessage(message);
|
|
678
|
+
}
|
|
609
679
|
// JexkCode@Update - Add support for code block and table with richResponseMessage
|
|
610
680
|
else if (hasNonNullishProperty(message, 'code') ||
|
|
611
681
|
hasNonNullishProperty(message, 'links') ||
|
|
@@ -803,6 +873,25 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
803
873
|
m.eventMessage.isScheduleCall = message.event.isScheduleCall ?? false;
|
|
804
874
|
m.eventMessage.location = message.event.location;
|
|
805
875
|
}
|
|
876
|
+
// JexkCode@Port (JAPofc/baileys, MIT) - scheduled call. callType: 'voice' (default) | 'video'
|
|
877
|
+
else if (hasNonNullishProperty(message, 'scheduledCall')) {
|
|
878
|
+
const sc = message.scheduledCall;
|
|
879
|
+
const ts = sc.scheduledAt instanceof Date ? sc.scheduledAt.getTime() : Number(sc.scheduledAt);
|
|
880
|
+
if (!Number.isFinite(ts) || ts <= 0) {
|
|
881
|
+
throw new Boom('Invalid scheduledCall.scheduledAt (expected a Date or epoch-ms number)', { statusCode: 400 });
|
|
882
|
+
}
|
|
883
|
+
m.scheduledCallCreationMessage = {
|
|
884
|
+
scheduledTimestampMs: ts,
|
|
885
|
+
callType: sc.callType === 'video' ? 2 : 1,
|
|
886
|
+
title: sc.title
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
else if (hasNonNullishProperty(message, 'scheduledCallEdit')) {
|
|
890
|
+
m.scheduledCallEditMessage = {
|
|
891
|
+
key: message.scheduledCallEdit.key,
|
|
892
|
+
editType: 1
|
|
893
|
+
};
|
|
894
|
+
}
|
|
806
895
|
else if (hasNonNullishProperty(message, 'poll')) {
|
|
807
896
|
(_a = message.poll).selectableCount || (_a.selectableCount = 0);
|
|
808
897
|
(_b = message.poll).toAnnouncementGroup || (_b.toAnnouncementGroup = false);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAP@Add --- Type declarations for the Mini App sender.
|
|
3
|
+
*/
|
|
4
|
+
export declare const MINI_APP_DEFAULT_BUTTON_TEXT: string;
|
|
5
|
+
export interface MiniAppFlowOptions {
|
|
6
|
+
id: string;
|
|
7
|
+
cta?: string;
|
|
8
|
+
screen?: string;
|
|
9
|
+
data?: any;
|
|
10
|
+
action?: string;
|
|
11
|
+
actionPayload?: any;
|
|
12
|
+
version?: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface MiniAppOptions {
|
|
16
|
+
title?: string;
|
|
17
|
+
body?: string;
|
|
18
|
+
text?: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
appUrl?: string;
|
|
21
|
+
flow?: string | MiniAppFlowOptions;
|
|
22
|
+
params?: Record<string, string | number | boolean>;
|
|
23
|
+
/** HMAC-SHA256 key; when set, the opener URL's params are signed (tamper-proof). */
|
|
24
|
+
secret?: string;
|
|
25
|
+
/** Opener-URL lifetime in seconds; signs an `exp` the web app can enforce. */
|
|
26
|
+
expiresIn?: number;
|
|
27
|
+
buttonText?: string;
|
|
28
|
+
buttons?: any[];
|
|
29
|
+
footer?: string;
|
|
30
|
+
thumbnail?: Buffer | string;
|
|
31
|
+
/** Toggle cta_url's (WA-ignored) `webview_interaction` flag. Default true. Kept for backward compatibility — for a REAL in-app webview use `openWebview`. */
|
|
32
|
+
useWebview?: boolean;
|
|
33
|
+
/** Emit a real native in-app webview button (`open_webview`) instead of `cta_url`. Default false (cta_url renders on regular accounts; open_webview needs the in-app-webview capability). */
|
|
34
|
+
openWebview?: boolean;
|
|
35
|
+
onThumbnailError?: (err: any) => void;
|
|
36
|
+
/** Remote thumbnail fetch timeout (default 10s). */
|
|
37
|
+
thumbnailTimeoutMs?: number;
|
|
38
|
+
/** Remote thumbnail byte cap (default 512 KiB). */
|
|
39
|
+
thumbnailMaxBytes?: number;
|
|
40
|
+
/** Allow localhost/private-IP thumbnail URLs. Off by default to reduce SSRF risk. */
|
|
41
|
+
allowPrivateThumbnail?: boolean;
|
|
42
|
+
thumbnailHeaders?: any;
|
|
43
|
+
dispatcher?: any;
|
|
44
|
+
fetchImpl?: typeof fetch;
|
|
45
|
+
[key: string]: any;
|
|
46
|
+
}
|
|
47
|
+
/** A parsed mini-app / WhatsApp Flow in-chat submission. */
|
|
48
|
+
export interface MiniAppResponse {
|
|
49
|
+
name?: string;
|
|
50
|
+
version?: number;
|
|
51
|
+
params: Record<string, any>;
|
|
52
|
+
flowToken?: string;
|
|
53
|
+
body?: string;
|
|
54
|
+
}
|
|
55
|
+
export declare const buildMiniAppContent: (opts?: MiniAppOptions) => Promise<any>;
|
|
56
|
+
export declare const sendMiniApp: (sock: any, jid: any, miniApp: MiniAppOptions, options?: any) => Promise<any>;
|
|
57
|
+
/** Single-use nonce store for one-time mini-app / webview links. */
|
|
58
|
+
export interface NonceStore {
|
|
59
|
+
/** Mint a fresh nonce to embed in a signed link (via createMiniAppLink's `nonce`). */
|
|
60
|
+
issue(size?: number): string;
|
|
61
|
+
/** Returns true exactly once per issued nonce; false for unknown/used/expired. */
|
|
62
|
+
consume(nonce: string): boolean;
|
|
63
|
+
has(nonce: string): boolean;
|
|
64
|
+
clear(): void;
|
|
65
|
+
readonly size: number;
|
|
66
|
+
}
|
|
67
|
+
export declare const createNonceStore: (opts?: { ttlMs?: number; max?: number; now?: () => number }) => NonceStore;
|
|
68
|
+
export interface MiniAppLinkOptions {
|
|
69
|
+
secret?: string;
|
|
70
|
+
expiresIn?: number;
|
|
71
|
+
/** Bind the link to one opener (e.g. recipient JID); rejected for anyone else. */
|
|
72
|
+
audience?: string | number;
|
|
73
|
+
/** One-time token to embed (pair with a NonceStore on the verify side). */
|
|
74
|
+
nonce?: string;
|
|
75
|
+
now?: () => number;
|
|
76
|
+
}
|
|
77
|
+
export interface MiniAppVerifyOptions {
|
|
78
|
+
secret?: string;
|
|
79
|
+
now?: () => number;
|
|
80
|
+
/** Require the link's `aud` to equal this value (403 on mismatch). */
|
|
81
|
+
audience?: string | number;
|
|
82
|
+
/** Consume a one-time nonce; 403 on unknown/used/expired. */
|
|
83
|
+
nonceStore?: NonceStore;
|
|
84
|
+
}
|
|
85
|
+
export declare const createMiniAppLink: (baseUrl: string, params?: Record<string, string | number | boolean>, opts?: MiniAppLinkOptions) => string;
|
|
86
|
+
export declare const parseMiniAppParams: (link: string, opts?: MiniAppVerifyOptions) => Record<string, string>;
|
|
87
|
+
/** Verify a mini-app request (URL, query string, or params object) server-side. */
|
|
88
|
+
export declare const verifyMiniAppRequest: (input: string | Record<string, any>, opts?: MiniAppVerifyOptions) => Record<string, string>;
|
|
89
|
+
/** Read a WhatsApp Flow / mini-app submission from an incoming message (null if not one). */
|
|
90
|
+
export declare const parseMiniAppResponse: (message: any) => MiniAppResponse | null;
|
|
91
|
+
export declare const buildFlowDataExchange: (action: string, data?: any, opts?: { version?: string; token?: string }) => any;
|
|
92
|
+
/** Build a WhatsApp Flows `navigate` action payload targeting a screen. */
|
|
93
|
+
export declare const buildFlowNavigate: (screen: string, data?: any, opts?: { version?: string; token?: string }) => any;
|