@japofc/baileys 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/NOTICE.md +111 -0
  2. package/README.md +1254 -0
  3. package/WAProto/index.d.ts +9 -0
  4. package/WAProto/index.js +142276 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Builders/A2UI.d.ts +242 -0
  7. package/lib/Builders/A2UI.js +308 -0
  8. package/lib/Builders/AIRich.d.ts +105 -0
  9. package/lib/Builders/AIRich.js +2286 -0
  10. package/lib/Builders/Button.d.ts +103 -0
  11. package/lib/Builders/Button.js +883 -0
  12. package/lib/Builders/ButtonV2.d.ts +28 -0
  13. package/lib/Builders/ButtonV2.js +144 -0
  14. package/lib/Builders/ButtonV3.d.ts +25 -0
  15. package/lib/Builders/ButtonV3.js +184 -0
  16. package/lib/Builders/Carousel.d.ts +22 -0
  17. package/lib/Builders/Carousel.js +111 -0
  18. package/lib/Builders/JapBaileys.d.ts +34 -0
  19. package/lib/Builders/JapBaileys.js +108 -0
  20. package/lib/Builders/Poll.d.ts +25 -0
  21. package/lib/Builders/Poll.js +128 -0
  22. package/lib/Builders/index.d.ts +17 -0
  23. package/lib/Builders/index.js +11 -0
  24. package/lib/Builders/shared.d.ts +67 -0
  25. package/lib/Builders/shared.js +652 -0
  26. package/lib/Defaults/index.d.ts +154 -0
  27. package/lib/Defaults/index.js +178 -0
  28. package/lib/Framework/Bot.d.ts +61 -0
  29. package/lib/Framework/Bot.js +248 -0
  30. package/lib/Framework/Context.d.ts +21 -0
  31. package/lib/Framework/Context.js +89 -0
  32. package/lib/Framework/MediaManager.d.ts +17 -0
  33. package/lib/Framework/MediaManager.js +151 -0
  34. package/lib/Framework/SessionManager.d.ts +13 -0
  35. package/lib/Framework/SessionManager.js +33 -0
  36. package/lib/Framework/StatsManager.d.ts +26 -0
  37. package/lib/Framework/StatsManager.js +119 -0
  38. package/lib/Framework/Store/SQLiteStore.d.ts +11 -0
  39. package/lib/Framework/Store/SQLiteStore.js +73 -0
  40. package/lib/Framework/index.d.ts +9 -0
  41. package/lib/Framework/index.js +10 -0
  42. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  43. package/lib/Signal/Group/ciphertext-message.js +11 -0
  44. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  45. package/lib/Signal/Group/group-session-builder.js +29 -0
  46. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  47. package/lib/Signal/Group/group_cipher.js +81 -0
  48. package/lib/Signal/Group/index.d.ts +11 -0
  49. package/lib/Signal/Group/index.js +11 -0
  50. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  51. package/lib/Signal/Group/keyhelper.js +17 -0
  52. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  53. package/lib/Signal/Group/sender-chain-key.js +25 -0
  54. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  55. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  56. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  57. package/lib/Signal/Group/sender-key-message.js +65 -0
  58. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  59. package/lib/Signal/Group/sender-key-name.js +47 -0
  60. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  61. package/lib/Signal/Group/sender-key-record.js +40 -0
  62. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  63. package/lib/Signal/Group/sender-key-state.js +83 -0
  64. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  65. package/lib/Signal/Group/sender-message-key.js +25 -0
  66. package/lib/Signal/libsignal.d.ts +54 -0
  67. package/lib/Signal/libsignal.js +430 -0
  68. package/lib/Signal/lid-mapping.d.ts +20 -0
  69. package/lib/Signal/lid-mapping.js +276 -0
  70. package/lib/Socket/Client/index.d.ts +2 -0
  71. package/lib/Socket/Client/index.js +2 -0
  72. package/lib/Socket/Client/types.d.ts +5 -0
  73. package/lib/Socket/Client/types.js +10 -0
  74. package/lib/Socket/Client/websocket.d.ts +12 -0
  75. package/lib/Socket/Client/websocket.js +53 -0
  76. package/lib/Socket/business.d.ts +395 -0
  77. package/lib/Socket/business.js +379 -0
  78. package/lib/Socket/chats.d.ts +136 -0
  79. package/lib/Socket/chats.js +1327 -0
  80. package/lib/Socket/communities.d.ts +562 -0
  81. package/lib/Socket/communities.js +439 -0
  82. package/lib/Socket/dugong.d.ts +117 -0
  83. package/lib/Socket/dugong.js +798 -0
  84. package/lib/Socket/groups.d.ts +285 -0
  85. package/lib/Socket/groups.js +354 -0
  86. package/lib/Socket/index.d.ts +585 -0
  87. package/lib/Socket/index.js +52 -0
  88. package/lib/Socket/messages-recv.d.ts +333 -0
  89. package/lib/Socket/messages-recv.js +1781 -0
  90. package/lib/Socket/messages-send.d.ts +353 -0
  91. package/lib/Socket/messages-send.js +1524 -0
  92. package/lib/Socket/mex.d.ts +1 -0
  93. package/lib/Socket/mex.js +41 -0
  94. package/lib/Socket/newsletter.d.ts +286 -0
  95. package/lib/Socket/newsletter.js +364 -0
  96. package/lib/Socket/socket.d.ts +60 -0
  97. package/lib/Socket/socket.js +1012 -0
  98. package/lib/Socket/username.d.ts +82 -0
  99. package/lib/Socket/username.js +159 -0
  100. package/lib/Store/index.d.ts +3 -0
  101. package/lib/Store/index.js +3 -0
  102. package/lib/Store/make-in-memory-store.d.ts +62 -0
  103. package/lib/Store/make-in-memory-store.js +428 -0
  104. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  105. package/lib/Store/make-ordered-dictionary.js +78 -0
  106. package/lib/Store/object-repository.d.ts +10 -0
  107. package/lib/Store/object-repository.js +23 -0
  108. package/lib/Types/Auth.d.ts +117 -0
  109. package/lib/Types/Auth.js +1 -0
  110. package/lib/Types/Bussines.d.ts +25 -0
  111. package/lib/Types/Call.d.ts +15 -0
  112. package/lib/Types/Call.js +1 -0
  113. package/lib/Types/Chat.d.ts +124 -0
  114. package/lib/Types/Chat.js +7 -0
  115. package/lib/Types/Contact.d.ts +26 -0
  116. package/lib/Types/Contact.js +1 -0
  117. package/lib/Types/Events.d.ts +256 -0
  118. package/lib/Types/Events.js +1 -0
  119. package/lib/Types/GroupMetadata.d.ts +71 -0
  120. package/lib/Types/GroupMetadata.js +1 -0
  121. package/lib/Types/Label.d.ts +5 -0
  122. package/lib/Types/Label.js +24 -0
  123. package/lib/Types/LabelAssociation.d.ts +6 -0
  124. package/lib/Types/LabelAssociation.js +6 -0
  125. package/lib/Types/Message.d.ts +62 -0
  126. package/lib/Types/Message.js +17 -0
  127. package/lib/Types/Mex.d.ts +2 -0
  128. package/lib/Types/Mex.js +38 -0
  129. package/lib/Types/Product.d.ts +79 -0
  130. package/lib/Types/Product.js +1 -0
  131. package/lib/Types/RichType.d.ts +2 -0
  132. package/lib/Types/RichType.js +22 -0
  133. package/lib/Types/Signal.d.ts +87 -0
  134. package/lib/Types/Signal.js +1 -0
  135. package/lib/Types/Socket.d.ts +138 -0
  136. package/lib/Types/Socket.js +1 -0
  137. package/lib/Types/State.d.ts +8 -0
  138. package/lib/Types/State.js +55 -0
  139. package/lib/Types/USync.d.ts +26 -0
  140. package/lib/Types/index.d.ts +68 -0
  141. package/lib/Types/index.js +27 -0
  142. package/lib/Utils/MessageBuilder.d.ts +2 -0
  143. package/lib/Utils/MessageBuilder.js +2 -0
  144. package/lib/Utils/PersistentStore.d.ts +60 -0
  145. package/lib/Utils/PersistentStore.js +592 -0
  146. package/lib/Utils/anti-delete.d.ts +74 -0
  147. package/lib/Utils/anti-delete.js +221 -0
  148. package/lib/Utils/auth-secure.d.ts +86 -0
  149. package/lib/Utils/auth-secure.js +764 -0
  150. package/lib/Utils/auth-utils.d.ts +57 -0
  151. package/lib/Utils/auth-utils.js +306 -0
  152. package/lib/Utils/auto-reply.d.ts +47 -0
  153. package/lib/Utils/auto-reply.js +157 -0
  154. package/lib/Utils/baileys-event-stream.d.ts +8 -0
  155. package/lib/Utils/baileys-event-stream.js +62 -0
  156. package/lib/Utils/browser-utils.d.ts +8 -0
  157. package/lib/Utils/browser-utils.js +27 -0
  158. package/lib/Utils/business.d.ts +49 -0
  159. package/lib/Utils/business.js +239 -0
  160. package/lib/Utils/button-helper-utils.d.ts +53 -0
  161. package/lib/Utils/button-helper-utils.js +312 -0
  162. package/lib/Utils/button-sender.d.ts +54 -0
  163. package/lib/Utils/button-sender.js +822 -0
  164. package/lib/Utils/chat-control.d.ts +159 -0
  165. package/lib/Utils/chat-control.js +230 -0
  166. package/lib/Utils/chat-history-helpers.d.ts +21 -0
  167. package/lib/Utils/chat-history-helpers.js +70 -0
  168. package/lib/Utils/chat-utils.d.ts +407 -0
  169. package/lib/Utils/chat-utils.js +885 -0
  170. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  171. package/lib/Utils/companion-reg-client-utils.js +39 -0
  172. package/lib/Utils/crypto.d.ts +41 -0
  173. package/lib/Utils/crypto.js +147 -0
  174. package/lib/Utils/decode-wa-message.d.ts +83 -0
  175. package/lib/Utils/decode-wa-message.js +316 -0
  176. package/lib/Utils/event-buffer.d.ts +12 -0
  177. package/lib/Utils/event-buffer.js +635 -0
  178. package/lib/Utils/generics.d.ts +69 -0
  179. package/lib/Utils/generics.js +438 -0
  180. package/lib/Utils/history-share.d.ts +11 -0
  181. package/lib/Utils/history-share.js +70 -0
  182. package/lib/Utils/history.d.ts +90 -0
  183. package/lib/Utils/history.js +146 -0
  184. package/lib/Utils/humanizer.d.ts +12 -0
  185. package/lib/Utils/humanizer.js +73 -0
  186. package/lib/Utils/identity-change-handler.d.ts +13 -0
  187. package/lib/Utils/identity-change-handler.js +49 -0
  188. package/lib/Utils/index.d.ts +57 -0
  189. package/lib/Utils/index.js +56 -0
  190. package/lib/Utils/jid-tools.d.ts +6 -0
  191. package/lib/Utils/jid-tools.js +77 -0
  192. package/lib/Utils/link-preview.d.ts +12 -0
  193. package/lib/Utils/link-preview.js +84 -0
  194. package/lib/Utils/logger.d.ts +4 -0
  195. package/lib/Utils/logger.js +2 -0
  196. package/lib/Utils/lt-hash.d.ts +12 -0
  197. package/lib/Utils/lt-hash.js +26 -0
  198. package/lib/Utils/make-mutex.d.ts +6 -0
  199. package/lib/Utils/make-mutex.js +32 -0
  200. package/lib/Utils/media-messages.d.ts +18 -0
  201. package/lib/Utils/media-messages.js +70 -0
  202. package/lib/Utils/media-set.d.ts +13 -0
  203. package/lib/Utils/media-set.js +171 -0
  204. package/lib/Utils/message-kind.d.ts +32 -0
  205. package/lib/Utils/message-kind.js +136 -0
  206. package/lib/Utils/message-retry-manager.d.ts +79 -0
  207. package/lib/Utils/message-retry-manager.js +264 -0
  208. package/lib/Utils/message-search.d.ts +44 -0
  209. package/lib/Utils/message-search.js +188 -0
  210. package/lib/Utils/messages-media.d.ts +135 -0
  211. package/lib/Utils/messages-media.js +868 -0
  212. package/lib/Utils/messages.d.ts +44 -0
  213. package/lib/Utils/messages.js +2326 -0
  214. package/lib/Utils/meta-ai.d.ts +13 -0
  215. package/lib/Utils/meta-ai.js +74 -0
  216. package/lib/Utils/mini-app.d.ts +35 -0
  217. package/lib/Utils/mini-app.js +213 -0
  218. package/lib/Utils/noise-handler.d.ts +20 -0
  219. package/lib/Utils/noise-handler.js +200 -0
  220. package/lib/Utils/offline-node-processor.d.ts +9 -0
  221. package/lib/Utils/offline-node-processor.js +39 -0
  222. package/lib/Utils/past-participants.d.ts +14 -0
  223. package/lib/Utils/past-participants.js +40 -0
  224. package/lib/Utils/pre-key-manager.d.ts +25 -0
  225. package/lib/Utils/pre-key-manager.js +105 -0
  226. package/lib/Utils/process-message.d.ts +82 -0
  227. package/lib/Utils/process-message.js +808 -0
  228. package/lib/Utils/qr-render.d.ts +59 -0
  229. package/lib/Utils/qr-render.js +179 -0
  230. package/lib/Utils/qrcodegen.d.ts +79 -0
  231. package/lib/Utils/qrcodegen.js +848 -0
  232. package/lib/Utils/reporting-utils.d.ts +12 -0
  233. package/lib/Utils/reporting-utils.js +257 -0
  234. package/lib/Utils/rich-message-utils.d.ts +48 -0
  235. package/lib/Utils/rich-message-utils.js +444 -0
  236. package/lib/Utils/router.d.ts +37 -0
  237. package/lib/Utils/router.js +165 -0
  238. package/lib/Utils/scheduled-posts.d.ts +30 -0
  239. package/lib/Utils/scheduled-posts.js +110 -0
  240. package/lib/Utils/scheduling.d.ts +42 -0
  241. package/lib/Utils/scheduling.js +139 -0
  242. package/lib/Utils/signal.d.ts +82 -0
  243. package/lib/Utils/signal.js +200 -0
  244. package/lib/Utils/stanza-ack.d.ts +16 -0
  245. package/lib/Utils/stanza-ack.js +37 -0
  246. package/lib/Utils/status.d.ts +50 -0
  247. package/lib/Utils/status.js +107 -0
  248. package/lib/Utils/stickerpack.d.ts +51 -0
  249. package/lib/Utils/stickerpack.js +274 -0
  250. package/lib/Utils/sync-action-utils.d.ts +2 -0
  251. package/lib/Utils/sync-action-utils.js +48 -0
  252. package/lib/Utils/tag.d.ts +12 -0
  253. package/lib/Utils/tag.js +44 -0
  254. package/lib/Utils/tc-token-utils.d.ts +29 -0
  255. package/lib/Utils/tc-token-utils.js +162 -0
  256. package/lib/Utils/templates.d.ts +76 -0
  257. package/lib/Utils/templates.js +150 -0
  258. package/lib/Utils/transcribe.d.ts +12 -0
  259. package/lib/Utils/transcribe.js +107 -0
  260. package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
  261. package/lib/Utils/use-cache-manager-auth-state.js +81 -0
  262. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  263. package/lib/Utils/use-multi-file-auth-state.js +166 -0
  264. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  265. package/lib/Utils/use-single-file-auth-state.js +113 -0
  266. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  267. package/lib/Utils/use-sqlite-auth-state.js +169 -0
  268. package/lib/Utils/validate-connection.d.ts +42 -0
  269. package/lib/Utils/validate-connection.js +198 -0
  270. package/lib/Utils/vcard.d.ts +58 -0
  271. package/lib/Utils/vcard.js +104 -0
  272. package/lib/Utils/voice-note.d.ts +15 -0
  273. package/lib/Utils/voice-note.js +63 -0
  274. package/lib/VoIP/audio-feeder.d.ts +18 -0
  275. package/lib/VoIP/audio-feeder.js +160 -0
  276. package/lib/VoIP/call-recorder.d.ts +13 -0
  277. package/lib/VoIP/call-recorder.js +73 -0
  278. package/lib/VoIP/index.d.ts +86 -0
  279. package/lib/VoIP/index.js +611 -0
  280. package/lib/VoIP/relay-transport.d.ts +43 -0
  281. package/lib/VoIP/relay-transport.js +563 -0
  282. package/lib/VoIP/signaling.d.ts +26 -0
  283. package/lib/VoIP/signaling.js +662 -0
  284. package/lib/VoIP/types.d.ts +69 -0
  285. package/lib/VoIP/types.js +17 -0
  286. package/lib/VoIP/wasm-engine.d.ts +120 -0
  287. package/lib/VoIP/wasm-engine.js +1358 -0
  288. package/lib/VoIP/worker-bootstrap.d.ts +4 -0
  289. package/lib/VoIP/worker-bootstrap.js +1046 -0
  290. package/lib/WABinary/constants.d.ts +61 -0
  291. package/lib/WABinary/constants.js +1466 -0
  292. package/lib/WABinary/decode.d.ts +9 -0
  293. package/lib/WABinary/decode.js +261 -0
  294. package/lib/WABinary/encode.d.ts +2 -0
  295. package/lib/WABinary/encode.js +219 -0
  296. package/lib/WABinary/generic-utils.d.ts +74 -0
  297. package/lib/WABinary/generic-utils.js +276 -0
  298. package/lib/WABinary/index.d.ts +5 -0
  299. package/lib/WABinary/index.js +5 -0
  300. package/lib/WABinary/jid-utils.d.ts +28 -0
  301. package/lib/WABinary/jid-utils.js +95 -0
  302. package/lib/WABinary/types.d.ts +19 -0
  303. package/lib/WABinary/types.js +1 -0
  304. package/lib/WAM/BinaryInfo.d.ts +7 -0
  305. package/lib/WAM/BinaryInfo.js +9 -0
  306. package/lib/WAM/constants.d.ts +34926 -0
  307. package/lib/WAM/constants.js +22852 -0
  308. package/lib/WAM/encode.d.ts +1 -0
  309. package/lib/WAM/encode.js +149 -0
  310. package/lib/WAM/index.d.ts +3 -0
  311. package/lib/WAM/index.js +3 -0
  312. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  313. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  314. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  315. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  316. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  317. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  318. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  319. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  320. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  321. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  322. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  323. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  324. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  325. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  326. package/lib/WAUSync/Protocols/index.d.ts +7 -0
  327. package/lib/WAUSync/Protocols/index.js +7 -0
  328. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  329. package/lib/WAUSync/USyncQuery.js +121 -0
  330. package/lib/WAUSync/USyncUser.d.ts +16 -0
  331. package/lib/WAUSync/USyncUser.js +30 -0
  332. package/lib/WAUSync/index.d.ts +3 -0
  333. package/lib/WAUSync/index.js +3 -0
  334. package/lib/assets/wasm/loader.d.ts +5 -0
  335. package/lib/assets/wasm/loader.js +5 -0
  336. package/lib/assets/wasm/whatsapp.wasm +0 -0
  337. package/lib/assets/wasm/worker-modules.d.ts +5 -0
  338. package/lib/assets/wasm/worker-modules.js +273 -0
  339. package/lib/index.d.ts +18 -0
  340. package/lib/index.js +23 -0
  341. package/package.json +180 -0
  342. package/postinstall-banner.js +82 -0
