@vanzxy/baileys 2.0.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/NOTICE.md +111 -0
- package/README.md +830 -0
- package/WAProto/index.d.ts +9 -0
- package/WAProto/index.js +142036 -0
- package/engine-requirements.js +13 -0
- package/lib/Defaults/index.d.ts +152 -0
- package/lib/Defaults/index.js +179 -0
- package/lib/Framework/Bot.js +209 -0
- package/lib/Framework/Context.js +90 -0
- package/lib/Framework/MediaManager.js +152 -0
- package/lib/Framework/SessionManager.js +34 -0
- package/lib/Framework/StatsManager.js +120 -0
- package/lib/Framework/Store/SQLiteStore.js +74 -0
- package/lib/Framework/index.js +11 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.d.ts +10 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.d.ts +54 -0
- package/lib/Signal/libsignal.js +431 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +277 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +54 -0
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +380 -0
- package/lib/Socket/chats.d.ts +136 -0
- package/lib/Socket/chats.js +1328 -0
- package/lib/Socket/communities.d.ts +561 -0
- package/lib/Socket/communities.js +434 -0
- package/lib/Socket/dugong.d.ts +117 -0
- package/lib/Socket/dugong.js +799 -0
- package/lib/Socket/groups.d.ts +285 -0
- package/lib/Socket/groups.js +355 -0
- package/lib/Socket/index.d.ts +531 -0
- package/lib/Socket/index.js +34 -0
- package/lib/Socket/messages-recv.d.ts +333 -0
- package/lib/Socket/messages-recv.js +1782 -0
- package/lib/Socket/messages-send.d.ts +329 -0
- package/lib/Socket/messages-send.js +1383 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.d.ts +281 -0
- package/lib/Socket/newsletter.js +321 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1001 -0
- package/lib/Socket/username.js +153 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +4 -0
- package/lib/Store/make-in-memory-store.d.ts +62 -0
- package/lib/Store/make-in-memory-store.js +429 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +79 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +24 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +18 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +39 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +56 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +66 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/A2UI.js +277 -0
- package/lib/Utils/MessageBuilder.js +4405 -0
- package/lib/Utils/MessageBuilder_d.ts +411 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/PersistentStore_d.ts +60 -0
- package/lib/Utils/anti-delete.d.ts +74 -0
- package/lib/Utils/anti-delete.js +222 -0
- package/lib/Utils/auth-utils.d.ts +57 -0
- package/lib/Utils/auth-utils.js +307 -0
- package/lib/Utils/auto-reply.d.ts +47 -0
- package/lib/Utils/auto-reply.js +158 -0
- package/lib/Utils/baileys-event-stream.d.ts +8 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +8 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +240 -0
- package/lib/Utils/button-helper-utils.js +314 -0
- package/lib/Utils/button-sender.js +824 -0
- package/lib/Utils/chat-control.d.ts +159 -0
- package/lib/Utils/chat-control.js +232 -0
- package/lib/Utils/chat-history-helpers.d.ts +21 -0
- package/lib/Utils/chat-history-helpers.js +71 -0
- package/lib/Utils/chat-utils.d.ts +407 -0
- package/lib/Utils/chat-utils.js +886 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +40 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +148 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +317 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +636 -0
- package/lib/Utils/generics.d.ts +69 -0
- package/lib/Utils/generics.js +439 -0
- package/lib/Utils/history.d.ts +90 -0
- package/lib/Utils/history.js +147 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/index.d.ts +39 -0
- package/lib/Utils/index.js +46 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +27 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +33 -0
- package/lib/Utils/media-messages.d.ts +18 -0
- package/lib/Utils/media-messages.js +71 -0
- package/lib/Utils/media-set.d.ts +13 -0
- package/lib/Utils/media-set.js +172 -0
- package/lib/Utils/message-kind.js +139 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +265 -0
- package/lib/Utils/message-search.d.ts +44 -0
- package/lib/Utils/message-search.js +189 -0
- package/lib/Utils/messages-media.d.ts +135 -0
- package/lib/Utils/messages-media.js +869 -0
- package/lib/Utils/messages.d.ts +44 -0
- package/lib/Utils/messages.js +2155 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +201 -0
- package/lib/Utils/offline-node-processor.d.ts +9 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/past-participants.d.ts +14 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.d.ts +82 -0
- package/lib/Utils/process-message.js +809 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +445 -0
- package/lib/Utils/scheduling.d.ts +42 -0
- package/lib/Utils/scheduling.js +140 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +201 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/status.d.ts +50 -0
- package/lib/Utils/status.js +108 -0
- package/lib/Utils/stickerpack.d.ts +51 -0
- package/lib/Utils/stickerpack.js +275 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/templates.d.ts +76 -0
- package/lib/Utils/templates.js +151 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
- package/lib/Utils/use-cache-manager-auth-state.js +82 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +167 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +114 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +170 -0
- package/lib/Utils/validate-connection.d.ts +42 -0
- package/lib/Utils/validate-connection.js +199 -0
- package/lib/Utils/vcard.d.ts +58 -0
- package/lib/Utils/vcard.js +105 -0
- package/lib/VoIP/audio-feeder.d.ts +15 -0
- package/lib/VoIP/audio-feeder.js +132 -0
- package/lib/VoIP/index.js +277 -0
- package/lib/VoIP/relay-transport.d.ts +43 -0
- package/lib/VoIP/relay-transport.js +559 -0
- package/lib/VoIP/signaling.js +624 -0
- package/lib/VoIP/types.d.ts +69 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +103 -0
- package/lib/VoIP/wasm-engine.js +1214 -0
- package/lib/VoIP/worker-bootstrap.js +1042 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1467 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +262 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +220 -0
- package/lib/WABinary/generic-utils.d.ts +74 -0
- package/lib/WABinary/generic-utils.js +277 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +63 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.d.ts +7 -0
- package/lib/WAUSync/Protocols/index.js +8 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +122 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +31 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.js +20 -0
- package/package.json +175 -0
- package/postinstall-banner.js +56 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { Agent } from 'https';
|
|
2
|
+
import type { URL } from 'url';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
import type { ILogger } from '../Utils/logger.js';
|
|
5
|
+
import type { AuthenticationState, LIDMapping, SignalAuthState, TransactionCapabilityOptions } from './Auth.js';
|
|
6
|
+
import type { GroupMetadata } from './GroupMetadata.js';
|
|
7
|
+
import { type MediaConnInfo, type WAMessageKey } from './Message.js';
|
|
8
|
+
import type { SignalRepositoryWithLIDStore } from './Signal.js';
|
|
9
|
+
export type WAVersion = [number, number, number];
|
|
10
|
+
export type WABrowserDescription = [string, string, string];
|
|
11
|
+
export type CacheStore = {
|
|
12
|
+
/** get a cached key and change the stats */
|
|
13
|
+
get<T>(key: string): Promise<T> | T | undefined;
|
|
14
|
+
/** set a key in the cache */
|
|
15
|
+
set<T>(key: string, value: T): Promise<void> | void | number | boolean;
|
|
16
|
+
/** delete a key from the cache */
|
|
17
|
+
del(key: string): void | Promise<void> | number | boolean;
|
|
18
|
+
/** flush all data */
|
|
19
|
+
flushAll(): void | Promise<void>;
|
|
20
|
+
close?: () => void;
|
|
21
|
+
};
|
|
22
|
+
export type PossiblyExtendedCacheStore = CacheStore & {
|
|
23
|
+
mget?: <T>(keys: string[]) => Promise<Record<string, T | undefined>>;
|
|
24
|
+
mset?: <T>(entries: {
|
|
25
|
+
key: string;
|
|
26
|
+
value: T;
|
|
27
|
+
}[]) => Promise<void> | void | number | boolean;
|
|
28
|
+
mdel?: (keys: string[]) => void | Promise<void> | number | boolean;
|
|
29
|
+
};
|
|
30
|
+
export type PatchedMessageWithRecipientJID = proto.IMessage & {
|
|
31
|
+
recipientJid?: string;
|
|
32
|
+
};
|
|
33
|
+
export type SocketConfig = {
|
|
34
|
+
/** the WS url to connect to WA */
|
|
35
|
+
waWebSocketUrl: string | URL;
|
|
36
|
+
/** Fails the connection if the socket times out in this interval */
|
|
37
|
+
connectTimeoutMs: number;
|
|
38
|
+
/** Default timeout for queries, undefined for no timeout */
|
|
39
|
+
defaultQueryTimeoutMs: number | undefined;
|
|
40
|
+
/** ping-pong interval for WS connection */
|
|
41
|
+
keepAliveIntervalMs: number;
|
|
42
|
+
/** should baileys use the mobile api instead of the multi device api
|
|
43
|
+
* @deprecated This feature has been removed
|
|
44
|
+
*/
|
|
45
|
+
mobile?: boolean;
|
|
46
|
+
/** proxy agent */
|
|
47
|
+
agent?: Agent;
|
|
48
|
+
/** logger */
|
|
49
|
+
logger: ILogger;
|
|
50
|
+
/** version to connect with */
|
|
51
|
+
version: WAVersion;
|
|
52
|
+
/** override browser config */
|
|
53
|
+
browser: WABrowserDescription;
|
|
54
|
+
/** Initial pushName carried in the registration ClientPayload (used by mock servers for deterministic phone assignment). */
|
|
55
|
+
pushName?: string;
|
|
56
|
+
/** agent used for fetch requests -- uploading/downloading media */
|
|
57
|
+
fetchAgent?: Agent;
|
|
58
|
+
/** should the QR be printed in the terminal
|
|
59
|
+
* @deprecated This feature has been removed
|
|
60
|
+
*/
|
|
61
|
+
printQRInTerminal?: boolean;
|
|
62
|
+
/** should events be emitted for actions done by this socket connection */
|
|
63
|
+
emitOwnEvents: boolean;
|
|
64
|
+
/** custom upload hosts to upload media to */
|
|
65
|
+
customUploadHosts: MediaConnInfo['hosts'];
|
|
66
|
+
/** time to wait between sending new retry requests */
|
|
67
|
+
retryRequestDelayMs: number;
|
|
68
|
+
/** max retry count */
|
|
69
|
+
maxMsgRetryCount: number;
|
|
70
|
+
/** time to wait for the generation of the next QR in ms */
|
|
71
|
+
qrTimeout?: number;
|
|
72
|
+
/** provide an auth state object to maintain the auth state */
|
|
73
|
+
auth: AuthenticationState;
|
|
74
|
+
/** manage history processing with this control; by default will sync up everything */
|
|
75
|
+
shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean;
|
|
76
|
+
/** transaction capability options for SignalKeyStore */
|
|
77
|
+
transactionOpts: TransactionCapabilityOptions;
|
|
78
|
+
/** marks the client as online whenever the socket successfully connects */
|
|
79
|
+
markOnlineOnConnect: boolean;
|
|
80
|
+
/** alphanumeric country code (USA -> US) for the number used */
|
|
81
|
+
countryCode: string;
|
|
82
|
+
/** provide a cache to store media, so does not have to be re-uploaded */
|
|
83
|
+
mediaCache?: CacheStore;
|
|
84
|
+
/**
|
|
85
|
+
* map to store the retry counts for failed messages;
|
|
86
|
+
* used to determine whether to retry a message or not */
|
|
87
|
+
msgRetryCounterCache?: CacheStore;
|
|
88
|
+
/** provide a cache to store a user's device list */
|
|
89
|
+
userDevicesCache?: PossiblyExtendedCacheStore;
|
|
90
|
+
/** cache to store call offers */
|
|
91
|
+
callOfferCache?: CacheStore;
|
|
92
|
+
/** cache to track placeholder resends */
|
|
93
|
+
placeholderResendCache?: CacheStore;
|
|
94
|
+
/** width for link preview images */
|
|
95
|
+
linkPreviewImageThumbnailWidth: number;
|
|
96
|
+
/** Should Baileys ask the phone for full history, will be received async */
|
|
97
|
+
syncFullHistory: boolean;
|
|
98
|
+
/** Should baileys fire init queries automatically, default true */
|
|
99
|
+
fireInitQueries: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* generate a high quality link preview,
|
|
102
|
+
* entails uploading the jpegThumbnail to WA
|
|
103
|
+
* */
|
|
104
|
+
generateHighQualityLinkPreview: boolean;
|
|
105
|
+
/** Enable automatic session recreation for failed messages */
|
|
106
|
+
enableAutoSessionRecreation: boolean;
|
|
107
|
+
/** Enable recent message caching for retry handling */
|
|
108
|
+
enableRecentMessageCache: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Returns if a jid should be ignored,
|
|
111
|
+
* no event for that jid will be triggered.
|
|
112
|
+
* Messages from that jid will also not be decrypted
|
|
113
|
+
* */
|
|
114
|
+
shouldIgnoreJid: (jid: string) => boolean | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Optionally patch the message before sending out
|
|
117
|
+
* */
|
|
118
|
+
patchMessageBeforeSending: (msg: proto.IMessage, recipientJids?: string[]) => Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> | PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID;
|
|
119
|
+
/** verify app state MACs */
|
|
120
|
+
appStateMacVerification: {
|
|
121
|
+
patch: boolean;
|
|
122
|
+
snapshot: boolean;
|
|
123
|
+
};
|
|
124
|
+
/** options for HTTP fetch requests */
|
|
125
|
+
options: RequestInit;
|
|
126
|
+
/**
|
|
127
|
+
* fetch a message from your store
|
|
128
|
+
* implement this so that messages failed to send
|
|
129
|
+
* (solves the "this message can take a while" issue) can be retried
|
|
130
|
+
* */
|
|
131
|
+
getMessage: (key: WAMessageKey) => Promise<proto.IMessage | undefined>;
|
|
132
|
+
/** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
|
|
133
|
+
cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
|
|
134
|
+
makeSignalRepository: (auth: SignalAuthState, logger: ILogger, pnToLIDFunc?: (jids: string[]) => Promise<LIDMapping[] | undefined>) => SignalRepositoryWithLIDStore;
|
|
135
|
+
};
|
|
136
|
+
//# sourceMappingURL=Socket.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
export var SyncState;
|
|
3
|
+
(function (SyncState) {
|
|
4
|
+
/** The socket is connecting, but we haven't received pending notifications yet. */
|
|
5
|
+
SyncState[SyncState["Connecting"] = 0] = "Connecting";
|
|
6
|
+
/** Pending notifications received. Buffering events until we decide whether to sync or not. */
|
|
7
|
+
SyncState[SyncState["AwaitingInitialSync"] = 1] = "AwaitingInitialSync";
|
|
8
|
+
/** The initial app state sync (history, etc.) is in progress. Buffering continues. */
|
|
9
|
+
SyncState[SyncState["Syncing"] = 2] = "Syncing";
|
|
10
|
+
/** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
|
|
11
|
+
SyncState[SyncState["Online"] = 3] = "Online";
|
|
12
|
+
})(SyncState || (SyncState = {}));
|
|
13
|
+
export var ReachoutTimelockEnforcementType;
|
|
14
|
+
(function (ReachoutTimelockEnforcementType) {
|
|
15
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ALCOHOL"] = "BIZ_COMMERCE_VIOLATION_ALCOHOL";
|
|
16
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ADULT"] = "BIZ_COMMERCE_VIOLATION_ADULT";
|
|
17
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_ANIMALS"] = "BIZ_COMMERCE_VIOLATION_ANIMALS";
|
|
18
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS"] = "BIZ_COMMERCE_VIOLATION_BODY_PARTS_FLUIDS";
|
|
19
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DATING"] = "BIZ_COMMERCE_VIOLATION_DATING";
|
|
20
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS"] = "BIZ_COMMERCE_VIOLATION_DIGITAL_SERVICES_PRODUCTS";
|
|
21
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS"] = "BIZ_COMMERCE_VIOLATION_DRUGS";
|
|
22
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC"] = "BIZ_COMMERCE_VIOLATION_DRUGS_ONLY_OTC";
|
|
23
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_GAMBLING"] = "BIZ_COMMERCE_VIOLATION_GAMBLING";
|
|
24
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_HEALTHCARE"] = "BIZ_COMMERCE_VIOLATION_HEALTHCARE";
|
|
25
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY"] = "BIZ_COMMERCE_VIOLATION_REAL_FAKE_CURRENCY";
|
|
26
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_SUPPLEMENTS"] = "BIZ_COMMERCE_VIOLATION_SUPPLEMENTS";
|
|
27
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_TOBACCO"] = "BIZ_COMMERCE_VIOLATION_TOBACCO";
|
|
28
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT"] = "BIZ_COMMERCE_VIOLATION_VIOLENT_CONTENT";
|
|
29
|
+
ReachoutTimelockEnforcementType["BIZ_COMMERCE_VIOLATION_WEAPONS"] = "BIZ_COMMERCE_VIOLATION_WEAPONS";
|
|
30
|
+
ReachoutTimelockEnforcementType["BIZ_QUALITY"] = "BIZ_QUALITY";
|
|
31
|
+
/** This means there is no restriction */
|
|
32
|
+
ReachoutTimelockEnforcementType["DEFAULT"] = "DEFAULT";
|
|
33
|
+
ReachoutTimelockEnforcementType["WEB_COMPANION_ONLY"] = "WEB_COMPANION_ONLY";
|
|
34
|
+
})(ReachoutTimelockEnforcementType || (ReachoutTimelockEnforcementType = {}));
|
|
35
|
+
export var NewChatMessageCappingStatusType;
|
|
36
|
+
(function (NewChatMessageCappingStatusType) {
|
|
37
|
+
NewChatMessageCappingStatusType["NONE"] = "NONE";
|
|
38
|
+
NewChatMessageCappingStatusType["FIRST_WARNING"] = "FIRST_WARNING";
|
|
39
|
+
NewChatMessageCappingStatusType["SECOND_WARNING"] = "SECOND_WARNING";
|
|
40
|
+
NewChatMessageCappingStatusType["CAPPED"] = "CAPPED";
|
|
41
|
+
})(NewChatMessageCappingStatusType || (NewChatMessageCappingStatusType = {}));
|
|
42
|
+
export var NewChatMessageCappingMVStatusType;
|
|
43
|
+
(function (NewChatMessageCappingMVStatusType) {
|
|
44
|
+
NewChatMessageCappingMVStatusType["NOT_ELIGIBLE"] = "NOT_ELIGIBLE";
|
|
45
|
+
NewChatMessageCappingMVStatusType["NOT_ACTIVE"] = "NOT_ACTIVE";
|
|
46
|
+
NewChatMessageCappingMVStatusType["ACTIVE"] = "ACTIVE";
|
|
47
|
+
NewChatMessageCappingMVStatusType["ACTIVE_UPGRADE_AVAILABLE"] = "ACTIVE_UPGRADE_AVAILABLE";
|
|
48
|
+
})(NewChatMessageCappingMVStatusType || (NewChatMessageCappingMVStatusType = {}));
|
|
49
|
+
export var NewChatMessageCappingOTEStatusType;
|
|
50
|
+
(function (NewChatMessageCappingOTEStatusType) {
|
|
51
|
+
NewChatMessageCappingOTEStatusType["NOT_ELIGIBLE"] = "NOT_ELIGIBLE";
|
|
52
|
+
NewChatMessageCappingOTEStatusType["ELIGIBLE"] = "ELIGIBLE";
|
|
53
|
+
NewChatMessageCappingOTEStatusType["ACTIVE_IN_CURRENT_CYCLE"] = "ACTIVE_IN_CURRENT_CYCLE";
|
|
54
|
+
NewChatMessageCappingOTEStatusType["EXHAUSTED"] = "EXHAUSTED";
|
|
55
|
+
})(NewChatMessageCappingOTEStatusType || (NewChatMessageCappingOTEStatusType = {}));
|
|
56
|
+
//# sourceMappingURL=State.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BinaryNode } from '../WABinary/index.js';
|
|
2
|
+
import { USyncUser } from '../WAUSync/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Defines the interface for a USyncQuery protocol
|
|
5
|
+
*/
|
|
6
|
+
export interface USyncQueryProtocol {
|
|
7
|
+
/**
|
|
8
|
+
* The name of the protocol
|
|
9
|
+
*/
|
|
10
|
+
name: string;
|
|
11
|
+
/**
|
|
12
|
+
* Defines what goes inside the query part of a USyncQuery
|
|
13
|
+
*/
|
|
14
|
+
getQueryElement: () => BinaryNode;
|
|
15
|
+
/**
|
|
16
|
+
* Defines what goes inside the user part of a USyncQuery
|
|
17
|
+
*/
|
|
18
|
+
getUserElement: (user: USyncUser) => BinaryNode | null;
|
|
19
|
+
/**
|
|
20
|
+
* Parse the result of the query
|
|
21
|
+
* @param data Data from the result
|
|
22
|
+
* @returns Whatever the protocol is supposed to return
|
|
23
|
+
*/
|
|
24
|
+
parser: (data: BinaryNode) => unknown;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=USync.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export * from './Auth.js';
|
|
2
|
+
export * from './GroupMetadata.js';
|
|
3
|
+
export * from './Chat.js';
|
|
4
|
+
export * from './Contact.js';
|
|
5
|
+
export * from './State.js';
|
|
6
|
+
export * from './Message.js';
|
|
7
|
+
export * from './Socket.js';
|
|
8
|
+
export * from './Events.js';
|
|
9
|
+
export * from './Product.js';
|
|
10
|
+
export * from './Call.js';
|
|
11
|
+
export * from './Signal.js';
|
|
12
|
+
export * from './Mex.js';
|
|
13
|
+
import type { AuthenticationState } from './Auth.js';
|
|
14
|
+
import type { SocketConfig } from './Socket.js';
|
|
15
|
+
export type UserFacingSocketConfig = Partial<SocketConfig> & {
|
|
16
|
+
auth: AuthenticationState;
|
|
17
|
+
};
|
|
18
|
+
export type BrowsersMap = {
|
|
19
|
+
ubuntu(browser: string): [string, string, string];
|
|
20
|
+
macOS(browser: string): [string, string, string];
|
|
21
|
+
baileys(browser: string): [string, string, string];
|
|
22
|
+
windows(browser: string): [string, string, string];
|
|
23
|
+
android(browser: string): [string, string, string];
|
|
24
|
+
appropriate(browser: string): [string, string, string];
|
|
25
|
+
};
|
|
26
|
+
export declare enum DisconnectReason {
|
|
27
|
+
connectionClosed = 428,
|
|
28
|
+
connectionLost = 408,
|
|
29
|
+
connectionReplaced = 440,
|
|
30
|
+
timedOut = 408,
|
|
31
|
+
loggedOut = 401,
|
|
32
|
+
badSession = 500,
|
|
33
|
+
restartRequired = 515,
|
|
34
|
+
multideviceMismatch = 411,
|
|
35
|
+
forbidden = 403,
|
|
36
|
+
unavailableService = 503
|
|
37
|
+
}
|
|
38
|
+
export type WAInitResponse = {
|
|
39
|
+
ref: string;
|
|
40
|
+
ttl: number;
|
|
41
|
+
status: 200;
|
|
42
|
+
};
|
|
43
|
+
export type WABusinessHoursConfig = {
|
|
44
|
+
day_of_week: string;
|
|
45
|
+
mode: string;
|
|
46
|
+
open_time?: number;
|
|
47
|
+
close_time?: number;
|
|
48
|
+
};
|
|
49
|
+
export type WABusinessProfile = {
|
|
50
|
+
description: string;
|
|
51
|
+
email: string | undefined;
|
|
52
|
+
business_hours: {
|
|
53
|
+
timezone?: string;
|
|
54
|
+
config?: WABusinessHoursConfig[];
|
|
55
|
+
business_config?: WABusinessHoursConfig[];
|
|
56
|
+
};
|
|
57
|
+
website: string[];
|
|
58
|
+
category?: string;
|
|
59
|
+
wid?: string;
|
|
60
|
+
address?: string;
|
|
61
|
+
};
|
|
62
|
+
export type CurveKeyPair = {
|
|
63
|
+
private: Uint8Array;
|
|
64
|
+
public: Uint8Array;
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from './Auth.js';
|
|
2
|
+
export * from './GroupMetadata.js';
|
|
3
|
+
export * from './Chat.js';
|
|
4
|
+
export * from './Contact.js';
|
|
5
|
+
export * from './State.js';
|
|
6
|
+
export * from './Message.js';
|
|
7
|
+
export * from './Socket.js';
|
|
8
|
+
export * from './Events.js';
|
|
9
|
+
export * from './Product.js';
|
|
10
|
+
export * from './Call.js';
|
|
11
|
+
export * from './Signal.js';
|
|
12
|
+
export * from './Mex.js';
|
|
13
|
+
export var DisconnectReason;
|
|
14
|
+
(function (DisconnectReason) {
|
|
15
|
+
DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
|
|
16
|
+
DisconnectReason[DisconnectReason["connectionLost"] = 408] = "connectionLost";
|
|
17
|
+
DisconnectReason[DisconnectReason["connectionReplaced"] = 440] = "connectionReplaced";
|
|
18
|
+
DisconnectReason[DisconnectReason["timedOut"] = 408] = "timedOut";
|
|
19
|
+
DisconnectReason[DisconnectReason["loggedOut"] = 401] = "loggedOut";
|
|
20
|
+
DisconnectReason[DisconnectReason["badSession"] = 500] = "badSession";
|
|
21
|
+
DisconnectReason[DisconnectReason["restartRequired"] = 515] = "restartRequired";
|
|
22
|
+
DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
|
|
23
|
+
DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
|
|
24
|
+
DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
|
|
25
|
+
})(DisconnectReason || (DisconnectReason = {}));
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* lib/Utils/A2UI.js — A2UI (Bloks) widget builder + sender
|
|
3
|
+
*
|
|
4
|
+
* Part of @vanzxy/baileys. Builds the flat `components` array A2UI/Bloks
|
|
5
|
+
* expects (id-referencing tree: Column/Row hold `children`, Card/Button hold
|
|
6
|
+
* `child`, Modal holds `trigger`/`content`) and sends it as an
|
|
7
|
+
* `interactiveMessage.bloksWidget` via the same `getBizBinaryNode()` path
|
|
8
|
+
* Button/ButtonV2 use, so the wire-level <biz>/<native_flow> node always
|
|
9
|
+
* matches the actual button names sent — no more hand-rolled duplicate of
|
|
10
|
+
* that logic living outside the library.
|
|
11
|
+
*
|
|
12
|
+
* See MessageBuilder.js's `Button.setBloksWidget()` for the declarative
|
|
13
|
+
* (nested-tree) alternative to this imperative (id-returning-factory) API;
|
|
14
|
+
* both produce the same wire format and can be mixed freely.
|
|
15
|
+
*/
|
|
16
|
+
"use strict";
|
|
17
|
+
|
|
18
|
+
import crypto from "crypto";
|
|
19
|
+
import { generateWAMessageFromContent, prepareWAMessageMedia } from "./messages.js";
|
|
20
|
+
import { getBizBinaryNode } from "../WABinary/index.js";
|
|
21
|
+
|
|
22
|
+
class A2UI {
|
|
23
|
+
constructor({ catalogId = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json", version = "v0.9" } = {}) {
|
|
24
|
+
this._version = version;
|
|
25
|
+
this._catalogId = catalogId;
|
|
26
|
+
this._components = new Map();
|
|
27
|
+
this._counter = 0;
|
|
28
|
+
this._rootChildren = [];
|
|
29
|
+
}
|
|
30
|
+
#nextId(prefix) {
|
|
31
|
+
return `${prefix}_${(this._counter++).toString(36)}`;
|
|
32
|
+
}
|
|
33
|
+
#reg(id, component, extra = {}) {
|
|
34
|
+
id ??= this.#nextId(component.toLowerCase());
|
|
35
|
+
if (id === "root") throw new Error(`Component id "root" is reserved for the implicit root wrapper`);
|
|
36
|
+
if (this._components.has(id)) throw new Error(`Component id "${id}" already used`);
|
|
37
|
+
this._components.set(id, { id, component, ...extra });
|
|
38
|
+
return id;
|
|
39
|
+
}
|
|
40
|
+
text(text, { id, variant = "body" } = {}) {
|
|
41
|
+
return this.#reg(id, "Text", { text, variant });
|
|
42
|
+
}
|
|
43
|
+
image(url, { id, variant, fit = "cover" } = {}) {
|
|
44
|
+
return this.#reg(id, "Image", { url, ...(variant ? { variant } : {}), fit });
|
|
45
|
+
}
|
|
46
|
+
video(url, { id } = {}) {
|
|
47
|
+
return this.#reg(id, "Video", { url });
|
|
48
|
+
}
|
|
49
|
+
checkbox(label, { id, value = false } = {}) {
|
|
50
|
+
return this.#reg(id, "CheckBox", { label, value });
|
|
51
|
+
}
|
|
52
|
+
textField(label, { id, variant = "text" } = {}) {
|
|
53
|
+
return this.#reg(id, "TextField", { label, variant });
|
|
54
|
+
}
|
|
55
|
+
button(childId, { id, variant = "primary", action } = {}) {
|
|
56
|
+
if (!childId) throw new TypeError("button(childId) requires the id of a child component (e.g. from .text())");
|
|
57
|
+
return this.#reg(id, "Button", { child: childId, variant, ...(action ? { action } : {}) });
|
|
58
|
+
}
|
|
59
|
+
card(childId, { id } = {}) {
|
|
60
|
+
return this.#reg(id, "Card", { child: childId });
|
|
61
|
+
}
|
|
62
|
+
// trigger: id of the component that opens the modal (e.g. a Button); content: id of the
|
|
63
|
+
// component shown inside it. Both are ids of already-registered SIBLING components, not
|
|
64
|
+
// nested children — that's how the wire format expects Modal to reference them.
|
|
65
|
+
modal(triggerId, contentId, { id } = {}) {
|
|
66
|
+
if (!triggerId) throw new TypeError("modal(triggerId, contentId) requires the id of the trigger component");
|
|
67
|
+
if (!contentId) throw new TypeError("modal(triggerId, contentId) requires the id of the content component");
|
|
68
|
+
return this.#reg(id, "Modal", { trigger: triggerId, content: contentId });
|
|
69
|
+
}
|
|
70
|
+
// Escape hatch for any catalog component without a dedicated method yet (Divider, Slider,
|
|
71
|
+
// Switch, List, etc). props is merged as-is into the registered node.
|
|
72
|
+
raw(component, props = {}, { id } = {}) {
|
|
73
|
+
if (typeof component !== "string" || !component) throw new TypeError("raw(component, props) requires a non-empty component type string");
|
|
74
|
+
return this.#reg(id, component, props);
|
|
75
|
+
}
|
|
76
|
+
column(children = [], { id } = {}) {
|
|
77
|
+
if (!children.length) throw new TypeError("column(children) requires at least one child id");
|
|
78
|
+
return this.#reg(id, "Column", { children });
|
|
79
|
+
}
|
|
80
|
+
row(children = [], { id } = {}) {
|
|
81
|
+
if (!children.length) throw new TypeError("row(children) requires at least one child id");
|
|
82
|
+
return this.#reg(id, "Row", { children });
|
|
83
|
+
}
|
|
84
|
+
divider({ id } = {}) {
|
|
85
|
+
return this.#reg(id, "Divider", {});
|
|
86
|
+
}
|
|
87
|
+
choicePicker(label, options, { id, variant = "mutuallyExclusive", value, displayStyle = "checkbox", filterable = false } = {}) {
|
|
88
|
+
if (!Array.isArray(options) || !options.length) {
|
|
89
|
+
throw new TypeError("choicePicker(label, options) requires a non-empty options array of {label, value}");
|
|
90
|
+
}
|
|
91
|
+
return this.#reg(id, "ChoicePicker", {
|
|
92
|
+
label,
|
|
93
|
+
variant,
|
|
94
|
+
...(value !== undefined ? { value } : {}),
|
|
95
|
+
options,
|
|
96
|
+
displayStyle,
|
|
97
|
+
filterable
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
root(children) {
|
|
101
|
+
if (!Array.isArray(children) || !children.length) {
|
|
102
|
+
throw new TypeError("root(children) requires a non-empty array of top-level component ids");
|
|
103
|
+
}
|
|
104
|
+
this._rootChildren = children;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
// Vanz@Add 29-08-26 --- Product/list carousel card. This is a DIFFERENT wire
|
|
108
|
+
// payload shape from the Column/Row component-tree the rest of this class
|
|
109
|
+
// builds (type: 'list_card', flat items array) — not a catalog component, so
|
|
110
|
+
// it doesn't go through #reg()/root(). Call this instead of root()+build();
|
|
111
|
+
// build() returns the list_card payload directly when this was set.
|
|
112
|
+
listCard({ title, items, fallbackText, uuid = crypto.randomUUID() } = {}) {
|
|
113
|
+
if (!title) throw new TypeError("listCard requires a title");
|
|
114
|
+
if (!Array.isArray(items) || !items.length) {
|
|
115
|
+
throw new TypeError("listCard requires a non-empty items array");
|
|
116
|
+
}
|
|
117
|
+
this._listCardPayload = {
|
|
118
|
+
uuid,
|
|
119
|
+
data: JSON.stringify({
|
|
120
|
+
type: "list_card",
|
|
121
|
+
title,
|
|
122
|
+
fallback_text: fallbackText ?? "",
|
|
123
|
+
items: items.map((it) => ({
|
|
124
|
+
asset_id: it.assetId ?? crypto.randomUUID().replace(/-/g, "").slice(0, 17),
|
|
125
|
+
asset_type: it.assetType ?? "PRODUCT_ITEM",
|
|
126
|
+
title: it.title,
|
|
127
|
+
trailing_label: it.price ?? it.trailingLabel ?? "",
|
|
128
|
+
trailing_emphasis: it.emphasis ?? "strong"
|
|
129
|
+
}))
|
|
130
|
+
}),
|
|
131
|
+
type: "im_a2ui",
|
|
132
|
+
fallback: fallbackText ?? ""
|
|
133
|
+
};
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
// Vanz@Add 30-08-26 --- send(): terminal method so A2UI can be used as a one-liner like
|
|
137
|
+
// the other builders (Button/ButtonV2/AIRich `.send()`), instead of always needing the
|
|
138
|
+
// separate `sendA2UIWidget()` call. Thin wrapper only — root([...ids])/listCard() must
|
|
139
|
+
// still be called first, same as before build(); this doesn't change the id-returning
|
|
140
|
+
// factory API (child methods still return ids, not `this`, since sibling nodes need to
|
|
141
|
+
// reference each other by id when wiring children/trigger/content).
|
|
142
|
+
async send(client, jid, opts = {}) {
|
|
143
|
+
return sendA2UIWidget(client, jid, { ...opts, a2ui: this });
|
|
144
|
+
}
|
|
145
|
+
// Vanz@Add 30-08-26 --- validates that every structural id-reference (child/children on
|
|
146
|
+
// Button/Card/Column/Row, trigger/content on Modal) points at a component that was
|
|
147
|
+
// actually registered. Without this, a typo'd id just gets written into the wire payload
|
|
148
|
+
// as-is and the failure only surfaces as a broken/blank widget on the WA client, with no
|
|
149
|
+
// error on this end. Only covers the dedicated methods' known reference keys — raw()'s
|
|
150
|
+
// free-form props aren't inspected, since there's no way to know which of those are id
|
|
151
|
+
// references vs plain data.
|
|
152
|
+
#validateRefs(components) {
|
|
153
|
+
const validIds = new Set(components.map((c) => c.id));
|
|
154
|
+
for (const c of components) {
|
|
155
|
+
for (const key of ["child", "trigger", "content"]) {
|
|
156
|
+
if (c[key] !== undefined && !validIds.has(c[key])) {
|
|
157
|
+
throw new Error(`A2UI: component "${c.id}" (${c.component}) references unknown id "${c[key]}" via "${key}"`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (Array.isArray(c.children)) {
|
|
161
|
+
for (const childId of c.children) {
|
|
162
|
+
if (!validIds.has(childId)) {
|
|
163
|
+
throw new Error(`A2UI: component "${c.id}" (${c.component}) references unknown id "${childId}" in "children"`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
build({ uuid = crypto.randomUUID(), surfaceId, type = "im_a2ui", wrapped = true } = {}) {
|
|
170
|
+
if (this._listCardPayload) return this._listCardPayload;
|
|
171
|
+
if (!this._rootChildren.length) throw new Error("Call root([...ids]) before build()");
|
|
172
|
+
const root = { id: "root", component: "Column", children: this._rootChildren };
|
|
173
|
+
const components = [root, ...this._components.values()];
|
|
174
|
+
this.#validateRefs(components);
|
|
175
|
+
const data = wrapped
|
|
176
|
+
? {
|
|
177
|
+
version: this._version,
|
|
178
|
+
createSurface: {
|
|
179
|
+
surfaceId: surfaceId ?? `starcore-widget=${uuid}`,
|
|
180
|
+
catalogId: this._catalogId,
|
|
181
|
+
components
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
: { components };
|
|
185
|
+
return {
|
|
186
|
+
uuid,
|
|
187
|
+
data: JSON.stringify(data),
|
|
188
|
+
type
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Build + send an A2UI/Bloks widget as an interactiveMessage.
|
|
195
|
+
* @param {import('../../WAProto/index.js').WASocket} client Active Baileys socket.
|
|
196
|
+
* @param {string} jid Destination chat/group jid.
|
|
197
|
+
*/
|
|
198
|
+
async function sendA2UIWidget(client, jid, {
|
|
199
|
+
a2ui,
|
|
200
|
+
bodyText = "",
|
|
201
|
+
footer = "",
|
|
202
|
+
buttons = [],
|
|
203
|
+
contextInfo = {},
|
|
204
|
+
expiration,
|
|
205
|
+
quoted,
|
|
206
|
+
type = "im_a2ui",
|
|
207
|
+
wrapped = true,
|
|
208
|
+
singleScreen = false,
|
|
209
|
+
// Vanz@Add 30-08-26 --- optional header media, mirroring Button/ButtonV2's toCard()
|
|
210
|
+
// pattern (prepareWAMessageMedia + client.waUploadToServer). { title, subtitle, image
|
|
211
|
+
// | video | document: path/buffer/{url} } — media is mutually exclusive, image wins if
|
|
212
|
+
// more than one is passed. Falls back to a title/subtitle-only header (no attachment)
|
|
213
|
+
// when no media is given, same shape as before this change.
|
|
214
|
+
header
|
|
215
|
+
} = {}) {
|
|
216
|
+
if (!client) throw new Error("Socket is required");
|
|
217
|
+
if (!(a2ui instanceof A2UI)) throw new TypeError("a2ui must be an A2UI instance");
|
|
218
|
+
|
|
219
|
+
const nativeFlowMessage = buttons && buttons.length
|
|
220
|
+
? {
|
|
221
|
+
buttons: buttons.map((b) => ({
|
|
222
|
+
name: b.name ?? "cta_url",
|
|
223
|
+
buttonParamsJson: typeof b.params === "string" ? b.params : JSON.stringify(b.params ?? {}),
|
|
224
|
+
})),
|
|
225
|
+
messageParamsJson: "{}",
|
|
226
|
+
messageVersion: 1
|
|
227
|
+
}
|
|
228
|
+
: { messageParamsJson: "" };
|
|
229
|
+
|
|
230
|
+
const headerMediaData = header?.image
|
|
231
|
+
? { image: header.image }
|
|
232
|
+
: header?.video
|
|
233
|
+
? { video: header.video }
|
|
234
|
+
: header?.document
|
|
235
|
+
? { document: header.document }
|
|
236
|
+
: null;
|
|
237
|
+
|
|
238
|
+
const headerBlock = {
|
|
239
|
+
...(header?.title !== undefined ? { title: header.title } : {}),
|
|
240
|
+
...(header?.subtitle !== undefined ? { subtitle: header.subtitle } : {}),
|
|
241
|
+
hasMediaAttachment: !!headerMediaData,
|
|
242
|
+
...(headerMediaData
|
|
243
|
+
? await prepareWAMessageMedia(headerMediaData, { upload: client.waUploadToServer }).catch((e) => {
|
|
244
|
+
if (String(e).includes("Invalid media type")) return headerMediaData;
|
|
245
|
+
throw e;
|
|
246
|
+
})
|
|
247
|
+
: {})
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const interactiveMessage = singleScreen
|
|
251
|
+
? {
|
|
252
|
+
nativeFlowMessage,
|
|
253
|
+
bloksWidget: a2ui.build({ type, wrapped }),
|
|
254
|
+
...(expiration || Object.keys(contextInfo).length ? { contextInfo: { ...(expiration ? { expiration } : {}), ...contextInfo } } : {})
|
|
255
|
+
}
|
|
256
|
+
: {
|
|
257
|
+
header: headerBlock,
|
|
258
|
+
body: { text: bodyText },
|
|
259
|
+
...(footer ? { footer: { text: footer } } : {}),
|
|
260
|
+
nativeFlowMessage,
|
|
261
|
+
bloksWidget: a2ui.build({ type, wrapped }),
|
|
262
|
+
...(expiration || Object.keys(contextInfo).length ? { contextInfo: { ...(expiration ? { expiration } : {}), ...contextInfo } } : {})
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const msg = generateWAMessageFromContent(jid, {
|
|
266
|
+
messageContextInfo: { messageSecret: crypto.randomBytes(32) },
|
|
267
|
+
interactiveMessage
|
|
268
|
+
}, { quoted });
|
|
269
|
+
|
|
270
|
+
await client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
271
|
+
messageId: msg.key.id,
|
|
272
|
+
additionalNodes: [getBizBinaryNode(msg.message)]
|
|
273
|
+
});
|
|
274
|
+
return msg;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export { A2UI, sendA2UIWidget };
|