kage-baileys 25.3.11 → 25.3.13

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.
Files changed (364) hide show
  1. package/Example/plugins/scarr.mjs +1 -1
  2. package/Example/plugins/unico6.mjs +1 -1
  3. package/extras/Extensions/package.json +3 -0
  4. package/extras/Extensions/rich-carousel.js +1 -1
  5. package/extras/Extensions/rich-classic.js +1 -1
  6. package/extras/index.js +10 -10
  7. package/helpers/package.json +3 -0
  8. package/lib/Defaults/connection.js +49 -108
  9. package/lib/Defaults/constants.js +71 -153
  10. package/lib/Defaults/index.js +0 -199
  11. package/lib/Defaults/media.js +0 -60
  12. package/lib/Defaults/prefix.js +17 -43
  13. package/lib/Modded/message_builder.js +0 -2355
  14. package/lib/Signal/Group/ciphertext-message.js +0 -54
  15. package/lib/Signal/Group/group-session-builder.js +0 -124
  16. package/lib/Signal/Group/group_cipher.js +0 -230
  17. package/lib/Signal/Group/index.js +0 -124
  18. package/lib/Signal/Group/keyhelper.js +0 -108
  19. package/lib/Signal/Group/sender-chain-key.js +0 -88
  20. package/lib/Signal/Group/sender-key-distribution-message.js +0 -157
  21. package/lib/Signal/Group/sender-key-message.js +0 -166
  22. package/lib/Signal/Group/sender-key-name.js +0 -130
  23. package/lib/Signal/Group/sender-key-record.js +0 -122
  24. package/lib/Signal/Group/sender-key-state.js +0 -220
  25. package/lib/Signal/Group/sender-message-key.js +0 -82
  26. package/lib/Signal/libsignal.js +0 -646
  27. package/lib/Signal/lid-mapping.js +0 -537
  28. package/lib/Socket/Client/index.js +0 -60
  29. package/lib/Socket/Client/types.js +0 -51
  30. package/lib/Socket/Client/websocket.js +0 -164
  31. package/lib/Socket/business.js +0 -708
  32. package/lib/Socket/chats.js +0 -2253
  33. package/lib/Socket/communities.js +0 -441
  34. package/lib/Socket/community.js +504 -1019
  35. package/lib/Socket/groups.js +0 -727
  36. package/lib/Socket/messages-recv.js +0 -2780
  37. package/lib/Socket/messages-send.js +0 -2640
  38. package/lib/Socket/mex.js +0 -128
  39. package/lib/Socket/newsletter.js +0 -486
  40. package/lib/Socket/socket.js +0 -1899
  41. package/lib/Store/index.js +0 -68
  42. package/lib/Store/make-cache-manager-store.js +0 -97
  43. package/lib/Store/make-in-memory-store.js +0 -908
  44. package/lib/Store/make-ordered-dictionary.js +0 -187
  45. package/lib/Store/object-repository.js +0 -78
  46. package/lib/Types/Bussines.js +2 -2
  47. package/lib/Types/Chat.js +0 -33
  48. package/lib/Types/Label.js +0 -78
  49. package/lib/Types/LabelAssociation.js +0 -42
  50. package/lib/Types/Message.js +0 -46
  51. package/lib/Types/Mex.js +0 -53
  52. package/lib/Types/MexUpdates.js +16 -43
  53. package/lib/Types/Newsletter.js +0 -27
  54. package/lib/Types/State.js +0 -42
  55. package/lib/Types/index.js +0 -134
  56. package/lib/Utils/auth-utils.js +0 -579
  57. package/lib/Utils/baileys-event-stream.js +65 -142
  58. package/lib/Utils/browser-utils.js +0 -104
  59. package/lib/Utils/business.js +0 -519
  60. package/lib/Utils/chat-utils.js +0 -1702
  61. package/lib/Utils/companion-reg-client-utils.js +0 -45
  62. package/lib/Utils/crypto.js +0 -382
  63. package/lib/Utils/decode-wa-message.js +0 -605
  64. package/lib/Utils/event-buffer.js +0 -1207
  65. package/lib/Utils/generics.js +0 -1020
  66. package/lib/Utils/history.js +0 -231
  67. package/lib/Utils/identity-change-handler.js +0 -59
  68. package/lib/Utils/index.js +0 -133
  69. package/lib/Utils/link-preview.js +0 -228
  70. package/lib/Utils/logger.js +0 -35
  71. package/lib/Utils/lt-hash.js +0 -60
  72. package/lib/Utils/make-mutex.js +0 -110
  73. package/lib/Utils/message-retry-manager.js +0 -429
  74. package/lib/Utils/messages-media.js +0 -1899
  75. package/lib/Utils/messages.js +0 -2950
  76. package/lib/Utils/noise-handler.js +0 -369
  77. package/lib/Utils/offline-node-processor.js +0 -50
  78. package/lib/Utils/pre-key-manager.js +0 -251
  79. package/lib/Utils/process-message.js +0 -1239
  80. package/lib/Utils/reporting-utils.js +0 -268
  81. package/lib/Utils/signal.js +0 -377
  82. package/lib/Utils/stanza-ack.js +0 -48
  83. package/lib/Utils/sync-action-utils.js +0 -58
  84. package/lib/Utils/tc-token-utils.js +0 -28
  85. package/lib/Utils/validate-connection.js +0 -508
  86. package/lib/VoIP/audio-feeder.js +0 -146
  87. package/lib/VoIP/index.js +0 -292
  88. package/lib/VoIP/relay-transport.js +0 -569
  89. package/lib/VoIP/signaling.js +0 -613
  90. package/lib/VoIP/types.js +0 -27
  91. package/lib/VoIP/wasm-engine.js +0 -1222
  92. package/lib/VoIP/worker-bootstrap.js +0 -1785
  93. package/lib/WABinary/constants.js +0 -2639
  94. package/lib/WABinary/decode.js +0 -612
  95. package/lib/WABinary/encode.js +0 -556
  96. package/lib/WABinary/generic-utils.js +0 -272
  97. package/lib/WABinary/index.js +0 -82
  98. package/lib/WABinary/jid-utils.js +0 -262
  99. package/lib/WAM/BinaryInfo.js +0 -50
  100. package/lib/WAM/constants.js +0 -38242
  101. package/lib/WAM/encode.js +0 -396
  102. package/lib/WAM/index.js +0 -78
  103. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +47 -109
  104. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -88
  105. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -142
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -85
  107. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -63
  108. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -114
  109. package/lib/WAUSync/Protocols/index.js +0 -82
  110. package/lib/WAUSync/index.js +0 -78
  111. package/lib/assets/wasm/loader.js +0 -13
  112. package/lib/assets/wasm/worker-modules.js +0 -283
  113. package/lib/index.d.ts +483 -41
  114. package/lib/index.js +0 -93
  115. package/package.json +9 -6
  116. package/WAProto/index.d.ts +0 -46
  117. package/lib/Builders/index.d.ts +0 -454
  118. package/lib/Builders/mbuilder/bot-signature.d.ts +0 -22
  119. package/lib/Builders/mbuilder/extras.d.ts +0 -348
  120. package/lib/Builders/mbuilder/html-app.d.ts +0 -19
  121. package/lib/Builders/mbuilder/index.d.ts +0 -221
  122. package/lib/Builders/mbuilder/metaai.d.ts +0 -438
  123. package/lib/Defaults/index.d.ts +0 -145
  124. package/lib/Defaults/index.d.ts.map +0 -1
  125. package/lib/Defaults/index.js.map +0 -1
  126. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  127. package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
  128. package/lib/Signal/Group/ciphertext-message.js.map +0 -1
  129. package/lib/Signal/Group/group-session-builder.d.ts +0 -8
  130. package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
  131. package/lib/Signal/Group/group-session-builder.js.map +0 -1
  132. package/lib/Signal/Group/group_cipher.d.ts +0 -11
  133. package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
  134. package/lib/Signal/Group/group_cipher.js.map +0 -1
  135. package/lib/Signal/Group/index.d.ts +0 -12
  136. package/lib/Signal/Group/index.d.ts.map +0 -1
  137. package/lib/Signal/Group/index.js.map +0 -1
  138. package/lib/Signal/Group/keyhelper.d.ts +0 -7
  139. package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
  140. package/lib/Signal/Group/keyhelper.js.map +0 -1
  141. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  142. package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
  143. package/lib/Signal/Group/sender-chain-key.js.map +0 -1
  144. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  145. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
  146. package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
  147. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  148. package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
  149. package/lib/Signal/Group/sender-key-message.js.map +0 -1
  150. package/lib/Signal/Group/sender-key-name.d.ts +0 -12
  151. package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
  152. package/lib/Signal/Group/sender-key-name.js.map +0 -1
  153. package/lib/Signal/Group/sender-key-record.d.ts +0 -13
  154. package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
  155. package/lib/Signal/Group/sender-key-record.js.map +0 -1
  156. package/lib/Signal/Group/sender-key-state.d.ts +0 -17
  157. package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
  158. package/lib/Signal/Group/sender-key-state.js.map +0 -1
  159. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  160. package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
  161. package/lib/Signal/Group/sender-message-key.js.map +0 -1
  162. package/lib/Signal/libsignal.d.ts +0 -55
  163. package/lib/Signal/libsignal.d.ts.map +0 -1
  164. package/lib/Signal/libsignal.js.map +0 -1
  165. package/lib/Signal/lid-mapping.d.ts +0 -21
  166. package/lib/Signal/lid-mapping.d.ts.map +0 -1
  167. package/lib/Signal/lid-mapping.js.map +0 -1
  168. package/lib/Socket/Client/index.d.ts +0 -3
  169. package/lib/Socket/Client/index.d.ts.map +0 -1
  170. package/lib/Socket/Client/index.js.map +0 -1
  171. package/lib/Socket/Client/types.d.ts +0 -6
  172. package/lib/Socket/Client/types.d.ts.map +0 -1
  173. package/lib/Socket/Client/types.js.map +0 -1
  174. package/lib/Socket/Client/websocket.d.ts +0 -13
  175. package/lib/Socket/Client/websocket.d.ts.map +0 -1
  176. package/lib/Socket/Client/websocket.js.map +0 -1
  177. package/lib/Socket/business.d.ts +0 -395
  178. package/lib/Socket/business.d.ts.map +0 -1
  179. package/lib/Socket/business.js.map +0 -1
  180. package/lib/Socket/chats.d.ts +0 -137
  181. package/lib/Socket/chats.d.ts.map +0 -1
  182. package/lib/Socket/chats.js.map +0 -1
  183. package/lib/Socket/communities.d.ts +0 -562
  184. package/lib/Socket/communities.d.ts.map +0 -1
  185. package/lib/Socket/communities.js.map +0 -1
  186. package/lib/Socket/groups.d.ts +0 -286
  187. package/lib/Socket/groups.d.ts.map +0 -1
  188. package/lib/Socket/groups.js.map +0 -1
  189. package/lib/Socket/index.d.ts +0 -530
  190. package/lib/Socket/index.d.ts.map +0 -1
  191. package/lib/Socket/index.js.map +0 -1
  192. package/lib/Socket/messages-recv.d.ts +0 -334
  193. package/lib/Socket/messages-recv.d.ts.map +0 -1
  194. package/lib/Socket/messages-recv.js.map +0 -1
  195. package/lib/Socket/messages-send.d.ts +0 -330
  196. package/lib/Socket/messages-send.d.ts.map +0 -1
  197. package/lib/Socket/messages-send.js.map +0 -1
  198. package/lib/Socket/mex.d.ts +0 -2
  199. package/lib/Socket/mex.d.ts.map +0 -1
  200. package/lib/Socket/mex.js.map +0 -1
  201. package/lib/Socket/newsletter.d.ts +0 -283
  202. package/lib/Socket/newsletter.d.ts.map +0 -1
  203. package/lib/Socket/newsletter.js.map +0 -1
  204. package/lib/Socket/socket.d.ts +0 -61
  205. package/lib/Socket/socket.d.ts.map +0 -1
  206. package/lib/Socket/socket.js.map +0 -1
  207. package/lib/Store/index.d.ts +0 -4
  208. package/lib/Store/index.d.ts.map +0 -1
  209. package/lib/Store/index.js.map +0 -1
  210. package/lib/Store/make-in-memory-store.d.ts +0 -63
  211. package/lib/Store/make-in-memory-store.d.ts.map +0 -1
  212. package/lib/Store/make-in-memory-store.js.map +0 -1
  213. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  214. package/lib/Store/make-ordered-dictionary.d.ts.map +0 -1
  215. package/lib/Store/make-ordered-dictionary.js.map +0 -1
  216. package/lib/Store/object-repository.d.ts +0 -11
  217. package/lib/Store/object-repository.d.ts.map +0 -1
  218. package/lib/Store/object-repository.js.map +0 -1
  219. package/lib/Types/Auth.d.ts +0 -2
  220. package/lib/Types/Auth.d.ts.map +0 -1
  221. package/lib/Types/Auth.js.map +0 -1
  222. package/lib/Types/Bussines.d.ts +0 -2
  223. package/lib/Types/Bussines.d.ts.map +0 -1
  224. package/lib/Types/Call.d.ts +0 -2
  225. package/lib/Types/Call.d.ts.map +0 -1
  226. package/lib/Types/Chat.d.ts +0 -2
  227. package/lib/Types/Chat.d.ts.map +0 -1
  228. package/lib/Types/Contact.d.ts +0 -2
  229. package/lib/Types/Contact.d.ts.map +0 -1
  230. package/lib/Types/Events.d.ts +0 -2
  231. package/lib/Types/Events.d.ts.map +0 -1
  232. package/lib/Types/GroupMetadata.d.ts +0 -2
  233. package/lib/Types/GroupMetadata.d.ts.map +0 -1
  234. package/lib/Types/Label.d.ts +0 -3
  235. package/lib/Types/Label.d.ts.map +0 -1
  236. package/lib/Types/LabelAssociation.d.ts +0 -3
  237. package/lib/Types/LabelAssociation.d.ts.map +0 -1
  238. package/lib/Types/Message.d.ts +0 -12
  239. package/lib/Types/Message.d.ts.map +0 -1
  240. package/lib/Types/Mex.d.ts +0 -3
  241. package/lib/Types/Mex.d.ts.map +0 -1
  242. package/lib/Types/Product.d.ts +0 -2
  243. package/lib/Types/Product.d.ts.map +0 -1
  244. package/lib/Types/RichType.d.ts +0 -3
  245. package/lib/Types/RichType.d.ts.map +0 -1
  246. package/lib/Types/Signal.d.ts +0 -2
  247. package/lib/Types/Signal.d.ts.map +0 -1
  248. package/lib/Types/Socket.d.ts +0 -2
  249. package/lib/Types/Socket.d.ts.map +0 -1
  250. package/lib/Types/State.d.ts +0 -6
  251. package/lib/Types/State.d.ts.map +0 -1
  252. package/lib/Types/USync.d.ts +0 -2
  253. package/lib/Types/USync.d.ts.map +0 -1
  254. package/lib/Types/index.d.ts +0 -14
  255. package/lib/Types/index.d.ts.map +0 -1
  256. package/lib/Utils/auth-utils.d.ts +0 -58
  257. package/lib/Utils/auth-utils.d.ts.map +0 -1
  258. package/lib/Utils/auth-utils.js.map +0 -1
  259. package/lib/Utils/browser-utils.d.ts +0 -9
  260. package/lib/Utils/browser-utils.d.ts.map +0 -1
  261. package/lib/Utils/browser-utils.js.map +0 -1
  262. package/lib/Utils/business.d.ts +0 -50
  263. package/lib/Utils/business.d.ts.map +0 -1
  264. package/lib/Utils/business.js.map +0 -1
  265. package/lib/Utils/chat-utils.d.ts +0 -409
  266. package/lib/Utils/chat-utils.d.ts.map +0 -1
  267. package/lib/Utils/chat-utils.js.map +0 -1
  268. package/lib/Utils/companion-reg-client-utils.d.ts +0 -5
  269. package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
  270. package/lib/Utils/companion-reg-client-utils.js.map +0 -1
  271. package/lib/Utils/crypto.d.ts +0 -40
  272. package/lib/Utils/crypto.d.ts.map +0 -1
  273. package/lib/Utils/crypto.js.map +0 -1
  274. package/lib/Utils/decode-wa-message.d.ts +0 -84
  275. package/lib/Utils/decode-wa-message.d.ts.map +0 -1
  276. package/lib/Utils/decode-wa-message.js.map +0 -1
  277. package/lib/Utils/event-buffer.d.ts +0 -13
  278. package/lib/Utils/event-buffer.d.ts.map +0 -1
  279. package/lib/Utils/event-buffer.js.map +0 -1
  280. package/lib/Utils/generics.d.ts +0 -71
  281. package/lib/Utils/generics.d.ts.map +0 -1
  282. package/lib/Utils/generics.js.map +0 -1
  283. package/lib/Utils/history.d.ts +0 -76
  284. package/lib/Utils/history.d.ts.map +0 -1
  285. package/lib/Utils/history.js.map +0 -1
  286. package/lib/Utils/identity-change-handler.d.ts +0 -14
  287. package/lib/Utils/identity-change-handler.d.ts.map +0 -1
  288. package/lib/Utils/identity-change-handler.js.map +0 -1
  289. package/lib/Utils/index.d.ts +0 -25
  290. package/lib/Utils/index.d.ts.map +0 -1
  291. package/lib/Utils/index.js.map +0 -1
  292. package/lib/Utils/link-preview.d.ts +0 -13
  293. package/lib/Utils/link-preview.d.ts.map +0 -1
  294. package/lib/Utils/link-preview.js.map +0 -1
  295. package/lib/Utils/logger.d.ts +0 -3
  296. package/lib/Utils/logger.d.ts.map +0 -1
  297. package/lib/Utils/logger.js.map +0 -1
  298. package/lib/Utils/lt-hash.d.ts +0 -7
  299. package/lib/Utils/lt-hash.d.ts.map +0 -1
  300. package/lib/Utils/lt-hash.js.map +0 -1
  301. package/lib/Utils/make-mutex.d.ts +0 -7
  302. package/lib/Utils/make-mutex.d.ts.map +0 -1
  303. package/lib/Utils/make-mutex.js.map +0 -1
  304. package/lib/Utils/message-retry-manager.d.ts +0 -80
  305. package/lib/Utils/message-retry-manager.d.ts.map +0 -1
  306. package/lib/Utils/message-retry-manager.js.map +0 -1
  307. package/lib/Utils/messages-media.d.ts +0 -137
  308. package/lib/Utils/messages-media.d.ts.map +0 -1
  309. package/lib/Utils/messages-media.js.map +0 -1
  310. package/lib/Utils/messages.d.ts +0 -47
  311. package/lib/Utils/messages.d.ts.map +0 -1
  312. package/lib/Utils/messages.js.map +0 -1
  313. package/lib/Utils/noise-handler.d.ts +0 -21
  314. package/lib/Utils/noise-handler.d.ts.map +0 -1
  315. package/lib/Utils/noise-handler.js.map +0 -1
  316. package/lib/Utils/offline-node-processor.d.ts +0 -10
  317. package/lib/Utils/offline-node-processor.d.ts.map +0 -1
  318. package/lib/Utils/offline-node-processor.js.map +0 -1
  319. package/lib/Utils/pre-key-manager.d.ts +0 -26
  320. package/lib/Utils/pre-key-manager.d.ts.map +0 -1
  321. package/lib/Utils/pre-key-manager.js.map +0 -1
  322. package/lib/Utils/process-message.d.ts +0 -84
  323. package/lib/Utils/process-message.d.ts.map +0 -1
  324. package/lib/Utils/process-message.js.map +0 -1
  325. package/lib/Utils/reporting-utils.d.ts +0 -13
  326. package/lib/Utils/reporting-utils.d.ts.map +0 -1
  327. package/lib/Utils/reporting-utils.js.map +0 -1
  328. package/lib/Utils/rich-message-utils.d.ts +0 -49
  329. package/lib/Utils/rich-message-utils.d.ts.map +0 -1
  330. package/lib/Utils/rich-message-utils.js.map +0 -1
  331. package/lib/Utils/signal.d.ts +0 -83
  332. package/lib/Utils/signal.d.ts.map +0 -1
  333. package/lib/Utils/signal.js.map +0 -1
  334. package/lib/Utils/stanza-ack.d.ts +0 -17
  335. package/lib/Utils/stanza-ack.d.ts.map +0 -1
  336. package/lib/Utils/stanza-ack.js.map +0 -1
  337. package/lib/Utils/sync-action-utils.d.ts +0 -3
  338. package/lib/Utils/sync-action-utils.d.ts.map +0 -1
  339. package/lib/Utils/sync-action-utils.js.map +0 -1
  340. package/lib/Utils/tc-token-utils.d.ts +0 -30
  341. package/lib/Utils/tc-token-utils.d.ts.map +0 -1
  342. package/lib/Utils/tc-token-utils.js.map +0 -1
  343. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -11
  344. package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
  345. package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
  346. package/lib/Utils/use-single-file-auth-state.d.ts +0 -11
  347. package/lib/Utils/use-single-file-auth-state.d.ts.map +0 -1
  348. package/lib/Utils/use-single-file-auth-state.js.map +0 -1
  349. package/lib/Utils/use-sqlite-auth-state.d.ts +0 -11
  350. package/lib/Utils/use-sqlite-auth-state.d.ts.map +0 -1
  351. package/lib/Utils/use-sqlite-auth-state.js.map +0 -1
  352. package/lib/Utils/validate-connection.d.ts +0 -44
  353. package/lib/Utils/validate-connection.d.ts.map +0 -1
  354. package/lib/Utils/validate-connection.js.map +0 -1
  355. package/lib/WABinary/constants.d.ts +0 -62
  356. package/lib/WABinary/decode.d.ts +0 -10
  357. package/lib/WABinary/encode.d.ts +0 -3
  358. package/lib/WABinary/generic-utils.d.ts +0 -77
  359. package/lib/WABinary/index.d.ts +0 -6
  360. package/lib/WABinary/jid-utils.d.ts +0 -29
  361. package/lib/WABinary/types.d.ts +0 -2
  362. package/lib/index.d.ts.map +0 -1
  363. package/lib/index.js.map +0 -1
  364. /package/extras/{optional-media.js → optional-media.mjs} +0 -0