@@ -0,0 +1,798 @@
1
+ import crypto from "crypto";
2
+ import { proto } from "../../WAProto/index.js";
3
+ import {
4
+ delay,
5
+ generateMessageID,
6
+ generateWAMessage,
7
+ generateWAMessageContent,
8
+ generateWAMessageFromContent,
9
+ getUrlFromDirectPath,
10
+ normalizeMessageContent,
11
+ prepareWAMessageMedia,
12
+ } from "../Utils/index.js";
13
+ import {
14
+ isJidGroup,
15
+ isPnUser,
16
+ jidNormalizedUser,
17
+ STORIES_JID,
18
+ } from "../WABinary/index.js";
19
+ export class Dugong {
20
+ constructor(waUploadToServer, relayMessageFn, config, sock) {
21
+ this.relayMessage = relayMessageFn;
22
+ this.waUploadToServer = waUploadToServer;
23
+ this.config = config;
24
+ this.sock = sock;
25
+ }
26
+ detectType(content) {
27
+ if (content.requestPaymentMessage) return "PAYMENT";
28
+ if (content.productMessage) return "PRODUCT";
29
+ if (content.groupInviteMessage) return "GROUP_INVITE"; // JAP@Fix (bug: field name mismatch — real message content is `groupInviteMessage`, not `groupInvite`, so this never actually matched a received message)
30
+ if (content.interactiveButtons) return "INTERACTIVE_BUTTONS";
31
+ if (content.interactiveMessage?.carouselMessage) return "CAROUSEL";
32
+ if (content.interactiveMessage) return "INTERACTIVE";
33
+ if (content.albumMessage || content.album) return "ALBUM";
34
+ if (content.eventMessage) return "EVENT";
35
+ if (content.pollResultMessage) return "POLL_RESULT";
36
+ if (content.groupStatusMessage) return "GROUP_STORY";
37
+ return null;
38
+ }
39
+ async handlePayment(content, quoted) {
40
+ const data = content.requestPaymentMessage;
41
+ let notes = {};
42
+ if (data.sticker?.stickerMessage) {
43
+ notes = {
44
+ stickerMessage: {
45
+ ...data.sticker.stickerMessage,
46
+ contextInfo: {
47
+ stanzaId: quoted?.key?.id,
48
+ participant: quoted?.key?.participant || content.sender,
49
+ quotedMessage: quoted?.message,
50
+ },
51
+ },
52
+ };
53
+ } else if (data.note) {
54
+ notes = {
55
+ extendedTextMessage: {
56
+ text: data.note,
57
+ contextInfo: {
58
+ stanzaId: quoted?.key?.id,
59
+ participant: quoted?.key?.participant || content.sender,
60
+ quotedMessage: quoted?.message,
61
+ },
62
+ },
63
+ };
64
+ }
65
+ return {
66
+ requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
67
+ expiryTimestamp: data.expiry || 0,
68
+ amount1000: data.amount || 0,
69
+ currencyCodeIso4217: data.currency || "IDR",
70
+ requestFrom: data.from || "0@s.whatsapp.net",
71
+ noteMessage: notes,
72
+ background: data.background ?? {
73
+ id: "DEFAULT",
74
+ placeholderArgb: 0xfff0f0f0,
75
+ },
76
+ }),
77
+ };
78
+ }
79
+ async handleProduct(content, _jid, _quoted) {
80
+ const {
81
+ title,
82
+ description,
83
+ thumbnail,
84
+ productId,
85
+ retailerId,
86
+ url,
87
+ body = "",
88
+ footer = "",
89
+ buttons = [],
90
+ priceAmount1000 = null,
91
+ currencyCode = "IDR",
92
+ } = content.productMessage;
93
+ let productImage;
94
+ if (Buffer.isBuffer(thumbnail)) {
95
+ const { imageMessage } = await generateWAMessageContent(
96
+ { image: thumbnail },
97
+ { upload: this.waUploadToServer },
98
+ );
99
+ productImage = imageMessage;
100
+ } else if (typeof thumbnail === "object" && thumbnail.url) {
101
+ const { imageMessage } = await generateWAMessageContent(
102
+ { image: { url: thumbnail.url } },
103
+ { upload: this.waUploadToServer },
104
+ );
105
+ productImage = imageMessage;
106
+ }
107
+ return {
108
+ viewOnceMessage: {
109
+ message: {
110
+ interactiveMessage: {
111
+ body: { text: body },
112
+ footer: { text: footer },
113
+ header: {
114
+ title,
115
+ hasMediaAttachment: true,
116
+ productMessage: {
117
+ product: {
118
+ productImage,
119
+ productId,
120
+ title,
121
+ description,
122
+ currencyCode,
123
+ priceAmount1000,
124
+ retailerId,
125
+ url,
126
+ productImageCount: 1,
127
+ },
128
+ businessOwnerJid: "0@s.whatsapp.net",
129
+ },
130
+ },
131
+ nativeFlowMessage: { buttons },
132
+ },
133
+ },
134
+ },
135
+ };
136
+ }
137
+ async handleInteractive(content, _jid, _quoted) {
138
+ const {
139
+ title,
140
+ footer,
141
+ thumbnail,
142
+ image,
143
+ video,
144
+ document,
145
+ mimetype,
146
+ fileName,
147
+ jpegThumbnail,
148
+ contextInfo,
149
+ externalAdReply,
150
+ buttons = [],
151
+ nativeFlowMessage,
152
+ header,
153
+ } = content.interactiveMessage;
154
+ let media = null;
155
+ let _mediaType = null;
156
+ if (thumbnail) {
157
+ media = await prepareWAMessageMedia(
158
+ { image: { url: thumbnail } },
159
+ { upload: this.waUploadToServer },
160
+ );
161
+ _mediaType = "image";
162
+ } else if (image) {
163
+ const src =
164
+ typeof image === "object" && image.url
165
+ ? { image: { url: image.url } }
166
+ : { image };
167
+ media = await prepareWAMessageMedia(src, {
168
+ upload: this.waUploadToServer,
169
+ });
170
+ _mediaType = "image";
171
+ } else if (video) {
172
+ const src =
173
+ typeof video === "object" && video.url
174
+ ? { video: { url: video.url } }
175
+ : { video };
176
+ media = await prepareWAMessageMedia(src, {
177
+ upload: this.waUploadToServer,
178
+ });
179
+ _mediaType = "video";
180
+ } else if (document) {
181
+ const docPayload = { document };
182
+ if (jpegThumbnail) {
183
+ docPayload.jpegThumbnail =
184
+ typeof jpegThumbnail === "object" && jpegThumbnail.url
185
+ ? { url: jpegThumbnail.url }
186
+ : jpegThumbnail;
187
+ }
188
+ media = await prepareWAMessageMedia(docPayload, {
189
+ upload: this.waUploadToServer,
190
+ });
191
+ if (fileName) media.documentMessage.fileName = fileName;
192
+ if (mimetype) media.documentMessage.mimetype = mimetype;
193
+ _mediaType = "document";
194
+ }
195
+ const interactiveMessage = {
196
+ body: { text: title || "" },
197
+ footer: { text: footer || "" },
198
+ };
199
+ if (buttons && buttons.length > 0) {
200
+ interactiveMessage.nativeFlowMessage = { buttons };
201
+ if (nativeFlowMessage) {
202
+ interactiveMessage.nativeFlowMessage = {
203
+ ...interactiveMessage.nativeFlowMessage,
204
+ ...nativeFlowMessage,
205
+ };
206
+ }
207
+ } else if (nativeFlowMessage) {
208
+ interactiveMessage.nativeFlowMessage = nativeFlowMessage;
209
+ }
210
+ if (media) {
211
+ interactiveMessage.header = {
212
+ title: header || "",
213
+ hasMediaAttachment: true,
214
+ ...media,
215
+ };
216
+ } else {
217
+ interactiveMessage.header = {
218
+ title: header || "",
219
+ hasMediaAttachment: false,
220
+ };
221
+ }
222
+ const finalContextInfo = {};
223
+ if (contextInfo) {
224
+ Object.assign(finalContextInfo, {
225
+ mentionedJid: contextInfo.mentionedJid || [],
226
+ forwardingScore: contextInfo.forwardingScore || 0,
227
+ isForwarded: contextInfo.isForwarded || false,
228
+ ...contextInfo,
229
+ });
230
+ }
231
+ if (externalAdReply) {
232
+ finalContextInfo.externalAdReply = {
233
+ title: externalAdReply.title || "",
234
+ body: externalAdReply.body || "",
235
+ mediaType: externalAdReply.mediaType || 1,
236
+ thumbnailUrl: externalAdReply.thumbnailUrl || "",
237
+ mediaUrl: externalAdReply.mediaUrl || "",
238
+ sourceUrl: externalAdReply.sourceUrl || "",
239
+ showAdAttribution: externalAdReply.showAdAttribution || false,
240
+ renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
241
+ ...externalAdReply,
242
+ };
243
+ }
244
+ if (Object.keys(finalContextInfo).length > 0) {
245
+ interactiveMessage.contextInfo = finalContextInfo;
246
+ }
247
+ return { interactiveMessage };
248
+ }
249
+ async handleInteractiveButtons(content, _jid, _quoted) {
250
+ const {
251
+ text,
252
+ caption,
253
+ title,
254
+ subtitle,
255
+ footer,
256
+ interactiveButtons,
257
+ hasMediaAttachment,
258
+ image,
259
+ video,
260
+ document,
261
+ mimetype,
262
+ jpegThumbnail,
263
+ location,
264
+ product,
265
+ businessOwnerJid,
266
+ } = content;
267
+ const bodyText = text || caption || "";
268
+ const buttons = interactiveButtons.map((btn) => ({
269
+ name: btn.name,
270
+ buttonParamsJson:
271
+ typeof btn.buttonParamsJson === "string"
272
+ ? btn.buttonParamsJson
273
+ : JSON.stringify(btn.buttonParamsJson),
274
+ }));
275
+ let headerContent = {};
276
+ let mediaAttached =
277
+ typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : false;
278
+ if (image) {
279
+ const src =
280
+ typeof image === "object" && image.url
281
+ ? { image: { url: image.url } }
282
+ : { image };
283
+ const uploaded = await prepareWAMessageMedia(src, {
284
+ upload: this.waUploadToServer,
285
+ });
286
+ headerContent = { ...uploaded };
287
+ mediaAttached =
288
+ typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
289
+ } else if (video) {
290
+ const src =
291
+ typeof video === "object" && video.url
292
+ ? { video: { url: video.url } }
293
+ : { video };
294
+ const uploaded = await prepareWAMessageMedia(src, {
295
+ upload: this.waUploadToServer,
296
+ });
297
+ headerContent = { ...uploaded };
298
+ mediaAttached =
299
+ typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
300
+ } else if (document) {
301
+ const docPayload =
302
+ typeof document === "object" && document.url
303
+ ? { document: { url: document.url } }
304
+ : { document };
305
+ if (mimetype) docPayload.mimetype = mimetype;
306
+ const uploaded = await prepareWAMessageMedia(docPayload, {
307
+ upload: this.waUploadToServer,
308
+ });
309
+ if (jpegThumbnail) {
310
+ uploaded.documentMessage.jpegThumbnail =
311
+ typeof jpegThumbnail === "string"
312
+ ? Buffer.from(jpegThumbnail, "base64")
313
+ : jpegThumbnail;
314
+ }
315
+ headerContent = { ...uploaded };
316
+ mediaAttached =
317
+ typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
318
+ } else if (location) {
319
+ headerContent = {
320
+ locationMessage: {
321
+ degreesLatitude:
322
+ location.degressLatitude || location.degreesLatitude || 0,
323
+ degreesLongitude:
324
+ location.degressLongitude || location.degreesLongitude || 0,
325
+ name: location.name || "",
326
+ },
327
+ };
328
+ mediaAttached =
329
+ typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
330
+ } else if (product) {
331
+ let productImage;
332
+ if (product.productImage) {
333
+ const imgSrc =
334
+ typeof product.productImage === "object" && product.productImage.url
335
+ ? { image: { url: product.productImage.url } }
336
+ : { image: product.productImage };
337
+ const uploaded = await prepareWAMessageMedia(imgSrc, {
338
+ upload: this.waUploadToServer,
339
+ });
340
+ productImage = uploaded.imageMessage;
341
+ }
342
+ headerContent = {
343
+ productMessage: {
344
+ product: {
345
+ productImage,
346
+ productId: product.productId,
347
+ title: product.title,
348
+ description: product.description,
349
+ currencyCode: product.currencyCode || "IDR",
350
+ priceAmount1000: product.priceAmount1000,
351
+ retailerId: product.retailerId,
352
+ url: product.url,
353
+ productImageCount: product.productImageCount || 1,
354
+ },
355
+ businessOwnerJid: businessOwnerJid || "0@s.whatsapp.net",
356
+ },
357
+ };
358
+ mediaAttached =
359
+ typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
360
+ }
361
+ const interactiveMessage = {
362
+ body: { text: bodyText },
363
+ footer: { text: footer || "" },
364
+ header: {
365
+ title: title || "",
366
+ subtitle: subtitle || "",
367
+ hasMediaAttachment: mediaAttached,
368
+ ...headerContent,
369
+ },
370
+ nativeFlowMessage: { buttons },
371
+ };
372
+ return {
373
+ viewOnceMessage: {
374
+ message: {
375
+ messageContextInfo: {
376
+ deviceListMetadata: {},
377
+ deviceListMetadataVersion: 2,
378
+ messageSecret: crypto.randomBytes(32),
379
+ },
380
+ interactiveMessage,
381
+ },
382
+ },
383
+ };
384
+ }
385
+ async handleCarousel(content, _jid, _quoted) {
386
+ const { interactiveMessage } = content;
387
+ const { body, footer, header, carouselMessage, contextInfo } =
388
+ interactiveMessage;
389
+ const processedCards = [];
390
+ for (const card of carouselMessage.cards) {
391
+ const cardMsg = {
392
+ body: card.body || { text: "" },
393
+ footer: card.footer || { text: "" },
394
+ header: {
395
+ title: card.header?.title || "",
396
+ hasMediaAttachment: false,
397
+ },
398
+ };
399
+ if (card.nativeFlowMessage) {
400
+ cardMsg.nativeFlowMessage = card.nativeFlowMessage;
401
+ }
402
+ if (
403
+ card.header?.imageMessage ||
404
+ card.header?.videoMessage ||
405
+ card.header?.documentMessage
406
+ ) {
407
+ let headerContent = {};
408
+ let mediaAttached = true;
409
+ if (card.header.imageMessage) {
410
+ const url = card.header.imageMessage.url || card.header.imageMessage;
411
+ const src =
412
+ typeof url === "string" ? { image: { url } } : { image: url };
413
+ const uploaded = await prepareWAMessageMedia(src, {
414
+ upload: this.waUploadToServer,
415
+ });
416
+ headerContent = { ...uploaded };
417
+ } else if (card.header.videoMessage) {
418
+ const url = card.header.videoMessage.url || card.header.videoMessage;
419
+ const src =
420
+ typeof url === "string" ? { video: { url } } : { video: url };
421
+ const uploaded = await prepareWAMessageMedia(src, {
422
+ upload: this.waUploadToServer,
423
+ });
424
+ headerContent = { ...uploaded };
425
+ } else if (card.header.documentMessage) {
426
+ const url =
427
+ card.header.documentMessage.url || card.header.documentMessage;
428
+ const src =
429
+ typeof url === "string" ? { document: { url } } : { document: url };
430
+ const uploaded = await prepareWAMessageMedia(src, {
431
+ upload: this.waUploadToServer,
432
+ });
433
+ headerContent = { ...uploaded };
434
+ }
435
+ cardMsg.header = {
436
+ title: card.header?.title || "",
437
+ hasMediaAttachment: mediaAttached,
438
+ ...headerContent,
439
+ };
440
+ }
441
+ processedCards.push(cardMsg);
442
+ }
443
+ const interactiveMsg = {
444
+ body: body || { text: "" },
445
+ footer: footer || { text: "" },
446
+ header: header || { title: "", hasMediaAttachment: false },
447
+ carouselMessage: {
448
+ cards: processedCards,
449
+ messageVersion: carouselMessage.messageVersion || 1,
450
+ carouselCardType: carouselMessage.carouselCardType ?? 1,
451
+ },
452
+ };
453
+ if (contextInfo) {
454
+ interactiveMsg.contextInfo = contextInfo;
455
+ }
456
+ return {
457
+ viewOnceMessage: {
458
+ message: {
459
+ messageContextInfo: {
460
+ deviceListMetadata: {},
461
+ deviceListMetadataVersion: 2,
462
+ messageSecret: crypto.randomBytes(32),
463
+ },
464
+ interactiveMessage: interactiveMsg,
465
+ },
466
+ },
467
+ };
468
+ }
469
+ async handleAlbum(content, jid, quoted) {
470
+ const array = content.albumMessage || content.album;
471
+ const ctxInfo = content.contextInfo || {};
472
+ const album = await generateWAMessageFromContent(
473
+ jid,
474
+ {
475
+ messageContextInfo: {
476
+ messageSecret: crypto.randomBytes(32),
477
+ },
478
+ albumMessage: {
479
+ expectedImageCount: array.filter((a) => "image" in a).length,
480
+ expectedVideoCount: array.filter((a) => "video" in a).length,
481
+ },
482
+ },
483
+ {
484
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
485
+ quoted,
486
+ upload: this.waUploadToServer,
487
+ },
488
+ );
489
+ await this.relayMessage(jid, album.message, {
490
+ messageId: album.key.id,
491
+ });
492
+ for (let item of array) {
493
+ if (ctxInfo && Object.keys(ctxInfo).length > 0 && !item.contextInfo) {
494
+ item = { ...item, contextInfo: ctxInfo };
495
+ }
496
+ try { // JAP@Fix: per-item try-catch so one failed upload doesn't abort the whole album
497
+ const img = await generateWAMessage(jid, item, {
498
+ upload: this.waUploadToServer,
499
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
500
+ });
501
+ img.message.messageContextInfo = {
502
+ messageSecret: crypto.randomBytes(32),
503
+ messageAssociation: {
504
+ associationType: 1,
505
+ parentMessageKey: album.key,
506
+ },
507
+ };
508
+ await this.relayMessage(jid, img.message, {
509
+ messageId: img.key.id,
510
+ });
511
+ } catch (err) {
512
+ this.config.logger?.error(`handleAlbum: failed to send item — ${err}`);
513
+ }
514
+ await delay(300); // JAP@Fix: prevent WA rate-limit / out-of-order delivery
515
+ }
516
+ return album;
517
+ }
518
+ async handleEvent(content, jid, quoted) {
519
+ const eventData = content.eventMessage;
520
+ const msg = await generateWAMessageFromContent(
521
+ jid,
522
+ {
523
+ viewOnceMessage: {
524
+ message: {
525
+ messageContextInfo: {
526
+ deviceListMetadata: {},
527
+ deviceListMetadataVersion: 2,
528
+ messageSecret: crypto.randomBytes(32),
529
+ },
530
+ eventMessage: {
531
+ isCanceled: eventData.isCanceled || false,
532
+ name: eventData.name,
533
+ description: eventData.description,
534
+ location: eventData.location || {
535
+ degreesLatitude: 0,
536
+ degreesLongitude: 0,
537
+ name: "Location",
538
+ },
539
+ joinLink: eventData.joinLink || "",
540
+ startTime:
541
+ typeof eventData.startTime === "string"
542
+ ? parseInt(eventData.startTime)
543
+ : eventData.startTime || Date.now(),
544
+ endTime:
545
+ typeof eventData.endTime === "string"
546
+ ? parseInt(eventData.endTime)
547
+ : eventData.endTime || Date.now() + 3600000,
548
+ extraGuestsAllowed: eventData.extraGuestsAllowed !== false,
549
+ },
550
+ },
551
+ },
552
+ },
553
+ {
554
+ quoted,
555
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
556
+ },
557
+ );
558
+ await this.relayMessage(jid, msg.message, {
559
+ messageId: msg.key.id,
560
+ });
561
+ return msg;
562
+ }
563
+ async handlePollResult(content, jid, quoted) {
564
+ const pollData = content.pollResultMessage;
565
+ const msg = await generateWAMessageFromContent(
566
+ jid,
567
+ {
568
+ pollResultSnapshotMessage: {
569
+ name: pollData.name,
570
+ pollVotes: pollData.pollVotes.map((vote) => ({
571
+ optionName: vote.optionName,
572
+ optionVoteCount:
573
+ typeof vote.optionVoteCount === "number"
574
+ ? vote.optionVoteCount.toString()
575
+ : vote.optionVoteCount,
576
+ })),
577
+ },
578
+ },
579
+ {
580
+ quoted,
581
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
582
+ },
583
+ );
584
+ await this.relayMessage(jid, msg.message, {
585
+ messageId: msg.key.id,
586
+ });
587
+ return msg;
588
+ }
589
+ async handleGroupInvite(content, jid, quoted) {
590
+ const inviteData = content.groupInviteMessage;
591
+ const msg = await generateWAMessageFromContent(
592
+ jid,
593
+ {
594
+ groupInviteMessage: {
595
+ groupJid: inviteData.groupJid,
596
+ inviteCode: inviteData.inviteCode,
597
+ inviteExpiration: inviteData.inviteExpiration ?? 0,
598
+ groupName: inviteData.groupName,
599
+ jpegThumbnail: inviteData.jpegThumbnail,
600
+ caption: inviteData.caption,
601
+ groupType: inviteData.groupType,
602
+ },
603
+ },
604
+ {
605
+ quoted,
606
+ userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
607
+ },
608
+ );
609
+ await this.relayMessage(jid, msg.message, {
610
+ messageId: msg.key.id,
611
+ });
612
+ return msg;
613
+ }
614
+ async handleGroupStory(content, jid, _quoted, options = {}) {
615
+ const storyData = content.groupStatusMessage;
616
+ let waMsgContent;
617
+ if (storyData.message) {
618
+ waMsgContent = storyData;
619
+ } else {
620
+ waMsgContent = await generateWAMessageContent(storyData, {
621
+ upload: this.waUploadToServer,
622
+ });
623
+ }
624
+ const innerMsg = waMsgContent.message || waMsgContent;
625
+ const msgKey = Object.keys(innerMsg).find(
626
+ (k) => innerMsg[k] && typeof innerMsg[k] === "object",
627
+ );
628
+ if (msgKey) {
629
+ innerMsg[msgKey].contextInfo = innerMsg[msgKey].contextInfo || {};
630
+ innerMsg[msgKey].contextInfo.isGroupStatus = true;
631
+ if (!innerMsg[msgKey].contextInfo.statusSourceType) {
632
+ if (innerMsg.imageMessage)
633
+ innerMsg[msgKey].contextInfo.statusSourceType = 0;
634
+ else if (innerMsg.videoMessage)
635
+ innerMsg[msgKey].contextInfo.statusSourceType = 1;
636
+ else if (innerMsg.audioMessage)
637
+ innerMsg[msgKey].contextInfo.statusSourceType = 3;
638
+ else if (innerMsg.extendedTextMessage)
639
+ innerMsg[msgKey].contextInfo.statusSourceType = 4;
640
+ }
641
+ }
642
+ const finalMsg = {
643
+ groupStatusMessageV2: {
644
+ message: innerMsg,
645
+ },
646
+ };
647
+ return await this.relayMessage(jid, finalMsg, {
648
+ messageId: generateMessageID(),
649
+ });
650
+ }
651
+ async sendStatusWhatsApp(content, jids = []) {
652
+ const userJid = jidNormalizedUser(this.sock.authState.creds.me.id);
653
+ const allUsers = new Set();
654
+ allUsers.add(userJid);
655
+ for (const id of jids) {
656
+ if (isJidGroup(id)) {
657
+ try {
658
+ const metadata = await this.sock.groupMetadata(id);
659
+ metadata.participants.forEach((p) =>
660
+ allUsers.add(jidNormalizedUser(p.id)),
661
+ );
662
+ } catch (error) {
663
+ this.config.logger.error(
664
+ `Error getting metadata for group ${id}: ${error}`,
665
+ );
666
+ }
667
+ } else if (isPnUser(id)) {
668
+ allUsers.add(jidNormalizedUser(id));
669
+ }
670
+ }
671
+ const uniqueUsers = Array.from(allUsers);
672
+ const getRandomHexColor = () =>
673
+ "#" +
674
+ Math.floor(Math.random() * 16777215)
675
+ .toString(16)
676
+ .padStart(6, "0");
677
+ const isMedia = content.image || content.video || content.audio;
678
+ const isAudio = !!content.audio;
679
+ const messageContent = { ...content };
680
+ if (isMedia && !isAudio) {
681
+ if (messageContent.text) {
682
+ messageContent.caption = messageContent.text;
683
+ delete messageContent.text;
684
+ }
685
+ delete messageContent.ptt;
686
+ delete messageContent.font;
687
+ delete messageContent.backgroundColor;
688
+ delete messageContent.textColor;
689
+ }
690
+ if (isAudio) {
691
+ delete messageContent.text;
692
+ delete messageContent.caption;
693
+ delete messageContent.font;
694
+ delete messageContent.textColor;
695
+ }
696
+ const font = !isMedia
697
+ ? content.font || Math.floor(Math.random() * 9)
698
+ : undefined;
699
+ const textColor = !isMedia
700
+ ? content.textColor || getRandomHexColor()
701
+ : undefined;
702
+ const backgroundColor =
703
+ !isMedia || isAudio
704
+ ? content.backgroundColor || getRandomHexColor()
705
+ : undefined;
706
+ const ptt = isAudio
707
+ ? typeof content.ptt === "boolean"
708
+ ? content.ptt
709
+ : true
710
+ : undefined;
711
+ const { getUrlInfo } = await import("../Utils/link-preview.js");
712
+ const msg = await generateWAMessage(STORIES_JID, messageContent, {
713
+ logger: this.config.logger,
714
+ userJid,
715
+ getUrlInfo: (text) =>
716
+ getUrlInfo(text, {
717
+ thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
718
+ fetchOpts: { timeout: 3000, ...(this.config.options || {}) },
719
+ logger: this.config.logger,
720
+ uploadImage: this.config.generateHighQualityLinkPreview
721
+ ? this.waUploadToServer
722
+ : undefined,
723
+ }),
724
+ upload: this.waUploadToServer,
725
+ mediaCache: this.config.mediaCache,
726
+ options: this.config.options,
727
+ font,
728
+ textColor,
729
+ backgroundColor,
730
+ ptt,
731
+ });
732
+ await this.relayMessage(STORIES_JID, msg.message, {
733
+ messageId: msg.key.id,
734
+ statusJidList: uniqueUsers,
735
+ additionalNodes: [
736
+ {
737
+ tag: "meta",
738
+ attrs: {},
739
+ content: [
740
+ {
741
+ tag: "mentioned_users",
742
+ attrs: {},
743
+ content: jids.map((jid) => ({
744
+ tag: "to",
745
+ attrs: { jid: jidNormalizedUser(jid) },
746
+ })),
747
+ },
748
+ ],
749
+ },
750
+ ],
751
+ });
752
+ for (const id of jids) {
753
+ try {
754
+ const normalizedId = jidNormalizedUser(id);
755
+ const isPrivate = isPnUser(normalizedId);
756
+ const type = isPrivate
757
+ ? "statusMentionMessage"
758
+ : "groupStatusMentionMessage";
759
+ const protocolMessage = {
760
+ [type]: {
761
+ message: {
762
+ protocolMessage: {
763
+ key: msg.key,
764
+ type: 25,
765
+ },
766
+ },
767
+ },
768
+ messageContextInfo: {
769
+ messageSecret: crypto.randomBytes(32),
770
+ },
771
+ };
772
+ const statusMsg = await generateWAMessageFromContent(
773
+ normalizedId,
774
+ protocolMessage,
775
+ {
776
+ userJid: jidNormalizedUser(
777
+ this.sock.authState?.creds?.me?.id || "",
778
+ ),
779
+ },
780
+ );
781
+ await this.relayMessage(normalizedId, statusMsg.message, {
782
+ additionalNodes: [
783
+ {
784
+ tag: "meta",
785
+ attrs: isPrivate
786
+ ? { is_status_mention: "true" }
787
+ : { is_group_status_mention: "true" },
788
+ },
789
+ ],
790
+ });
791
+ await delay(2000);
792
+ } catch (error) {
793
+ this.config.logger.error(`Error sending to ${id}: ${error}`);
794
+ }
795
+ }
796
+ return msg;
797
+ }
798
+ }