@pontalabs/baileys 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +267 -839
- package/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -55
- package/WAProto/index.js +97689 -29
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +72 -74
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +94 -108
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +8 -7
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -16
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +11 -13
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +19 -61
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +14 -16
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +41 -70
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -61
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +9 -14
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +10 -58
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +13 -34
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +28 -36
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +38 -45
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +14 -15
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +20 -31
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +24 -25
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +18 -35
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +29 -34
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +37 -100
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -10
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +15 -22
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -8
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +279 -121
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -28
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +277 -184
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -22
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +8 -15
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +29 -37
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +208 -178
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +91 -127
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +120 -93
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +727 -652
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/dugong.js +261 -0
- package/lib/Socket/dugong.js.bak +204 -0
- package/lib/Socket/groups.d.ts +143 -111
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +165 -177
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +252 -183
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +38 -18
- package/lib/Socket/index.js.bak +44 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +196 -167
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1443 -1563
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +192 -158
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1102 -1208
- package/lib/Socket/messages-send.js.bak +1400 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +163 -138
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +153 -249
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +50 -36
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +749 -820
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.d.ts.map +1 -0
- package/lib/Store/index.js +4 -24
- package/lib/Store/index.js.map +1 -0
- package/lib/Store/make-in-memory-store.d.ts +44 -104
- package/lib/Store/make-in-memory-store.d.ts.map +1 -0
- package/lib/Store/make-in-memory-store.js +199 -213
- package/lib/Store/make-in-memory-store.js.map +1 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -12
- package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
- package/lib/Store/make-ordered-dictionary.js +38 -45
- package/lib/Store/make-ordered-dictionary.js.map +1 -0
- package/lib/Store/object-repository.d.ts +11 -10
- package/lib/Store/object-repository.d.ts.map +1 -0
- package/lib/Store/object-repository.js +9 -16
- package/lib/Store/object-repository.js.map +1 -0
- package/lib/Types/Auth.d.ts +93 -97
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +14 -13
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +78 -97
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -9
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +12 -9
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +206 -176
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +53 -48
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +13 -14
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +24 -30
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +15 -20
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +6 -12
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +248 -412
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +17 -19
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +58 -71
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.d.ts.map +1 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/RichType.js.bak +23 -0
- package/lib/Types/RichType.js.map +1 -0
- package/lib/Types/Signal.d.ts +71 -82
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +76 -81
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +75 -19
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -14
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +47 -62
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -50
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +13 -10
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +213 -454
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +14 -20
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +110 -134
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +88 -70
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +466 -403
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +27 -46
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +117 -188
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +58 -45
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +213 -303
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +14 -17
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +321 -296
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +66 -92
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +270 -436
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -23
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +106 -76
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +24 -21
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +24 -41
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +12 -14
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +40 -75
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +10 -11
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -14
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -53
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +28 -44
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -88
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -160
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +105 -107
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +548 -619
- package/lib/Utils/messages-media.js.bak +786 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +52 -66
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1730 -1558
- package/lib/Utils/messages.js.backup +1768 -0
- package/lib/Utils/messages.js.bak +1809 -0
- package/lib/Utils/messages.js.bak2 +893 -0
- package/lib/Utils/messages.js.bak3 +1183 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +176 -130
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +43 -32
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +484 -282
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.d.ts.map +1 -0
- package/lib/Utils/rich-message-utils.js +1220 -724
- package/lib/Utils/rich-message-utils.js.backup +706 -0
- package/lib/Utils/rich-message-utils.js.bak +246 -0
- package/lib/Utils/rich-message-utils.js.map +1 -0
- package/lib/Utils/rich-message-utils.js.original +1332 -0
- package/lib/Utils/signal.d.ts +37 -32
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +140 -105
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +70 -120
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -13
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +92 -66
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -13
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +128 -113
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1451 -1292
- package/lib/WABinary/constants.js.bak +1373 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -9
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +163 -189
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +14 -27
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +177 -105
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -25
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +41 -51
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +83 -120
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +10 -13
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -15
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +7 -14
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +30 -37
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19193 -11711
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +95 -109
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -23
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -21
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -26
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +27 -28
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +68 -62
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +15 -10
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +20 -19
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -23
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +11 -12
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -39
- package/lib/index.js.map +1 -0
- package/package.json +86 -42
|
@@ -0,0 +1,1332 @@
|
|
|
1
|
+
import { getRandomValues, randomUUID, randomBytes } from 'crypto';
|
|
2
|
+
import { DONATE_URL, LEXER_REGEX } from '../Defaults/index.js';
|
|
3
|
+
import { LANGUAGE_KEYWORDS } from '../WABinary/constants.js';
|
|
4
|
+
import { CodeHighlightType, RichSubMessageType } from '../Types/RichType.js';
|
|
5
|
+
import { proto } from '../../WAProto/index.js';
|
|
6
|
+
import { unixTimestampSeconds, generateMessageIDV2 } from './generics.js';
|
|
7
|
+
|
|
8
|
+
const NOOP = new Set([]);
|
|
9
|
+
|
|
10
|
+
/* ─────────────────────────────────────────────────────────────
|
|
11
|
+
LATEX URL GENERATOR
|
|
12
|
+
WhatsApp client membutuhkan URL gambar render untuk setiap
|
|
13
|
+
LaTeX expression. Tanpa URL, pesan tampil kosong.
|
|
14
|
+
Gunakan latex.codecogs.com sebagai fallback gratis~
|
|
15
|
+
───────────────────────────────────────────────────────────── */
|
|
16
|
+
const buildLatexUrl = (expression) => {
|
|
17
|
+
if (!expression) return null;
|
|
18
|
+
const encoded = encodeURIComponent(expression);
|
|
19
|
+
return `https://latex.codecogs.com/png.image?\dpi{150}\bg{white}${encoded}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/* ─────────────────────────────────────────────────────────────
|
|
23
|
+
IMAGE URL HELPER
|
|
24
|
+
Konversi objek AIRichResponseImageURL ke snake_case JSON
|
|
25
|
+
agar WA client bisa baca dengan benar~
|
|
26
|
+
───────────────────────────────────────────────────────────── */
|
|
27
|
+
const toImageUrlJson = (imgUrl) => {
|
|
28
|
+
if (!imgUrl) return null;
|
|
29
|
+
// support both plain string and object
|
|
30
|
+
if (typeof imgUrl === 'string') return { image_preview_url: imgUrl, image_high_res_url: imgUrl, source_url: null };
|
|
31
|
+
return {
|
|
32
|
+
image_preview_url: imgUrl.imagePreviewUrl || imgUrl.image_preview_url || null,
|
|
33
|
+
image_high_res_url: imgUrl.imageHighResUrl || imgUrl.image_high_res_url || null,
|
|
34
|
+
source_url: imgUrl.sourceUrl || imgUrl.source_url || null
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/* ─────────────────────────────────────────────────────────────
|
|
39
|
+
TOKENIZER
|
|
40
|
+
───────────────────────────────────────────────────────────── */
|
|
41
|
+
|
|
42
|
+
export const tokenizeCode = (code, language = 'javascript') => {
|
|
43
|
+
const keywords = LANGUAGE_KEYWORDS[language] || NOOP;
|
|
44
|
+
const blocks = [];
|
|
45
|
+
LEXER_REGEX.lastIndex = 0;
|
|
46
|
+
let match;
|
|
47
|
+
while ((match = LEXER_REGEX.exec(code)) !== null) {
|
|
48
|
+
if (match[1]) {
|
|
49
|
+
blocks.push({ highlightType: CodeHighlightType.COMMENT, codeContent: match[1] });
|
|
50
|
+
} else if (match[2]) {
|
|
51
|
+
blocks.push({ highlightType: CodeHighlightType.STRING, codeContent: match[2] });
|
|
52
|
+
} else if (match[3]) {
|
|
53
|
+
blocks.push({
|
|
54
|
+
highlightType: keywords.has(match[3]) ? CodeHighlightType.KEYWORD : CodeHighlightType.METHOD,
|
|
55
|
+
codeContent: match[3],
|
|
56
|
+
});
|
|
57
|
+
} else if (match[4]) {
|
|
58
|
+
blocks.push({
|
|
59
|
+
highlightType: keywords.has(match[4]) ? CodeHighlightType.KEYWORD : CodeHighlightType.DEFAULT,
|
|
60
|
+
codeContent: match[4],
|
|
61
|
+
});
|
|
62
|
+
} else if (match[5]) {
|
|
63
|
+
blocks.push({ highlightType: CodeHighlightType.NUMBER, codeContent: match[5] });
|
|
64
|
+
} else {
|
|
65
|
+
blocks.push({ highlightType: CodeHighlightType.DEFAULT, codeContent: match[6] });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return blocks;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/* ─────────────────────────────────────────────────────────────
|
|
72
|
+
INCOMING DECODER — parse rich message yang diterima
|
|
73
|
+
───────────────────────────────────────────────────────────── */
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Parse sebuah AIRichResponseSubMessage proto menjadi object JS yang mudah dipakai.
|
|
77
|
+
* Return null kalau tipe tidak dikenal.
|
|
78
|
+
*/
|
|
79
|
+
export const parseRichSubMessage = (submessage) => {
|
|
80
|
+
if (!submessage) return null;
|
|
81
|
+
const type = submessage.messageType;
|
|
82
|
+
|
|
83
|
+
switch (type) {
|
|
84
|
+
case RichSubMessageType.TEXT:
|
|
85
|
+
return {
|
|
86
|
+
type: 'text',
|
|
87
|
+
text: submessage.messageText || '',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
case RichSubMessageType.CODE:
|
|
91
|
+
return {
|
|
92
|
+
type: 'code',
|
|
93
|
+
language: submessage.codeMetadata?.codeLanguage || 'plain',
|
|
94
|
+
blocks: (submessage.codeMetadata?.codeBlocks || []).map(b => ({
|
|
95
|
+
highlight: CodeHighlightType[b.highlightType] ?? 'DEFAULT',
|
|
96
|
+
content: b.codeContent || '',
|
|
97
|
+
})),
|
|
98
|
+
/** Helper: ambil source code mentah tanpa highlight info */
|
|
99
|
+
get raw() {
|
|
100
|
+
return this.blocks.map(b => b.content).join('');
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
case RichSubMessageType.TABLE:
|
|
105
|
+
return {
|
|
106
|
+
type: 'table',
|
|
107
|
+
title: submessage.tableMetadata?.title || '',
|
|
108
|
+
rows: (submessage.tableMetadata?.rows || []).map(row => ({
|
|
109
|
+
isHeading: row.isHeading ?? false,
|
|
110
|
+
items: row.items || [],
|
|
111
|
+
})),
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
case RichSubMessageType.GRID_IMAGE:
|
|
115
|
+
return {
|
|
116
|
+
type: 'gridImage',
|
|
117
|
+
gridImageUrl: submessage.gridImageMetadata?.gridImageUrl || null,
|
|
118
|
+
imageUrls: submessage.gridImageMetadata?.imageUrls || [],
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
case RichSubMessageType.INLINE_IMAGE:
|
|
122
|
+
return {
|
|
123
|
+
type: 'inlineImage',
|
|
124
|
+
imageUrl: submessage.imageMetadata?.imageUrl || null,
|
|
125
|
+
imageText: submessage.imageMetadata?.imageText || '',
|
|
126
|
+
alignment: submessage.imageMetadata?.alignment ?? 0,
|
|
127
|
+
tapLinkUrl: submessage.imageMetadata?.tapLinkUrl || null,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
case RichSubMessageType.DYNAMIC:
|
|
131
|
+
return {
|
|
132
|
+
type: 'dynamic',
|
|
133
|
+
dynamicType: submessage.dynamicMetadata?.type ?? 0,
|
|
134
|
+
version: submessage.dynamicMetadata?.version ?? 0,
|
|
135
|
+
url: submessage.dynamicMetadata?.url || null,
|
|
136
|
+
loopCount: submessage.dynamicMetadata?.loopCount ?? 0,
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
case RichSubMessageType.MAP:
|
|
140
|
+
return {
|
|
141
|
+
type: 'map',
|
|
142
|
+
centerLatitude: submessage.mapMetadata?.centerLatitude ?? 0,
|
|
143
|
+
centerLongitude: submessage.mapMetadata?.centerLongitude ?? 0,
|
|
144
|
+
latitudeDelta: submessage.mapMetadata?.latitudeDelta ?? 0,
|
|
145
|
+
longitudeDelta: submessage.mapMetadata?.longitudeDelta ?? 0,
|
|
146
|
+
showInfoList: submessage.mapMetadata?.showInfoList ?? false,
|
|
147
|
+
annotations: (submessage.mapMetadata?.annotations || []).map(a => ({
|
|
148
|
+
number: a.annotationNumber ?? 0,
|
|
149
|
+
latitude: a.latitude ?? 0,
|
|
150
|
+
longitude: a.longitude ?? 0,
|
|
151
|
+
title: a.title || '',
|
|
152
|
+
body: a.body || '',
|
|
153
|
+
})),
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
case RichSubMessageType.LATEX:
|
|
157
|
+
return {
|
|
158
|
+
type: 'latex',
|
|
159
|
+
text: submessage.latexMetadata?.text || '',
|
|
160
|
+
expressions: (submessage.latexMetadata?.expressions || []).map(e => ({
|
|
161
|
+
expression: e.latexExpression || '',
|
|
162
|
+
url: e.url || null,
|
|
163
|
+
width: e.width ?? 0,
|
|
164
|
+
height: e.height ?? 0,
|
|
165
|
+
})),
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
case RichSubMessageType.CONTENT_ITEMS:
|
|
169
|
+
return {
|
|
170
|
+
type: 'contentItems',
|
|
171
|
+
contentType: submessage.contentItemsMetadata?.contentType ?? 0,
|
|
172
|
+
items: (submessage.contentItemsMetadata?.itemsMetadata || []).map(item => {
|
|
173
|
+
if (item.reelItem) {
|
|
174
|
+
return {
|
|
175
|
+
kind: 'reel',
|
|
176
|
+
title: item.reelItem.title || '',
|
|
177
|
+
profileIconUrl: item.reelItem.profileIconUrl || null,
|
|
178
|
+
thumbnailUrl: item.reelItem.thumbnailUrl || null,
|
|
179
|
+
videoUrl: item.reelItem.videoUrl || null,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return { kind: 'unknown' };
|
|
183
|
+
}),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
default:
|
|
187
|
+
return { type: 'unknown', raw: submessage };
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Parse seluruh AIRichResponseMessage menjadi array parsed submessages.
|
|
193
|
+
* Bisa dipanggil langsung dari handler messages.upsert:
|
|
194
|
+
*
|
|
195
|
+
* const inner = normalizeMessageContent(msg.message)
|
|
196
|
+
* const parsed = parseRichMessage(inner?.richResponseMessage)
|
|
197
|
+
*/
|
|
198
|
+
export const parseRichMessage = (richResponseMessage) => {
|
|
199
|
+
if (!richResponseMessage) return null;
|
|
200
|
+
|
|
201
|
+
const submessages = (richResponseMessage.submessages || [])
|
|
202
|
+
.map(parseRichSubMessage)
|
|
203
|
+
.filter(Boolean);
|
|
204
|
+
|
|
205
|
+
let unifiedData = null;
|
|
206
|
+
if (richResponseMessage.unifiedResponse?.data) {
|
|
207
|
+
try {
|
|
208
|
+
const buf = richResponseMessage.unifiedResponse.data;
|
|
209
|
+
unifiedData = JSON.parse(Buffer.isBuffer(buf) ? buf.toString('utf-8') : Buffer.from(buf).toString('utf-8'));
|
|
210
|
+
} catch (_) { /* ignore parse error */ }
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
messageType: richResponseMessage.messageType ?? 0,
|
|
215
|
+
submessages,
|
|
216
|
+
unifiedData,
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/* ─────────────────────────────────────────────────────────────
|
|
221
|
+
OUTGOING BUILDER — unified response JSON per subtype
|
|
222
|
+
───────────────────────────────────────────────────────────── */
|
|
223
|
+
|
|
224
|
+
const buildUnifiedSection = (submessage) => {
|
|
225
|
+
switch (submessage.messageType) {
|
|
226
|
+
case RichSubMessageType.TEXT:
|
|
227
|
+
return {
|
|
228
|
+
view_model: {
|
|
229
|
+
primitive: {
|
|
230
|
+
text: submessage.messageText,
|
|
231
|
+
inline_entities: submessage.inlineEntities || [],
|
|
232
|
+
__typename: 'GenAIMarkdownTextUXPrimitive'
|
|
233
|
+
},
|
|
234
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
case RichSubMessageType.CODE: {
|
|
239
|
+
const cm = submessage.codeMetadata;
|
|
240
|
+
return {
|
|
241
|
+
view_model: {
|
|
242
|
+
primitive: {
|
|
243
|
+
language: cm.codeLanguage,
|
|
244
|
+
code_blocks: cm.codeBlocks.map(b => ({
|
|
245
|
+
content: b.codeContent,
|
|
246
|
+
type: CodeHighlightType[b.highlightType]
|
|
247
|
+
})),
|
|
248
|
+
__typename: 'GenAICodeUXPrimitive'
|
|
249
|
+
},
|
|
250
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
case RichSubMessageType.TABLE: {
|
|
256
|
+
const tm = submessage.tableMetadata;
|
|
257
|
+
return {
|
|
258
|
+
view_model: {
|
|
259
|
+
primitive: {
|
|
260
|
+
title: tm.title,
|
|
261
|
+
rows: tm.rows.map(row => ({
|
|
262
|
+
is_header: row.isHeading,
|
|
263
|
+
cells: row.items,
|
|
264
|
+
markdown_cells: row.items.map(item => ({ text: item }))
|
|
265
|
+
})),
|
|
266
|
+
__typename: 'GenATableUXPrimitive'
|
|
267
|
+
},
|
|
268
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
case RichSubMessageType.GRID_IMAGE: {
|
|
274
|
+
const gm = submessage.gridImageMetadata;
|
|
275
|
+
return {
|
|
276
|
+
view_model: {
|
|
277
|
+
primitive: {
|
|
278
|
+
grid_image_url: toImageUrlJson(gm.gridImageUrl),
|
|
279
|
+
image_urls: (gm.imageUrls || []).map(toImageUrlJson),
|
|
280
|
+
__typename: 'GenAIGridImageUXPrimitive'
|
|
281
|
+
},
|
|
282
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
case RichSubMessageType.INLINE_IMAGE: {
|
|
288
|
+
const im = submessage.imageMetadata;
|
|
289
|
+
return {
|
|
290
|
+
view_model: {
|
|
291
|
+
primitive: {
|
|
292
|
+
image_url: toImageUrlJson(im.imageUrl),
|
|
293
|
+
image_text: im.imageText,
|
|
294
|
+
alignment: im.alignment ?? 0,
|
|
295
|
+
tap_link_url: im.tapLinkUrl || null,
|
|
296
|
+
__typename: 'GenAIInlineImageUXPrimitive'
|
|
297
|
+
},
|
|
298
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
case RichSubMessageType.DYNAMIC: {
|
|
304
|
+
const dm = submessage.dynamicMetadata;
|
|
305
|
+
return {
|
|
306
|
+
view_model: {
|
|
307
|
+
primitive: {
|
|
308
|
+
type: dm.type ?? 0,
|
|
309
|
+
version: dm.version ?? 0,
|
|
310
|
+
url: dm.url,
|
|
311
|
+
loop_count: dm.loopCount ?? 0,
|
|
312
|
+
__typename: 'GenAIDynamicUXPrimitive'
|
|
313
|
+
},
|
|
314
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
case RichSubMessageType.MAP: {
|
|
320
|
+
const mm = submessage.mapMetadata;
|
|
321
|
+
return {
|
|
322
|
+
view_model: {
|
|
323
|
+
primitive: {
|
|
324
|
+
center_latitude: mm.centerLatitude,
|
|
325
|
+
center_longitude: mm.centerLongitude,
|
|
326
|
+
latitude_delta: mm.latitudeDelta,
|
|
327
|
+
longitude_delta: mm.longitudeDelta,
|
|
328
|
+
show_info_list: mm.showInfoList ?? false,
|
|
329
|
+
annotations: (mm.annotations || []).map(a => ({
|
|
330
|
+
annotation_number: a.annotationNumber,
|
|
331
|
+
latitude: a.latitude,
|
|
332
|
+
longitude: a.longitude,
|
|
333
|
+
title: a.title,
|
|
334
|
+
body: a.body
|
|
335
|
+
})),
|
|
336
|
+
__typename: 'GenAIMapUXPrimitive'
|
|
337
|
+
},
|
|
338
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
case RichSubMessageType.LATEX: {
|
|
344
|
+
const lm = submessage.latexMetadata;
|
|
345
|
+
return {
|
|
346
|
+
view_model: {
|
|
347
|
+
primitive: {
|
|
348
|
+
text: lm.text,
|
|
349
|
+
expressions: (lm.expressions || []).map(e => ({
|
|
350
|
+
latex_expression: e.latexExpression,
|
|
351
|
+
url: e.url,
|
|
352
|
+
width: e.width,
|
|
353
|
+
height: e.height,
|
|
354
|
+
font_height: e.fontHeight,
|
|
355
|
+
image_top_padding: e.imageTopPadding,
|
|
356
|
+
image_leading_padding: e.imageLeadingPadding,
|
|
357
|
+
image_bottom_padding: e.imageBottomPadding,
|
|
358
|
+
image_trailing_padding: e.imageTrailingPadding
|
|
359
|
+
})),
|
|
360
|
+
__typename: 'GenAILatexUXPrimitive'
|
|
361
|
+
},
|
|
362
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
case RichSubMessageType.CONTENT_ITEMS: {
|
|
368
|
+
const ci = submessage.contentItemsMetadata;
|
|
369
|
+
return {
|
|
370
|
+
view_model: {
|
|
371
|
+
primitive: {
|
|
372
|
+
content_type: ci.contentType ?? 0,
|
|
373
|
+
items_metadata: (ci.itemsMetadata || []).map(item => {
|
|
374
|
+
if (item.reelItem) {
|
|
375
|
+
return {
|
|
376
|
+
reel_item: {
|
|
377
|
+
title: item.reelItem.title,
|
|
378
|
+
profile_icon_url: item.reelItem.profileIconUrl,
|
|
379
|
+
thumbnail_url: item.reelItem.thumbnailUrl,
|
|
380
|
+
video_url: item.reelItem.videoUrl
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
return {};
|
|
385
|
+
}),
|
|
386
|
+
__typename: 'GenAIContentItemsUXPrimitive'
|
|
387
|
+
},
|
|
388
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
default:
|
|
394
|
+
return submessage;
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
export const toUnified = (submessages) => ({
|
|
399
|
+
response_id: randomUUID(),
|
|
400
|
+
sections: submessages.map(buildUnifiedSection)
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
/* ─────────────────────────────────────────────────────────────
|
|
404
|
+
PREPARE HELPERS — builder per tipe submessage
|
|
405
|
+
───────────────────────────────────────────────────────────── */
|
|
406
|
+
|
|
407
|
+
/** Buat submessage TEXT */
|
|
408
|
+
const makeTextSub = (text, inlineEntities) => ({
|
|
409
|
+
messageType: RichSubMessageType.TEXT,
|
|
410
|
+
messageText: text,
|
|
411
|
+
...(inlineEntities ? { inlineEntities } : {})
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
/** Buat submessage CODE dengan auto-tokenize */
|
|
415
|
+
const makeCodeSub = (code, language = 'javascript') => ({
|
|
416
|
+
messageType: RichSubMessageType.CODE,
|
|
417
|
+
codeMetadata: {
|
|
418
|
+
codeLanguage: language,
|
|
419
|
+
codeBlocks: tokenizeCode(code, language)
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
/** Buat submessage TABLE */
|
|
424
|
+
const makeTableSub = (rows, title, noHeading) => ({
|
|
425
|
+
messageType: RichSubMessageType.TABLE,
|
|
426
|
+
tableMetadata: {
|
|
427
|
+
title: title || '',
|
|
428
|
+
rows: rows.map((items, i) => ({
|
|
429
|
+
isHeading: !noHeading && i === 0,
|
|
430
|
+
items
|
|
431
|
+
}))
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
/** Normalize input ke format AIRichResponseImageURL */
|
|
436
|
+
const normalizeImageUrl = (u) => {
|
|
437
|
+
if (!u) return null;
|
|
438
|
+
if (typeof u === 'string') return { imagePreviewUrl: u, imageHighResUrl: u, sourceUrl: null };
|
|
439
|
+
return {
|
|
440
|
+
imagePreviewUrl: u.imagePreviewUrl || u.image_preview_url || null,
|
|
441
|
+
imageHighResUrl: u.imageHighResUrl || u.image_high_res_url || null,
|
|
442
|
+
sourceUrl: u.sourceUrl || u.source_url || null
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/** Buat submessage GRID_IMAGE */
|
|
447
|
+
const makeGridImageSub = (gridImageUrl, imageUrls = []) => ({
|
|
448
|
+
messageType: RichSubMessageType.GRID_IMAGE,
|
|
449
|
+
gridImageMetadata: {
|
|
450
|
+
gridImageUrl: normalizeImageUrl(gridImageUrl),
|
|
451
|
+
imageUrls: (imageUrls || []).map(normalizeImageUrl)
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
/** Buat submessage INLINE_IMAGE */
|
|
456
|
+
const makeInlineImageSub = (imageUrl, imageText = '', alignment = 0, tapLinkUrl = null) => ({
|
|
457
|
+
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
458
|
+
imageMetadata: {
|
|
459
|
+
imageUrl: normalizeImageUrl(imageUrl),
|
|
460
|
+
imageText,
|
|
461
|
+
alignment,
|
|
462
|
+
tapLinkUrl
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
/** Buat submessage DYNAMIC (animated image/GIF) */
|
|
467
|
+
const makeDynamicSub = (url, dynamicType = 1, version = 1, loopCount = 0) => ({
|
|
468
|
+
messageType: RichSubMessageType.DYNAMIC,
|
|
469
|
+
dynamicMetadata: { type: dynamicType, version, url, loopCount }
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
/** Buat submessage MAP */
|
|
473
|
+
const makeMapSub = (centerLatitude, centerLongitude, options = {}) => ({
|
|
474
|
+
messageType: RichSubMessageType.MAP,
|
|
475
|
+
mapMetadata: {
|
|
476
|
+
centerLatitude,
|
|
477
|
+
centerLongitude,
|
|
478
|
+
latitudeDelta: options.latitudeDelta ?? 0.05,
|
|
479
|
+
longitudeDelta: options.longitudeDelta ?? 0.05,
|
|
480
|
+
showInfoList: options.showInfoList ?? false,
|
|
481
|
+
annotations: (options.annotations || []).map((a, i) => ({
|
|
482
|
+
annotationNumber: a.number ?? i + 1,
|
|
483
|
+
latitude: a.latitude,
|
|
484
|
+
longitude: a.longitude,
|
|
485
|
+
title: a.title || '',
|
|
486
|
+
body: a.body || ''
|
|
487
|
+
}))
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
/** Buat submessage LATEX */
|
|
492
|
+
const makeLatexSub = (text, expressions = []) => ({
|
|
493
|
+
messageType: RichSubMessageType.LATEX,
|
|
494
|
+
latexMetadata: {
|
|
495
|
+
text,
|
|
496
|
+
expressions: expressions.map(e => {
|
|
497
|
+
const expr = e.expression || e.latexExpression || '';
|
|
498
|
+
// url WAJIB ada agar WA client bisa render — auto-generate jika tidak disupply
|
|
499
|
+
const url = e.url || buildLatexUrl(expr);
|
|
500
|
+
return {
|
|
501
|
+
latexExpression: expr,
|
|
502
|
+
url,
|
|
503
|
+
width: e.width ?? 120,
|
|
504
|
+
height: e.height ?? 40,
|
|
505
|
+
fontHeight: e.fontHeight ?? 0,
|
|
506
|
+
imageTopPadding: e.imageTopPadding ?? 0,
|
|
507
|
+
imageLeadingPadding: e.imageLeadingPadding ?? 0,
|
|
508
|
+
imageBottomPadding: e.imageBottomPadding ?? 0,
|
|
509
|
+
imageTrailingPadding: e.imageTrailingPadding ?? 0
|
|
510
|
+
};
|
|
511
|
+
})
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
/** Buat submessage CONTENT_ITEMS (carousel reel) */
|
|
516
|
+
const makeContentItemsSub = (items, contentType = 0) => ({
|
|
517
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
518
|
+
contentItemsMetadata: {
|
|
519
|
+
contentType,
|
|
520
|
+
itemsMetadata: items.map(item => {
|
|
521
|
+
if (item.reelItem || item.kind === 'reel') {
|
|
522
|
+
const r = item.reelItem || item;
|
|
523
|
+
return {
|
|
524
|
+
reelItem: {
|
|
525
|
+
title: r.title || '',
|
|
526
|
+
profileIconUrl: r.profileIconUrl || null,
|
|
527
|
+
thumbnailUrl: r.thumbnailUrl || null,
|
|
528
|
+
videoUrl: r.videoUrl || null
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
return {};
|
|
533
|
+
})
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
/** Buat section SOURCE (search result links) — hanya unified, tidak ada submessage proto */
|
|
538
|
+
const makeSourceSection = (sources = []) => {
|
|
539
|
+
const list = Array.isArray(sources) ? sources : [sources];
|
|
540
|
+
return {
|
|
541
|
+
view_model: {
|
|
542
|
+
primitive: {
|
|
543
|
+
sources: list.map(s => ({
|
|
544
|
+
source_url: s.url ?? s.source_url ?? '',
|
|
545
|
+
source_title: s.title ?? s.source_title ?? '',
|
|
546
|
+
source_display_name: s.display_name ?? s.displayName ?? s.title ?? '',
|
|
547
|
+
source_subtitle: s.subtitle ?? s.source_subtitle ?? '',
|
|
548
|
+
source_type: s.source_type ?? 'THIRD_PARTY',
|
|
549
|
+
favicon: {
|
|
550
|
+
url: s.favicon ?? s.faviconCDNURL ?? '',
|
|
551
|
+
width: 16,
|
|
552
|
+
height: 16
|
|
553
|
+
}
|
|
554
|
+
})),
|
|
555
|
+
__typename: 'GenAISearchResultPrimitive'
|
|
556
|
+
},
|
|
557
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
/** Buat submessage + unified section untuk IMAGE (grid image style) */
|
|
563
|
+
const makeImageSub = (imageUrl) => {
|
|
564
|
+
const urls = Array.isArray(imageUrl) ? imageUrl : [imageUrl];
|
|
565
|
+
const imageUrls = urls.map(u => ({
|
|
566
|
+
imagePreviewUrl: u,
|
|
567
|
+
imageHighResUrl: u,
|
|
568
|
+
sourceUrl: null
|
|
569
|
+
}));
|
|
570
|
+
return {
|
|
571
|
+
sub: {
|
|
572
|
+
messageType: RichSubMessageType.GRID_IMAGE,
|
|
573
|
+
gridImageMetadata: {
|
|
574
|
+
gridImageUrl: normalizeImageUrl(urls[0]),
|
|
575
|
+
imageUrls: imageUrls.map(normalizeImageUrl)
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
sections: imageUrls.map(({ imagePreviewUrl }) => ({
|
|
579
|
+
view_model: {
|
|
580
|
+
primitive: {
|
|
581
|
+
media: { url: imagePreviewUrl, mime_type: 'image/png' },
|
|
582
|
+
imagine_type: 'IMAGE',
|
|
583
|
+
status: { status: 'READY' },
|
|
584
|
+
__typename: 'GenAIImaginePrimitive'
|
|
585
|
+
},
|
|
586
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
587
|
+
}
|
|
588
|
+
}))
|
|
589
|
+
};
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
/** Buat submessage + unified section untuk VIDEO */
|
|
593
|
+
const makeVideoSub = (videoUrl) => {
|
|
594
|
+
const urls = Array.isArray(videoUrl) ? videoUrl : [videoUrl];
|
|
595
|
+
const parsed = urls.map(item => {
|
|
596
|
+
const [url, duration = '0'] = item.split('|');
|
|
597
|
+
return { url, duration: Number(duration) || 0 };
|
|
598
|
+
});
|
|
599
|
+
return {
|
|
600
|
+
sub: {
|
|
601
|
+
messageType: RichSubMessageType.DYNAMIC,
|
|
602
|
+
dynamicMetadata: {
|
|
603
|
+
type: 1,
|
|
604
|
+
version: 1,
|
|
605
|
+
url: parsed[0]?.url || '',
|
|
606
|
+
loopCount: 0
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
sections: parsed.map(({ url, duration }) => ({
|
|
610
|
+
view_model: {
|
|
611
|
+
primitive: {
|
|
612
|
+
media: { url, mime_type: 'video/mp4', duration },
|
|
613
|
+
imagine_type: 'ANIMATE',
|
|
614
|
+
status: { status: 'READY' },
|
|
615
|
+
__typename: 'GenAIImaginePrimitive'
|
|
616
|
+
},
|
|
617
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
618
|
+
}
|
|
619
|
+
}))
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
/** Buat submessage + unified section untuk REELS (HScroll) */
|
|
624
|
+
const makeReelsSub = (reelsItems = []) => {
|
|
625
|
+
const list = Array.isArray(reelsItems) ? reelsItems : [reelsItems];
|
|
626
|
+
return {
|
|
627
|
+
sub: {
|
|
628
|
+
messageType: RichSubMessageType.CONTENT_ITEMS,
|
|
629
|
+
contentItemsMetadata: {
|
|
630
|
+
contentType: 1,
|
|
631
|
+
itemsMetadata: list.map(item => ({
|
|
632
|
+
reelItem: {
|
|
633
|
+
title: item.username ?? item.title ?? '',
|
|
634
|
+
profileIconUrl: item.profileIconUrl ?? item.profile_url ?? null,
|
|
635
|
+
thumbnailUrl: item.thumbnailUrl ?? item.thumbnail ?? null,
|
|
636
|
+
videoUrl: item.videoUrl ?? item.url ?? null
|
|
637
|
+
}
|
|
638
|
+
}))
|
|
639
|
+
}
|
|
640
|
+
},
|
|
641
|
+
section: {
|
|
642
|
+
view_model: {
|
|
643
|
+
primitives: list.map(item => ({
|
|
644
|
+
reels_url: item.videoUrl ?? item.url ?? '',
|
|
645
|
+
thumbnail_url: item.thumbnailUrl ?? item.thumbnail ?? '',
|
|
646
|
+
creator: item.username ?? item.title ?? '',
|
|
647
|
+
avatar_url: item.profileIconUrl ?? item.profile_url ?? '',
|
|
648
|
+
reels_title: item.reels_title ?? item.title ?? '',
|
|
649
|
+
likes_count: item.likes_count ?? item.like ?? 0,
|
|
650
|
+
shares_count: item.shares_count ?? item.share ?? 0,
|
|
651
|
+
view_count: item.view_count ?? item.view ?? 0,
|
|
652
|
+
reel_source: item.reel_source ?? item.source ?? 'IG',
|
|
653
|
+
is_verified: !!(item.is_verified || item.verified),
|
|
654
|
+
__typename: 'GenAIReelPrimitive'
|
|
655
|
+
})),
|
|
656
|
+
__typename: 'GenAIHScrollLayoutViewModel'
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
/** Buat unified section untuk PRODUCT (single: Single layout, array: HScroll) */
|
|
663
|
+
const makeProductSection = (data) => {
|
|
664
|
+
const items = Array.isArray(data) ? data : [data];
|
|
665
|
+
const primitives = items.map(item => ({
|
|
666
|
+
title: item.title ?? '',
|
|
667
|
+
brand: item.brand ?? '',
|
|
668
|
+
price: item.price ?? '',
|
|
669
|
+
sale_price: item.sale_price ?? item.salePrice ?? '',
|
|
670
|
+
product_url: item.product_url ?? item.url ?? '',
|
|
671
|
+
image: { url: item.image_url ?? item.image ?? '' },
|
|
672
|
+
additional_images: [{ url: item.icon_url ?? item.icon ?? '' }],
|
|
673
|
+
__typename: 'GenAIProductItemCardPrimitive'
|
|
674
|
+
}));
|
|
675
|
+
const isMultiple = Array.isArray(data);
|
|
676
|
+
return {
|
|
677
|
+
sub: {
|
|
678
|
+
messageType: RichSubMessageType.TEXT,
|
|
679
|
+
messageText: '[ CANNOT_LOAD_PRODUCT ]'
|
|
680
|
+
},
|
|
681
|
+
section: isMultiple
|
|
682
|
+
? {
|
|
683
|
+
view_model: {
|
|
684
|
+
primitives,
|
|
685
|
+
__typename: 'GenAIHScrollLayoutViewModel'
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
: {
|
|
689
|
+
view_model: {
|
|
690
|
+
primitive: primitives[0],
|
|
691
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
};
|
|
696
|
+
|
|
697
|
+
/** Buat unified section untuk POST (HScroll) */
|
|
698
|
+
const makePostSection = (data) => {
|
|
699
|
+
const posts = Array.isArray(data) ? data : [data];
|
|
700
|
+
const primitives = posts.map(p => ({
|
|
701
|
+
title: p.title ?? '',
|
|
702
|
+
subtitle: p.subtitle ?? '',
|
|
703
|
+
username: p.username ?? '',
|
|
704
|
+
profile_picture_url: p.profile_picture_url ?? p.profile_url ?? '',
|
|
705
|
+
is_verified: !!(p.is_verified || p.verified),
|
|
706
|
+
thumbnail_url: p.thumbnail_url ?? p.thumbnail ?? '',
|
|
707
|
+
post_caption: p.post_caption ?? p.caption ?? '',
|
|
708
|
+
likes_count: p.likes_count ?? p.like ?? 0,
|
|
709
|
+
comments_count: p.comments_count ?? p.comment ?? 0,
|
|
710
|
+
shares_count: p.shares_count ?? p.share ?? 0,
|
|
711
|
+
post_url: p.post_url ?? p.url ?? '',
|
|
712
|
+
post_deeplink: p.post_deeplink ?? p.deeplink ?? '',
|
|
713
|
+
source_app: p.source_app ?? p.source ?? 'INSTAGRAM',
|
|
714
|
+
footer_label: p.footer_label ?? p.footer ?? '',
|
|
715
|
+
footer_icon: p.footer_icon ?? p.icon ?? '',
|
|
716
|
+
is_carousel: posts.length > 1,
|
|
717
|
+
orientation: p.orientation ?? 'LANDSCAPE',
|
|
718
|
+
post_type: p.post_type ?? 'VIDEO',
|
|
719
|
+
__typename: 'GenAIPostPrimitive'
|
|
720
|
+
}));
|
|
721
|
+
return {
|
|
722
|
+
sub: {
|
|
723
|
+
messageType: RichSubMessageType.TEXT,
|
|
724
|
+
messageText: '[ CANNOT_LOAD_POST ]'
|
|
725
|
+
},
|
|
726
|
+
section: {
|
|
727
|
+
view_model: {
|
|
728
|
+
primitives,
|
|
729
|
+
__typename: 'GenAIHScrollLayoutViewModel'
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
/** Buat submessage + unified section untuk TIP (metadata text) */
|
|
736
|
+
const makeTipSub = (text) => ({
|
|
737
|
+
sub: {
|
|
738
|
+
messageType: RichSubMessageType.TEXT,
|
|
739
|
+
messageText: text
|
|
740
|
+
},
|
|
741
|
+
section: {
|
|
742
|
+
view_model: {
|
|
743
|
+
primitive: {
|
|
744
|
+
text,
|
|
745
|
+
__typename: 'GenAIMetadataTextPrimitive'
|
|
746
|
+
},
|
|
747
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
|
|
752
|
+
/** Buat unified section untuk SUGGEST (ActionRow pill buttons) — tidak ada submessage proto */
|
|
753
|
+
const makeSuggestSection = (suggestion) => {
|
|
754
|
+
const suggestions = Array.isArray(suggestion) ? suggestion : [suggestion];
|
|
755
|
+
return {
|
|
756
|
+
view_model: {
|
|
757
|
+
primitives: suggestions.map(text => ({
|
|
758
|
+
prompt_text: text,
|
|
759
|
+
prompt_type: 'SUGGESTED_PROMPT',
|
|
760
|
+
__typename: 'GenAIFollowUpSuggestionPillPrimitive'
|
|
761
|
+
})),
|
|
762
|
+
__typename: 'GenAIActionRowLayoutViewModel'
|
|
763
|
+
}
|
|
764
|
+
};
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
/* ─────────────────────────────────────────────────────────────
|
|
768
|
+
MAIN BUILDER — prepareRichResponseMessage
|
|
769
|
+
───────────────────────────────────────────────────────────── */
|
|
770
|
+
|
|
771
|
+
export const prepareRichResponseMessage = (content) => {
|
|
772
|
+
const {
|
|
773
|
+
code, contentText, disclaimerText, footerText, headerText,
|
|
774
|
+
language, links, noHeading, richResponse, table, title,
|
|
775
|
+
// sub-types lama
|
|
776
|
+
gridImage, inlineImage, dynamic: dynamicContent,
|
|
777
|
+
map: mapContent, latex, contentItems,
|
|
778
|
+
// sub-types baru (prefixed 'rich' agar tidak konflik dengan media biasa)
|
|
779
|
+
richImage, richVideo, reels, source, richProduct, richPost, tip, suggest
|
|
780
|
+
} = content;
|
|
781
|
+
|
|
782
|
+
let submessages = [];
|
|
783
|
+
// extraSections: section-section unified yang tidak punya proto submessage 1:1
|
|
784
|
+
// (source, product, post, suggest) atau punya struktur multi-section (image, video, reels)
|
|
785
|
+
let extraSections = null;
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Helper: push ke submessages dan optionally ke extraSections.
|
|
789
|
+
* Untuk tipe yang punya make*Sub yang mengembalikan { sub, sections[] } atau { sub, section }
|
|
790
|
+
*/
|
|
791
|
+
const pushRich = (built) => {
|
|
792
|
+
if (!built) return;
|
|
793
|
+
if (built.sub) submessages.push(built.sub);
|
|
794
|
+
if (!extraSections) extraSections = [];
|
|
795
|
+
if (built.sections) extraSections.push(...built.sections);
|
|
796
|
+
else if (built.section) extraSections.push(built.section);
|
|
797
|
+
};
|
|
798
|
+
|
|
799
|
+
/* ── mode array (richResponse) — multi-section campuran ── */
|
|
800
|
+
if (Array.isArray(richResponse)) {
|
|
801
|
+
if (headerText) submessages.push(makeTextSub(headerText));
|
|
802
|
+
richResponse.forEach(sub => {
|
|
803
|
+
if (sub.text != null) { submessages.push(makeTextSub(sub.text, sub.inlineEntities)); return; }
|
|
804
|
+
if (sub.code != null) { submessages.push(makeCodeSub(sub.code, sub.language || 'javascript')); return; }
|
|
805
|
+
if (sub.table != null) { submessages.push(makeTableSub(sub.table, sub.title, sub.noHeading)); return; }
|
|
806
|
+
if (sub.gridImage != null) { submessages.push(makeGridImageSub(sub.gridImage.gridImageUrl, sub.gridImage.imageUrls)); return; }
|
|
807
|
+
if (sub.inlineImage != null) { submessages.push(makeInlineImageSub(sub.inlineImage.imageUrl, sub.inlineImage.imageText, sub.inlineImage.alignment, sub.inlineImage.tapLinkUrl)); return; }
|
|
808
|
+
if (sub.dynamic != null) { submessages.push(makeDynamicSub(sub.dynamic.url, sub.dynamic.type, sub.dynamic.version, sub.dynamic.loopCount)); return; }
|
|
809
|
+
if (sub.map != null) { submessages.push(makeMapSub(sub.map.centerLatitude, sub.map.centerLongitude, sub.map)); return; }
|
|
810
|
+
if (sub.latex != null) { submessages.push(makeLatexSub(sub.latex.text, sub.latex.expressions)); return; }
|
|
811
|
+
if (sub.contentItems != null) { submessages.push(makeContentItemsSub(sub.contentItems.items, sub.contentItems.contentType)); return; }
|
|
812
|
+
// tipe baru
|
|
813
|
+
if (sub.richImage != null) { pushRich(makeImageSub(sub.richImage)); return; }
|
|
814
|
+
if (sub.richVideo != null) { pushRich(makeVideoSub(sub.richVideo)); return; }
|
|
815
|
+
if (sub.reels != null) { pushRich(makeReelsSub(sub.reels)); return; }
|
|
816
|
+
if (sub.source != null) { if (!extraSections) extraSections = []; extraSections.push(makeSourceSection(sub.source)); return; }
|
|
817
|
+
if (sub.richProduct != null) { pushRich(makeProductSection(sub.richProduct)); return; }
|
|
818
|
+
if (sub.richPost != null) { pushRich(makePostSection(sub.richPost)); return; }
|
|
819
|
+
if (sub.tip != null) { pushRich(makeTipSub(sub.tip)); return; }
|
|
820
|
+
if (sub.suggest != null) { if (!extraSections) extraSections = []; extraSections.push(makeSuggestSection(sub.suggest)); return; }
|
|
821
|
+
submessages.push(sub); // passthrough kalau sudah bentuk proto
|
|
822
|
+
});
|
|
823
|
+
if (footerText) submessages.push(makeTextSub(footerText));
|
|
824
|
+
|
|
825
|
+
/* ── mode flat (convenience fields) ── */
|
|
826
|
+
} else {
|
|
827
|
+
if (headerText) submessages.push(makeTextSub(headerText));
|
|
828
|
+
if (contentText) submessages.push(makeTextSub(contentText));
|
|
829
|
+
|
|
830
|
+
if (code) submessages.push(makeCodeSub(code, language || 'javascript'));
|
|
831
|
+
if (table) submessages.push(makeTableSub(table, title, noHeading));
|
|
832
|
+
if (gridImage) submessages.push(makeGridImageSub(gridImage.gridImageUrl, gridImage.imageUrls));
|
|
833
|
+
if (inlineImage) submessages.push(makeInlineImageSub(inlineImage.imageUrl, inlineImage.imageText, inlineImage.alignment, inlineImage.tapLinkUrl));
|
|
834
|
+
if (dynamicContent) submessages.push(makeDynamicSub(dynamicContent.url, dynamicContent.type, dynamicContent.version, dynamicContent.loopCount));
|
|
835
|
+
if (mapContent) submessages.push(makeMapSub(mapContent.centerLatitude, mapContent.centerLongitude, mapContent));
|
|
836
|
+
if (latex) submessages.push(makeLatexSub(latex.text, latex.expressions));
|
|
837
|
+
if (contentItems) submessages.push(makeContentItemsSub(contentItems.items, contentItems.contentType));
|
|
838
|
+
|
|
839
|
+
// ── tipe baru ──
|
|
840
|
+
if (richImage) pushRich(makeImageSub(richImage));
|
|
841
|
+
if (richVideo) pushRich(makeVideoSub(richVideo));
|
|
842
|
+
if (reels) pushRich(makeReelsSub(reels));
|
|
843
|
+
if (source) { if (!extraSections) extraSections = []; extraSections.push(makeSourceSection(source)); }
|
|
844
|
+
if (richProduct) pushRich(makeProductSection(richProduct));
|
|
845
|
+
if (richPost) pushRich(makePostSection(richPost));
|
|
846
|
+
if (tip) pushRich(makeTipSub(tip));
|
|
847
|
+
if (suggest) { if (!extraSections) extraSections = []; extraSections.push(makeSuggestSection(suggest)); }
|
|
848
|
+
|
|
849
|
+
/* links — bisa dikombinasi dengan tipe lain di atas */
|
|
850
|
+
if (links && Array.isArray(links)) {
|
|
851
|
+
links.forEach((linkField, index) => {
|
|
852
|
+
const prefix = 'SS_' + index;
|
|
853
|
+
const url = linkField.url || DONATE_URL;
|
|
854
|
+
const sources = (linkField.sources || []).map(s => ({
|
|
855
|
+
source_type: 'THIRD_PARTY',
|
|
856
|
+
source_display_name: s.displayName || 'Source',
|
|
857
|
+
source_subtitle: s.subtitle || '',
|
|
858
|
+
source_url: s.url || url
|
|
859
|
+
}));
|
|
860
|
+
submessages.push(makeTextSub(
|
|
861
|
+
linkField.text + ` {{${prefix}}}¹{{/${prefix}}} `,
|
|
862
|
+
[{
|
|
863
|
+
key: prefix,
|
|
864
|
+
metadata: {
|
|
865
|
+
reference_id: index + 1,
|
|
866
|
+
reference_url: url,
|
|
867
|
+
reference_title: linkField.title || url,
|
|
868
|
+
reference_display_name: linkField.displayName || url,
|
|
869
|
+
sources,
|
|
870
|
+
__typename: 'GenAISearchCitationItem'
|
|
871
|
+
}
|
|
872
|
+
}]
|
|
873
|
+
));
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
if (footerText) submessages.push(makeTextSub(footerText));
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/* build unifiedResponse JSON — gabungkan sections dari submessages + extraSections */
|
|
881
|
+
// Pisahkan footerSubs (teks setelah media) agar selalu muncul SETELAH extraSections (video/image)
|
|
882
|
+
const footerSubMessages = footerText ? [makeTextSub(footerText)] : [];
|
|
883
|
+
// Hapus footerText dari submessages jika sudah ada (sudah di-push sebelumnya)
|
|
884
|
+
const mainSubmessages = footerText
|
|
885
|
+
? submessages.filter(s => !(s.messageType === RichSubMessageType.TEXT && s.messageText === footerText))
|
|
886
|
+
: submessages;
|
|
887
|
+
const baseUnified = toUnified(mainSubmessages);
|
|
888
|
+
const footerSections = footerSubMessages.map(buildUnifiedSection);
|
|
889
|
+
const unified = extraSections && extraSections.length > 0
|
|
890
|
+
? { ...baseUnified, sections: [...baseUnified.sections, ...extraSections, ...footerSections] }
|
|
891
|
+
: { ...baseUnified, sections: [...baseUnified.sections, ...footerSections] };
|
|
892
|
+
|
|
893
|
+
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
894
|
+
submessages,
|
|
895
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
896
|
+
unifiedResponse: {
|
|
897
|
+
data: Buffer.from(JSON.stringify(unified), 'utf-8')
|
|
898
|
+
},
|
|
899
|
+
contextInfo: {
|
|
900
|
+
isForwarded: true,
|
|
901
|
+
forwardingScore: 1,
|
|
902
|
+
forwardOrigin: 4
|
|
903
|
+
}
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
const message = wrapToBotForwardedMessage(richResponseMessage);
|
|
907
|
+
const botMetadata = message.messageContextInfo.botMetadata;
|
|
908
|
+
|
|
909
|
+
if (disclaimerText) {
|
|
910
|
+
botMetadata.messageDisclaimerText = disclaimerText;
|
|
911
|
+
}
|
|
912
|
+
botMetadata.botResponseId = unified.response_id;
|
|
913
|
+
|
|
914
|
+
return message;
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
/* ─────────────────────────────────────────────────────────────
|
|
918
|
+
BOT WRAPPER HELPERS
|
|
919
|
+
───────────────────────────────────────────────────────────── */
|
|
920
|
+
|
|
921
|
+
export const botMetadataSignature = () => {
|
|
922
|
+
const signature = new Uint8Array(64);
|
|
923
|
+
getRandomValues(signature);
|
|
924
|
+
return signature;
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
export const botMetadataCertificate = (length = 685) => {
|
|
928
|
+
const certificate = new Uint8Array(length);
|
|
929
|
+
certificate[0] = 48;
|
|
930
|
+
certificate[1] = 130;
|
|
931
|
+
getRandomValues(certificate.subarray(2));
|
|
932
|
+
return certificate;
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
export const wrapToBotForwardedMessage = (richResponseMessage) => ({
|
|
936
|
+
messageContextInfo: {
|
|
937
|
+
botMetadata: {
|
|
938
|
+
verificationMetadata: {
|
|
939
|
+
proofs: [
|
|
940
|
+
{
|
|
941
|
+
certificateChain: [
|
|
942
|
+
botMetadataCertificate(),
|
|
943
|
+
botMetadataCertificate(892)
|
|
944
|
+
],
|
|
945
|
+
version: 1,
|
|
946
|
+
useCase: 1,
|
|
947
|
+
signature: botMetadataSignature()
|
|
948
|
+
}
|
|
949
|
+
]
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
},
|
|
953
|
+
botForwardedMessage: {
|
|
954
|
+
message: { richResponseMessage }
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
|
|
958
|
+
/* ─────────────────────────────────────────────────────────────
|
|
959
|
+
STANDALONE GENERATORS (kompatibel dengan baileys upstream)
|
|
960
|
+
Semua fungsi di bawah ini di-port dari baileys-main/src/Utils/rich-messages.js
|
|
961
|
+
agar API nya 100% kompatibel dengan baileys — termasuk sendTable, sendLatex, dll.
|
|
962
|
+
───────────────────────────────────────────────────────────── */
|
|
963
|
+
|
|
964
|
+
/* helper: bangun contextInfo dari quoted */
|
|
965
|
+
const buildRichContextInfo = (quoted) => {
|
|
966
|
+
const ctxInfo = {
|
|
967
|
+
isForwarded: true,
|
|
968
|
+
forwardingScore: 1,
|
|
969
|
+
forwardOrigin: 4,
|
|
970
|
+
};
|
|
971
|
+
if (quoted?.key) {
|
|
972
|
+
ctxInfo.stanzaId = quoted.key.id;
|
|
973
|
+
ctxInfo.participant = quoted.key.participant || quoted.sender || quoted.key.remoteJid;
|
|
974
|
+
ctxInfo.quotedMessage = quoted.message;
|
|
975
|
+
}
|
|
976
|
+
return ctxInfo;
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
/* helper: wrap submessages + contextInfo ke botForwardedMessage (format lama/V1) */
|
|
980
|
+
const buildBotForwardedMessage = (submessages, contextInfo, unifiedResponse) => {
|
|
981
|
+
const richResponse = { messageType: 1, submessages, contextInfo };
|
|
982
|
+
if (unifiedResponse) richResponse.unifiedResponse = unifiedResponse;
|
|
983
|
+
return { botForwardedMessage: { message: { richResponseMessage: richResponse } } };
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
/* helper: wrap proto AIRichResponseMessage ke botForwardedMessage dengan messageContextInfo */
|
|
987
|
+
const _wrapProtoToResult = (submessages, quoted) => {
|
|
988
|
+
const unified = toUnified(submessages);
|
|
989
|
+
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
990
|
+
submessages,
|
|
991
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
992
|
+
unifiedResponse: { data: Buffer.from(JSON.stringify(unified), 'utf-8') },
|
|
993
|
+
contextInfo: buildRichContextInfo(quoted),
|
|
994
|
+
});
|
|
995
|
+
return { message: wrapToBotForwardedMessage(richResponseMessage), messageId: generateMessageIDV2() };
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
// ── Table ──────────────────────────────────────────────────
|
|
999
|
+
|
|
1000
|
+
export const generateTableContent = (title, headers, rows, quoted, options = {}) => {
|
|
1001
|
+
const { footer, headerText } = options;
|
|
1002
|
+
const tableRows = [{ items: headers, isHeading: true }, ...rows.map(row => ({ items: row.map(String) }))];
|
|
1003
|
+
const subs = [];
|
|
1004
|
+
if (headerText) subs.push({ messageType: RichSubMessageType.TEXT, messageText: headerText });
|
|
1005
|
+
subs.push({ messageType: RichSubMessageType.TABLE, tableMetadata: { title, rows: tableRows } });
|
|
1006
|
+
if (footer) subs.push({ messageType: RichSubMessageType.TEXT, messageText: footer });
|
|
1007
|
+
return _wrapProtoToResult(subs, quoted);
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
export const generateListContent = (title, items, quoted, options = {}) => {
|
|
1011
|
+
const { footer, headerText } = options;
|
|
1012
|
+
const tableRows = items.map(item => ({ items: Array.isArray(item) ? item.map(String) : [String(item)] }));
|
|
1013
|
+
const subs = [];
|
|
1014
|
+
if (headerText) subs.push({ messageType: RichSubMessageType.TEXT, messageText: headerText });
|
|
1015
|
+
subs.push({ messageType: RichSubMessageType.TABLE, tableMetadata: { title, rows: tableRows } });
|
|
1016
|
+
if (footer) subs.push({ messageType: RichSubMessageType.TEXT, messageText: footer });
|
|
1017
|
+
return _wrapProtoToResult(subs, quoted);
|
|
1018
|
+
};
|
|
1019
|
+
|
|
1020
|
+
export const toTableMetadataV2 = (arr) => {
|
|
1021
|
+
if (!Array.isArray(arr) || arr.length === 0) throw new Error('Input must be a non-empty array');
|
|
1022
|
+
const [title, headerStr, ...rest] = arr;
|
|
1023
|
+
const splitCols = (str) => typeof str !== 'string' ? [] : str.includes('|') ? str.split('|').map(s => s.trim()) : str.split(',').map(s => s.trim());
|
|
1024
|
+
const splitRows = (str) => typeof str !== 'string' ? [] : str.split(';;').map(row => splitCols(row));
|
|
1025
|
+
const header = splitCols(headerStr);
|
|
1026
|
+
const parsedRows = rest.flatMap(splitRows);
|
|
1027
|
+
const maxLen = Math.max(header.length, ...parsedRows.map(r => r.length));
|
|
1028
|
+
const unified_rows = [
|
|
1029
|
+
{ is_header: true, cells: [...header, ...Array(maxLen - header.length).fill('')] },
|
|
1030
|
+
...parsedRows.map(cells => ({ is_header: false, cells: [...cells, ...Array(maxLen - cells.length).fill('')] }))
|
|
1031
|
+
];
|
|
1032
|
+
const rows = unified_rows.map(r => ({ items: r.cells, ...(r.is_header ? { isHeading: true } : {}) }));
|
|
1033
|
+
return { title, rows, unified_rows };
|
|
1034
|
+
};
|
|
1035
|
+
|
|
1036
|
+
export const generateTableContentV2 = (table, quoted, options = {}) => {
|
|
1037
|
+
const { title, footer, headerText, text } = options;
|
|
1038
|
+
const { unified_rows } = toTableMetadataV2(table);
|
|
1039
|
+
const subs = [];
|
|
1040
|
+
const sections = [];
|
|
1041
|
+
if (headerText || title) sections.push({ view_model: { primitive: { text: headerText || title, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1042
|
+
if (text) sections.push({ view_model: { primitive: { text, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1043
|
+
sections.push({ view_model: { primitive: { rows: unified_rows, __typename: 'GenATableUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1044
|
+
if (footer) sections.push({ view_model: { primitive: { text: footer, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1045
|
+
// using randomUUID and randomBytes from top-level import
|
|
1046
|
+
const base64Data = Buffer.from(JSON.stringify({ response_id: randomUUID(), sections })).toString('base64');
|
|
1047
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
1048
|
+
ctxInfo.forwardingScore = 2;
|
|
1049
|
+
ctxInfo.botMessageSharingInfo = { botEntryPointOrigin: 1, forwardScore: 2 };
|
|
1050
|
+
const content = {
|
|
1051
|
+
messageContextInfo: { threadId: [], deviceListMetadata: { senderKeyIndexes: [], recipientKeyIndexes: [], recipientKeyHash: '', recipientTimestamp: Math.floor(Date.now() / 1000) }, deviceListMetadataVersion: 2, messageSecret: randomBytes(32) },
|
|
1052
|
+
botForwardedMessage: { message: { richResponseMessage: { submessages: subs, messageType: 1, unifiedResponse: { data: base64Data }, contextInfo: ctxInfo } } }
|
|
1053
|
+
};
|
|
1054
|
+
return { message: content, messageId: generateMessageIDV2() };
|
|
1055
|
+
};
|
|
1056
|
+
|
|
1057
|
+
// ── Code Block ────────────────────────────────────────────
|
|
1058
|
+
|
|
1059
|
+
export const generateCodeBlockContent = (code, quoted, options = {}) => {
|
|
1060
|
+
const { title, footer, language = 'javascript' } = options;
|
|
1061
|
+
const subs = [];
|
|
1062
|
+
if (title) subs.push({ messageType: RichSubMessageType.TEXT, messageText: title });
|
|
1063
|
+
subs.push({ messageType: RichSubMessageType.CODE, codeMetadata: { codeLanguage: language, codeBlocks: tokenizeCode(code, language) } });
|
|
1064
|
+
if (footer) subs.push({ messageType: RichSubMessageType.TEXT, messageText: footer });
|
|
1065
|
+
return _wrapProtoToResult(subs, quoted);
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
export const generateCodeBlockContentV2 = (code, quoted, options = {}) => {
|
|
1069
|
+
const { title, footer, language = 'javascript', text } = options;
|
|
1070
|
+
const { unified_codeBlock } = tokenizeCodeV2(code, language);
|
|
1071
|
+
const sections = [];
|
|
1072
|
+
if (text) sections.push({ view_model: { primitive: { text, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1073
|
+
sections.push({ view_model: { primitive: { language, code_blocks: unified_codeBlock, __typename: 'GenAICodeUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1074
|
+
if (footer) sections.push({ view_model: { primitive: { text: footer, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1075
|
+
// using randomUUID and randomBytes from top-level import
|
|
1076
|
+
const base64Data = Buffer.from(JSON.stringify({ response_id: randomUUID(), sections })).toString('base64');
|
|
1077
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
1078
|
+
ctxInfo.forwardingScore = 2;
|
|
1079
|
+
ctxInfo.mentionedJid = [];
|
|
1080
|
+
ctxInfo.groupMentions = [];
|
|
1081
|
+
ctxInfo.statusAttributions = [];
|
|
1082
|
+
ctxInfo.botMessageSharingInfo = { botEntryPointOrigin: 1, forwardScore: 2 };
|
|
1083
|
+
const content = {
|
|
1084
|
+
messageContextInfo: { threadId: [], deviceListMetadata: { senderKeyIndexes: [], recipientKeyIndexes: [], recipientKeyHash: '', recipientTimestamp: Math.floor(Date.now() / 1000) }, deviceListMetadataVersion: 2, messageSecret: randomBytes(32) },
|
|
1085
|
+
botForwardedMessage: { message: { richResponseMessage: { submessages: [], messageType: 1, unifiedResponse: { data: base64Data }, contextInfo: ctxInfo } } }
|
|
1086
|
+
};
|
|
1087
|
+
return { message: content, messageId: generateMessageIDV2() };
|
|
1088
|
+
};
|
|
1089
|
+
|
|
1090
|
+
// ── Rich Message (generic) ────────────────────────────────
|
|
1091
|
+
|
|
1092
|
+
export const generateRichMessageContent = (submessages, quoted) => {
|
|
1093
|
+
return _wrapProtoToResult(submessages, quoted);
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
export const generateUnifiedResponseContent = (quoted, captured) => {
|
|
1097
|
+
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
1098
|
+
submessages: captured.submessages,
|
|
1099
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
1100
|
+
unifiedResponse: captured.unifiedResponse,
|
|
1101
|
+
contextInfo: buildRichContextInfo(quoted),
|
|
1102
|
+
});
|
|
1103
|
+
return { message: wrapToBotForwardedMessage(richResponseMessage), messageId: generateMessageIDV2() };
|
|
1104
|
+
};
|
|
1105
|
+
|
|
1106
|
+
export const captureUnifiedResponse = (msg) => {
|
|
1107
|
+
const botFwd = msg?.botForwardedMessage?.message;
|
|
1108
|
+
if (!botFwd) return null;
|
|
1109
|
+
const rich = botFwd.richResponseMessage;
|
|
1110
|
+
if (!rich?.unifiedResponse?.data) return null;
|
|
1111
|
+
return { unifiedResponse: { data: rich.unifiedResponse.data }, submessages: rich.submessages || [], contextInfo: rich.contextInfo || {} };
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1114
|
+
// ── Link ──────────────────────────────────────────────────
|
|
1115
|
+
|
|
1116
|
+
export const generateLinkContent = (text, links, quoted, options = {}) => {
|
|
1117
|
+
const { footer, forwardingScore = 3, citations = [], proofs = [] } = options;
|
|
1118
|
+
const subs = [];
|
|
1119
|
+
const fullText = footer ? `${text}${footer}` : text;
|
|
1120
|
+
subs.push({ messageType: RichSubMessageType.TEXT, messageText: fullText });
|
|
1121
|
+
const sections = [];
|
|
1122
|
+
const inlineEntities = links.map((link, i) => {
|
|
1123
|
+
const url = typeof link === 'string' ? link : link.url;
|
|
1124
|
+
const displayName = typeof link === 'object' && link.displayName ? link.displayName : citations[i]?.sourceTitle || `Link ${i + 1}`;
|
|
1125
|
+
return { key: `IE_${i}`, metadata: { display_name: displayName, is_trusted: false, url, __typename: 'GenAIInlineLinkItem' } };
|
|
1126
|
+
});
|
|
1127
|
+
sections.push({ view_model: { primitive: { text, inline_entities: inlineEntities, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1128
|
+
if (footer) sections.push({ view_model: { primitive: { text: footer, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1129
|
+
// using randomUUID and randomBytes from top-level import
|
|
1130
|
+
const base64Data = Buffer.from(JSON.stringify({ response_id: randomUUID(), sections })).toString('base64');
|
|
1131
|
+
const ctxInfo = buildRichContextInfo(quoted);
|
|
1132
|
+
ctxInfo.forwardingScore = forwardingScore;
|
|
1133
|
+
ctxInfo.botMessageSharingInfo = { forwardScore: forwardingScore };
|
|
1134
|
+
const messageContextInfo = { messageSecret: randomBytes(32) };
|
|
1135
|
+
if (citations.length > 0 || proofs.length > 0) {
|
|
1136
|
+
const botMetadata = {};
|
|
1137
|
+
if (citations.length > 0) botMetadata.richResponseSourcesMetadata = { sources: citations.map((c, i) => ({ provider: 1, thumbnailCdnUrl: '', sourceProviderUrl: typeof links[i] === 'string' ? links[i] : links[i]?.url || '', sourceQuery: c.sourceQuery || '', faviconCdnUrl: c.faviconCdnUrl || '', citationNumber: c.citationNumber ?? i + 1, sourceTitle: c.sourceTitle || '' })) };
|
|
1138
|
+
if (proofs.length > 0) botMetadata.verificationMetadata = { proofs: proofs.map(p => ({ version: p.version || 1, useCase: p.useCase || 1, signature: p.signature || '', certificateChain: p.certificateChain || [] })) };
|
|
1139
|
+
messageContextInfo.botMetadata = botMetadata;
|
|
1140
|
+
}
|
|
1141
|
+
const content = { messageContextInfo, botForwardedMessage: { message: { richResponseMessage: { messageType: 1, submessages: subs, unifiedResponse: { data: base64Data }, contextInfo: ctxInfo } } } };
|
|
1142
|
+
return { message: content, messageId: generateMessageIDV2() };
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
export const generateLinkContentV2 = (text, links, quoted, options = {}) => {
|
|
1146
|
+
const { footer, searchEngine = 'MAME' } = options;
|
|
1147
|
+
const subs = [];
|
|
1148
|
+
const fullText = footer ? `${text}${footer}` : text;
|
|
1149
|
+
subs.push({ messageType: RichSubMessageType.TEXT, messageText: fullText });
|
|
1150
|
+
const sections = [];
|
|
1151
|
+
const inlineEntities = links.map((link, i) => {
|
|
1152
|
+
const url = typeof link === 'string' ? link : link.url;
|
|
1153
|
+
const displayName = typeof link === 'object' && link.displayName ? link.displayName : `Link ${i + 1}`;
|
|
1154
|
+
const sourceDisplayName = typeof link === 'object' && link.sourceDisplayName ? link.sourceDisplayName : `Source ${i + 1}`;
|
|
1155
|
+
const sourceSubtitle = typeof link === 'object' && link.sourceSubtitle ? link.sourceSubtitle : '';
|
|
1156
|
+
return { key: `IE_${i}`, metadata: { reference_id: i + 1, reference_url: url, reference_title: displayName, reference_display_name: displayName, sources: [{ source_type: 'THIRD_PARTY', source_display_name: sourceDisplayName, source_subtitle: sourceSubtitle, source_url: url }], __typename: 'GenAISearchCitationItem' } };
|
|
1157
|
+
});
|
|
1158
|
+
sections.push({ view_model: { primitive: { text, inline_entities: inlineEntities, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1159
|
+
const searchSources = links.map((link, i) => {
|
|
1160
|
+
const url = typeof link === 'string' ? link : link.url;
|
|
1161
|
+
const sourceDisplayName = typeof link === 'object' && link.sourceDisplayName ? link.sourceDisplayName : `Source ${i + 1}`;
|
|
1162
|
+
const sourceSubtitle = typeof link === 'object' && link.sourceSubtitle ? link.sourceSubtitle : '';
|
|
1163
|
+
return { source_type: 'THIRD_PARTY', source_display_name: sourceDisplayName, source_subtitle: sourceSubtitle, source_url: url };
|
|
1164
|
+
});
|
|
1165
|
+
sections.push({ view_model: { primitive: { sources: searchSources, search_engine: searchEngine, __typename: 'GenAISearchResultPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1166
|
+
if (footer) sections.push({ view_model: { primitive: { text: footer, __typename: 'GenAIMarkdownTextUXPrimitive' }, __typename: 'GenAISingleLayoutViewModel' } });
|
|
1167
|
+
// using randomUUID and randomBytes from top-level import
|
|
1168
|
+
const base64Data = Buffer.from(JSON.stringify({ response_id: randomUUID(), sections })).toString('base64');
|
|
1169
|
+
const ctxInfo = { isForwarded: true, forwardOrigin: 4 };
|
|
1170
|
+
if (quoted?.key) { ctxInfo.participant = quoted.key.participant || quoted.sender || quoted.key.remoteJid; ctxInfo.quotedMessage = quoted.message; }
|
|
1171
|
+
const content = { messageContextInfo: { threadId: [], messageSecret: randomBytes(32) }, botForwardedMessage: { message: { richResponseMessage: { messageType: 1, submessages: subs, unifiedResponse: { data: base64Data }, contextInfo: ctxInfo } } } };
|
|
1172
|
+
return { message: content, messageId: generateMessageIDV2() };
|
|
1173
|
+
};
|
|
1174
|
+
|
|
1175
|
+
// ── LaTeX (3 varian, port dari baileys) ──────────────────
|
|
1176
|
+
|
|
1177
|
+
/**
|
|
1178
|
+
* generateLatexContent — kirim LaTeX dengan URL gambar yang sudah ada (pre-rendered).
|
|
1179
|
+
* Jika `expr.url` tidak diisi, otomatis di-generate via buildLatexUrl (codecogs).
|
|
1180
|
+
*
|
|
1181
|
+
* @param {object} quoted - pesan yang di-quote (boleh null)
|
|
1182
|
+
* @param {object} options - { text, expressions, headerText, footer }
|
|
1183
|
+
* expressions: Array<{ latexExpression, url?, width?, height?,
|
|
1184
|
+
* fontHeight?, imageTopPadding?, imageLeadingPadding?,
|
|
1185
|
+
* imageBottomPadding?, imageTrailingPadding? }>
|
|
1186
|
+
*/
|
|
1187
|
+
export const generateLatexContent = (quoted, options) => {
|
|
1188
|
+
const { text, expressions, headerText, footer } = options;
|
|
1189
|
+
const subs = [];
|
|
1190
|
+
if (headerText) subs.push({ messageType: RichSubMessageType.TEXT, messageText: headerText });
|
|
1191
|
+
const latexExpressions = expressions.map((expr) => {
|
|
1192
|
+
const entry = {
|
|
1193
|
+
latexExpression: expr.latexExpression,
|
|
1194
|
+
url: expr.url || buildLatexUrl(expr.latexExpression),
|
|
1195
|
+
width: expr.width ?? 120,
|
|
1196
|
+
height: expr.height ?? 40,
|
|
1197
|
+
};
|
|
1198
|
+
if (expr.fontHeight !== undefined) entry.fontHeight = expr.fontHeight;
|
|
1199
|
+
if (expr.imageTopPadding !== undefined) entry.imageTopPadding = expr.imageTopPadding;
|
|
1200
|
+
if (expr.imageLeadingPadding !== undefined) entry.imageLeadingPadding = expr.imageLeadingPadding;
|
|
1201
|
+
if (expr.imageBottomPadding !== undefined) entry.imageBottomPadding = expr.imageBottomPadding;
|
|
1202
|
+
if (expr.imageTrailingPadding !== undefined) entry.imageTrailingPadding = expr.imageTrailingPadding;
|
|
1203
|
+
return entry;
|
|
1204
|
+
});
|
|
1205
|
+
subs.push({ messageType: RichSubMessageType.LATEX, latexMetadata: { text: text || '', expressions: latexExpressions } });
|
|
1206
|
+
if (footer) subs.push({ messageType: RichSubMessageType.TEXT, messageText: footer });
|
|
1207
|
+
return _wrapProtoToResult(subs, quoted);
|
|
1208
|
+
};
|
|
1209
|
+
|
|
1210
|
+
/**
|
|
1211
|
+
* generateLatexImageContent — render LaTeX ke PNG via renderLatexToPng,
|
|
1212
|
+
* upload via uploadFn, kirim sebagai LaTeX message dengan URL hasil upload.
|
|
1213
|
+
*
|
|
1214
|
+
* @param {object} quoted - pesan yang di-quote (boleh null)
|
|
1215
|
+
* @param {object} options - { text, expressions, headerText, footer }
|
|
1216
|
+
* @param {Function} uploadFn - async (buffer, type) => { url, directPath }
|
|
1217
|
+
* @param {Function} renderLatexToPng - async (latexExpression) => { buffer, width, height }
|
|
1218
|
+
*/
|
|
1219
|
+
export const generateLatexImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
1220
|
+
const { text, expressions, headerText, footer } = options;
|
|
1221
|
+
const subs = [];
|
|
1222
|
+
if (headerText) subs.push({ messageType: RichSubMessageType.TEXT, messageText: headerText });
|
|
1223
|
+
const latexExpressions = await Promise.all(
|
|
1224
|
+
expressions.map(async (expr) => {
|
|
1225
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
|
|
1226
|
+
const uploadResult = await uploadFn(buffer, 'image');
|
|
1227
|
+
const imageUrl = uploadResult.url || uploadResult.directPath;
|
|
1228
|
+
return { latexExpression: expr.latexExpression, url: imageUrl, width, height };
|
|
1229
|
+
}),
|
|
1230
|
+
);
|
|
1231
|
+
subs.push({ messageType: RichSubMessageType.LATEX, latexMetadata: { text: text || '', expressions: latexExpressions } });
|
|
1232
|
+
if (footer) subs.push({ messageType: RichSubMessageType.TEXT, messageText: footer });
|
|
1233
|
+
return _wrapProtoToResult(subs, quoted);
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
/**
|
|
1237
|
+
* generateLatexInlineImageContent — render LaTeX ke PNG, upload, kirim sebagai
|
|
1238
|
+
* deretan INLINE_IMAGE (satu per expression). Fallback untuk klien tanpa LaTeX native.
|
|
1239
|
+
*
|
|
1240
|
+
* @param {object} quoted - pesan yang di-quote (boleh null)
|
|
1241
|
+
* @param {object} options - { text, expressions, headerText, footer }
|
|
1242
|
+
* @param {Function} uploadFn - async (buffer, type) => { url, directPath }
|
|
1243
|
+
* @param {Function} renderLatexToPng - async (latexExpression) => { buffer, width, height }
|
|
1244
|
+
*/
|
|
1245
|
+
export const generateLatexInlineImageContent = async (quoted, options, uploadFn, renderLatexToPng) => {
|
|
1246
|
+
const { text, expressions, headerText, footer } = options;
|
|
1247
|
+
const subs = [];
|
|
1248
|
+
if (headerText) subs.push({ messageType: RichSubMessageType.TEXT, messageText: headerText });
|
|
1249
|
+
if (text) subs.push({ messageType: RichSubMessageType.TEXT, messageText: text });
|
|
1250
|
+
for (const expr of expressions) {
|
|
1251
|
+
const { buffer, width, height } = await renderLatexToPng(expr.latexExpression);
|
|
1252
|
+
const uploadResult = await uploadFn(buffer, 'image');
|
|
1253
|
+
const imageUrl = uploadResult.url || uploadResult.directPath;
|
|
1254
|
+
subs.push({
|
|
1255
|
+
messageType: RichSubMessageType.INLINE_IMAGE,
|
|
1256
|
+
imageMetadata: {
|
|
1257
|
+
imageUrl: { imagePreviewUrl: imageUrl, imageHighResUrl: imageUrl },
|
|
1258
|
+
imageText: expr.latexExpression,
|
|
1259
|
+
alignment: 2,
|
|
1260
|
+
},
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
if (footer) subs.push({ messageType: RichSubMessageType.TEXT, messageText: footer });
|
|
1264
|
+
return _wrapProtoToResult(subs, quoted);
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
// ── tokenizeCodeV2 (dipakai oleh generateCodeBlockContentV2) ─
|
|
1268
|
+
|
|
1269
|
+
export const tokenizeCodeV2 = (code, language = 'javascript') => {
|
|
1270
|
+
const keywords = LANGUAGE_KEYWORDS[language] || LANGUAGE_KEYWORDS['javascript'] || new Set();
|
|
1271
|
+
const tokens = [];
|
|
1272
|
+
let i = 0;
|
|
1273
|
+
const n = code.length;
|
|
1274
|
+
const push = (codeContent, highlightType) => {
|
|
1275
|
+
if (!codeContent) return;
|
|
1276
|
+
const last = tokens[tokens.length - 1];
|
|
1277
|
+
if (last && last.highlightType === highlightType) last.codeContent += codeContent;
|
|
1278
|
+
else tokens.push({ codeContent, highlightType });
|
|
1279
|
+
};
|
|
1280
|
+
const isWordStart = (c) => /[a-zA-Z_$]/.test(c);
|
|
1281
|
+
const isWord = (c) => /[a-zA-Z0-9_$]/.test(c);
|
|
1282
|
+
const isNum = (c) => /[0-9]/.test(c);
|
|
1283
|
+
const HIGHLIGHT_TYPE_MAP = { 0: 'DEFAULT', 1: 'KEYWORD', 2: 'METHOD', 3: 'STR', 4: 'NUMBER', 5: 'COMMENT' };
|
|
1284
|
+
const isPyBash = ['python','py','bash','sh','shell'].includes(language);
|
|
1285
|
+
while (i < n) {
|
|
1286
|
+
const c = code[i];
|
|
1287
|
+
if (/\s/.test(c)) {
|
|
1288
|
+
let s = i; while (i < n && /\s/.test(code[i])) i++;
|
|
1289
|
+
push(code.slice(s, i), 0); continue;
|
|
1290
|
+
}
|
|
1291
|
+
if (c === '/' && code[i + 1] === '/') {
|
|
1292
|
+
let s = i; i += 2; while (i < n && code[i] !== '\n') i++;
|
|
1293
|
+
push(code.slice(s, i), 5); continue;
|
|
1294
|
+
}
|
|
1295
|
+
if (c === '/' && code[i + 1] === '*') {
|
|
1296
|
+
let s = i; i += 2;
|
|
1297
|
+
while (i < n - 1 && !(code[i] === '*' && code[i + 1] === '/')) i++;
|
|
1298
|
+
i += 2; push(code.slice(s, i), 5); continue;
|
|
1299
|
+
}
|
|
1300
|
+
if (c === '#' && isPyBash) {
|
|
1301
|
+
let s = i; i++; while (i < n && code[i] !== '\n') i++;
|
|
1302
|
+
push(code.slice(s, i), 5); continue;
|
|
1303
|
+
}
|
|
1304
|
+
if (c === '"' || c === "'" || c === '`') {
|
|
1305
|
+
let s = i; const q = c; i++;
|
|
1306
|
+
while (i < n) { if (code[i] === '\\' && i + 1 < n) i += 2; else if (code[i] === q) { i++; break; } else i++; }
|
|
1307
|
+
push(code.slice(s, i), 3); continue;
|
|
1308
|
+
}
|
|
1309
|
+
if (isNum(c)) {
|
|
1310
|
+
let s = i; while (i < n && /[0-9.xXa-fA-FeEbBoO_]/.test(code[i])) i++;
|
|
1311
|
+
push(code.slice(s, i), 4); continue;
|
|
1312
|
+
}
|
|
1313
|
+
if (isWordStart(c)) {
|
|
1314
|
+
let s = i; while (i < n && isWord(code[i])) i++;
|
|
1315
|
+
const word = code.slice(s, i);
|
|
1316
|
+
let type = 0;
|
|
1317
|
+
if (keywords.has(word)) type = 1;
|
|
1318
|
+
else { let j = i; while (j < n && /\s/.test(code[j])) j++; if (code[j] === '(') type = 2; }
|
|
1319
|
+
push(word, type); continue;
|
|
1320
|
+
}
|
|
1321
|
+
push(c, 0); i++;
|
|
1322
|
+
}
|
|
1323
|
+
return {
|
|
1324
|
+
codeBlock: tokens,
|
|
1325
|
+
unified_codeBlock: tokens.map(t => ({ content: t.codeContent, type: HIGHLIGHT_TYPE_MAP[t.highlightType] || 'DEFAULT' }))
|
|
1326
|
+
};
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
/* Re-export LANGUAGE_KEYWORDS dari WABinary/constants.js agar kompatibel dengan baileys export */
|
|
1330
|
+
export { LANGUAGE_KEYWORDS } from '../WABinary/constants.js';
|
|
1331
|
+
|
|
1332
|
+
//# sourceMappingURL=rich-message-utils.js.map
|