@x4r1s3/baileys 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +1262 -2
- package/SECURITY.md +47 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8892 -0
- package/WAProto/index.d.ts +104128 -0
- package/WAProto/index.js +334920 -0
- package/assets/rolling-circle.svg +133 -0
- package/assets/x4r1s3-banner.svg +32 -0
- package/engine-requirements.js +27 -0
- package/lib/Builders/A2UI.js +245 -0
- package/lib/Builders/AIRich.js +179 -0
- package/lib/Builders/Button.js +108 -0
- package/lib/Builders/CFC.js +284 -0
- package/lib/Builders/Carousel.js +81 -0
- package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
- package/lib/Call/audio-feeder.mjs +179 -0
- package/lib/Call/audio-recorder.mjs +250 -0
- package/lib/Call/fetch-wasm-resources.mjs +104 -0
- package/lib/Call/index.mjs +680 -0
- package/lib/Call/relay-transport.mjs +563 -0
- package/lib/Call/signaling.mjs +641 -0
- package/lib/Call/types.mjs +17 -0
- package/lib/Call/video-feeder.mjs +94 -0
- package/lib/Call/wasm-engine.mjs +1372 -0
- package/lib/Call/worker-bootstrap.mjs +1042 -0
- package/lib/Defaults/ban-checker.js +56 -0
- package/lib/Defaults/index.js +170 -0
- package/lib/Signal/Group/ciphertext-message.js +23 -0
- package/lib/Signal/Group/group-session-builder.js +41 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.js +23 -0
- package/lib/Signal/Group/keyhelper.js +29 -0
- package/lib/Signal/Group/sender-chain-key.js +37 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
- package/lib/Signal/Group/sender-key-message.js +77 -0
- package/lib/Signal/Group/sender-key-name.js +59 -0
- package/lib/Signal/Group/sender-key-record.js +52 -0
- package/lib/Signal/Group/sender-key-state.js +95 -0
- package/lib/Signal/Group/sender-message-key.js +37 -0
- package/lib/Signal/libsignal.js +440 -0
- package/lib/Signal/lid-mapping.js +292 -0
- package/lib/Socket/Client/index.js +14 -0
- package/lib/Socket/Client/types.js +22 -0
- package/lib/Socket/Client/websocket.js +65 -0
- package/lib/Socket/aigroups.js +327 -0
- package/lib/Socket/ban-checker.js +165 -0
- package/lib/Socket/business.js +419 -0
- package/lib/Socket/chats.js +1921 -0
- package/lib/Socket/communities.js +443 -0
- package/lib/Socket/graphql.js +911 -0
- package/lib/Socket/groups.js +561 -0
- package/lib/Socket/index.js +49 -0
- package/lib/Socket/interactive-handler.js +612 -0
- package/lib/Socket/interop.js +575 -0
- package/lib/Socket/managed-account.js +220 -0
- package/lib/Socket/messages-recv.js +2191 -0
- package/lib/Socket/messages-send.js +4104 -0
- package/lib/Socket/mex.js +53 -0
- package/lib/Socket/newsletter.js +291 -0
- package/lib/Socket/privacy.js +458 -0
- package/lib/Socket/registration.js +440 -0
- package/lib/Socket/socket.js +1029 -0
- package/lib/Socket/status-actions.js +287 -0
- package/lib/Socket/username.js +241 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +101 -0
- package/lib/Store/make-in-memory-store.js +432 -0
- package/lib/Store/make-ordered-dictionary.js +90 -0
- package/lib/Store/object-repository.js +35 -0
- package/lib/Types/Auth.js +13 -0
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -0
- package/lib/Types/Chat.js +19 -0
- package/lib/Types/Contact.js +13 -0
- package/lib/Types/Events.js +13 -0
- package/lib/Types/GroupMetadata.js +13 -0
- package/lib/Types/Label.js +36 -0
- package/lib/Types/LabelAssociation.js +18 -0
- package/lib/Types/Message.js +30 -0
- package/lib/Types/Mex.js +53 -0
- package/lib/Types/Product.js +13 -0
- package/lib/Types/RichType.js +34 -0
- package/lib/Types/Signal.js +13 -0
- package/lib/Types/Socket.js +14 -0
- package/lib/Types/State.js +60 -0
- package/lib/Types/USync.js +13 -0
- package/lib/Types/index.js +37 -0
- package/lib/Utils/auth-utils.js +313 -0
- package/lib/Utils/ban-checker.js +48 -0
- package/lib/Utils/bot-capabilities.js +96 -0
- package/lib/Utils/bot-planning-replay.js +177 -0
- package/lib/Utils/browser-utils.js +40 -0
- package/lib/Utils/business.js +242 -0
- package/lib/Utils/c2582.js +147 -0
- package/lib/Utils/chat-utils.js +905 -0
- package/lib/Utils/companion-reg-client-utils.js +44 -0
- package/lib/Utils/consumer-application.js +114 -0
- package/lib/Utils/crypto.js +129 -0
- package/lib/Utils/decode-wa-message.js +496 -0
- package/lib/Utils/direct-chat-theme.js +164 -0
- package/lib/Utils/event-buffer.js +601 -0
- package/lib/Utils/experimental-proto.js +206 -0
- package/lib/Utils/games/miniapp.js +17 -0
- package/lib/Utils/games/slot-machine.js +270 -0
- package/lib/Utils/games/website-preview.js +306 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/group-history.js +68 -0
- package/lib/Utils/group-wallpaper.js +168 -0
- package/lib/Utils/history.js +162 -0
- package/lib/Utils/identity-change-handler.js +60 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/jid-display-normalization.js +221 -0
- package/lib/Utils/link-preview.js +96 -0
- package/lib/Utils/logger.js +14 -0
- package/lib/Utils/lt-hash.js +19 -0
- package/lib/Utils/make-mutex.js +44 -0
- package/lib/Utils/message-composer.js +709 -0
- package/lib/Utils/message-inspect.js +79 -0
- package/lib/Utils/message-retry-manager.js +253 -0
- package/lib/Utils/message-security.js +167 -0
- package/lib/Utils/messages-media.js +1027 -0
- package/lib/Utils/messages.js +2467 -0
- package/lib/Utils/meta-ai-msmsg.js +215 -0
- package/lib/Utils/meta-compositing.js +239 -0
- package/lib/Utils/native-flow.js +158 -0
- package/lib/Utils/newsletter-live-update-utils.js +74 -0
- package/lib/Utils/newsletter-status-utils.js +152 -0
- package/lib/Utils/noise-handler.js +212 -0
- package/lib/Utils/offline-node-processor.js +51 -0
- package/lib/Utils/poll-manager.js +206 -0
- package/lib/Utils/portable-compat.js +12 -0
- package/lib/Utils/pre-key-manager.js +117 -0
- package/lib/Utils/process-message.js +610 -0
- package/lib/Utils/reporting-utils.js +269 -0
- package/lib/Utils/rich-message-utils.js +2841 -0
- package/lib/Utils/scheduled-message.js +107 -0
- package/lib/Utils/signal.js +212 -0
- package/lib/Utils/source-grep.js +57 -0
- package/lib/Utils/stanza-ack.js +49 -0
- package/lib/Utils/sticker-annotation.js +87 -0
- package/lib/Utils/sync-action-utils.js +59 -0
- package/lib/Utils/tc-token-utils.js +174 -0
- package/lib/Utils/use-multi-file-auth-state.js +132 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +120 -0
- package/lib/Utils/validate-connection.js +220 -0
- package/lib/Utils/view-once-utils.js +218 -0
- package/lib/Utils/voip-rekey.js +32 -0
- package/lib/Utils/website-preview.js +27 -0
- package/lib/Utils/welcome-flow.js +228 -0
- package/lib/Utils/x4r1s3.js +144 -0
- package/lib/WABinary/constants.js +1475 -0
- package/lib/WABinary/decode.js +273 -0
- package/lib/WABinary/encode.js +231 -0
- package/lib/WABinary/generic-utils.js +242 -0
- package/lib/WABinary/index.js +17 -0
- package/lib/WABinary/jid-utils.js +107 -0
- package/lib/WABinary/types.js +13 -0
- package/lib/WAM/BinaryInfo.js +21 -0
- package/lib/WAM/constants.js +22864 -0
- package/lib/WAM/encode.js +161 -0
- package/lib/WAM/index.js +15 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
- package/lib/WAUSync/Protocols/index.js +24 -0
- package/lib/WAUSync/USyncQuery.js +213 -0
- package/lib/WAUSync/USyncUser.js +66 -0
- package/lib/WAUSync/index.js +15 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +1285 -0
- package/lib/index.js +30 -0
- package/package.json +125 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<svg width="240" height="240" viewBox="0 0 240 240" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<defs>
|
|
3
|
+
<radialGradient id="space" cx="50%" cy="50%" r="70%">
|
|
4
|
+
<stop offset="0%" stop-color="#0B1030"/>
|
|
5
|
+
<stop offset="55%" stop-color="#05061A"/>
|
|
6
|
+
<stop offset="100%" stop-color="#000000"/>
|
|
7
|
+
</radialGradient>
|
|
8
|
+
<radialGradient id="nebula1" cx="30%" cy="35%" r="45%">
|
|
9
|
+
<stop offset="0%" stop-color="#5B2CFF" stop-opacity="0.35"/>
|
|
10
|
+
<stop offset="100%" stop-color="#5B2CFF" stop-opacity="0"/>
|
|
11
|
+
</radialGradient>
|
|
12
|
+
<radialGradient id="nebula2" cx="75%" cy="70%" r="45%">
|
|
13
|
+
<stop offset="0%" stop-color="#00E5FF" stop-opacity="0.25"/>
|
|
14
|
+
<stop offset="100%" stop-color="#00E5FF" stop-opacity="0"/>
|
|
15
|
+
</radialGradient>
|
|
16
|
+
<radialGradient id="glow" cx="50%" cy="50%" r="50%">
|
|
17
|
+
<stop offset="0%" stop-color="#7DF9FF" stop-opacity="1"/>
|
|
18
|
+
<stop offset="35%" stop-color="#1F51FF" stop-opacity="0.9"/>
|
|
19
|
+
<stop offset="100%" stop-color="#1F51FF" stop-opacity="0"/>
|
|
20
|
+
</radialGradient>
|
|
21
|
+
<linearGradient id="sweep" x1="120" y1="34" x2="187.4" y2="65.5" gradientUnits="userSpaceOnUse">
|
|
22
|
+
<stop offset="0%" stop-color="#7DF9FF" stop-opacity="0.55"/>
|
|
23
|
+
<stop offset="100%" stop-color="#7DF9FF" stop-opacity="0"/>
|
|
24
|
+
</linearGradient>
|
|
25
|
+
<filter id="soft" x="-50%" y="-50%" width="200%" height="200%">
|
|
26
|
+
<feGaussianBlur stdDeviation="1.4"/>
|
|
27
|
+
</filter>
|
|
28
|
+
<filter id="core" x="-50%" y="-50%" width="200%" height="200%">
|
|
29
|
+
<feGaussianBlur stdDeviation="3"/>
|
|
30
|
+
</filter>
|
|
31
|
+
<clipPath id="frame">
|
|
32
|
+
<circle cx="120" cy="120" r="118"/>
|
|
33
|
+
</clipPath>
|
|
34
|
+
</defs>
|
|
35
|
+
|
|
36
|
+
<g clip-path="url(#frame)">
|
|
37
|
+
<!-- deep space backdrop -->
|
|
38
|
+
<circle cx="120" cy="120" r="118" fill="url(#space)"/>
|
|
39
|
+
<circle cx="120" cy="120" r="118" fill="url(#nebula1)"/>
|
|
40
|
+
<circle cx="120" cy="120" r="118" fill="url(#nebula2)"/>
|
|
41
|
+
|
|
42
|
+
<!-- starfield -->
|
|
43
|
+
<circle cx="151.8" cy="11.7" r="0.86" fill="#EAF6FF"><animate attributeName="opacity" values="0.29;1;0.29" dur="2.17s" begin="2.21s" repeatCount="indefinite"/></circle>
|
|
44
|
+
<circle cx="209.4" cy="25.8" r="1.05" fill="#EAF6FF"><animate attributeName="opacity" values="0.25;1;0.25" dur="1.59s" begin="0.66s" repeatCount="indefinite"/></circle>
|
|
45
|
+
<circle cx="12.1" cy="51.3" r="1.34" fill="#EAF6FF"><animate attributeName="opacity" values="0.27;1;0.27" dur="3.13s" begin="0.66s" repeatCount="indefinite"/></circle>
|
|
46
|
+
<circle cx="190.6" cy="7.5" r="1.55" fill="#EAF6FF"><animate attributeName="opacity" values="0.18;1;0.18" dur="3.59s" begin="1.02s" repeatCount="indefinite"/></circle>
|
|
47
|
+
<circle cx="224.2" cy="82.7" r="0.62" fill="#EAF6FF"><animate attributeName="opacity" values="0.27;1;0.27" dur="1.79s" begin="2.54s" repeatCount="indefinite"/></circle>
|
|
48
|
+
<circle cx="128.3" cy="227.9" r="0.99" fill="#EAF6FF"><animate attributeName="opacity" values="0.27;1;0.27" dur="3.16s" begin="2.49s" repeatCount="indefinite"/></circle>
|
|
49
|
+
<circle cx="166.6" cy="16.4" r="0.8" fill="#EAF6FF"><animate attributeName="opacity" values="0.2;1;0.2" dur="2.37s" begin="0.24s" repeatCount="indefinite"/></circle>
|
|
50
|
+
<circle cx="29.0" cy="69.4" r="1.33" fill="#EAF6FF"><animate attributeName="opacity" values="0.19;1;0.19" dur="2.59s" begin="1.11s" repeatCount="indefinite"/></circle>
|
|
51
|
+
<circle cx="66.9" cy="219.6" r="1.34" fill="#EAF6FF"><animate attributeName="opacity" values="0.3;1;0.3" dur="3.33s" begin="0.51s" repeatCount="indefinite"/></circle>
|
|
52
|
+
<circle cx="231.6" cy="151.9" r="1.22" fill="#EAF6FF"><animate attributeName="opacity" values="0.31;1;0.31" dur="3.55s" begin="2.53s" repeatCount="indefinite"/></circle>
|
|
53
|
+
<circle cx="58.2" cy="13.3" r="0.91" fill="#EAF6FF"><animate attributeName="opacity" values="0.34;1;0.34" dur="2.3s" begin="0.63s" repeatCount="indefinite"/></circle>
|
|
54
|
+
<circle cx="205.8" cy="77.7" r="1.35" fill="#EAF6FF"><animate attributeName="opacity" values="0.24;1;0.24" dur="2.69s" begin="2.74s" repeatCount="indefinite"/></circle>
|
|
55
|
+
<circle cx="233.4" cy="122.2" r="0.62" fill="#EAF6FF"><animate attributeName="opacity" values="0.28;1;0.28" dur="1.64s" begin="0.33s" repeatCount="indefinite"/></circle>
|
|
56
|
+
<circle cx="20.5" cy="93.0" r="1.79" fill="#EAF6FF"><animate attributeName="opacity" values="0.32;1;0.32" dur="3.09s" begin="2.91s" repeatCount="indefinite"/></circle>
|
|
57
|
+
<circle cx="8.6" cy="170.3" r="1.39" fill="#EAF6FF"><animate attributeName="opacity" values="0.28;1;0.28" dur="3.11s" begin="0.8s" repeatCount="indefinite"/></circle>
|
|
58
|
+
<circle cx="109.4" cy="223.5" r="1.64" fill="#EAF6FF"><animate attributeName="opacity" values="0.19;1;0.19" dur="2.29s" begin="1.5s" repeatCount="indefinite"/></circle>
|
|
59
|
+
<circle cx="214.1" cy="204.5" r="0.89" fill="#EAF6FF"><animate attributeName="opacity" values="0.18;1;0.18" dur="3.42s" begin="1.83s" repeatCount="indefinite"/></circle>
|
|
60
|
+
<circle cx="6.1" cy="79.9" r="0.53" fill="#EAF6FF"><animate attributeName="opacity" values="0.32;1;0.32" dur="4.29s" begin="2.64s" repeatCount="indefinite"/></circle>
|
|
61
|
+
<circle cx="76.1" cy="19.2" r="1.64" fill="#EAF6FF"><animate attributeName="opacity" values="0.25;1;0.25" dur="4.34s" begin="0.26s" repeatCount="indefinite"/></circle>
|
|
62
|
+
<circle cx="21.8" cy="179.4" r="1.5" fill="#EAF6FF"><animate attributeName="opacity" values="0.26;1;0.26" dur="1.89s" begin="1.43s" repeatCount="indefinite"/></circle>
|
|
63
|
+
<circle cx="66.4" cy="204.9" r="1.05" fill="#EAF6FF"><animate attributeName="opacity" values="0.3;1;0.3" dur="2.14s" begin="1.62s" repeatCount="indefinite"/></circle>
|
|
64
|
+
<circle cx="232.9" cy="154.2" r="1.07" fill="#EAF6FF"><animate attributeName="opacity" values="0.19;1;0.19" dur="3.05s" begin="0.36s" repeatCount="indefinite"/></circle>
|
|
65
|
+
<circle cx="22.2" cy="149.9" r="0.8" fill="#EAF6FF"><animate attributeName="opacity" values="0.16;1;0.16" dur="4.22s" begin="2.58s" repeatCount="indefinite"/></circle>
|
|
66
|
+
<circle cx="54.8" cy="36.2" r="1.72" fill="#EAF6FF"><animate attributeName="opacity" values="0.31;1;0.31" dur="3.21s" begin="1.42s" repeatCount="indefinite"/></circle>
|
|
67
|
+
<circle cx="190.1" cy="49.4" r="0.63" fill="#EAF6FF"><animate attributeName="opacity" values="0.24;1;0.24" dur="2.79s" begin="1.27s" repeatCount="indefinite"/></circle>
|
|
68
|
+
<circle cx="230.4" cy="28.4" r="1.02" fill="#EAF6FF"><animate attributeName="opacity" values="0.2;1;0.2" dur="2.52s" begin="2.59s" repeatCount="indefinite"/></circle>
|
|
69
|
+
<circle cx="63.0" cy="216.5" r="1.08" fill="#EAF6FF"><animate attributeName="opacity" values="0.16;1;0.16" dur="4.08s" begin="1.65s" repeatCount="indefinite"/></circle>
|
|
70
|
+
<circle cx="233.8" cy="196.6" r="1.76" fill="#EAF6FF"><animate attributeName="opacity" values="0.18;1;0.18" dur="4.28s" begin="2.55s" repeatCount="indefinite"/></circle>
|
|
71
|
+
<circle cx="97.4" cy="19.4" r="0.99" fill="#EAF6FF"><animate attributeName="opacity" values="0.31;1;0.31" dur="4.46s" begin="0.8s" repeatCount="indefinite"/></circle>
|
|
72
|
+
<circle cx="224.3" cy="233.0" r="1.22" fill="#EAF6FF"><animate attributeName="opacity" values="0.21;1;0.21" dur="3.66s" begin="0.46s" repeatCount="indefinite"/></circle>
|
|
73
|
+
<circle cx="226.9" cy="138.1" r="1.2" fill="#EAF6FF"><animate attributeName="opacity" values="0.27;1;0.27" dur="3.74s" begin="0.17s" repeatCount="indefinite"/></circle>
|
|
74
|
+
<circle cx="41.9" cy="225.1" r="0.6" fill="#EAF6FF"><animate attributeName="opacity" values="0.29;1;0.29" dur="2.06s" begin="1.79s" repeatCount="indefinite"/></circle>
|
|
75
|
+
<circle cx="59.6" cy="33.3" r="1.66" fill="#EAF6FF"><animate attributeName="opacity" values="0.27;1;0.27" dur="2.24s" begin="1.78s" repeatCount="indefinite"/></circle>
|
|
76
|
+
<circle cx="125.2" cy="219.1" r="0.77" fill="#EAF6FF"><animate attributeName="opacity" values="0.23;1;0.23" dur="3.65s" begin="0.72s" repeatCount="indefinite"/></circle>
|
|
77
|
+
<circle cx="22.5" cy="110.5" r="1.8" fill="#EAF6FF"><animate attributeName="opacity" values="0.19;1;0.19" dur="4.49s" begin="0.22s" repeatCount="indefinite"/></circle>
|
|
78
|
+
<circle cx="66.5" cy="218.8" r="1.65" fill="#EAF6FF"><animate attributeName="opacity" values="0.18;1;0.18" dur="4.14s" begin="1.11s" repeatCount="indefinite"/></circle>
|
|
79
|
+
|
|
80
|
+
<!-- a slow shooting star crossing the field -->
|
|
81
|
+
<g>
|
|
82
|
+
<line x1="-10" y1="-10" x2="14" y2="4" stroke="#EAF6FF" stroke-width="1.5" stroke-linecap="round" opacity="0">
|
|
83
|
+
<animate attributeName="opacity" values="0;0;0.9;0" keyTimes="0;0.55;0.62;0.78" dur="7s" repeatCount="indefinite"/>
|
|
84
|
+
<animateTransform attributeName="transform" type="translate"
|
|
85
|
+
values="0,0; 0,0; 200,90; 260,120" keyTimes="0;0.55;0.72;0.78" dur="7s" repeatCount="indefinite"/>
|
|
86
|
+
</line>
|
|
87
|
+
</g>
|
|
88
|
+
|
|
89
|
+
<!-- ambient glow behind the scanner -->
|
|
90
|
+
<circle cx="120" cy="120" r="88" fill="url(#glow)" opacity="0.3">
|
|
91
|
+
<animate attributeName="opacity" values="0.2;0.4;0.2" dur="3s" repeatCount="indefinite"/>
|
|
92
|
+
</circle>
|
|
93
|
+
|
|
94
|
+
<!-- radar screen -->
|
|
95
|
+
<circle cx="120" cy="120" r="86" fill="#04122A" opacity="0.55"/>
|
|
96
|
+
<circle cx="120" cy="120" r="86" fill="none" stroke="#1F51FF" stroke-width="2" opacity="0.6"/>
|
|
97
|
+
<circle cx="120" cy="120" r="64" fill="none" stroke="#00E5FF" stroke-width="1" opacity="0.35"/>
|
|
98
|
+
<circle cx="120" cy="120" r="42" fill="none" stroke="#00E5FF" stroke-width="1" opacity="0.3"/>
|
|
99
|
+
<circle cx="120" cy="120" r="20" fill="none" stroke="#00E5FF" stroke-width="1" opacity="0.25"/>
|
|
100
|
+
|
|
101
|
+
<!-- crosshairs -->
|
|
102
|
+
<line x1="120" y1="34" x2="120" y2="206" stroke="#1F51FF" stroke-width="1" opacity="0.25"/>
|
|
103
|
+
<line x1="34" y1="120" x2="206" y2="120" stroke="#1F51FF" stroke-width="1" opacity="0.25"/>
|
|
104
|
+
|
|
105
|
+
<!-- blips that flash as the sweep passes them -->
|
|
106
|
+
<circle cx="152" cy="88" r="2.6" fill="#7DF9FF">
|
|
107
|
+
<animate attributeName="opacity" values="0;0;1;0.2;0" keyTimes="0;0.2;0.24;0.4;0.6" dur="4s" repeatCount="indefinite"/>
|
|
108
|
+
</circle>
|
|
109
|
+
<circle cx="90" cy="158" r="2.2" fill="#7DF9FF">
|
|
110
|
+
<animate attributeName="opacity" values="0;0;1;0.2;0" keyTimes="0;0.55;0.59;0.7;0.85" dur="4s" repeatCount="indefinite"/>
|
|
111
|
+
</circle>
|
|
112
|
+
<circle cx="150" cy="150" r="2" fill="#7DF9FF">
|
|
113
|
+
<animate attributeName="opacity" values="0;0;1;0.2;0" keyTimes="0;0.82;0.86;0.95;1" dur="4s" repeatCount="indefinite"/>
|
|
114
|
+
</circle>
|
|
115
|
+
|
|
116
|
+
<!-- rotating sweep beam with fading trail -->
|
|
117
|
+
<g>
|
|
118
|
+
<animateTransform attributeName="transform" type="rotate"
|
|
119
|
+
from="0 120 120" to="360 120 120" dur="4s" repeatCount="indefinite"/>
|
|
120
|
+
<path d="M 120 120 L 120 34 A 86 86 0 0 1 187.4 65.5 Z" fill="url(#sweep)"/>
|
|
121
|
+
<line x1="120" y1="120" x2="120" y2="34" stroke="#7DF9FF" stroke-width="2" filter="url(#soft)"/>
|
|
122
|
+
</g>
|
|
123
|
+
|
|
124
|
+
<!-- center core -->
|
|
125
|
+
<circle cx="120" cy="120" r="8" fill="#1F51FF" filter="url(#core)">
|
|
126
|
+
<animate attributeName="opacity" values="0.8;1;0.8" dur="2s" repeatCount="indefinite"/>
|
|
127
|
+
</circle>
|
|
128
|
+
<circle cx="120" cy="120" r="3.5" fill="#E0FFFF"/>
|
|
129
|
+
|
|
130
|
+
<!-- subtle outer rim to frame the space capsule -->
|
|
131
|
+
<circle cx="120" cy="120" r="117" fill="none" stroke="#1F51FF" stroke-width="2" opacity="0.4"/>
|
|
132
|
+
</g>
|
|
133
|
+
</svg>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<svg width="1200" height="220" viewBox="0 0 1200 220" fill="none" xmlns="http://www.w3.org/2000/svg" role="img" aria-labelledby="title desc">
|
|
2
|
+
<title id="title">X4R1S3 TECHNOLOGY Baileys banner</title>
|
|
3
|
+
<desc id="desc">A branded banner for the X4R1S3 Baileys protocol toolkit.</desc>
|
|
4
|
+
<defs>
|
|
5
|
+
<linearGradient id="background" x1="0" y1="0" x2="1200" y2="220" gradientUnits="userSpaceOnUse">
|
|
6
|
+
<stop stop-color="#07111F"/>
|
|
7
|
+
<stop offset="0.5" stop-color="#101B3D"/>
|
|
8
|
+
<stop offset="1" stop-color="#07111F"/>
|
|
9
|
+
</linearGradient>
|
|
10
|
+
<linearGradient id="accent" x1="140" y1="24" x2="1060" y2="196" gradientUnits="userSpaceOnUse">
|
|
11
|
+
<stop stop-color="#00FFF0"/>
|
|
12
|
+
<stop offset="0.5" stop-color="#B88CFF"/>
|
|
13
|
+
<stop offset="1" stop-color="#7CFFB2"/>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
<radialGradient id="glow" cx="0" cy="0" r="1" gradientTransform="translate(600 110) rotate(90) scale(170 560)" gradientUnits="userSpaceOnUse">
|
|
16
|
+
<stop stop-color="#00FFF0" stop-opacity="0.18"/>
|
|
17
|
+
<stop offset="1" stop-color="#00FFF0" stop-opacity="0"/>
|
|
18
|
+
</radialGradient>
|
|
19
|
+
<filter id="softGlow" x="-20%" y="-80%" width="140%" height="260%">
|
|
20
|
+
<feGaussianBlur stdDeviation="7"/>
|
|
21
|
+
</filter>
|
|
22
|
+
</defs>
|
|
23
|
+
<rect x="2" y="2" width="1196" height="216" rx="30" fill="url(#background)" stroke="url(#accent)" stroke-width="3"/>
|
|
24
|
+
<rect x="18" y="18" width="1164" height="184" rx="22" fill="url(#glow)"/>
|
|
25
|
+
<path d="M70 166C250 42 410 206 600 110C790 14 950 178 1130 54" stroke="#00FFF0" stroke-opacity="0.18" stroke-width="3"/>
|
|
26
|
+
<path d="M70 176C250 52 410 216 600 120C790 24 950 188 1130 64" stroke="url(#accent)" stroke-opacity="0.78" stroke-width="2"/>
|
|
27
|
+
<circle cx="1070" cy="64" r="7" fill="#00FFF0" filter="url(#softGlow)"/>
|
|
28
|
+
<circle cx="1070" cy="64" r="3" fill="#D9FFFF"/>
|
|
29
|
+
<text x="70" y="88" fill="#F4FFFF" font-family="Space Mono, ui-monospace, SFMono-Regular, Menlo, monospace" font-size="34" font-weight="700" letter-spacing="4">X4R1S3 TECHNOLOGY</text>
|
|
30
|
+
<text x="72" y="132" fill="url(#accent)" font-family="Space Mono, ui-monospace, SFMono-Regular, Menlo, monospace" font-size="24" font-weight="700" letter-spacing="2">@x4r1s3/baileys</text>
|
|
31
|
+
<text x="74" y="166" fill="#C7D4F4" font-family="Inter, ui-sans-serif, system-ui, sans-serif" font-size="16" letter-spacing="1">RESPONSIBLE • INSPECTABLE • RELIABLE WHATSAPP PROTOCOL TOOLING</text>
|
|
32
|
+
</svg>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: engine-requirements.js
|
|
5
|
+
* About: Engine requirements module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: No public exports detected; module side effects or declarations are local.
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync } from 'fs';
|
|
14
|
+
|
|
15
|
+
const major = parseInt(
|
|
16
|
+
process.versions.node.split('.')[0],
|
|
17
|
+
10
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
if (major < 20) {
|
|
21
|
+
console.error(
|
|
22
|
+
`\n⚉ This package requires Node.js 20+ to run reliably.\n` +
|
|
23
|
+
` You are using Node.js ${process.versions.node}.\n` +
|
|
24
|
+
` Please upgrade to Node.js 20+ to proceed.\n`
|
|
25
|
+
);
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 X4R1S3x — @X4R1S3/baileys
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* A2UI builders for WhatsApp Bloks widgets and a transport helper.
|
|
6
|
+
* Adapted from T3rri's working implementation to use this package's own
|
|
7
|
+
* message generator instead of importing a separate `baileys` package.
|
|
8
|
+
*/
|
|
9
|
+
import crypto from 'node:crypto';
|
|
10
|
+
import { generateWAMessageFromContent } from '../Utils/messages.js';
|
|
11
|
+
|
|
12
|
+
export class A2UI {
|
|
13
|
+
constructor({ catalogId = 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json', version = 'v0.9' } = {}) {
|
|
14
|
+
this._version = version;
|
|
15
|
+
this._catalogId = catalogId;
|
|
16
|
+
this._components = new Map();
|
|
17
|
+
this._counter = 0;
|
|
18
|
+
this._rootChildren = [];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#nextId(prefix) {
|
|
22
|
+
return `${prefix}_${(this._counter++).toString(36)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#reg(id, component, extra = {}) {
|
|
26
|
+
id ??= this.#nextId(component.toLowerCase());
|
|
27
|
+
if (this._components.has(id)) throw new Error(`Component id "${id}" already used`);
|
|
28
|
+
this._components.set(id, { id, component, ...extra });
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
text(text, { id, variant = 'body' } = {}) {
|
|
33
|
+
return this.#reg(id, 'Text', { text, variant });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
image(url, { id, variant, fit = 'cover' } = {}) {
|
|
37
|
+
return this.#reg(id, 'Image', { url, ...(variant ? { variant } : {}), fit });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Add an image using the A2UI catalog's header image variant. */
|
|
41
|
+
header(url, options = {}) {
|
|
42
|
+
return this.image(url, { ...options, variant: options.variant ?? 'header' });
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
video(url, { id } = {}) {
|
|
46
|
+
return this.#reg(id, 'Video', { url });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
checkbox(label, { id, value = false } = {}) {
|
|
50
|
+
return this.#reg(id, 'CheckBox', { label, value });
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
textField(label, { id, variant = 'text' } = {}) {
|
|
54
|
+
return this.#reg(id, 'TextField', { label, variant });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
button(childId, { id, variant = 'primary', action } = {}) {
|
|
58
|
+
if (!childId) throw new TypeError('button(childId) requires the id of a child component (e.g. from .text())');
|
|
59
|
+
return this.#reg(id, 'Button', { child: childId, variant, ...(action ? { action } : {}) });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
card(childId, { id } = {}) {
|
|
63
|
+
return this.#reg(id, 'Card', { child: childId });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
column(children = [], { id, justify, align } = {}) {
|
|
67
|
+
if (!Array.isArray(children) || !children.length) throw new TypeError('column(children) requires at least one child id');
|
|
68
|
+
return this.#reg(id, 'Column', { children, ...(justify ? { justify } : {}), ...(align ? { align } : {}) });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
row(children = [], { id } = {}) {
|
|
72
|
+
if (!Array.isArray(children) || !children.length) throw new TypeError('row(children) requires at least one child id');
|
|
73
|
+
return this.#reg(id, 'Row', { children });
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
divider({ id } = {}) {
|
|
77
|
+
return this.#reg(id, 'Divider', {});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
choicePicker(label, options, { id, variant = 'mutuallyExclusive', value, displayStyle = 'checkbox', filterable = false } = {}) {
|
|
81
|
+
if (!Array.isArray(options) || !options.length) {
|
|
82
|
+
throw new TypeError('choicePicker(label, options) requires a non-empty options array of {label, value}');
|
|
83
|
+
}
|
|
84
|
+
return this.#reg(id, 'ChoicePicker', {
|
|
85
|
+
label,
|
|
86
|
+
variant,
|
|
87
|
+
...(value !== undefined ? { value } : {}),
|
|
88
|
+
options,
|
|
89
|
+
displayStyle,
|
|
90
|
+
filterable,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
root(children) {
|
|
95
|
+
if (!Array.isArray(children) || !children.length) {
|
|
96
|
+
throw new TypeError('root(children) requires a non-empty array of top-level component ids');
|
|
97
|
+
}
|
|
98
|
+
this._rootChildren = children;
|
|
99
|
+
return this;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Use one previously-created component as the entire surface. */
|
|
103
|
+
only(componentId) {
|
|
104
|
+
if (!componentId) throw new TypeError('only(componentId) requires a component id');
|
|
105
|
+
return this.root([componentId]);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Convenience builder for an image-only A2UI surface. */
|
|
109
|
+
imageOnly(url, options = {}) {
|
|
110
|
+
return this.only(this.image(url, { ...options, variant: options.variant ?? 'header' }));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Convenience builder for a video-only A2UI surface. */
|
|
114
|
+
videoOnly(url, options = {}) {
|
|
115
|
+
return this.only(this.video(url, options));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Convenience builder for a header-image-only A2UI surface. */
|
|
119
|
+
headerOnly(url, options = {}) {
|
|
120
|
+
return this.only(this.header(url, options));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Convenience builder for a card-only surface around an existing child. */
|
|
124
|
+
cardOnly(childId, options = {}) {
|
|
125
|
+
return this.only(this.card(childId, options));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
listCard({ title, items, fallbackText, uuid = crypto.randomUUID() } = {}) {
|
|
129
|
+
if (!title) throw new TypeError('listCard requires a title');
|
|
130
|
+
if (!Array.isArray(items) || !items.length) throw new TypeError('listCard requires a non-empty items array');
|
|
131
|
+
this._listCardPayload = {
|
|
132
|
+
uuid,
|
|
133
|
+
data: JSON.stringify({
|
|
134
|
+
type: 'list_card',
|
|
135
|
+
title,
|
|
136
|
+
fallback_text: fallbackText ?? '',
|
|
137
|
+
items: items.map((item) => ({
|
|
138
|
+
asset_id: item.assetId ?? crypto.randomUUID().replace(/-/g, '').slice(0, 17),
|
|
139
|
+
asset_type: item.assetType ?? 'PRODUCT_ITEM',
|
|
140
|
+
title: item.title,
|
|
141
|
+
trailing_label: item.price ?? item.trailingLabel ?? '',
|
|
142
|
+
trailing_emphasis: item.emphasis ?? 'strong',
|
|
143
|
+
})),
|
|
144
|
+
}),
|
|
145
|
+
type: 'im_a2ui',
|
|
146
|
+
fallback: fallbackText ?? '',
|
|
147
|
+
};
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
build({ uuid = crypto.randomUUID(), surfaceId, type = 'im_a2ui', wrapped = true } = {}) {
|
|
152
|
+
if (this._listCardPayload) return this._listCardPayload;
|
|
153
|
+
if (!this._rootChildren.length) throw new Error('Call root([...ids]) before build()');
|
|
154
|
+
const root = { id: 'root', component: 'Column', children: this._rootChildren };
|
|
155
|
+
const components = [root, ...this._components.values()];
|
|
156
|
+
const data = wrapped
|
|
157
|
+
? {
|
|
158
|
+
version: this._version,
|
|
159
|
+
createSurface: {
|
|
160
|
+
surfaceId: surfaceId ?? `starcore-widget=${uuid}`,
|
|
161
|
+
catalogId: this._catalogId,
|
|
162
|
+
components,
|
|
163
|
+
},
|
|
164
|
+
}
|
|
165
|
+
: { components };
|
|
166
|
+
return { uuid, data: JSON.stringify(data), type };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Send an A2UI widget using the same native-flow stanza metadata as T3rri's implementation. */
|
|
171
|
+
export async function sendA2UIWidget(client, jid, {
|
|
172
|
+
a2ui,
|
|
173
|
+
bodyText = '',
|
|
174
|
+
fallback = '',
|
|
175
|
+
footer = '',
|
|
176
|
+
buttons = [],
|
|
177
|
+
contextInfo = {},
|
|
178
|
+
expiration,
|
|
179
|
+
quoted,
|
|
180
|
+
type = 'im_a2ui',
|
|
181
|
+
wrapped = true,
|
|
182
|
+
singleScreen = false,
|
|
183
|
+
} = {}) {
|
|
184
|
+
if (!client?.relayMessage) throw new TypeError('A socket with relayMessage() is required');
|
|
185
|
+
if (!jid || typeof jid !== 'string') throw new TypeError('A valid destination JID is required');
|
|
186
|
+
if (!(a2ui instanceof A2UI)) throw new TypeError('a2ui must be an A2UI instance');
|
|
187
|
+
if (!Array.isArray(buttons)) throw new TypeError('buttons must be an array');
|
|
188
|
+
if (!contextInfo || typeof contextInfo !== 'object' || Array.isArray(contextInfo)) throw new TypeError('contextInfo must be an object');
|
|
189
|
+
|
|
190
|
+
const nativeFlowMessage = buttons.length
|
|
191
|
+
? {
|
|
192
|
+
buttons: buttons.map((button) => ({
|
|
193
|
+
name: button.name ?? 'cta_url',
|
|
194
|
+
buttonParamsJson: typeof button.params === 'string' ? button.params : JSON.stringify(button.params ?? {}),
|
|
195
|
+
})),
|
|
196
|
+
messageParamsJson: '{}',
|
|
197
|
+
messageVersion: 1,
|
|
198
|
+
}
|
|
199
|
+
: { messageParamsJson: '' };
|
|
200
|
+
|
|
201
|
+
const widget = a2ui.build({ type, wrapped });
|
|
202
|
+
const { fallback: _builtFallback, ...widgetPayload } = widget;
|
|
203
|
+
const widgetFallback = typeof fallback === 'string' && fallback.trim()
|
|
204
|
+
? fallback.trim()
|
|
205
|
+
: typeof _builtFallback === 'string' && _builtFallback.trim()
|
|
206
|
+
? _builtFallback.trim()
|
|
207
|
+
: undefined;
|
|
208
|
+
const bloksWidget = {
|
|
209
|
+
...widgetPayload,
|
|
210
|
+
...(widgetFallback ? { fallback: widgetFallback } : {}),
|
|
211
|
+
};
|
|
212
|
+
const hasContextInfo = expiration !== undefined || Object.keys(contextInfo).length > 0;
|
|
213
|
+
const interactiveMessage = singleScreen
|
|
214
|
+
? {
|
|
215
|
+
nativeFlowMessage,
|
|
216
|
+
bloksWidget,
|
|
217
|
+
...(hasContextInfo ? { contextInfo: { ...(expiration !== undefined ? { expiration } : {}), ...contextInfo } } : {}),
|
|
218
|
+
}
|
|
219
|
+
: {
|
|
220
|
+
...(footer !== undefined ? { header: { hasMediaAttachment: false } } : {}),
|
|
221
|
+
...(bodyText !== undefined ? { body: { text: bodyText } } : {}),
|
|
222
|
+
...(footer !== undefined ? { footer: { text: footer } } : {}),
|
|
223
|
+
nativeFlowMessage,
|
|
224
|
+
bloksWidget,
|
|
225
|
+
...(hasContextInfo ? { contextInfo: { ...(expiration !== undefined ? { expiration } : {}), ...contextInfo } } : {}),
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
const msg = generateWAMessageFromContent(jid, {
|
|
229
|
+
messageContextInfo: { messageSecret: crypto.randomBytes(32) },
|
|
230
|
+
interactiveMessage,
|
|
231
|
+
}, { quoted });
|
|
232
|
+
|
|
233
|
+
await client.relayMessage(msg.key.remoteJid, msg.message, {
|
|
234
|
+
messageId: msg.key.id,
|
|
235
|
+
additionalNodes: [{
|
|
236
|
+
tag: 'biz',
|
|
237
|
+
attrs: { actual_actors: '2', host_storage: '2', privacy_mode_ts: String(Math.floor(Date.now() / 1000)) },
|
|
238
|
+
content: [
|
|
239
|
+
{ tag: 'interactive', attrs: { type: 'native_flow', v: '1' }, content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }] },
|
|
240
|
+
{ tag: 'quality_control', attrs: { decision_id: crypto.randomUUID().replace(/-/g, ''), source_type: 'third_party' }, content: [{ tag: 'decision_source', attrs: { value: 'df' } }] },
|
|
241
|
+
],
|
|
242
|
+
}],
|
|
243
|
+
});
|
|
244
|
+
return msg;
|
|
245
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026 X4R1S3x — @X4R1S3/baileys
|
|
3
|
+
*/
|
|
4
|
+
import { randomUUID } from 'crypto';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { generateMessageIDV2 } from '../Utils/generics.js';
|
|
7
|
+
import { generateWAMessageFromContent } from '../Utils/messages.js';
|
|
8
|
+
import { prepareRichResponseMessage } from '../Utils/rich-message-utils.js';
|
|
9
|
+
|
|
10
|
+
const splitAtWords = (text, chunkSize) => {
|
|
11
|
+
const size = Math.max(1, Number(chunkSize) || 120);
|
|
12
|
+
const chunks = [];
|
|
13
|
+
let start = 0;
|
|
14
|
+
while (start < text.length) {
|
|
15
|
+
if (text.length - start <= size) {
|
|
16
|
+
chunks.push(text.slice(start));
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
let end = start + size;
|
|
20
|
+
const lastSpace = text.lastIndexOf(' ', end);
|
|
21
|
+
if (lastSpace > start) end = lastSpace + 1;
|
|
22
|
+
chunks.push(text.slice(start, end));
|
|
23
|
+
start = end;
|
|
24
|
+
}
|
|
25
|
+
return chunks;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const readUnified = richResponse => {
|
|
29
|
+
const data = richResponse?.unifiedResponse?.data;
|
|
30
|
+
if (!data) return null;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(Buffer.from(data).toString('utf8'));
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Compose AIRich-compatible headings, text, and tables. streamText() sends the
|
|
41
|
+
* first version once, then applies type-14 edits to that same message key.
|
|
42
|
+
*/
|
|
43
|
+
export class AIRich {
|
|
44
|
+
#client;
|
|
45
|
+
|
|
46
|
+
constructor(client) {
|
|
47
|
+
if (!client || typeof client.relayMessage !== 'function') {
|
|
48
|
+
throw new Error('AIRich requires a socket with relayMessage');
|
|
49
|
+
}
|
|
50
|
+
this.#client = client;
|
|
51
|
+
this._blocks = [];
|
|
52
|
+
this._responseId = randomUUID();
|
|
53
|
+
this._lastMessageKey = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
addHeading(text) {
|
|
57
|
+
if (typeof text !== 'string' || !text.trim()) throw new TypeError('addHeading(text) requires non-empty text');
|
|
58
|
+
this._blocks.push({ type: 'heading', text });
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
addText(text) {
|
|
63
|
+
if (typeof text !== 'string') throw new TypeError('addText(text) requires a string');
|
|
64
|
+
this._blocks.push({ type: 'text', text });
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
addTable(rows) {
|
|
69
|
+
if (!Array.isArray(rows) || !rows.length || rows.some(row => !Array.isArray(row))) {
|
|
70
|
+
throw new TypeError('addTable(rows) requires a non-empty array of row arrays');
|
|
71
|
+
}
|
|
72
|
+
this._blocks.push({ type: 'table', rows: rows.map(row => [...row]) });
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
build() {
|
|
77
|
+
if (!this._blocks.length) throw new Error('AIRich has no content to build');
|
|
78
|
+
const prepared = prepareRichResponseMessage({
|
|
79
|
+
richResponse: this._blocks.map(block => block.type === 'table' ? { table: block.rows } : { text: block.text }),
|
|
80
|
+
noDonation: true
|
|
81
|
+
});
|
|
82
|
+
const richResponse = prepared?.botForwardedMessage?.message?.richResponseMessage;
|
|
83
|
+
const unified = readUnified(richResponse);
|
|
84
|
+
if (!richResponse || !unified) throw new Error('AIRich could not compose the unified response');
|
|
85
|
+
|
|
86
|
+
unified.response_id = this._responseId;
|
|
87
|
+
let sectionIndex = 0;
|
|
88
|
+
for (const block of this._blocks) {
|
|
89
|
+
const section = unified.sections?.[sectionIndex];
|
|
90
|
+
if (block.type === 'heading' && section?.view_model?.primitive) {
|
|
91
|
+
section.view_model.primitive.__typename = 'FOATextPrimitive';
|
|
92
|
+
}
|
|
93
|
+
sectionIndex += 1;
|
|
94
|
+
}
|
|
95
|
+
richResponse.unifiedResponse.data = Buffer.from(JSON.stringify(unified));
|
|
96
|
+
const botMetadata = prepared.messageContextInfo?.botMetadata;
|
|
97
|
+
if (botMetadata) botMetadata.botResponseId = this._responseId;
|
|
98
|
+
return prepared;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async send(jid, options = {}) {
|
|
102
|
+
if (!jid) throw new TypeError('AIRich.send(jid) requires a target JID');
|
|
103
|
+
const { quoted, messageId, ...relayOptions } = options;
|
|
104
|
+
const id = messageId || generateMessageIDV2(this.#client.user?.id || jid);
|
|
105
|
+
const generated = generateWAMessageFromContent(jid, this.build(), {
|
|
106
|
+
logger: this.#client.logger,
|
|
107
|
+
userJid: this.#client.user?.id,
|
|
108
|
+
messageId: id,
|
|
109
|
+
quoted,
|
|
110
|
+
...relayOptions
|
|
111
|
+
});
|
|
112
|
+
await this.#client.relayMessage(jid, generated.message, {
|
|
113
|
+
...relayOptions,
|
|
114
|
+
messageId: generated.key.id
|
|
115
|
+
});
|
|
116
|
+
this._lastMessageKey = { remoteJid: jid, fromMe: true, id: generated.key.id };
|
|
117
|
+
return { key: this._lastMessageKey, message: generated.message };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async sendEdit(jid, id, options = {}) {
|
|
121
|
+
jid = jid ?? this._lastMessageKey?.remoteJid;
|
|
122
|
+
id = id ?? this._lastMessageKey?.id;
|
|
123
|
+
if (!jid) throw new Error('sendEdit: no jid — pass one explicitly, or call send() first');
|
|
124
|
+
if (!id) throw new Error('sendEdit: no message id — pass one explicitly, or call send() first');
|
|
125
|
+
const { quoted: _quoted, messageId, ...relayOptions } = options;
|
|
126
|
+
const edit = generateWAMessageFromContent(jid, {
|
|
127
|
+
botForwardedMessage: {
|
|
128
|
+
message: {
|
|
129
|
+
protocolMessage: {
|
|
130
|
+
key: { remoteJid: jid, fromMe: true, id },
|
|
131
|
+
type: proto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
|
|
132
|
+
editedMessage: this.build()
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}, {
|
|
137
|
+
logger: this.#client.logger,
|
|
138
|
+
userJid: this.#client.user?.id,
|
|
139
|
+
messageId: messageId || generateMessageIDV2(this.#client.user?.id || jid),
|
|
140
|
+
...relayOptions
|
|
141
|
+
});
|
|
142
|
+
await this.#client.relayMessage(jid, edit.message, {
|
|
143
|
+
...relayOptions,
|
|
144
|
+
messageId: edit.key.id
|
|
145
|
+
});
|
|
146
|
+
return edit;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async streamText(jid, text, { chunkSize = 120, intervalMs = 900, cursor = ' ▍', ...sendOptions } = {}) {
|
|
150
|
+
if (!jid) throw new TypeError('streamText(jid, text) requires a jid');
|
|
151
|
+
const chunks = (Array.isArray(text) ? text.map(String) : splitAtWords(String(text ?? ''), chunkSize))
|
|
152
|
+
.filter(chunk => chunk.length > 0);
|
|
153
|
+
if (!chunks.length || chunks.every(chunk => !chunk.trim())) {
|
|
154
|
+
throw new TypeError('streamText(jid, text) requires non-empty text');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const waitMs = Math.max(300, Number(intervalMs) || 0);
|
|
158
|
+
const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
159
|
+
let revealed = '';
|
|
160
|
+
let edits = 0;
|
|
161
|
+
const block = { type: 'text', text: '' };
|
|
162
|
+
this._blocks.push(block);
|
|
163
|
+
|
|
164
|
+
for (let index = 0; index < chunks.length; index += 1) {
|
|
165
|
+
revealed += chunks[index];
|
|
166
|
+
const isLast = index === chunks.length - 1;
|
|
167
|
+
block.text = isLast ? revealed : revealed + (cursor || '');
|
|
168
|
+
if (index === 0) {
|
|
169
|
+
await this.send(jid, sendOptions);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
await wait(waitMs);
|
|
173
|
+
await this.sendEdit(undefined, undefined, sendOptions);
|
|
174
|
+
edits += 1;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return { key: this._lastMessageKey, text: revealed, edits };
|
|
178
|
+
}
|
|
179
|
+
}
|