@@ -1,2336 +1,3 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
- 'use strict';
31
-
32
- const VERSION = '4.7-kage.1';
33
-
34
- const _indexjs = new Proxy({}, {get(_target, key) { return require('../index.js')[key]; }});
35
- var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
36
- var _stream = require('stream');
37
-
38
- let ffmpeg;
39
- const { resizeImage: resizeKageImage } = require('../Utils/image-processing');
40
-
41
- try {
42
- ffmpeg = require('fluent-ffmpeg');
43
- } catch (e3) {
44
- console.warn('⚠️ [kage-baileys] El módulo opcional fluent-ffmpeg no está instalado. Algunas vistas previas de vídeo no estarán disponibles.');
45
- }
46
-
47
- function extractIE(text, { extract = true, hyperlink = true, citation = true, latex = true } = {}) {
48
- if (!extract) {
49
- return {
50
- text,
51
- ie: [],
52
- inline_entities: [],
53
- };
54
- }
55
-
56
- const createIE = (type, ie) => {
57
- if (type == 'hyperlink') {
58
- return {
59
- key: ie.key,
60
- metadata: {
61
- display_name: ie.text,
62
- is_trusted: ie.is_trusted,
63
- url: ie.url,
64
- __typename: 'GenAIInlineLinkItem',
65
- },
66
- };
67
- }
68
-
69
- if (type == 'citation') {
70
- return {
71
- key: ie.key,
72
- metadata: {
73
- reference_id: ie.reference_id,
74
- reference_url: ie.url,
75
- reference_title: ie.url,
76
- reference_display_name: ie.url,
77
- sources: [],
78
- __typename: 'GenAISearchCitationItem',
79
- },
80
- };
81
- }
82
-
83
- if (type == 'latex') {
84
- return {
85
- key: ie.key,
86
- metadata: {
87
- latex_expression: ie.text,
88
- latex_image: {
89
- url: ie.url,
90
- width: Number(ie.width) || 100,
91
- height: Number(ie.height) || 100,
92
- },
93
- font_height: Number(ie.font_height) || 83.333333333333,
94
- padding: Number(ie.padding) || 15,
95
- __typename: 'GenAILatexItem',
96
- },
97
- };
98
- }
99
- };
100
-
101
- let ie = [];
102
- let inline_entities = [];
103
- let result = '';
104
- let last = 0;
105
- let citation_index = 1;
106
- let hyperlink_index = 0;
107
- let latex_index = 0;
108
- let stack = [];
109
-
110
- for (let i = 0; i < text.length; i++) {
111
- if (text[i] == '[' && text[i - 1] != '\\') {
112
- stack.push(i);
113
- } else if (text[i] == ']' && (text[i + 1] == '(' || text[i + 1] == '<')) {
114
- let start = stack.pop();
115
-
116
- if (start == null) continue;
117
-
118
- let open = text[i + 1];
119
- let close = open == '(' ? ')' : '>';
120
- let type = open == '(' ? 'link' : 'latex';
121
- let end = i + 2;
122
- let depth = 1;
123
-
124
- while (end < text.length && depth) {
125
- if (text[end] == open && text[end - 1] != '\\') depth++;
126
- else if (text[end] == close && text[end - 1] != '\\') depth--;
127
- end++;
128
- }
129
-
130
- if (depth) continue;
131
-
132
- let raw = text.slice(start + 1, i).trim();
133
- let url = text.slice(i + 2, end - 1).trim();
134
-
135
- let key;
136
- let tag;
137
- let data;
138
-
139
- if (type == 'latex') {
140
- if (!latex) continue;
141
-
142
- let [txt = '', width = null, height = null, font_height = null, padding = null] = raw.split('|');
143
-
144
- key = `\u004E\u0049\u0058\u0045\u004C_LATEX_${latex_index++}`;
145
- tag = `{{${key}}}${txt || 'image'}{{/${key}}}`;
146
-
147
- data = {
148
- type: 'latex',
149
- ie: {
150
- key,
151
- text: txt,
152
- url,
153
- width,
154
- height,
155
- font_height,
156
- padding,
157
- },
158
- };
159
- } else if (raw) {
160
- if (!hyperlink) continue;
161
-
162
- const trusted = !url.startsWith('!');
163
-
164
- if (!trusted) {
165
- url = url.slice(1);
166
- }
167
-
168
- key = `\u004E\u0049\u0058\u0045\u004C_HYPERLINK_${hyperlink_index++}`;
169
- tag = `{{${key}}}${url}{{/${key}}}`;
170
-
171
- data = {
172
- type: 'hyperlink',
173
- ie: {
174
- key,
175
- text: raw,
176
- url,
177
- is_trusted: trusted,
178
- },
179
- };
180
- } else {
181
- if (!citation) continue;
182
-
183
- key = `\u004E\u0049\u0058\u0045\u004C_CITATION_${citation_index - 1}`;
184
- tag = `{{${key}}}${url}{{/${key}}}`;
185
-
186
- data = {
187
- type: 'citation',
188
- ie: {
189
- reference_id: citation_index++,
190
- key,
191
- text: '',
192
- url,
193
- },
194
- };
195
- }
196
-
197
- result += text.slice(last, start) + tag;
198
- last = end;
199
-
200
- ie.push(data);
201
-
202
- const entity = createIE(data.type, data.ie);
203
-
204
- if (entity) {
205
- inline_entities.push(entity);
206
- }
207
-
208
- i = end - 1;
209
- }
210
- }
211
-
212
- result += text.slice(last);
213
-
214
- return {
215
- text: result,
216
- ie,
217
- inline_entities,
218
- };
219
- }
220
-
221
- async function waitAllPromises(input) {
222
- const isPromise = (v) => v && typeof v.then === 'function';
223
- const isObject = (v) => v && typeof v === 'object';
224
-
225
- const deep = async (v) => {
226
- if (isPromise(v)) return deep(await v);
227
- if (Array.isArray(v)) return Promise.all(v.map(deep));
228
- if (isObject(v)) {
229
- const entries = await Promise.all(Object.entries(v).map(async ([k, val]) => [k, await deep(val)]));
230
- return Object.fromEntries(entries);
231
- }
232
- return v;
233
- };
234
-
235
- return deep(await input);
236
- }
237
-
238
- class Toolkit {
239
- constructor() { }
240
-
241
- static extractIE(text, { extract = true, hyperlink = true, citation = true, latex = true } = {}) {
242
- return extractIE(text, { extract, hyperlink, citation, latex });
243
- }
244
-
245
- static async resize(buffer, x, y, fit = 'cover') {
246
- return resizeKageImage(buffer, x, y, fit);
247
- }
248
-
249
- static async waitAllPromises(input) {
250
- return await waitAllPromises(input);
251
- }
252
-
253
- static async fetchBuffer(url, options = {}, { silent = true } = {}) {
254
- try {
255
- let response = await fetch(url, options);
256
- if (!response.ok) throw Error(`HTTP ${response.status}`);
257
- return Buffer.from(await response.arrayBuffer());
258
- } catch (error) {
259
- if (silent) return Buffer.alloc(0);
260
- throw error;
261
- }
262
- }
263
-
264
- static async toUrl(_client, path, mediaType = 'document') {
265
- if (!path) throw new Error('Url or buffer needed');
266
-
267
- const media = await _indexjs.prepareWAMessageMedia.call(void 0,
268
- {
269
- [mediaType]: Buffer.isBuffer(path) ? path : { url: path },
270
- },
271
- {
272
- upload: _client.waUploadToServer,
273
- jid: '\u0040\u006e\u0065\u0077\u0073\u006c\u0065\u0074\u0074\u0065\u0072',
274
- }
275
- );
276
-
277
- return _optionalChain([Object, 'access', _ => _.values, 'call', _2 => _2(media), 'access', _3 => _3[0], 'optionalAccess', _4 => _4.url]);
278
- }
279
-
280
- static async resolveMedia(_client, media, mediaType = 'image', { resolveUrl = false, resolveWAUrl = false, result = 'url', resize = false, width = 300, height = 300 } = {}) {
281
- const isUrl = (str) => /^https?:\/\/.+/i.test(str);
282
-
283
- const isWAUrl = (str) => /^https?:\/\/[^/]*\.whatsapp\.net\//i.test(str);
284
-
285
- if (Array.isArray(media)) {
286
- return Promise.all(
287
- media.map((item) =>
288
- Toolkit.resolveMedia(_client, item, mediaType, {
289
- resolveUrl,
290
- resolveWAUrl,
291
- result,
292
- resize,
293
- width,
294
- height,
295
- })
296
- )
297
- );
298
- }
299
-
300
- const originalIsBuffer = Buffer.isBuffer(media);
301
-
302
- if (typeof media === 'string' && isUrl(media)) {
303
- if (isWAUrl(media)) {
304
- if (resolveWAUrl) {
305
- media = await Toolkit.fetchBuffer(media, {}, { silent: true });
306
- } else if (!resolveUrl) {
307
- if (result === 'url') return media;
308
-
309
- media = await Toolkit.fetchBuffer(media, {}, { silent: true });
310
- }
311
- } else {
312
- if (!resolveUrl) {
313
- if (result === 'url') return media;
314
-
315
- media = await Toolkit.fetchBuffer(media, {}, { silent: true });
316
- } else {
317
- media = await Toolkit.fetchBuffer(media, {}, { silent: true });
318
- }
319
- }
320
- }
321
-
322
- if (typeof media === 'string' && !isUrl(media)) {
323
- media = Buffer.from(media, 'base64');
324
- }
325
-
326
- if (!Buffer.isBuffer(media) || !media.length) {
327
- return;
328
- }
329
-
330
- if (resize && Buffer.isBuffer(media)) {
331
- media = await Toolkit.resize(media, width, height);
332
- }
333
-
334
- if (result === 'buffer') {
335
- return media;
336
- }
337
-
338
- if (result === 'base64') {
339
- return media.toString('base64');
340
- }
341
-
342
- if (originalIsBuffer) {
343
- return Toolkit.toUrl(_client, media, mediaType);
344
- }
345
-
346
- return Toolkit.toUrl(_client, media, mediaType);
347
- }
348
-
349
- static getMp4Duration(buffer, { silent = true } = {}) {
350
- try {
351
- if (!Buffer.isBuffer(buffer) || buffer.length < 8) {
352
- if (silent) return 0;
353
- throw new Error('Invalid buffer');
354
- }
355
-
356
- let offset = 0;
357
-
358
- while (offset < buffer.length - 8) {
359
- const size = buffer.readUInt32BE(offset);
360
-
361
- if (size < 8 || offset + size > buffer.length) {
362
- if (silent) return 0;
363
- throw new Error('Invalid atom size');
364
- }
365
-
366
- const type = buffer.toString('ascii', offset + 4, offset + 8);
367
-
368
- if (type === 'moov') {
369
- let moovOffset = offset + 8;
370
- const moovEnd = offset + size;
371
-
372
- while (moovOffset < moovEnd - 8) {
373
- const childSize = buffer.readUInt32BE(moovOffset);
374
-
375
- if (childSize < 8 || moovOffset + childSize > moovEnd) {
376
- if (silent) return 0;
377
- throw new Error('Invalid child atom size');
378
- }
379
-
380
- const childType = buffer.toString('ascii', moovOffset + 4, moovOffset + 8);
381
-
382
- if (childType === 'mvhd') {
383
- const version = buffer.readUInt8(moovOffset + 8);
384
-
385
- if (version === 0) {
386
- const timescale = buffer.readUInt32BE(moovOffset + 20);
387
- const duration = buffer.readUInt32BE(moovOffset + 24);
388
-
389
- if (!timescale) {
390
- if (silent) return 0;
391
- throw new Error('Invalid timescale');
392
- }
393
-
394
- return duration / timescale;
395
- }
396
-
397
- if (version === 1) {
398
- const timescale = buffer.readUInt32BE(moovOffset + 32);
399
- const duration = Number(buffer.readBigUInt64BE(moovOffset + 36));
400
-
401
- if (!timescale) {
402
- if (silent) return 0;
403
- throw new Error('Invalid timescale');
404
- }
405
-
406
- return duration / timescale;
407
- }
408
- }
409
-
410
- moovOffset += childSize;
411
- }
412
- }
413
-
414
- offset += size;
415
- }
416
-
417
- if (silent) return 0;
418
-
419
- throw new Error('No mvhd found!');
420
- } catch (err) {
421
- if (silent) return 0;
422
- throw err;
423
- }
424
- }
425
-
426
- static getMp4Preview(videoBuffer, { time, result = 'buffer', resize = true, width = 300, height = 300, silent = true } = {}) {
427
- return new Promise((resolve, reject) => {
428
- const fail = (err) => {
429
- if (silent) {
430
- return resolve(result === 'base64' ? '' : Buffer.alloc(0));
431
- }
432
- return reject(err);
433
- };
434
-
435
- try {
436
- if (!Buffer.isBuffer(videoBuffer) || !videoBuffer.length) {
437
- return fail(new Error('videoBuffer tidak valid atau kosong'));
438
- }
439
-
440
- const inputStream = new (0, _stream.Readable)({ read() { } });
441
- inputStream.push(videoBuffer);
442
- inputStream.push(null);
443
-
444
- const outputStream = new (0, _stream.PassThrough)();
445
- const chunks = [];
446
-
447
- outputStream.on('data', (chunk) => chunks.push(chunk));
448
-
449
- outputStream.on('end', async () => {
450
- try {
451
- let output = Buffer.concat(chunks);
452
-
453
- if (!output.length) {
454
- return fail(new Error('Output kosong — cek format atau timestamp video'));
455
- }
456
-
457
- if (resize) {
458
- output = await Toolkit.resize(output, width, height);
459
- }
460
-
461
- return resolve(result === 'base64' ? output.toString('base64') : output);
462
- } catch (err) {
463
- return fail(err);
464
- }
465
- });
466
-
467
- outputStream.on('error', fail);
468
-
469
- time ??= Math.min(Toolkit.getMp4Duration(videoBuffer) * 0.2, 10);
470
-
471
- ffmpeg(inputStream)
472
- .outputOptions([`-ss ${time}`, '-vframes 1', '-vcodec png', '-f image2pipe'])
473
- .on('error', (err) => fail(new Error(`ffmpeg error: ${err.message}`)))
474
- .pipe(outputStream, { end: true });
475
- } catch (err) {
476
- return fail(err);
477
- }
478
- });
479
- }
480
- }
481
-
482
-
483
-
484
- function finishBuilderMessage(jid, payload, options = {}, viewOnce = false) {
485
- const content = viewOnce ? {viewOnceMessage:{message:payload}} : payload;
486
- if (jid == null) return require('../../WAProto').proto.Message.fromObject(content);
487
- if (typeof jid !== 'string' || !jid.includes('@')) throw new TypeError('Recipient JID is required');
488
- return require('../Utils/messages').generateWAMessageFromContent(jid, content, options);
489
- }
490
- async function prepareBuilderMedia(data, socket) {
491
- const prepared = ['imageMessage','videoMessage','documentMessage','locationMessage','productMessage'].filter(key => data[key]);
492
- if (prepared.length) {
493
- if (prepared.length !== 1) throw new TypeError('Only one header media field is permitted');
494
- return data;
495
- }
496
- if (!socket?.waUploadToServer) throw new TypeError('Media upload requires a connected socket; pass prepared media for offline builds');
497
- return require('../Utils/messages').prepareWAMessageMedia(data, {upload:socket.waUploadToServer});
498
- }
499
-
500
- class RowBuilder {
501
- constructor() { this.buttons = []; }
502
- button(displayText, buttonId) {
503
- this.buttons.push({ buttonId, buttonText: { displayText }, type: 1 });
504
- return this;
505
- }
506
- }
507
- class CardBuilder {
508
- constructor(client) { this._card = new Button(client); }
509
- image(url) { this._card.setImage(url); return this; }
510
- video(url) { this._card.setVideo(url); return this; }
511
- footer(text) { this._card.setFooter(text); return this; }
512
- url(label, url) { this._card.addUrl(label, url); return this; }
513
- title(t) { this._card.setTitle(t); return this; }
514
- text(t) { this._card.setBody(t); return this; }
515
- button(displayText, id) { this._card.addReply(displayText, id); return this; }
516
- }
517
-
518
- class BaseBuilder {
519
- constructor() {
520
- this._title = '';
521
- this._subtitle = '';
522
- this._body = '';
523
- this._footer = '';
524
- this._contextInfo = {};
525
- this._extraPayload = {};
526
- this._viewOnce = false;
527
- }
528
-
529
- setTitle(title) {
530
- if (typeof title !== 'string') {
531
- throw new TypeError('Title must be a string');
532
- }
533
- this._title = title;
534
- return this;
535
- }
536
-
537
- setSubtitle(subtitle) {
538
- if (typeof subtitle !== 'string') {
539
- throw new TypeError('Subtitle must be a string');
540
- }
541
- this._subtitle = subtitle;
542
- return this;
543
- }
544
-
545
- setBody(body) {
546
- if (typeof body !== 'string') {
547
- throw new TypeError('Body must be a string');
548
- }
549
- this._body = body;
550
- return this;
551
- }
552
-
553
- setFooter(footer) {
554
- if (typeof footer !== 'string') {
555
- throw new TypeError('Footer must be a string');
556
- }
557
- this._footer = footer;
558
- return this;
559
- }
560
-
561
- setContextInfo(obj) {
562
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
563
- throw new TypeError('ContextInfo must be a plain object');
564
- }
565
-
566
- this._contextInfo = obj;
567
- return this;
568
- }
569
-
570
- addPayload(obj) {
571
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
572
- throw new TypeError('Payload must be a plain object');
573
- }
574
-
575
- Object.assign(this._extraPayload, obj);
576
-
577
- return this;
578
- }
579
- text(t) { return this.setBody(t); }
580
- header(t) { return this.setTitle(t); }
581
- viewOnce(enabled = true) { this._viewOnce = !!enabled; return this; }
582
- footer(f) { return this.setFooter(f); }
583
- title(t) { return this.setTitle(t); }
584
- subtitle(s) { return this.setSubtitle(s); }
585
- image(url, opts = {}) {
586
- if (this.setImage) return this.setImage(url, opts);
587
- if (this.setThumbnail) return this.setThumbnail(url);
588
- if (this.addImage) return this.addImage(url, opts);
589
- return this;
590
- }
591
-
592
- }
593
-
594
- class Button extends BaseBuilder {
595
- #client;
596
-
597
- constructor(client) {
598
- super();
599
- this.#client = client;
600
-
601
- this._buttons = [];
602
- this._data;
603
- this._currentSelectionIndex = -1;
604
- this._currentSectionIndex = -1;
605
- this._params = {};
606
- }
607
-
608
- setVideo(path, options = {}) {
609
- if (!path) throw new Error('Url or buffer needed');
610
- Buffer.isBuffer(path) ? (this._data = { video: path, ...options }) : (this._data = { video: { url: path }, ...options });
611
- return this;
612
- }
613
-
614
- setImage(path, options = {}) {
615
- if (!path) throw new Error('Url or buffer needed');
616
- Buffer.isBuffer(path) ? (this._data = { image: path, ...options }) : (this._data = { image: { url: path }, ...options });
617
- return this;
618
- }
619
-
620
- setDocument(path, options = {}) {
621
- if (!path) throw new Error('Url or buffer needed');
622
- Buffer.isBuffer(path) ? (this._data = { document: path, ...options }) : (this._data = { document: { url: path }, ...options });
623
- return this;
624
- }
625
-
626
- setMedia(obj) {
627
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
628
- throw new TypeError('Media must be a plain object');
629
- }
630
-
631
- this._data = obj;
632
- return this;
633
- }
634
-
635
- clearButtons() {
636
- this._buttons = [];
637
- return this;
638
- }
639
-
640
- setParams(obj) {
641
- this._params = obj;
642
- return this;
643
- }
644
-
645
- addButton(name, params) {
646
- this._buttons.push({
647
- name,
648
- buttonParamsJson: typeof params === 'string' ? params : JSON.stringify(params),
649
- });
650
-
651
- return this;
652
- }
653
-
654
- makeRow(header = '', title = '', description = '', id = '') {
655
- if (this._currentSelectionIndex === -1 || this._currentSectionIndex === -1) {
656
- throw new Error('You need to create a selection and a section first');
657
- }
658
- const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
659
- buttonParams.sections[this._currentSectionIndex].rows.push({ header, title, description, id });
660
- this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
661
- return this;
662
- }
663
-
664
- makeSection(title = '', highlight_label = '') {
665
- if (this._currentSelectionIndex === -1) {
666
- throw new Error('You need to create a selection first');
667
- }
668
- const buttonParams = JSON.parse(this._buttons[this._currentSelectionIndex].buttonParamsJson);
669
- buttonParams.sections.push({ title, highlight_label, rows: [] });
670
- this._currentSectionIndex = buttonParams.sections.length - 1;
671
- this._buttons[this._currentSelectionIndex].buttonParamsJson = JSON.stringify(buttonParams);
672
- return this;
673
- }
674
-
675
- addSelection(title, options = {}) {
676
- this._buttons.push({ ...options, name: 'single_select', buttonParamsJson: JSON.stringify({ title, sections: [] }) });
677
- this._currentSelectionIndex = this._buttons.length - 1;
678
- this._currentSectionIndex = -1;
679
- return this;
680
- }
681
-
682
- addReply(display_text = '', id = '', options = {}) {
683
- this._buttons.push({
684
- name: 'quick_reply',
685
- buttonParamsJson: JSON.stringify({
686
- display_text,
687
- id,
688
- ...options,
689
- }),
690
- });
691
- return this;
692
- }
693
-
694
- addCall(display_text = '', id = '', options = {}) {
695
- this._buttons.push({
696
- name: 'cta_call',
697
- buttonParamsJson: JSON.stringify({
698
- display_text,
699
- id,
700
- ...options,
701
- }),
702
- });
703
- return this;
704
- }
705
-
706
- addReminder(display_text = '', id = '', options = {}) {
707
- this._buttons.push({
708
- name: 'cta_reminder',
709
- buttonParamsJson: JSON.stringify({
710
- display_text,
711
- id,
712
- ...options,
713
- }),
714
- });
715
- return this;
716
- }
717
-
718
- addCancelReminder(display_text = '', id = '', options = {}) {
719
- this._buttons.push({
720
- name: 'cta_cancel_reminder',
721
- buttonParamsJson: JSON.stringify({
722
- display_text,
723
- id,
724
- ...options,
725
- }),
726
- });
727
- return this;
728
- }
729
-
730
- addAddress(display_text = '', id = '', options = {}) {
731
- this._buttons.push({
732
- name: 'address_message',
733
- buttonParamsJson: JSON.stringify({
734
- display_text,
735
- id,
736
- ...options,
737
- }),
738
- });
739
- return this;
740
- }
741
-
742
- addLocation(options = {}) {
743
- this._buttons.push({
744
- name: 'send_location',
745
- buttonParamsJson: JSON.stringify(options),
746
- });
747
- return this;
748
- }
749
-
750
- addUrl(display_text = '', url = '', webview_interaction = false, options = {}) {
751
- this._buttons.push({
752
- ...options,
753
- name: 'cta_url',
754
- buttonParamsJson: JSON.stringify({
755
- display_text,
756
- url,
757
- webview_interaction,
758
- ...options,
759
- }),
760
- });
761
- return this;
762
- }
763
-
764
- addCopy(display_text = '', copy_code = '', options = {}) {
765
- this._buttons.push({
766
- name: 'cta_copy',
767
- buttonParamsJson: JSON.stringify({
768
- display_text,
769
- copy_code,
770
- ...options,
771
- }),
772
- });
773
- return this;
774
- }
775
-
776
- static __initStatic() {this.paramsList = {
777
- limited_time_offer: {
778
- text: 'string',
779
- url: 'string',
780
- copy_code: 'string',
781
- expiration_time: 'number',
782
- },
783
- bottom_sheet: {
784
- in_thread_buttons_limit: 'number',
785
- divider_indices: ['number'],
786
- list_title: 'string',
787
- button_title: 'string',
788
- },
789
- tap_target_configuration: {
790
- title: 'string',
791
- description: 'string',
792
- canonical_url: 'string',
793
- domain: 'string',
794
- buttonIndex: 'number',
795
- },
796
- }}
797
-
798
- async toCard() {
799
- return {
800
- body: {
801
- text: this._body,
802
- },
803
- footer: {
804
- text: this._footer,
805
- },
806
- header: {
807
- title: this._title,
808
- subtitle: this._subtitle,
809
- hasMediaAttachment: !!this._data,
810
- ...(this._data
811
- ? await prepareBuilderMedia(this._data, this.#client)
812
- : {}),
813
- },
814
- nativeFlowMessage: {
815
- messageParamsJson: JSON.stringify(this._params),
816
- buttons: this._buttons,
817
- },
818
- };
819
- }
820
-
821
- async build(jid, options = {}) {
822
- const message = await this.toCard();
823
- const validation = require('../Utils/interactive-compat').validateKageInteractiveMessage({interactiveMessage:message});
824
- if (!validation.valid) throw new TypeError(validation.errors.join('; '));
825
- return finishBuilderMessage(jid, { ...this._extraPayload, interactiveMessage: { ...message, contextInfo: this._contextInfo } }, options, this._viewOnce);
826
- }
827
-
828
- async send(jid, { ...options } = {}) {
829
- const msg = await this.build(jid, options);
830
-
831
- if (!this.#client?.relayMessage) throw new TypeError('A connected socket is required to send; bind(socket) or pass it to the constructor');
832
- await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
833
- messageId: msg.key.id,
834
- additionalNodes: [
835
- {
836
- tag: 'biz',
837
- attrs: {},
838
- content: [
839
- {
840
- tag: 'interactive',
841
- attrs: { type: 'native_flow', v: '1' },
842
- content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
843
- },
844
- ],
845
- },
846
- ],
847
- ...options,
848
- });
849
- return msg;
850
- }
851
- button(displayText, id) { return this.addReply(displayText, id || _crypto2.default.randomUUID()); }
852
- row(callback) {
853
- if (typeof callback !== 'function') throw new TypeError('Row callback required');
854
- const row = new RowBuilder(); callback(row);
855
- for (const button of row.buttons) this.addReply(button.buttonText.displayText, button.buttonId || _crypto2.default.randomUUID());
856
- return this;
857
- }
858
-
859
- } Button.__initStatic();
860
-
861
- class ButtonV2 extends BaseBuilder {
862
- #client;
863
-
864
- constructor(client) {
865
- super();
866
-
867
- this.#client = client;
868
- this._image;
869
- this._data;
870
- this._buttons = [];
871
- }
872
-
873
- addButton(displayText = '', buttonId = _crypto2.default.randomUUID()) {
874
- this._buttons.push({
875
- buttonId,
876
- buttonText: { displayText },
877
- type: 1,
878
- });
879
- return this;
880
- }
881
-
882
- addRawButton(obj) {
883
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
884
- throw new TypeError('Buttons must be a plain object');
885
- }
886
-
887
- this._buttons.push(obj);
888
- return this;
889
- }
890
-
891
- setThumbnail(path) {
892
- if (!path) throw new Error('Url or buffer needed');
893
- this._image = path;
894
- return this;
895
- }
896
-
897
- setMedia(obj) {
898
- if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {
899
- throw new TypeError('Media must be a plain object');
900
- }
901
-
902
- this._data = obj;
903
- return this;
904
- }
905
-
906
- async build(jid, options = {}) {
907
- if (!this._buttons.length) throw new TypeError('ButtonV2 requires at least one button');
908
- const media = this._data ? await prepareBuilderMedia(this._data, this.#client) : {};
909
- const keys = ['imageMessage','videoMessage','documentMessage','locationMessage'].filter(key => media[key]);
910
- const headerTypes = {documentMessage:3,imageMessage:4,videoMessage:5,locationMessage:6};
911
- const thumbnail = this._image ? await Toolkit.resize(Buffer.isBuffer(this._image) ? this._image : await Toolkit.fetchBuffer(this._image, {}, {silent:true}),300,300) : undefined;
912
- const buttonsMessage = {contentText:this._body, footerText:this._footer, contextInfo:this._contextInfo,
913
- headerType: keys.length ? headerTypes[keys[0]] : this._title ? 2 : 1,
914
- ...(this._title ? {text:this._title} : {}), ...media,
915
- ...(thumbnail ? {headerType:6,locationMessage:{degreesLatitude:0,degreesLongitude:0,name:this._title,address:this._subtitle,jpegThumbnail:thumbnail}} : {}),
916
- buttons:this._buttons};
917
- return finishBuilderMessage(jid,{...this._extraPayload,buttonsMessage},options,this._viewOnce);
918
- }
919
-
920
- async send(jid, { ...options } = {}) {
921
- if (this._buttons.length < 1) throw new Error('ButtonV2 requires at least one button');
922
- const msg = await this.build(jid, options);
923
-
924
- if (!this.#client?.relayMessage) throw new TypeError('A connected socket is required to send; bind(socket) or pass it to the constructor');
925
- await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
926
- messageId: msg.key.id,
927
- additionalNodes: [
928
- {
929
- tag: 'biz',
930
- attrs: {},
931
- content: [
932
- {
933
- tag: 'interactive',
934
- attrs: { type: 'native_flow', v: '1' },
935
- content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
936
- },
937
- ],
938
- },
939
- ],
940
- ...options,
941
- });
942
- return msg;
943
- }
944
- button(displayText, id) { return this.addButton(displayText, id); }
945
- row(cb) {
946
- const r = new RowBuilder();
947
- cb(r);
948
- r.buttons.forEach(b => this._buttons.push(b));
949
- return this;
950
- }
951
-
952
- }
953
-
954
- class Carousel extends BaseBuilder {
955
- #client;
956
-
957
- constructor(client) {
958
- super();
959
-
960
- this.#client = client;
961
- this._cards = [];
962
- }
963
-
964
- addCard(card) {
965
- const cards = Array.isArray(card) ? card : [card];
966
- const baseIndex = this._cards.length;
967
-
968
- for (const [index, c] of cards.entries()) {
969
- if (!_optionalChain([c, 'optionalAccess', _5 => _5.header, 'optionalAccess', _6 => _6.hasMediaAttachment])) {
970
- throw new Error(`Card [${baseIndex + index}] must include an image or video in header`);
971
- }
972
- }
973
-
974
- this._cards.push(...cards);
975
- return this;
976
- }
977
-
978
- async build(jid, options = {}) {
979
- const cards = [...this._cards];
980
- for (const builder of this._cardBuilders || []) cards.push(await builder._card.toCard());
981
- if (!cards.length) throw new TypeError('Carousel requires at least one card');
982
- const message = { body:{text:this._body}, footer:{text:this._footer}, contextInfo:this._contextInfo, carouselMessage:{cards,messageVersion:1} };
983
- const validation = require('../Utils/interactive-compat').validateKageInteractiveMessage({interactiveMessage:message});
984
- if (!validation.valid) throw new TypeError(validation.errors.join('; '));
985
- return finishBuilderMessage(jid, { ...this._extraPayload, interactiveMessage:message }, options, this._viewOnce);
986
- }
987
-
988
- async send(jid, { ...options } = {}) {
989
- const msg = await this.build(jid, options);
990
-
991
- if (!this.#client?.relayMessage) throw new TypeError('A connected socket is required to send; bind(socket) or pass it to the constructor');
992
- await this.#client.relayMessage(msg.key.remoteJid, msg.message, {
993
- messageId: msg.key.id,
994
- additionalNodes: [
995
- {
996
- tag: 'biz',
997
- attrs: {},
998
- content: [
999
- {
1000
- tag: 'interactive',
1001
- attrs: { type: 'native_flow', v: '1' },
1002
- content: [{ tag: 'native_flow', attrs: { v: '9', name: 'mixed' } }],
1003
- },
1004
- ],
1005
- },
1006
- ],
1007
- ...options,
1008
- });
1009
- return msg;
1010
- }
1011
- card(cb) {
1012
- if (!this._cardBuilders) this._cardBuilders = [];
1013
- const cbObj = new CardBuilder(this.#client);
1014
- cb(cbObj);
1015
- this._cardBuilders.push(cbObj);
1016
- return this;
1017
- }
1018
-
1019
- }
1020
-
1021
- class AIRich extends BaseBuilder {
1022
- #client;
1023
-
1024
- constructor(client) {
1025
-
1026
- super();
1027
- this.#client = client;
1028
- this._contextInfo = {};
1029
- this._submessages = [];
1030
- this._sections = [];
1031
- this._richResponseSources = [];
1032
- }
1033
-
1034
- addSubmessage(submessage) {
1035
- const items = Array.isArray(submessage) ? submessage : [submessage];
1036
-
1037
- for (const item of items) {
1038
- if (typeof item !== 'object' || item === null || Array.isArray(item)) {
1039
- throw new TypeError('Submessage must be a plain object or array of plain objects');
1040
- }
1041
-
1042
- this._submessages.push(item);
1043
- }
1044
-
1045
- return this;
1046
- }
1047
-
1048
- addSection(section) {
1049
- const items = Array.isArray(section) ? section : [section];
1050
-
1051
- for (const item of items) {
1052
- if (typeof item !== 'object' || item === null || Array.isArray(item)) {
1053
- throw new TypeError('Section must be a plain object or array of plain objects');
1054
- }
1055
-
1056
- this._sections.push(item);
1057
- }
1058
-
1059
- return this;
1060
- }
1061
-
1062
- addText(text, { extract = true, hyperlink = true, citation = true, latex = true } = {}) {
1063
- if (typeof text != 'string') {
1064
- throw new TypeError('Text must be a string');
1065
- }
1066
-
1067
- const { text: extractedText, inline_entities } = extractIE(text, {
1068
- extract,
1069
- hyperlink,
1070
- citation,
1071
- latex,
1072
- });
1073
-
1074
- this._submessages.push({
1075
- messageType: 2,
1076
- messageText: extractedText,
1077
- });
1078
-
1079
- this._sections.push(
1080
- AIRich.newLayout('Single', {
1081
- text: extractedText,
1082
- ...(inline_entities.length && {
1083
- inline_entities,
1084
- }),
1085
- __typename: 'GenAIMarkdownTextUXPrimitive',
1086
- })
1087
- );
1088
-
1089
- return this;
1090
- }
1091
-
1092
- addCode(language, code) {
1093
- if (typeof language !== 'string' || typeof code !== 'string') {
1094
- throw new TypeError('Language and code must be a string');
1095
- }
1096
-
1097
- const meta = AIRich.tokenizer(code, language);
1098
-
1099
- this._submessages.push({
1100
- messageType: 5,
1101
- codeMetadata: {
1102
- codeLanguage: language,
1103
- codeBlocks: meta.codeBlock,
1104
- },
1105
- });
1106
-
1107
- this._sections.push(
1108
- AIRich.newLayout('Single', {
1109
- language,
1110
- code_blocks: meta.unified_codeBlock,
1111
- __typename: 'GenAICodeUXPrimitive',
1112
- })
1113
- );
1114
-
1115
- return this;
1116
- }
1117
-
1118
- addTable(table, { hyperlink = true, citation = true, latex = true } = {}) {
1119
- if (!Array.isArray(table)) {
1120
- throw new TypeError('Table must be an array');
1121
- }
1122
-
1123
- const meta = AIRich.toTableMetadata(table, { hyperlink, citation, latex });
1124
-
1125
- this._submessages.push({
1126
- messageType: 4,
1127
- tableMetadata: {
1128
- title: meta.title,
1129
- rows: meta.rows,
1130
- },
1131
- });
1132
-
1133
- this._sections.push(
1134
- AIRich.newLayout('Single', {
1135
- rows: meta.unified_rows,
1136
- __typename: 'GenATableUXPrimitive',
1137
- })
1138
- );
1139
-
1140
- return this;
1141
- }
1142
-
1143
- addSource(sources = []) {
1144
- if (!(Array.isArray(sources) && (sources.every((item) => typeof item === 'string') || sources.every((item) => Array.isArray(item) && item.every((v) => typeof v === 'string'))))) {
1145
- throw new TypeError('Sources must be a string array or an array of string arrays');
1146
- }
1147
-
1148
- if (sources.every((item) => typeof item === 'string')) {
1149
- sources = [sources];
1150
- }
1151
-
1152
- const source = sources.map(([icon, url, text]) => ({
1153
- source_type: 'THIRD_PARTY',
1154
- source_display_name: _nullishCoalesce(text, () => ( '')),
1155
- source_subtitle: 'AI',
1156
- source_url: _nullishCoalesce(url, () => ( '')),
1157
- favicon: {
1158
- url: Toolkit.resolveMedia(this.#client, _nullishCoalesce(icon, () => ( '')), 'image'),
1159
- mime_type: 'image/jpeg',
1160
- width: 16,
1161
- height: 16,
1162
- },
1163
- }));
1164
-
1165
- this._sections.push(
1166
- AIRich.newLayout('Single', {
1167
- sources: source,
1168
- __typename: 'GenAISearchResultPrimitive',
1169
- })
1170
- );
1171
-
1172
- return this;
1173
- }
1174
-
1175
- addReels(reelsItems = []) {
1176
- if (
1177
- !(
1178
- (reelsItems && typeof reelsItems === 'object' && !Array.isArray(reelsItems)) ||
1179
- (Array.isArray(reelsItems) && reelsItems.every((item) => item && typeof item === 'object' && !Array.isArray(item)))
1180
- )
1181
- ) {
1182
- throw new TypeError('Reels items must be an object or an array of objects');
1183
- }
1184
-
1185
- if (!Array.isArray(reelsItems)) {
1186
- reelsItems = [reelsItems];
1187
- }
1188
-
1189
- const reels = reelsItems.map((item) => ({
1190
- ...item,
1191
- _avatar: Toolkit.resolveMedia(this.#client, _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(item.profileIconUrl, () => ( item.profile_url)), () => ( item.profile)), () => ( '')), 'image'),
1192
- _thumbnail: Toolkit.resolveMedia(this.#client, _nullishCoalesce(_nullishCoalesce(item.thumbnailUrl, () => ( item.thumbnail)), () => ( '')), 'image'),
1193
- }));
1194
-
1195
- this._submessages.push({
1196
- messageType: 9,
1197
- contentItemsMetadata: {
1198
- contentType: 1,
1199
- itemsMetadata: reels.map((item) => ({
1200
- reelItem: {
1201
- title: _nullishCoalesce(item.username, () => ( '')),
1202
- profileIconUrl: item._avatar,
1203
- thumbnailUrl: item._thumbnail,
1204
- videoUrl: _nullishCoalesce(_nullishCoalesce(item.videoUrl, () => ( item.url)), () => ( '')),
1205
- },
1206
- })),
1207
- },
1208
- });
1209
-
1210
- reels.forEach((item, idx) => {
1211
- this._richResponseSources.push({
1212
- provider: '\u004E\u0049\u0058\u0045\u004C',
1213
- thumbnailCDNURL: item._thumbnail,
1214
- sourceProviderURL: _nullishCoalesce(_nullishCoalesce(item.videoUrl, () => ( item.url)), () => ( '')),
1215
- sourceQuery: '',
1216
- faviconCDNURL: item._avatar,
1217
- citationNumber: idx + 1,
1218
- sourceTitle: _nullishCoalesce(item.username, () => ( '')),
1219
- });
1220
- });
1221
-
1222
- this._sections.push(
1223
- AIRich.newLayout(
1224
- 'HScroll',
1225
- reels.map((item) => ({
1226
- reels_url: _nullishCoalesce(_nullishCoalesce(item.videoUrl, () => ( item.url)), () => ( '')),
1227
- thumbnail_url: item._thumbnail,
1228
- creator: _nullishCoalesce(_nullishCoalesce(item.username, () => ( item.title)), () => ( '')),
1229
- avatar_url: item._avatar,
1230
- reels_title: _nullishCoalesce(_nullishCoalesce(item.reels_title, () => ( item.title)), () => ( '')),
1231
- likes_count: _nullishCoalesce(_nullishCoalesce(item.likes_count, () => ( item.like)), () => ( 0)),
1232
- shares_count: _nullishCoalesce(_nullishCoalesce(item.shares_count, () => ( item.share)), () => ( 0)),
1233
- view_count: _nullishCoalesce(_nullishCoalesce(item.view_count, () => ( item.view)), () => ( 0)),
1234
- reel_source: _nullishCoalesce(_nullishCoalesce(item.reel_source, () => ( item.source)), () => ( 'IG')),
1235
- is_verified: !!(item.is_verified || item.verified),
1236
- __typename: 'GenAIReelPrimitive',
1237
- }))
1238
- )
1239
- );
1240
-
1241
- return this;
1242
- }
1243
-
1244
- addImage(imageUrl, { resolveUrl = false } = {}) {
1245
- if (!(typeof imageUrl === 'string' || Buffer.isBuffer(imageUrl) || (Array.isArray(imageUrl) && imageUrl.every((v) => typeof v === 'string' || Buffer.isBuffer(v))))) {
1246
- throw new TypeError('imageUrl must be string | buffer | array of string/buffer');
1247
- }
1248
-
1249
- const list = Array.isArray(imageUrl)
1250
- ? imageUrl.map((v) => {
1251
- const url = Toolkit.resolveMedia(this.#client, v, 'image', { resolveUrl });
1252
- return {
1253
- imagePreviewUrl: url,
1254
- imageHighResUrl: url,
1255
- sourceUrl: url,
1256
- };
1257
- })
1258
- : (() => {
1259
- const url = Toolkit.resolveMedia(this.#client, imageUrl, 'image', { resolveUrl });
1260
- return [
1261
- {
1262
- imagePreviewUrl: url,
1263
- imageHighResUrl: url,
1264
- sourceUrl: url,
1265
- },
1266
- ];
1267
- })();
1268
-
1269
- this._submessages.push({
1270
- messageType: 1,
1271
- gridImageMetadata: {
1272
- gridImageUrl: {
1273
- imagePreviewUrl: _optionalChain([list, 'access', _7 => _7[0], 'optionalAccess', _8 => _8.imagePreviewUrl]),
1274
- },
1275
- imageUrls: list,
1276
- },
1277
- });
1278
-
1279
- list.forEach(({ imagePreviewUrl }) => {
1280
- this._sections.push(
1281
- AIRich.newLayout('Single', {
1282
- media: {
1283
- url: imagePreviewUrl,
1284
- mime_type: 'image/png',
1285
- },
1286
- imagine_type: 'IMAGE',
1287
- status: { status: 'READY' },
1288
- __typename: 'GenAIImaginePrimitive',
1289
- })
1290
- );
1291
- });
1292
-
1293
- return this;
1294
- }
1295
-
1296
- addVideo(videoUrl, { autoFill = true } = {}) {
1297
- const isObjectVideo = (v) => v && typeof v === 'object' && v.url;
1298
-
1299
- const isValidPrimitive =
1300
- typeof videoUrl === 'string' ||
1301
- Buffer.isBuffer(videoUrl) ||
1302
- isObjectVideo(videoUrl) ||
1303
- (Array.isArray(videoUrl) && videoUrl.every((v) => typeof v === 'string' || Buffer.isBuffer(v) || isObjectVideo(v)));
1304
-
1305
- if (!isValidPrimitive) {
1306
- throw new TypeError('videoUrl must be string | buffer | object | array');
1307
- }
1308
-
1309
- const items = Array.isArray(videoUrl) ? videoUrl : [videoUrl];
1310
-
1311
- this._submessages.push({
1312
- messageType: 2,
1313
- messageText: '[ CANNOT_LOAD_VIDEO - \u004E\u0049\u0058\u0045\u004C ]',
1314
- });
1315
-
1316
- items.forEach((item) => {
1317
- const isObject = isObjectVideo(item);
1318
-
1319
- const url = isObject ? Toolkit.resolveMedia(this.#client, _nullishCoalesce(item.url, () => ( '')), 'video') : Toolkit.resolveMedia(this.#client, item, 'video');
1320
-
1321
- const bufferPromise = autoFill ? Promise.resolve(url).then((u) => Toolkit.fetchBuffer(u)) : null;
1322
-
1323
- const file_length = isObject && item.file_length != null ? item.file_length : autoFill ? bufferPromise.then((b) => _nullishCoalesce(_optionalChain([b, 'optionalAccess', _9 => _9.length]), () => ( 0))) : 0;
1324
-
1325
- const duration =
1326
- isObject && item.duration != null
1327
- ? item.duration
1328
- : autoFill
1329
- ? bufferPromise.then((b) =>
1330
- Toolkit.getMp4Duration(b, {
1331
- silent: true,
1332
- })
1333
- )
1334
- : 0;
1335
-
1336
- const thumbnail =
1337
- isObject && item.thumbnail
1338
- ? Toolkit.resolveMedia(this.#client, item.thumbnail, 'image', {
1339
- result: 'base64',
1340
- resize: true,
1341
- width: 300,
1342
- height: 300,
1343
- })
1344
- : autoFill
1345
- ? bufferPromise
1346
- ? bufferPromise.then((b) =>
1347
- Toolkit.getMp4Preview(b, {
1348
- time: 0,
1349
- result: 'base64',
1350
- })
1351
- )
1352
- : null
1353
- : null;
1354
-
1355
- this._sections.push(
1356
- AIRich.newLayout('Single', {
1357
- media: {
1358
- url,
1359
- mime_type: isObject ? (_nullishCoalesce(item.mime_type, () => ( 'video/mp4'))) : 'video/mp4',
1360
- file_length,
1361
- duration,
1362
- },
1363
- imagine_type: 'ANIMATE',
1364
- status: { status: 'READY' },
1365
- thumbnail: {
1366
- raw_media: thumbnail,
1367
- },
1368
- __typename: 'GenAIImaginePrimitive',
1369
- })
1370
- );
1371
- });
1372
-
1373
- return this;
1374
- }
1375
-
1376
- addProduct(data = {}) {
1377
- if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
1378
- throw new TypeError('Product items must be an object or an array of objects');
1379
- }
1380
-
1381
- this._submessages.push({
1382
- messageType: 2,
1383
- messageText: '[ CANNOT_LOAD_PRODUCT - NIXEL ]',
1384
- });
1385
-
1386
- const items = Array.isArray(data) ? data : [data];
1387
-
1388
- const product = items.map((item) => ({
1389
- title: item.title,
1390
- brand: item.brand,
1391
- price: item.price,
1392
- sale_price: item.sale_price,
1393
- product_url: _nullishCoalesce(item.product_url, () => ( item.url)),
1394
- image: {
1395
- url: Toolkit.resolveMedia(this.#client, _nullishCoalesce(item.image_url, () => ( item.image)), 'image'),
1396
- },
1397
- additional_images: [
1398
- {
1399
- url: Toolkit.resolveMedia(this.#client, _nullishCoalesce(item.icon_url, () => ( item.icon)), 'image'),
1400
- },
1401
- ],
1402
- __typename: 'GenAIProductItemCardPrimitive',
1403
- }));
1404
-
1405
- this._sections.push(AIRich.newLayout(Array.isArray(data) ? 'HScroll' : 'Single', Array.isArray(data) ? product : product[0]));
1406
-
1407
- return this;
1408
- }
1409
-
1410
- addPost(data = {}) {
1411
- if (!((data && typeof data === 'object' && !Array.isArray(data)) || (Array.isArray(data) && data.every((item) => item && typeof item === 'object' && !Array.isArray(item))))) {
1412
- throw new TypeError('Post items must be an object or an array of objects');
1413
- }
1414
-
1415
- const posts = Array.isArray(data) ? data : [data];
1416
-
1417
- this._submessages.push({
1418
- messageType: 2,
1419
- messageText: '[ CANNOT_LOAD_POST - NIXEL ]',
1420
- });
1421
-
1422
- const primitives = posts.map((p) => ({
1423
- title: _nullishCoalesce(p.title, () => ( '')),
1424
- subtitle: _nullishCoalesce(p.subtitle, () => ( '')),
1425
- username: _nullishCoalesce(p.username, () => ( '')),
1426
- profile_picture_url: Toolkit.resolveMedia(this.#client, _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(p.profile_picture_url, () => ( p.profile_url)), () => ( p.profile)), () => ( '')), 'image'),
1427
- is_verified: !!(p.is_verified || p.verified),
1428
- thumbnail_url: Toolkit.resolveMedia(this.#client, _nullishCoalesce(_nullishCoalesce(p.thumbnail_url, () => ( p.thumbnail)), () => ( '')), 'image'),
1429
- post_caption: _nullishCoalesce(_nullishCoalesce(p.post_caption, () => ( p.caption)), () => ( '')),
1430
- likes_count: _nullishCoalesce(_nullishCoalesce(p.likes_count, () => ( p.like)), () => ( 0)),
1431
- comments_count: _nullishCoalesce(_nullishCoalesce(p.comments_count, () => ( p.comment)), () => ( 0)),
1432
- shares_count: _nullishCoalesce(_nullishCoalesce(p.shares_count, () => ( p.share)), () => ( 0)),
1433
- post_url: _nullishCoalesce(_nullishCoalesce(p.post_url, () => ( p.url)), () => ( '')),
1434
- post_deeplink: _nullishCoalesce(_nullishCoalesce(p.post_deeplink, () => ( p.deeplink)), () => ( '')),
1435
- source_app: p.source_app || p.source || 'INSTAGRAM',
1436
- footer_label: _nullishCoalesce(_nullishCoalesce(p.footer_label, () => ( p.footer)), () => ( '')),
1437
- footer_icon: Toolkit.resolveMedia(this.#client, _nullishCoalesce(_nullishCoalesce(p.footer_icon, () => ( p.icon)), () => ( '')), 'image'),
1438
- is_carousel: posts.length > 1,
1439
- orientation: _nullishCoalesce(p.orientation, () => ( 'LANDSCAPE')),
1440
- post_type: _nullishCoalesce(p.post_type, () => ( 'VIDEO')),
1441
- __typename: 'GenAIPostPrimitive',
1442
- }));
1443
-
1444
- this._sections.push(AIRich.newLayout('HScroll', primitives));
1445
-
1446
- return this;
1447
- }
1448
-
1449
- addTip(text) {
1450
- this._submessages.push({
1451
- messageType: 2,
1452
- messageText: text,
1453
- });
1454
-
1455
- this._sections.push(
1456
- AIRich.newLayout('Single', {
1457
- text,
1458
- __typename: 'GenAIMetadataTextPrimitive',
1459
- })
1460
- );
1461
-
1462
- return this;
1463
- }
1464
-
1465
- addSuggest(suggestion, { scroll = true, layout } = {}) {
1466
- if (!(typeof suggestion === 'string' || (Array.isArray(suggestion) && suggestion.every((v) => typeof v === 'string')))) {
1467
- throw new TypeError('Suggestion must be a string or array of strings');
1468
- }
1469
-
1470
- const suggest = Array.isArray(suggestion)
1471
- ? suggestion.map((text) => ({
1472
- prompt_text: text,
1473
- prompt_type: 'SUGGESTED_PROMPT',
1474
- __typename: 'GenAIFollowUpSuggestionPillPrimitive',
1475
- }))
1476
- : [
1477
- {
1478
- prompt_text: suggestion,
1479
- prompt_type: 'SUGGESTED_PROMPT',
1480
- __typename: 'GenAIFollowUpSuggestionPillPrimitive',
1481
- },
1482
- ];
1483
-
1484
- const type = _nullishCoalesce(layout, () => ( (suggest.length === 1 ? 'Single' : scroll ? 'HScroll' : 'ActionRow')));
1485
-
1486
- this._sections.push(AIRich.newLayout(type, type === 'Single' ? suggest[0] : suggest, { __typename: 'GenAIUnifiedResponseSection' }));
1487
-
1488
- return this;
1489
- }
1490
-
1491
- async build({ forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, quoted, quotedParticipant, ...options } = {}) {
1492
- const forward = forwarded
1493
- ? {
1494
- forwardingScore: 1,
1495
- isForwarded: true,
1496
- forwardedAiBotMessageInfo: { botJid: '0@bot' },
1497
- forwardOrigin: 4,
1498
- }
1499
- : {};
1500
-
1501
- const notif = notification
1502
- ? {
1503
- sessionTransparencyMetadata: {
1504
- disclaimerText: '~ Ahmad tumbuh kembang',
1505
- hcaId: `hca_${Date.now()}`,
1506
- sessionTransparencyType: 1,
1507
- },
1508
- }
1509
- : {};
1510
-
1511
- const qObj = quoted
1512
- ? {
1513
- stanzaId: _optionalChain([quoted, 'optionalAccess', _10 => _10.key, 'optionalAccess', _11 => _11.id]) || _optionalChain([quoted, 'optionalAccess', _12 => _12.id]),
1514
- participant: quotedParticipant || _optionalChain([quoted, 'optionalAccess', _13 => _13.key, 'optionalAccess', _14 => _14.participant]) || _optionalChain([quoted, 'optionalAccess', _15 => _15.key, 'optionalAccess', _16 => _16.remoteJid]),
1515
- quotedType: 0,
1516
- quotedMessage: typeof quoted === 'object' && quoted !== null ? (_nullishCoalesce(quoted.message, () => ( quoted))) : undefined,
1517
- }
1518
- : {};
1519
-
1520
- const sections = this._footer
1521
- ? [
1522
- ...(await waitAllPromises(this._sections)),
1523
- AIRich.newLayout('Single', {
1524
- text: this._footer,
1525
- __typename: 'GenAIMetadataTextPrimitive',
1526
- }),
1527
- ]
1528
- : [...(await waitAllPromises(this._sections))];
1529
-
1530
- return {
1531
- messageContextInfo: {
1532
- deviceListMetadata: {},
1533
- deviceListMetadataVersion: 2,
1534
- botMetadata: {
1535
- messageDisclaimerText: this._title,
1536
- richResponseSourcesMetadata: { sources: this._richResponseSources },
1537
- ...notif,
1538
- },
1539
- },
1540
- ...this._extraPayload,
1541
- botForwardedMessage: {
1542
- message: {
1543
- richResponseMessage: {
1544
- messageType: 1,
1545
- submessages: includesSubmessages ? await waitAllPromises(this._submessages) : [],
1546
- unifiedResponse: {
1547
- data: includesUnifiedResponse ? Buffer.from(JSON.stringify({ response_id: _crypto2.default.randomUUID(), sections })).toString('base64') : '',
1548
- },
1549
- contextInfo: {
1550
- ...forward,
1551
- ...qObj,
1552
- ...this._contextInfo,
1553
- },
1554
- },
1555
- },
1556
- },
1557
- };
1558
- }
1559
-
1560
- async send(jid, { forwarded, notification, includesUnifiedResponse, includesSubmessages, ...options } = {}) {
1561
- const msg = await this.build({ forwarded, notification, includesUnifiedResponse, includesSubmessages, ...options });
1562
-
1563
- if (!this.#client?.relayMessage) throw new TypeError('A connected socket is required to send');
1564
- return await this.#client.relayMessage(jid, msg, { ...options });
1565
- }
1566
-
1567
- static tokenizer(code, lang = 'javascript') {
1568
- const keywordsMap = {
1569
- javascript: new Set([
1570
- 'break',
1571
- 'case',
1572
- 'catch',
1573
- 'continue',
1574
- 'debugger',
1575
- 'delete',
1576
- 'do',
1577
- 'else',
1578
- 'finally',
1579
- 'for',
1580
- 'function',
1581
- 'if',
1582
- 'in',
1583
- 'instanceof',
1584
- 'new',
1585
- 'return',
1586
- 'switch',
1587
- 'this',
1588
- 'throw',
1589
- 'try',
1590
- 'typeof',
1591
- 'var',
1592
- 'void',
1593
- 'while',
1594
- 'with',
1595
- 'true',
1596
- 'false',
1597
- 'null',
1598
- 'undefined',
1599
- 'class',
1600
- 'const',
1601
- 'let',
1602
- 'super',
1603
- 'extends',
1604
- 'export',
1605
- 'import',
1606
- 'yield',
1607
- 'static',
1608
- 'constructor',
1609
- 'async',
1610
- 'await',
1611
- 'get',
1612
- 'set',
1613
- ]),
1614
-
1615
- typescript: new Set([
1616
- 'abstract',
1617
- 'any',
1618
- 'as',
1619
- 'asserts',
1620
- 'bigint',
1621
- 'boolean',
1622
- 'declare',
1623
- 'enum',
1624
- 'implements',
1625
- 'infer',
1626
- 'interface',
1627
- 'is',
1628
- 'keyof',
1629
- 'module',
1630
- 'namespace',
1631
- 'never',
1632
- 'readonly',
1633
- 'require',
1634
- 'number',
1635
- 'object',
1636
- 'override',
1637
- 'private',
1638
- 'protected',
1639
- 'public',
1640
- 'satisfies',
1641
- 'string',
1642
- 'symbol',
1643
- 'type',
1644
- 'unknown',
1645
- 'using',
1646
- 'from',
1647
- 'break',
1648
- 'case',
1649
- 'catch',
1650
- 'continue',
1651
- 'do',
1652
- 'else',
1653
- 'finally',
1654
- 'for',
1655
- 'function',
1656
- 'if',
1657
- 'new',
1658
- 'return',
1659
- 'switch',
1660
- 'this',
1661
- 'throw',
1662
- 'try',
1663
- 'var',
1664
- 'void',
1665
- 'while',
1666
- 'class',
1667
- 'const',
1668
- 'let',
1669
- 'extends',
1670
- 'import',
1671
- 'export',
1672
- 'async',
1673
- 'await',
1674
- ]),
1675
-
1676
- python: new Set([
1677
- 'False',
1678
- 'None',
1679
- 'True',
1680
- 'and',
1681
- 'as',
1682
- 'assert',
1683
- 'async',
1684
- 'await',
1685
- 'break',
1686
- 'class',
1687
- 'continue',
1688
- 'def',
1689
- 'del',
1690
- 'elif',
1691
- 'else',
1692
- 'except',
1693
- 'finally',
1694
- 'for',
1695
- 'from',
1696
- 'global',
1697
- 'if',
1698
- 'import',
1699
- 'in',
1700
- 'is',
1701
- 'lambda',
1702
- 'nonlocal',
1703
- 'not',
1704
- 'or',
1705
- 'pass',
1706
- 'raise',
1707
- 'return',
1708
- 'try',
1709
- 'while',
1710
- 'with',
1711
- 'yield',
1712
- ]),
1713
-
1714
- java: new Set([
1715
- 'abstract',
1716
- 'assert',
1717
- 'boolean',
1718
- 'break',
1719
- 'byte',
1720
- 'case',
1721
- 'catch',
1722
- 'char',
1723
- 'class',
1724
- 'const',
1725
- 'continue',
1726
- 'default',
1727
- 'do',
1728
- 'double',
1729
- 'else',
1730
- 'enum',
1731
- 'extends',
1732
- 'final',
1733
- 'finally',
1734
- 'float',
1735
- 'for',
1736
- 'goto',
1737
- 'if',
1738
- 'implements',
1739
- 'import',
1740
- 'instanceof',
1741
- 'int',
1742
- 'interface',
1743
- 'long',
1744
- 'native',
1745
- 'new',
1746
- 'package',
1747
- 'private',
1748
- 'protected',
1749
- 'public',
1750
- 'return',
1751
- 'short',
1752
- 'static',
1753
- 'strictfp',
1754
- 'super',
1755
- 'switch',
1756
- 'synchronized',
1757
- 'this',
1758
- 'throw',
1759
- 'throws',
1760
- 'transient',
1761
- 'try',
1762
- 'void',
1763
- 'volatile',
1764
- 'while',
1765
- ]),
1766
-
1767
- golang: new Set([
1768
- 'break',
1769
- 'case',
1770
- 'chan',
1771
- 'const',
1772
- 'continue',
1773
- 'default',
1774
- 'defer',
1775
- 'else',
1776
- 'fallthrough',
1777
- 'for',
1778
- 'func',
1779
- 'go',
1780
- 'goto',
1781
- 'if',
1782
- 'import',
1783
- 'interface',
1784
- 'map',
1785
- 'package',
1786
- 'range',
1787
- 'return',
1788
- 'select',
1789
- 'struct',
1790
- 'switch',
1791
- 'type',
1792
- 'var',
1793
- ]),
1794
-
1795
- c: new Set([
1796
- 'auto',
1797
- 'break',
1798
- 'case',
1799
- 'char',
1800
- 'const',
1801
- 'continue',
1802
- 'default',
1803
- 'do',
1804
- 'double',
1805
- 'else',
1806
- 'enum',
1807
- 'extern',
1808
- 'float',
1809
- 'for',
1810
- 'goto',
1811
- 'if',
1812
- 'int',
1813
- 'long',
1814
- 'register',
1815
- 'return',
1816
- 'short',
1817
- 'signed',
1818
- 'sizeof',
1819
- 'static',
1820
- 'struct',
1821
- 'switch',
1822
- 'typedef',
1823
- 'union',
1824
- 'unsigned',
1825
- 'void',
1826
- 'volatile',
1827
- 'while',
1828
- ]),
1829
-
1830
- cpp: new Set([
1831
- 'alignas',
1832
- 'alignof',
1833
- 'and',
1834
- 'auto',
1835
- 'bool',
1836
- 'break',
1837
- 'case',
1838
- 'catch',
1839
- 'class',
1840
- 'const',
1841
- 'constexpr',
1842
- 'continue',
1843
- 'delete',
1844
- 'do',
1845
- 'double',
1846
- 'else',
1847
- 'enum',
1848
- 'explicit',
1849
- 'export',
1850
- 'extern',
1851
- 'false',
1852
- 'float',
1853
- 'for',
1854
- 'friend',
1855
- 'if',
1856
- 'inline',
1857
- 'int',
1858
- 'long',
1859
- 'mutable',
1860
- 'namespace',
1861
- 'new',
1862
- 'noexcept',
1863
- 'nullptr',
1864
- 'operator',
1865
- 'private',
1866
- 'protected',
1867
- 'public',
1868
- 'return',
1869
- 'short',
1870
- 'signed',
1871
- 'sizeof',
1872
- 'static',
1873
- 'struct',
1874
- 'switch',
1875
- 'template',
1876
- 'this',
1877
- 'throw',
1878
- 'true',
1879
- 'try',
1880
- 'typedef',
1881
- 'typename',
1882
- 'union',
1883
- 'unsigned',
1884
- 'using',
1885
- 'virtual',
1886
- 'void',
1887
- 'while',
1888
- ]),
1889
-
1890
- php: new Set([
1891
- 'abstract',
1892
- 'and',
1893
- 'array',
1894
- 'as',
1895
- 'break',
1896
- 'callable',
1897
- 'case',
1898
- 'catch',
1899
- 'class',
1900
- 'clone',
1901
- 'const',
1902
- 'continue',
1903
- 'declare',
1904
- 'default',
1905
- 'do',
1906
- 'echo',
1907
- 'else',
1908
- 'elseif',
1909
- 'empty',
1910
- 'enddeclare',
1911
- 'endfor',
1912
- 'endforeach',
1913
- 'endif',
1914
- 'endswitch',
1915
- 'endwhile',
1916
- 'extends',
1917
- 'final',
1918
- 'finally',
1919
- 'fn',
1920
- 'for',
1921
- 'foreach',
1922
- 'function',
1923
- 'global',
1924
- 'goto',
1925
- 'if',
1926
- 'implements',
1927
- 'include',
1928
- 'include_once',
1929
- 'instanceof',
1930
- 'interface',
1931
- 'match',
1932
- 'namespace',
1933
- 'new',
1934
- 'null',
1935
- 'or',
1936
- 'private',
1937
- 'protected',
1938
- 'public',
1939
- 'require',
1940
- 'require_once',
1941
- 'return',
1942
- 'static',
1943
- 'switch',
1944
- 'throw',
1945
- 'trait',
1946
- 'try',
1947
- 'use',
1948
- 'var',
1949
- 'while',
1950
- 'yield',
1951
- ]),
1952
-
1953
- rust: new Set([
1954
- 'as',
1955
- 'break',
1956
- 'const',
1957
- 'continue',
1958
- 'crate',
1959
- 'else',
1960
- 'enum',
1961
- 'extern',
1962
- 'false',
1963
- 'fn',
1964
- 'for',
1965
- 'if',
1966
- 'impl',
1967
- 'in',
1968
- 'let',
1969
- 'loop',
1970
- 'match',
1971
- 'mod',
1972
- 'move',
1973
- 'mut',
1974
- 'pub',
1975
- 'ref',
1976
- 'return',
1977
- 'self',
1978
- 'Self',
1979
- 'static',
1980
- 'struct',
1981
- 'super',
1982
- 'trait',
1983
- 'true',
1984
- 'type',
1985
- 'unsafe',
1986
- 'use',
1987
- 'where',
1988
- 'while',
1989
- ]),
1990
-
1991
- html: new Set([
1992
- 'html',
1993
- 'head',
1994
- 'body',
1995
- 'div',
1996
- 'span',
1997
- 'p',
1998
- 'a',
1999
- 'img',
2000
- 'video',
2001
- 'audio',
2002
- 'script',
2003
- 'style',
2004
- 'link',
2005
- 'meta',
2006
- 'form',
2007
- 'input',
2008
- 'button',
2009
- 'table',
2010
- 'tr',
2011
- 'td',
2012
- 'th',
2013
- 'ul',
2014
- 'ol',
2015
- 'li',
2016
- 'section',
2017
- 'article',
2018
- 'header',
2019
- 'footer',
2020
- 'nav',
2021
- 'main',
2022
- ]),
2023
-
2024
- bash: new Set([
2025
- 'if',
2026
- 'then',
2027
- 'else',
2028
- 'elif',
2029
- 'fi',
2030
- 'for',
2031
- 'while',
2032
- 'do',
2033
- 'done',
2034
- 'case',
2035
- 'esac',
2036
- 'function',
2037
- 'in',
2038
- 'select',
2039
- 'until',
2040
- 'break',
2041
- 'continue',
2042
- 'return',
2043
- 'export',
2044
- 'readonly',
2045
- 'local',
2046
- 'declare',
2047
- ]),
2048
-
2049
- markdown: new Set(['#', '##', '###', '####', '#####', '######']),
2050
- };
2051
-
2052
- if (!lang || lang === 'txt' || lang === 'text' || lang === 'plaintext') {
2053
- return {
2054
- codeBlock: [
2055
- {
2056
- codeContent: code,
2057
- highlightType: 0,
2058
- },
2059
- ],
2060
- unified_codeBlock: [
2061
- {
2062
- content: code,
2063
- type: 'DEFAULT',
2064
- },
2065
- ],
2066
- };
2067
- }
2068
-
2069
- const TYPE_MAP = {
2070
- 0: 'DEFAULT',
2071
- 1: 'KEYWORD',
2072
- 2: 'METHOD',
2073
- 3: 'STR',
2074
- 4: 'NUMBER',
2075
- 5: 'COMMENT',
2076
- };
2077
-
2078
- const keywords = keywordsMap[lang.toLowerCase()] || new Set();
2079
- const tokens = [];
2080
-
2081
- let i = 0;
2082
-
2083
- const push = (content, type) => {
2084
- if (!content) return;
2085
-
2086
- const last = tokens[tokens.length - 1];
2087
-
2088
- if (last && last.highlightType === type) {
2089
- last.codeContent += content;
2090
- } else {
2091
- tokens.push({
2092
- codeContent: content,
2093
- highlightType: type,
2094
- });
2095
- }
2096
- };
2097
-
2098
- const isIdentifier = (char) => {
2099
- switch (lang.toLowerCase()) {
2100
- case 'css':
2101
- return /[a-zA-Z0-9_$-]/.test(char);
2102
-
2103
- case 'html':
2104
- return /[a-zA-Z0-9_$:-]/.test(char);
2105
-
2106
- default:
2107
- return /[a-zA-Z0-9_$]/.test(char);
2108
- }
2109
- };
2110
-
2111
- while (i < code.length) {
2112
- const c = code[i];
2113
-
2114
- if (/\s/.test(c)) {
2115
- let s = i;
2116
-
2117
- while (i < code.length && /\s/.test(code[i])) {
2118
- i++;
2119
- }
2120
-
2121
- push(code.slice(s, i), 0);
2122
- continue;
2123
- }
2124
-
2125
- if ((c === '/' && code[i + 1] === '/') || (c === '#' && ['python', 'bash'].includes(lang))) {
2126
- let s = i;
2127
-
2128
- while (i < code.length && code[i] !== '\n') {
2129
- i++;
2130
- }
2131
-
2132
- push(code.slice(s, i), 5);
2133
- continue;
2134
- }
2135
-
2136
- if (c === '"' || c === "'" || c === '`') {
2137
- let s = i;
2138
- const q = c;
2139
-
2140
- i++;
2141
-
2142
- while (i < code.length) {
2143
- if (code[i] === '\\' && i + 1 < code.length) {
2144
- i += 2;
2145
- } else if (code[i] === q) {
2146
- i++;
2147
- break;
2148
- } else {
2149
- i++;
2150
- }
2151
- }
2152
-
2153
- push(code.slice(s, i), 3);
2154
- continue;
2155
- }
2156
-
2157
- if (/[0-9]/.test(c)) {
2158
- let s = i;
2159
-
2160
- while (i < code.length && /[0-9._]/.test(code[i])) {
2161
- i++;
2162
- }
2163
-
2164
- push(code.slice(s, i), 4);
2165
- continue;
2166
- }
2167
-
2168
- if (/[a-zA-Z_$]/.test(c)) {
2169
- let s = i;
2170
-
2171
- while (i < code.length && isIdentifier(code[i])) {
2172
- i++;
2173
- }
2174
-
2175
- const word = code.slice(s, i);
2176
-
2177
- let type = 0;
2178
-
2179
- if (keywords.has(word)) {
2180
- type = 1;
2181
- } else if (lang === 'css') {
2182
- let j = i;
2183
-
2184
- while (j < code.length && /\s/.test(code[j])) {
2185
- j++;
2186
- }
2187
-
2188
- if (code[j] === ':') {
2189
- type = 1;
2190
- }
2191
- } else if (lang === 'html') {
2192
- let p = s - 1;
2193
-
2194
- while (p >= 0 && /\s/.test(code[p])) {
2195
- p--;
2196
- }
2197
-
2198
- if (code[p] === '<' || (code[p] === '/' && code[p - 1] === '<')) {
2199
- type = 1;
2200
- }
2201
- }
2202
-
2203
- if (type === 0) {
2204
- let j = i;
2205
-
2206
- while (j < code.length && /\s/.test(code[j])) {
2207
- j++;
2208
- }
2209
-
2210
- if (code[j] === '(') {
2211
- type = 2;
2212
- }
2213
- }
2214
-
2215
- push(word, type);
2216
- continue;
2217
- }
2218
-
2219
- push(c, 0);
2220
- i++;
2221
- }
2222
-
2223
- return {
2224
- codeBlock: tokens,
2225
- unified_codeBlock: tokens.map((t) => ({
2226
- content: t.codeContent,
2227
- type: TYPE_MAP[t.highlightType],
2228
- })),
2229
- };
2230
- }
2231
-
2232
- static toTableMetadata(arr, { hyperlink = true, citation = true, latex = true } = {}) {
2233
- if (!Array.isArray(arr) || !arr.every((row) => Array.isArray(row) && row.every((cell) => typeof cell === 'string'))) {
2234
- throw new TypeError('Table must be a nested array of strings');
2235
- }
2236
-
2237
- const [header, ...rows] = arr;
2238
-
2239
- const maxLen = Math.max(header.length, ...rows.map((r) => r.length));
2240
-
2241
- const normalize = (r) => [...r, ...Array(maxLen - r.length).fill('')];
2242
-
2243
- const unified_rows = [
2244
- {
2245
- is_header: true,
2246
- cells: normalize(header),
2247
- },
2248
- ...rows.map((r) => ({
2249
- is_header: false,
2250
- cells: normalize(r),
2251
- })),
2252
- ].map((row) => {
2253
- const markdown_cells = row.cells.map((cell) => {
2254
- const extracted = extractIE(cell, { hyperlink, citation, latex });
2255
-
2256
- return {
2257
- text: extracted.text,
2258
- ...(extracted.inline_entities.length ? { inline_entities: extracted.inline_entities } : {}),
2259
- };
2260
- });
2261
-
2262
- return {
2263
- ...row,
2264
- ...(markdown_cells.some((c) => _optionalChain([c, 'access', _17 => _17.inline_entities, 'optionalAccess', _18 => _18.length])) ? { markdown_cells } : {}),
2265
- };
2266
- });
2267
-
2268
- const rowsMeta = unified_rows.map((r) => ({
2269
- items: r.cells,
2270
- ...(r.is_header ? { isHeading: true } : {}),
2271
- }));
2272
-
2273
- return {
2274
- title: '',
2275
- rows: rowsMeta,
2276
- unified_rows,
2277
- };
2278
- }
2279
-
2280
- static newLayout(name, data, extra = {}) {
2281
- return {
2282
- ...extra,
2283
- view_model: {
2284
- [Array.isArray(data) ? 'primitives' : 'primitive']: data,
2285
- __typename: `GenAI${name}LayoutViewModel`,
2286
- },
2287
- };
2288
- }
2289
- text(t) { return this.addText(t, this._richTextOptions || {}); }
2290
- extract(enabled) { this._richTextOptions = {...this._richTextOptions, extract:!!enabled}; return this; }
2291
- hyperlink(enabled) { this._richTextOptions = {...this._richTextOptions, hyperlink:!!enabled}; return this; }
2292
- citation(enabled) { this._richTextOptions = {...this._richTextOptions, citation:!!enabled}; return this; }
2293
- latex(enabled) { this._richTextOptions = {...this._richTextOptions, latex:!!enabled}; return this; }
2294
-
2295
- }
2296
-
2297
- class ORich extends AIRich { }
2298
-
2299
-
2300
-
2301
- exports.VERSION = VERSION; exports.Button = Button; exports.ButtonV2 = ButtonV2; exports.Carousel = Carousel; exports.AIRich = AIRich; exports.ORich = ORich; exports.Toolkit = Toolkit;
2302
-
2303
-
2304
- const __kageModule102 = (() => {
2305
- const module = { exports: {} }; const exports = module.exports;
2306
-
2307
-
2308
-
2309
-
2310
-
2311
-
2312
-
2313
-
2314
-
2315
-
2316
-
2317
-
2318
-
2319
-
2320
-
2321
-
2322
-
2323
-
2324
-
2325
-
2326
-
2327
-
2328
-
2329
-
2330
-
2331
-
2332
-
2333
-
2334
1
  'use strict';
2335
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2336
3
  if (k2 === undefined) k2 = k;
@@ -4361,25 +2028,3 @@ exports.AIRich = AIRich;
4361
2028
  class ORich extends AIRich {
4362
2029
  }
4363
2030
  exports.ORich = ORich;
4364
-
4365
- return module.exports;
4366
- })();
4367
- for (const key of Object.keys(__kageModule102)) {
4368
- if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule102[key]});
4369
- }
4370
-
4371
- /** Bind constructors to one existing socket. No global connection or remote code updates. */
4372
- exports.bind = function bind(socket) {
4373
- if (!socket || typeof socket.relayMessage !== 'function') throw new TypeError('A socket with relayMessage is required');
4374
- const bound = { VERSION:exports.VERSION, Toolkit:exports.Toolkit };
4375
- for (const name of ['Button','ButtonV2','Carousel','AIRich','ORich']) {
4376
- const Base = exports[name];
4377
- bound[name] = class extends Base { constructor(...args) { super(socket, ...args); } };
4378
- }
4379
- return Object.freeze(bound);
4380
- };
4381
- exports.MessageBuilder = Object.freeze({VERSION:exports.VERSION,Button:exports.Button,ButtonV2:exports.ButtonV2,Carousel:exports.Carousel,AIRich:exports.AIRich,ORich:exports.ORich,Toolkit:exports.Toolkit,bind:exports.bind});
4382
-
4383
- const NativeMessageBuilder = require('../Utils/message-builder').MessageBuilder;
4384
- Object.assign(NativeMessageBuilder, exports.MessageBuilder);
4385
- exports.MessageBuilder = NativeMessageBuilder;