@vinzsocket/baileys 3.3.1 → 3.3.2

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 (209) hide show
  1. package/README.md +2684 -1336
  2. package/WAProto/WAProto.proto +360 -916
  3. package/WAProto/fix-imports.js +22 -18
  4. package/WAProto/index.d.ts +14015 -0
  5. package/WAProto/index.js +47122 -81757
  6. package/engine-requirements.js +27 -0
  7. package/lib/Defaults/index.d.ts +15 -14
  8. package/lib/Defaults/index.d.ts.map +1 -1
  9. package/lib/Defaults/index.js +98 -109
  10. package/lib/Defaults/index.js.map +1 -1
  11. package/lib/Signal/Group/group_cipher.js.map +1 -1
  12. package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
  13. package/lib/Signal/Group/keyhelper.js.map +1 -1
  14. package/lib/Signal/Group/sender-chain-key.js.map +1 -1
  15. package/lib/Signal/Group/sender-key-message.js.map +1 -1
  16. package/lib/Signal/Group/sender-message-key.js.map +1 -1
  17. package/lib/Signal/libsignal.d.ts.map +1 -1
  18. package/lib/Signal/libsignal.js +45 -17
  19. package/lib/Signal/libsignal.js.map +1 -1
  20. package/lib/Signal/lid-mapping.d.ts +4 -0
  21. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  22. package/lib/Signal/lid-mapping.js +6 -0
  23. package/lib/Signal/lid-mapping.js.map +1 -1
  24. package/lib/Socket/business.d.ts +213 -532
  25. package/lib/Socket/business.d.ts.map +1 -1
  26. package/lib/Socket/business.js +358 -401
  27. package/lib/Socket/chats.d.ts +15 -2
  28. package/lib/Socket/chats.d.ts.map +1 -1
  29. package/lib/Socket/chats.js +247 -40
  30. package/lib/Socket/chats.js.map +1 -1
  31. package/lib/Socket/communities.d.ts +269 -641
  32. package/lib/Socket/communities.d.ts.map +1 -1
  33. package/lib/Socket/dugong.d.ts +315 -127
  34. package/lib/Socket/dugong.js +653 -749
  35. package/lib/Socket/groups.d.ts +13 -2
  36. package/lib/Socket/groups.d.ts.map +1 -1
  37. package/lib/Socket/groups.js +21 -1
  38. package/lib/Socket/groups.js.map +1 -1
  39. package/lib/Socket/index.d.ts +256 -631
  40. package/lib/Socket/index.d.ts.map +1 -1
  41. package/lib/Socket/index.js +9 -12
  42. package/lib/Socket/index.js.map +1 -1
  43. package/lib/Socket/messages-recv.d.ts +23 -58
  44. package/lib/Socket/messages-recv.d.ts.map +1 -1
  45. package/lib/Socket/messages-recv.js +645 -181
  46. package/lib/Socket/messages-recv.js.map +1 -1
  47. package/lib/Socket/messages-send.d.ts +201 -575
  48. package/lib/Socket/messages-send.d.ts.map +1 -1
  49. package/lib/Socket/messages-send.js +1185 -1552
  50. package/lib/Socket/messages-send.js.map +1 -1
  51. package/lib/Socket/mex.d.ts.map +1 -1
  52. package/lib/Socket/mex.js +2 -8
  53. package/lib/Socket/mex.js.map +1 -1
  54. package/lib/Socket/newsletter.d.ts +11 -18
  55. package/lib/Socket/newsletter.d.ts.map +1 -1
  56. package/lib/Socket/newsletter.js +165 -440
  57. package/lib/Socket/newsletter.js.map +1 -1
  58. package/lib/Socket/socket.d.ts +6 -2
  59. package/lib/Socket/socket.d.ts.map +1 -1
  60. package/lib/Socket/socket.js +59 -25
  61. package/lib/Socket/socket.js.map +1 -1
  62. package/lib/Types/Auth.d.ts +1 -0
  63. package/lib/Types/Auth.d.ts.map +1 -1
  64. package/lib/Types/Bussines.d.ts +22 -34
  65. package/lib/Types/Call.d.ts +1 -1
  66. package/lib/Types/Call.d.ts.map +1 -1
  67. package/lib/Types/Chat.d.ts +1 -0
  68. package/lib/Types/Chat.d.ts.map +1 -1
  69. package/lib/Types/Contact.d.ts +2 -0
  70. package/lib/Types/Contact.d.ts.map +1 -1
  71. package/lib/Types/Events.d.ts +20 -1
  72. package/lib/Types/Events.d.ts.map +1 -1
  73. package/lib/Types/GroupMetadata.d.ts +4 -1
  74. package/lib/Types/GroupMetadata.d.ts.map +1 -1
  75. package/lib/Types/Message.d.ts +294 -348
  76. package/lib/Types/Message.d.ts.map +1 -1
  77. package/lib/Types/Message.js.map +1 -1
  78. package/lib/Types/Mex.d.ts +141 -0
  79. package/lib/Types/Mex.d.ts.map +1 -0
  80. package/lib/Types/Mex.js +37 -0
  81. package/lib/Types/Mex.js.map +1 -0
  82. package/lib/Types/Signal.d.ts +12 -1
  83. package/lib/Types/Signal.d.ts.map +1 -1
  84. package/lib/Types/Socket.d.ts +126 -148
  85. package/lib/Types/Socket.d.ts.map +1 -1
  86. package/lib/Types/State.d.ts +58 -0
  87. package/lib/Types/State.d.ts.map +1 -1
  88. package/lib/Types/State.js +43 -0
  89. package/lib/Types/State.js.map +1 -1
  90. package/lib/Types/index.d.ts +52 -52
  91. package/lib/Types/index.d.ts.map +1 -1
  92. package/lib/Types/index.js +23 -30
  93. package/lib/Types/index.js.map +1 -1
  94. package/lib/Utils/auth-utils.d.ts +5 -0
  95. package/lib/Utils/auth-utils.d.ts.map +1 -1
  96. package/lib/Utils/auth-utils.js +12 -0
  97. package/lib/Utils/auth-utils.js.map +1 -1
  98. package/lib/Utils/browser-utils.js +1 -0
  99. package/lib/Utils/chat-utils.d.ts +34 -4
  100. package/lib/Utils/chat-utils.d.ts.map +1 -1
  101. package/lib/Utils/chat-utils.js +80 -20
  102. package/lib/Utils/chat-utils.js.map +1 -1
  103. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  104. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  105. package/lib/Utils/companion-reg-client-utils.js +35 -0
  106. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  107. package/lib/Utils/crypto.d.ts +12 -12
  108. package/lib/Utils/crypto.d.ts.map +1 -1
  109. package/lib/Utils/crypto.js.map +1 -1
  110. package/lib/Utils/decode-wa-message.d.ts +18 -0
  111. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  112. package/lib/Utils/decode-wa-message.js +34 -0
  113. package/lib/Utils/decode-wa-message.js.map +1 -1
  114. package/lib/Utils/event-buffer.d.ts +2 -0
  115. package/lib/Utils/event-buffer.d.ts.map +1 -1
  116. package/lib/Utils/event-buffer.js +49 -1
  117. package/lib/Utils/event-buffer.js.map +1 -1
  118. package/lib/Utils/generics.d.ts +2 -2
  119. package/lib/Utils/generics.d.ts.map +1 -1
  120. package/lib/Utils/generics.js +10 -1
  121. package/lib/Utils/generics.js.map +1 -1
  122. package/lib/Utils/history.d.ts +2 -0
  123. package/lib/Utils/history.d.ts.map +1 -1
  124. package/lib/Utils/history.js +12 -9
  125. package/lib/Utils/history.js.map +1 -1
  126. package/lib/Utils/identity-change-handler.d.ts +7 -0
  127. package/lib/Utils/identity-change-handler.d.ts.map +1 -1
  128. package/lib/Utils/identity-change-handler.js +1 -0
  129. package/lib/Utils/identity-change-handler.js.map +1 -1
  130. package/lib/Utils/index.d.ts +23 -23
  131. package/lib/Utils/index.d.ts.map +1 -1
  132. package/lib/Utils/index.js +4 -1
  133. package/lib/Utils/index.js.map +1 -1
  134. package/lib/Utils/link-preview.js +2 -2
  135. package/lib/Utils/link-preview.js.map +1 -1
  136. package/lib/Utils/logger.d.ts +1 -2
  137. package/lib/Utils/logger.d.ts.map +1 -1
  138. package/lib/Utils/mention.d.ts +14 -0
  139. package/lib/Utils/mention.js +138 -0
  140. package/lib/Utils/message-retry-manager.d.ts +5 -0
  141. package/lib/Utils/message-retry-manager.d.ts.map +1 -1
  142. package/lib/Utils/message-retry-manager.js +40 -0
  143. package/lib/Utils/message-retry-manager.js.map +1 -1
  144. package/lib/Utils/messages-media.d.ts +16 -13
  145. package/lib/Utils/messages-media.d.ts.map +1 -1
  146. package/lib/Utils/messages-media.js +85 -79
  147. package/lib/Utils/messages-media.js.map +1 -1
  148. package/lib/Utils/messages.d.ts +16 -1
  149. package/lib/Utils/messages.d.ts.map +1 -1
  150. package/lib/Utils/messages.js +1021 -1121
  151. package/lib/Utils/messages.js.map +1 -1
  152. package/lib/Utils/noise-handler.d.ts +1 -1
  153. package/lib/Utils/process-message.d.ts.map +1 -1
  154. package/lib/Utils/process-message.js +103 -1
  155. package/lib/Utils/process-message.js.map +1 -1
  156. package/lib/Utils/signal.d.ts +13 -0
  157. package/lib/Utils/signal.d.ts.map +1 -1
  158. package/lib/Utils/signal.js +42 -0
  159. package/lib/Utils/signal.js.map +1 -1
  160. package/lib/Utils/story-card.js +107 -0
  161. package/lib/Utils/sync-action-utils.d.ts.map +1 -1
  162. package/lib/Utils/sync-action-utils.js +1 -0
  163. package/lib/Utils/sync-action-utils.js.map +1 -1
  164. package/lib/Utils/tc-token-utils.d.ts +26 -1
  165. package/lib/Utils/tc-token-utils.d.ts.map +1 -1
  166. package/lib/Utils/tc-token-utils.js +151 -5
  167. package/lib/Utils/tc-token-utils.js.map +1 -1
  168. package/lib/Utils/validate-connection.d.ts.map +1 -1
  169. package/lib/Utils/validate-connection.js +12 -2
  170. package/lib/Utils/validate-connection.js.map +1 -1
  171. package/lib/WABinary/decode.d.ts +1 -1
  172. package/lib/WABinary/decode.d.ts.map +1 -1
  173. package/lib/WABinary/generic-utils.d.ts +1 -3
  174. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  175. package/lib/WABinary/generic-utils.js +0 -78
  176. package/lib/WABinary/generic-utils.js.map +1 -1
  177. package/lib/WAM/encode.d.ts +1 -1
  178. package/lib/WAM/encode.d.ts.map +1 -1
  179. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
  180. package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
  181. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
  182. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  183. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  184. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  185. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  186. package/lib/WAUSync/Protocols/index.d.ts +1 -0
  187. package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
  188. package/lib/WAUSync/Protocols/index.js +1 -0
  189. package/lib/WAUSync/Protocols/index.js.map +1 -1
  190. package/lib/WAUSync/USyncQuery.d.ts +1 -0
  191. package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
  192. package/lib/WAUSync/USyncQuery.js +6 -2
  193. package/lib/WAUSync/USyncQuery.js.map +1 -1
  194. package/lib/WAUSync/USyncUser.d.ts +4 -0
  195. package/lib/WAUSync/USyncUser.d.ts.map +1 -1
  196. package/lib/WAUSync/USyncUser.js +8 -0
  197. package/lib/WAUSync/USyncUser.js.map +1 -1
  198. package/lib/index.d.ts +0 -1
  199. package/lib/index.d.ts.map +1 -1
  200. package/lib/index.js +0 -1
  201. package/lib/index.js.map +1 -1
  202. package/package.json +91 -24
  203. package/LICENSE +0 -21
  204. package/lib/Socket/dugong.d.ts.map +0 -1
  205. package/lib/Socket/dugong.js.map +0 -1
  206. package/lib/Types/Newsletter.d.ts.map +0 -1
  207. package/lib/Types/Newsletter.js.map +0 -1
  208. package/lib/Utils/rich-messages.d.ts.map +0 -1
  209. package/lib/Utils/rich-messages.js.map +0 -1
@@ -1,768 +1,672 @@
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.interactiveButtons) return "INTERACTIVE_BUTTONS";
30
- if (content.interactiveMessage?.carouselMessage) return "CAROUSEL";
31
- if (content.interactiveMessage) return "INTERACTIVE";
32
- if (content.albumMessage || content.album) return "ALBUM";
33
- if (content.eventMessage) return "EVENT";
34
- if (content.pollResultMessage) return "POLL_RESULT";
35
- if (content.groupStatusMessage) return "GROUP_STORY";
36
- return null;
37
- }
38
- async handlePayment(content, quoted) {
39
- const data = content.requestPaymentMessage;
40
- let notes = {};
41
- if (data.sticker?.stickerMessage) {
42
- notes = {
43
- stickerMessage: {
44
- ...data.sticker.stickerMessage,
45
- contextInfo: {
46
- stanzaId: quoted?.key?.id,
47
- participant: quoted?.key?.participant || content.sender,
48
- quotedMessage: quoted?.message,
49
- },
50
- },
51
- };
52
- } else if (data.note) {
53
- notes = {
54
- extendedTextMessage: {
55
- text: data.note,
56
- contextInfo: {
57
- stanzaId: quoted?.key?.id,
58
- participant: quoted?.key?.participant || content.sender,
59
- quotedMessage: quoted?.message,
60
- },
61
- },
62
- };
63
- }
64
- return {
65
- requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
66
- expiryTimestamp: data.expiry || 0,
67
- amount1000: data.amount || 0,
68
- currencyCodeIso4217: data.currency || "IDR",
69
- requestFrom: data.from || "0@s.whatsapp.net",
70
- noteMessage: notes,
71
- background: data.background ?? {
72
- id: "DEFAULT",
73
- placeholderArgb: 0xfff0f0f0,
74
- },
75
- }),
76
- };
77
- }
78
- async handleProduct(content, _jid, _quoted) {
79
- const {
80
- title,
81
- description,
82
- thumbnail,
83
- productId,
84
- retailerId,
85
- url,
86
- body = "",
87
- footer = "",
88
- buttons = [],
89
- priceAmount1000 = null,
90
- currencyCode = "IDR",
91
- } = content.productMessage;
92
- let productImage;
93
- if (Buffer.isBuffer(thumbnail)) {
94
- const { imageMessage } = await generateWAMessageContent(
95
- { image: thumbnail },
96
- { upload: this.waUploadToServer },
97
- );
98
- productImage = imageMessage;
99
- } else if (typeof thumbnail === "object" && thumbnail.url) {
100
- const { imageMessage } = await generateWAMessageContent(
101
- { image: { url: thumbnail.url } },
102
- { upload: this.waUploadToServer },
103
- );
104
- productImage = imageMessage;
105
- }
106
- return {
107
- viewOnceMessage: {
108
- message: {
109
- interactiveMessage: {
110
- body: { text: body },
111
- footer: { text: footer },
112
- header: {
113
- title,
114
- hasMediaAttachment: true,
115
- productMessage: {
116
- product: {
117
- productImage,
118
- productId,
119
- title,
120
- description,
121
- currencyCode,
122
- priceAmount1000,
123
- retailerId,
124
- url,
125
- productImageCount: 1,
126
- },
127
- businessOwnerJid: "0@s.whatsapp.net",
128
- },
129
- },
130
- nativeFlowMessage: { buttons },
131
- },
132
- },
133
- },
134
- };
135
- }
136
- async handleInteractive(content, _jid, _quoted) {
137
- const {
138
- title,
139
- footer,
140
- thumbnail,
141
- image,
142
- video,
143
- document,
144
- mimetype,
145
- fileName,
146
- jpegThumbnail,
147
- contextInfo,
148
- externalAdReply,
149
- buttons = [],
150
- nativeFlowMessage,
151
- header,
152
- } = content.interactiveMessage;
153
- let media = null;
154
- let _mediaType = null;
155
- if (thumbnail) {
156
- media = await prepareWAMessageMedia(
157
- { image: { url: thumbnail } },
158
- { upload: this.waUploadToServer },
159
- );
160
- _mediaType = "image";
161
- } else if (image) {
162
- const src =
163
- typeof image === "object" && image.url
164
- ? { image: { url: image.url } }
165
- : { image };
166
- media = await prepareWAMessageMedia(src, {
167
- upload: this.waUploadToServer,
168
- });
169
- _mediaType = "image";
170
- } else if (video) {
171
- const src =
172
- typeof video === "object" && video.url
173
- ? { video: { url: video.url } }
174
- : { video };
175
- media = await prepareWAMessageMedia(src, {
176
- upload: this.waUploadToServer,
177
- });
178
- _mediaType = "video";
179
- } else if (document) {
180
- const docPayload = { document };
181
- if (jpegThumbnail) {
182
- docPayload.jpegThumbnail =
183
- typeof jpegThumbnail === "object" && jpegThumbnail.url
184
- ? { url: jpegThumbnail.url }
185
- : jpegThumbnail;
186
- }
187
- media = await prepareWAMessageMedia(docPayload, {
188
- upload: this.waUploadToServer,
189
- });
190
- if (fileName) media.documentMessage.fileName = fileName;
191
- if (mimetype) media.documentMessage.mimetype = mimetype;
192
- _mediaType = "document";
1
+ // dugong.js — Harps-Baileys extended message builders v3.2.10
2
+ // Handles: Payment, Product, Interactive (NF V7 full), Album, Event,
3
+ // Poll Result, Group Status V2, Nested Legacy List, Multi-Select.
4
+
5
+ import { randomBytes } from 'crypto';
6
+ import { proto } from '../../WAProto/index.js';
7
+ import { normalizeMentions } from '../Utils/mention.js';
8
+ import { delay } from '../Utils/generics.js';
9
+ import { isJidGroup, isPnUser, jidNormalizedUser, STORIES_JID } from '../WABinary/index.js';
10
+
11
+ // ─── NF V7 Button Builders ────────────────────────────────────────────────────
12
+
13
+ export const nfButtonUrl = ({ id, displayText, url, merchantUrl }) => ({
14
+ name: 'cta_url',
15
+ buttonParamsJson: JSON.stringify({ display_text: displayText, url, merchant_url: merchantUrl || url }),
16
+ ...(id ? { id } : {})
17
+ });
18
+ export const nfButtonCall = ({ id, displayText, phoneNumber }) => ({
19
+ name: 'cta_call',
20
+ buttonParamsJson: JSON.stringify({ display_text: displayText, phone_number: phoneNumber }),
21
+ ...(id ? { id } : {})
22
+ });
23
+ export const nfButtonCopy = ({ id, displayText, copyCode }) => ({
24
+ name: 'cta_copy',
25
+ buttonParamsJson: JSON.stringify({ display_text: displayText, copy_code: copyCode }),
26
+ ...(id ? { id } : {})
27
+ });
28
+ export const nfButtonReminder = ({ id, displayText, title, notes, startTime, endTime, timezone = 'Asia/Jakarta' }) => ({
29
+ name: 'cta_reminder',
30
+ buttonParamsJson: JSON.stringify({ display_text: displayText, title, notes, start_timestamp: startTime, end_timestamp: endTime, timezone }),
31
+ ...(id ? { id } : {})
32
+ });
33
+ export const nfButtonCancelReminder = ({ id, displayText, reminderKey }) => ({
34
+ name: 'cta_cancel_reminder',
35
+ buttonParamsJson: JSON.stringify({ display_text: displayText, reminder_key: reminderKey }),
36
+ ...(id ? { id } : {})
37
+ });
38
+ export const nfButtonAddress = ({ id, displayText, label = '' }) => ({
39
+ name: 'address_message',
40
+ buttonParamsJson: JSON.stringify({ display_text: displayText, label }),
41
+ ...(id ? { id } : {})
42
+ });
43
+ export const nfButtonLocation = ({ id, displayText }) => ({
44
+ name: 'send_location',
45
+ buttonParamsJson: JSON.stringify({ display_text: displayText }),
46
+ ...(id ? { id } : {})
47
+ });
48
+ export const nfButtonQuickReply = ({ id, displayText, payload }) => ({
49
+ name: 'quick_reply',
50
+ buttonParamsJson: JSON.stringify({ display_text: displayText, id: id || payload || displayText }),
51
+ ...(id ? { id } : {})
52
+ });
53
+
54
+ /**
55
+ * Single-select dropdown.
56
+ * sections: [{ title, highlight_label?, rows: [{id, title, description?}] }]
57
+ */
58
+ export const nfButtonSingleSelect = ({ id, displayText, sections = [] }) => ({
59
+ name: 'single_select',
60
+ buttonParamsJson: JSON.stringify({
61
+ title: displayText,
62
+ sections: sections.map(sec => ({
63
+ title: sec.title || '',
64
+ highlight_label: sec.highlight_label || '',
65
+ rows: (sec.rows || []).map(r => ({
66
+ id: r.id || r.rowId || '',
67
+ title: r.title || '',
68
+ ...(r.description ? { description: r.description } : {})
69
+ }))
70
+ }))
71
+ }),
72
+ ...(id ? { id } : {})
73
+ });
74
+
75
+ /**
76
+ * Multi-select: beberapa single_select buttons sekaligus dalam 1 pesan.
77
+ * selectors: [{ id?, displayText, sections }]
78
+ * Returns: array of buttons
79
+ */
80
+ export const nfButtonMultiSelect = (selectors = []) =>
81
+ selectors.map((sel, i) => nfButtonSingleSelect({
82
+ id: sel.id || `select_${i}`,
83
+ displayText: sel.displayText,
84
+ sections: sel.sections
85
+ }));
86
+
87
+ export const nfButtonReviewPay = ({ id, currency = 'IDR', totalAmount1000, subtotal, tax, items = [], merchant = {} }) => ({
88
+ name: 'review_and_pay',
89
+ buttonParamsJson: JSON.stringify({ currency, total_amount: { value: totalAmount1000, offset: 1000 }, subtotal, tax, items, order: { status: 'pending', items }, merchant }),
90
+ ...(id ? { id } : {})
91
+ });
92
+ export const nfButtonReviewOrder = ({ id, referenceId, type = 'ORDER', orderId }) => ({
93
+ name: 'review_order',
94
+ buttonParamsJson: JSON.stringify({ reference_id: referenceId, type, order_id: orderId }),
95
+ ...(id ? { id } : {})
96
+ });
97
+ export const nfButtonMPM = ({ id, sections = [] }) => ({
98
+ name: 'mpm',
99
+ buttonParamsJson: JSON.stringify({
100
+ sections: sections.map(sec => ({
101
+ title: sec.title || '',
102
+ product_items: (sec.productItems || []).map(p => ({ product_id: p.productId || p.product_id }))
103
+ }))
104
+ }),
105
+ ...(id ? { id } : {})
106
+ });
107
+
108
+ // ─── Nested Legacy List Helper ────────────────────────────────────────────────
109
+
110
+ /**
111
+ * Build proto listMessage payload.
112
+ * Row yang punya field `rows` sendiri otomatis di-flatten jadi section baru.
113
+ */
114
+ export const buildNestedListMessage = ({ title, buttonText, footer = '', sections = [] }) => {
115
+ const flat = [];
116
+ for (const sec of sections) {
117
+ const topRows = [], childSecs = [];
118
+ for (const row of (sec.rows || [])) {
119
+ if (Array.isArray(row.rows) && row.rows.length > 0) {
120
+ childSecs.push({
121
+ title: row.title || '',
122
+ rows: row.rows.map(r => ({ rowId: r.rowId || r.id || '', title: r.title || '', description: r.description || '' }))
123
+ });
124
+ } else {
125
+ topRows.push({ rowId: row.rowId || row.id || '', title: row.title || '', description: row.description || '' });
126
+ }
127
+ }
128
+ if (topRows.length) flat.push({ title: sec.title || '', rows: topRows });
129
+ for (const cs of childSecs) flat.push(cs);
193
130
  }
194
- const interactiveMessage = {
195
- body: { text: title || "" },
196
- footer: { text: footer || "" },
197
- };
198
- if (buttons && buttons.length > 0) {
199
- interactiveMessage.nativeFlowMessage = { buttons };
200
- if (nativeFlowMessage) {
201
- interactiveMessage.nativeFlowMessage = {
202
- ...interactiveMessage.nativeFlowMessage,
203
- ...nativeFlowMessage,
131
+ return { listMessage: { title, description: footer, buttonText, listType: 1, sections: flat } };
132
+ };
133
+
134
+ // ─── ExtendedMessageBuilder ───────────────────────────────────────────────────
135
+
136
+ export class ExtendedMessageBuilder {
137
+ constructor(utils, waUploadToServer, relayMessageFn) {
138
+ this.utils = utils;
139
+ this.relayMessage = relayMessageFn;
140
+ this.waUploadToServer = waUploadToServer;
141
+ this.bail = {
142
+ generateWAMessageContent: this.utils.generateWAMessageContent,
143
+ generateMessageID: this.utils.generateMessageID,
144
+ getContentType: (msg) => Object.keys(msg.message || {})[0]
204
145
  };
205
- }
206
- } else if (nativeFlowMessage) {
207
- interactiveMessage.nativeFlowMessage = nativeFlowMessage;
208
- }
209
- if (media) {
210
- interactiveMessage.header = {
211
- title: header || "",
212
- hasMediaAttachment: true,
213
- ...media,
214
- };
215
- } else {
216
- interactiveMessage.header = {
217
- title: header || "",
218
- hasMediaAttachment: false,
219
- };
220
- }
221
- const finalContextInfo = {};
222
- if (contextInfo) {
223
- Object.assign(finalContextInfo, {
224
- mentionedJid: contextInfo.mentionedJid || [],
225
- forwardingScore: contextInfo.forwardingScore || 0,
226
- isForwarded: contextInfo.isForwarded || false,
227
- ...contextInfo,
228
- });
229
- }
230
- if (externalAdReply) {
231
- finalContextInfo.externalAdReply = {
232
- title: externalAdReply.title || "",
233
- body: externalAdReply.body || "",
234
- mediaType: externalAdReply.mediaType || 1,
235
- thumbnailUrl: externalAdReply.thumbnailUrl || "",
236
- mediaUrl: externalAdReply.mediaUrl || "",
237
- sourceUrl: externalAdReply.sourceUrl || "",
238
- showAdAttribution: externalAdReply.showAdAttribution || false,
239
- renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
240
- ...externalAdReply,
241
- };
242
146
  }
243
- if (Object.keys(finalContextInfo).length > 0) {
244
- interactiveMessage.contextInfo = finalContextInfo;
147
+
148
+ detectType(content) {
149
+ if (content.requestPaymentMessage) return 'PAYMENT';
150
+ if (content.productMessage) return 'PRODUCT';
151
+ if (content.interactiveMessage) return 'INTERACTIVE';
152
+ if (content.albumMessage) return 'ALBUM';
153
+ if (content.eventMessage) return 'EVENT';
154
+ if (content.pollResultMessage) return 'POLL_RESULT';
155
+ if (content.groupStatusMessage) return 'GROUP_STORY';
156
+ if (content.nestedListMessage) return 'NESTED_LIST';
157
+ if (content.multiSelectMessage) return 'MULTI_SELECT';
158
+ return null;
245
159
  }
246
- return { interactiveMessage };
247
- }
248
- async handleInteractiveButtons(content, _jid, _quoted) {
249
- const {
250
- text,
251
- caption,
252
- title,
253
- subtitle,
254
- footer,
255
- interactiveButtons,
256
- hasMediaAttachment,
257
- image,
258
- video,
259
- document,
260
- mimetype,
261
- jpegThumbnail,
262
- location,
263
- product,
264
- businessOwnerJid,
265
- } = content;
266
- const bodyText = text || caption || "";
267
- const buttons = interactiveButtons.map((btn) => ({
268
- name: btn.name,
269
- buttonParamsJson:
270
- typeof btn.buttonParamsJson === "string"
271
- ? btn.buttonParamsJson
272
- : JSON.stringify(btn.buttonParamsJson),
273
- }));
274
- let headerContent = {};
275
- let mediaAttached =
276
- typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : false;
277
- if (image) {
278
- const src =
279
- typeof image === "object" && image.url
280
- ? { image: { url: image.url } }
281
- : { image };
282
- const uploaded = await prepareWAMessageMedia(src, {
283
- upload: this.waUploadToServer,
284
- });
285
- headerContent = { ...uploaded };
286
- mediaAttached =
287
- typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
288
- } else if (video) {
289
- const src =
290
- typeof video === "object" && video.url
291
- ? { video: { url: video.url } }
292
- : { video };
293
- const uploaded = await prepareWAMessageMedia(src, {
294
- upload: this.waUploadToServer,
295
- });
296
- headerContent = { ...uploaded };
297
- mediaAttached =
298
- typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
299
- } else if (document) {
300
- const docPayload =
301
- typeof document === "object" && document.url
302
- ? { document: { url: document.url } }
303
- : { document };
304
- if (mimetype) docPayload.mimetype = mimetype;
305
- const uploaded = await prepareWAMessageMedia(docPayload, {
306
- upload: this.waUploadToServer,
307
- });
308
- if (jpegThumbnail) {
309
- uploaded.documentMessage.jpegThumbnail =
310
- typeof jpegThumbnail === "string"
311
- ? Buffer.from(jpegThumbnail, "base64")
312
- : jpegThumbnail;
313
- }
314
- headerContent = { ...uploaded };
315
- mediaAttached =
316
- typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
317
- } else if (location) {
318
- headerContent = {
319
- locationMessage: {
320
- degreesLatitude:
321
- location.degressLatitude || location.degreesLatitude || 0,
322
- degreesLongitude:
323
- location.degressLongitude || location.degreesLongitude || 0,
324
- name: location.name || "",
325
- },
326
- };
327
- mediaAttached =
328
- typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
329
- } else if (product) {
330
- let productImage;
331
- if (product.productImage) {
332
- const imgSrc =
333
- typeof product.productImage === "object" && product.productImage.url
334
- ? { image: { url: product.productImage.url } }
335
- : { image: product.productImage };
336
- const uploaded = await prepareWAMessageMedia(imgSrc, {
337
- upload: this.waUploadToServer,
338
- });
339
- productImage = uploaded.imageMessage;
340
- }
341
- headerContent = {
342
- productMessage: {
343
- product: {
344
- productImage,
345
- productId: product.productId,
346
- title: product.title,
347
- description: product.description,
348
- currencyCode: product.currencyCode || "IDR",
349
- priceAmount1000: product.priceAmount1000,
350
- retailerId: product.retailerId,
351
- url: product.url,
352
- productImageCount: product.productImageCount || 1,
353
- },
354
- businessOwnerJid: businessOwnerJid || "0@s.whatsapp.net",
355
- },
356
- };
357
- mediaAttached =
358
- typeof hasMediaAttachment === "boolean" ? hasMediaAttachment : true;
359
- }
360
- const interactiveMessage = {
361
- body: { text: bodyText },
362
- footer: { text: footer || "" },
363
- header: {
364
- title: title || "",
365
- subtitle: subtitle || "",
366
- hasMediaAttachment: mediaAttached,
367
- ...headerContent,
368
- },
369
- nativeFlowMessage: { buttons },
370
- };
371
- return {
372
- viewOnceMessage: {
373
- message: {
374
- messageContextInfo: {
375
- deviceListMetadata: {},
376
- deviceListMetadataVersion: 2,
377
- messageSecret: crypto.randomBytes(32),
378
- },
379
- interactiveMessage,
380
- },
381
- },
382
- };
383
- }
384
- async handleCarousel(content, _jid, _quoted) {
385
- const { interactiveMessage } = content;
386
- const { body, footer, header, carouselMessage, contextInfo } =
387
- interactiveMessage;
388
- const processedCards = [];
389
- for (const card of carouselMessage.cards) {
390
- const cardMsg = {
391
- body: card.body || { text: "" },
392
- footer: card.footer || { text: "" },
393
- header: {
394
- title: card.header?.title || "",
395
- hasMediaAttachment: false,
396
- },
397
- };
398
- if (card.nativeFlowMessage) {
399
- cardMsg.nativeFlowMessage = card.nativeFlowMessage;
400
- }
401
- if (
402
- card.header?.imageMessage ||
403
- card.header?.videoMessage ||
404
- card.header?.documentMessage
405
- ) {
406
- let headerContent = {};
407
- let mediaAttached = true;
408
- if (card.header.imageMessage) {
409
- const url = card.header.imageMessage.url || card.header.imageMessage;
410
- const src =
411
- typeof url === "string" ? { image: { url } } : { image: url };
412
- const uploaded = await prepareWAMessageMedia(src, {
413
- upload: this.waUploadToServer,
414
- });
415
- headerContent = { ...uploaded };
416
- } else if (card.header.videoMessage) {
417
- const url = card.header.videoMessage.url || card.header.videoMessage;
418
- const src =
419
- typeof url === "string" ? { video: { url } } : { video: url };
420
- const uploaded = await prepareWAMessageMedia(src, {
421
- upload: this.waUploadToServer,
422
- });
423
- headerContent = { ...uploaded };
424
- } else if (card.header.documentMessage) {
425
- const url =
426
- card.header.documentMessage.url || card.header.documentMessage;
427
- const src =
428
- typeof url === "string" ? { document: { url } } : { document: url };
429
- const uploaded = await prepareWAMessageMedia(src, {
430
- upload: this.waUploadToServer,
431
- });
432
- headerContent = { ...uploaded };
160
+
161
+ async handlePayment(content, quoted) {
162
+ const data = content.requestPaymentMessage;
163
+ let notes = {};
164
+ if (data.sticker?.stickerMessage) {
165
+ notes = { stickerMessage: { ...data.sticker.stickerMessage, contextInfo: { stanzaId: quoted?.key?.id, participant: quoted?.key?.participant || content.sender, quotedMessage: quoted?.message } } };
166
+ } else if (data.note) {
167
+ notes = { extendedTextMessage: { text: data.note, contextInfo: { stanzaId: quoted?.key?.id, participant: quoted?.key?.participant || content.sender, quotedMessage: quoted?.message } } };
433
168
  }
434
- cardMsg.header = {
435
- title: card.header?.title || "",
436
- hasMediaAttachment: mediaAttached,
437
- ...headerContent,
169
+ return {
170
+ requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
171
+ expiryTimestamp: data.expiry || 0, amount1000: data.amount || 0,
172
+ currencyCodeIso4217: data.currency || 'IDR', requestFrom: data.from || '0@s.whatsapp.net',
173
+ noteMessage: notes, background: data.background ?? { id: 'DEFAULT', placeholderArgb: 0xFFF0F0F0 }
174
+ })
438
175
  };
439
- }
440
- processedCards.push(cardMsg);
441
176
  }
442
- const interactiveMsg = {
443
- body: body || { text: "" },
444
- footer: footer || { text: "" },
445
- header: header || { title: "", hasMediaAttachment: false },
446
- carouselMessage: {
447
- cards: processedCards,
448
- messageVersion: carouselMessage.messageVersion || 1,
449
- carouselCardType: carouselMessage.carouselCardType ?? 1,
450
- },
451
- };
452
- if (contextInfo) {
453
- interactiveMsg.contextInfo = contextInfo;
177
+
178
+ async handleProduct(content, jid, quoted) {
179
+ const { title, description, thumbnail, productId, retailerId, url, body = '', footer = '', buttons = [], priceAmount1000 = null, currencyCode = 'IDR' } = content.productMessage;
180
+ let productImage;
181
+ if (Buffer.isBuffer(thumbnail)) {
182
+ const { imageMessage } = await this.utils.generateWAMessageContent({ image: thumbnail }, { upload: this.waUploadToServer });
183
+ productImage = imageMessage;
184
+ } else if (thumbnail?.url) {
185
+ const { imageMessage } = await this.utils.generateWAMessageContent({ image: { url: thumbnail.url } }, { upload: this.waUploadToServer });
186
+ productImage = imageMessage;
187
+ }
188
+ return { viewOnceMessage: { message: { interactiveMessage: { body: { text: body }, footer: { text: footer }, header: { title, hasMediaAttachment: true, productMessage: { product: { productImage, productId, title, description, currencyCode, priceAmount1000, retailerId, url, productImageCount: 1 }, businessOwnerJid: '0@s.whatsapp.net' } }, nativeFlowMessage: { buttons } } } } };
454
189
  }
455
- return {
456
- viewOnceMessage: {
457
- message: {
458
- messageContextInfo: {
459
- deviceListMetadata: {},
460
- deviceListMetadataVersion: 2,
461
- messageSecret: crypto.randomBytes(32),
462
- },
463
- interactiveMessage: interactiveMsg,
464
- },
465
- },
466
- };
467
- }
468
- async handleAlbum(content, jid, quoted) {
469
- const array = content.albumMessage || content.album;
470
- const ctxInfo = content.contextInfo || {};
471
- const album = await generateWAMessageFromContent(
472
- jid,
473
- {
474
- messageContextInfo: {
475
- messageSecret: crypto.randomBytes(32),
476
- },
477
- albumMessage: {
478
- expectedImageCount: array.filter((a) => "image" in a).length,
479
- expectedVideoCount: array.filter((a) => "video" in a).length,
480
- },
481
- },
482
- {
483
- userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
484
- quoted,
485
- upload: this.waUploadToServer,
486
- },
487
- );
488
- await this.relayMessage(jid, album.message, {
489
- messageId: album.key.id,
490
- });
491
- for (let item of array) {
492
- if (ctxInfo && Object.keys(ctxInfo).length > 0 && !item.contextInfo) {
493
- item = { ...item, contextInfo: ctxInfo };
494
- }
495
- const img = await generateWAMessage(jid, item, {
496
- upload: this.waUploadToServer,
497
- userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
498
- });
499
- img.message.messageContextInfo = {
500
- messageSecret: crypto.randomBytes(32),
501
- messageAssociation: {
502
- associationType: 1,
503
- parentMessageKey: album.key,
504
- },
505
- };
506
- await this.relayMessage(jid, img.message, {
507
- messageId: img.key.id,
508
- });
190
+
191
+ async handleInteractive(content, jid, quoted, options = {}) {
192
+ const { title, footer, thumbnail, image, video, document, mimetype, fileName, jpegThumbnail, contextInfo = {}, externalAdReply, buttons = [], nativeFlowMessage, header } = content.interactiveMessage;
193
+ let media = null;
194
+ if (thumbnail || image) {
195
+ const src = thumbnail || image;
196
+ media = await this.utils.prepareWAMessageMedia({ image: src?.url ? { url: src.url } : src }, { upload: this.waUploadToServer });
197
+ } else if (video) {
198
+ media = await this.utils.prepareWAMessageMedia({ video: video?.url ? { url: video.url } : video }, { upload: this.waUploadToServer });
199
+ } else if (document) {
200
+ let dp = { document };
201
+ if (jpegThumbnail) dp.jpegThumbnail = jpegThumbnail?.url ? { url: jpegThumbnail.url } : jpegThumbnail;
202
+ media = await this.utils.prepareWAMessageMedia(dp, { upload: this.waUploadToServer });
203
+ if (fileName && media.documentMessage) media.documentMessage.fileName = fileName;
204
+ if (mimetype && media.documentMessage) media.documentMessage.mimetype = mimetype;
205
+ }
206
+ let im = { body: { text: title || '' }, footer: { text: footer || '' } };
207
+ if (buttons?.length) { im.nativeFlowMessage = { buttons }; if (nativeFlowMessage) im.nativeFlowMessage = { ...im.nativeFlowMessage, ...nativeFlowMessage }; }
208
+ else if (nativeFlowMessage) im.nativeFlowMessage = nativeFlowMessage;
209
+ im.header = media ? { title: header || '', hasMediaAttachment: true, ...media } : { title: header || '', hasMediaAttachment: false };
210
+ let ci = { forwardingScore: contextInfo.forwardingScore || 0, isForwarded: contextInfo.isForwarded || false, ...contextInfo, mentionedJid: normalizeMentions(contextInfo.mentionedJid || options.mentions || []) };
211
+ if (externalAdReply) ci.externalAdReply = { title: '', body: '', mediaType: 1, thumbnailUrl: '', mediaUrl: '', sourceUrl: '', showAdAttribution: false, renderLargerThumbnail: false, ...externalAdReply };
212
+ if (!Array.isArray(ci.mentionedJid)) ci.mentionedJid = [ci.mentionedJid].filter(Boolean);
213
+ if (Object.keys(ci).length) im.contextInfo = ci;
214
+ return { interactiveMessage: im };
509
215
  }
510
- return album;
511
- }
512
- async handleEvent(content, jid, quoted) {
513
- const eventData = content.eventMessage;
514
- const msg = await generateWAMessageFromContent(
515
- jid,
516
- {
517
- viewOnceMessage: {
518
- message: {
519
- messageContextInfo: {
520
- deviceListMetadata: {},
521
- deviceListMetadataVersion: 2,
522
- messageSecret: crypto.randomBytes(32),
523
- },
524
- eventMessage: {
525
- isCanceled: eventData.isCanceled || false,
526
- name: eventData.name,
527
- description: eventData.description,
528
- location: eventData.location || {
529
- degreesLatitude: 0,
530
- degreesLongitude: 0,
531
- name: "Location",
532
- },
533
- joinLink: eventData.joinLink || "",
534
- startTime:
535
- typeof eventData.startTime === "string"
536
- ? parseInt(eventData.startTime)
537
- : eventData.startTime || Date.now(),
538
- endTime:
539
- typeof eventData.endTime === "string"
540
- ? parseInt(eventData.endTime)
541
- : eventData.endTime || Date.now() + 3600000,
542
- extraGuestsAllowed: eventData.extraGuestsAllowed !== false,
543
- },
544
- },
545
- },
546
- },
547
- {
548
- quoted,
549
- userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
550
- },
551
- );
552
- await this.relayMessage(jid, msg.message, {
553
- messageId: msg.key.id,
554
- });
555
- return msg;
556
- }
557
- async handlePollResult(content, jid, quoted) {
558
- const pollData = content.pollResultMessage;
559
- const msg = await generateWAMessageFromContent(
560
- jid,
561
- {
562
- pollResultSnapshotMessage: {
563
- name: pollData.name,
564
- pollVotes: pollData.pollVotes.map((vote) => ({
565
- optionName: vote.optionName,
566
- optionVoteCount:
567
- typeof vote.optionVoteCount === "number"
568
- ? vote.optionVoteCount.toString()
569
- : vote.optionVoteCount,
570
- })),
571
- },
572
- },
573
- {
574
- quoted,
575
- userJid: jidNormalizedUser(this.sock.authState?.creds?.me?.id || ""),
576
- },
577
- );
578
- await this.relayMessage(jid, msg.message, {
579
- messageId: msg.key.id,
580
- });
581
- return msg;
582
- }
583
- async handleGroupStory(content, jid, _quoted, options = {}) {
584
- const storyData = content.groupStatusMessage;
585
- let waMsgContent;
586
- if (storyData.message) {
587
- waMsgContent = storyData;
588
- } else {
589
- waMsgContent = await generateWAMessageContent(storyData, {
590
- upload: this.waUploadToServer,
591
- });
216
+
217
+ /**
218
+ * Multi-Select — 1 pesan dengan BEBERAPA tombol single_select.
219
+ * Tiap selector = 1 tombol dropdown terpisah, buka bottom sheet sendiri.
220
+ *
221
+ * Gunakan dari plugin:
222
+ * conn.sendMessage(jid, {
223
+ * multiSelectMessage: {
224
+ * title: 'Judul',
225
+ * footer: 'Footer',
226
+ * selectors: [
227
+ * { displayText: '⚔️ Senjata', sections: [{ title: 'Melee', rows: [{ id:'sword', title:'Pedang' }] }] },
228
+ * { displayText: '🛡️ Armor', sections: [{ title: 'Light', rows: [{ id:'cloth', title:'Cloth' }] }] },
229
+ * ]
230
+ * }
231
+ * })
232
+ */
233
+ async handleMultiSelect(content, jid, quoted, options = {}) {
234
+ const { title, footer, image, video, thumbnail, selectors = [], extraButtons = [], contextInfo = {}, header } = content.multiSelectMessage;
235
+ const buttons = [...nfButtonMultiSelect(selectors), ...extraButtons];
236
+ return this.handleInteractive({ interactiveMessage: { title, footer, image, video, thumbnail, header, contextInfo, buttons } }, jid, quoted, options);
592
237
  }
593
- const innerMsg = waMsgContent.message || waMsgContent;
594
- const msgKey = Object.keys(innerMsg).find(
595
- (k) => innerMsg[k] && typeof innerMsg[k] === "object",
596
- );
597
- if (msgKey) {
598
- innerMsg[msgKey].contextInfo = innerMsg[msgKey].contextInfo || {};
599
- innerMsg[msgKey].contextInfo.isGroupStatus = true;
600
- if (!innerMsg[msgKey].contextInfo.statusSourceType) {
601
- if (innerMsg.imageMessage)
602
- innerMsg[msgKey].contextInfo.statusSourceType = 0;
603
- else if (innerMsg.videoMessage)
604
- innerMsg[msgKey].contextInfo.statusSourceType = 1;
605
- else if (innerMsg.audioMessage)
606
- innerMsg[msgKey].contextInfo.statusSourceType = 3;
607
- else if (innerMsg.extendedTextMessage)
608
- innerMsg[msgKey].contextInfo.statusSourceType = 4;
609
- }
238
+
239
+ /**
240
+ * Nested List — legacy listMessage.
241
+ * Row yang punya `.rows` otomatis di-flatten jadi section baru.
242
+ *
243
+ * conn.sendMessage(jid, {
244
+ * nestedListMessage: {
245
+ * title: 'Menu',
246
+ * buttonText: 'Buka',
247
+ * footer: '...',
248
+ * sections: [
249
+ * { title: 'Kategori A', rows: [
250
+ * { rowId: 'a1', title: 'Item A1' },
251
+ * { title: 'Sub-Kategori', rows: [ ← ini jadi section baru
252
+ * { rowId: 'b1', title: 'Item B1' },
253
+ * ]}
254
+ * ]}
255
+ * ]
256
+ * }
257
+ * })
258
+ */
259
+ async handleNestedList(content, jid, quoted) {
260
+ const payload = buildNestedListMessage(content.nestedListMessage);
261
+ return await this.utils.generateWAMessageFromContent(jid, {
262
+ viewOnceMessage: { message: { messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2 }, ...payload } }
263
+ }, { quoted });
610
264
  }
611
- const finalMsg = {
612
- groupStatusMessageV2: {
613
- message: innerMsg,
614
- },
615
- };
616
- return await this.relayMessage(jid, finalMsg, {
617
- messageId: generateMessageID(),
618
- });
619
- }
620
- async sendStatusWhatsApp(content, jids = []) {
621
- const userJid = jidNormalizedUser(this.sock.authState.creds.me.id);
622
- const allUsers = new Set();
623
- allUsers.add(userJid);
624
- for (const id of jids) {
625
- if (isJidGroup(id)) {
626
- try {
627
- const metadata = await this.sock.groupMetadata(id);
628
- metadata.participants.forEach((p) =>
629
- allUsers.add(jidNormalizedUser(p.id)),
630
- );
631
- } catch (error) {
632
- this.config.logger.error(
633
- `Error getting metadata for group ${id}: ${error}`,
634
- );
265
+
266
+ async handleAlbum(content, jid, quoted) {
267
+ const array = content.albumMessage;
268
+ const album = await this.utils.generateWAMessageFromContent(jid, {
269
+ messageContextInfo: { messageSecret: randomBytes(32) },
270
+ albumMessage: {
271
+ expectedImageCount: array.filter(a => Object.hasOwn(a, 'image')).length,
272
+ expectedVideoCount: array.filter(a => Object.hasOwn(a, 'video')).length
273
+ }
274
+ }, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted, upload: this.waUploadToServer });
275
+ await this.relayMessage(jid, album.message, { messageId: album.key.id });
276
+ for (const item of array) {
277
+ const img = await this.utils.generateWAMessage(jid, item, { upload: this.waUploadToServer });
278
+ img.message.messageContextInfo = { messageSecret: randomBytes(32), messageAssociation: { associationType: 1, parentMessageKey: album.key }, participant: jid, forwardingScore: 0, isForwarded: false };
279
+ await this.relayMessage(jid, img.message, { messageId: img.key.id, quoted: { key: { remoteJid: album.key.remoteJid, id: album.key.id, fromMe: true, participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net' }, message: album.message } });
635
280
  }
636
- } else if (isPnUser(id)) {
637
- allUsers.add(jidNormalizedUser(id));
638
- }
281
+ return album;
639
282
  }
640
- const uniqueUsers = Array.from(allUsers);
641
- const getRandomHexColor = () =>
642
- "#" +
643
- Math.floor(Math.random() * 16777215)
644
- .toString(16)
645
- .padStart(6, "0");
646
- const isMedia = content.image || content.video || content.audio;
647
- const isAudio = !!content.audio;
648
- const messageContent = { ...content };
649
- if (isMedia && !isAudio) {
650
- if (messageContent.text) {
651
- messageContent.caption = messageContent.text;
652
- delete messageContent.text;
653
- }
654
- delete messageContent.ptt;
655
- delete messageContent.font;
656
- delete messageContent.backgroundColor;
657
- delete messageContent.textColor;
283
+
284
+ async handleEvent(content, jid, quoted) {
285
+ const e = content.eventMessage;
286
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
287
+ viewOnceMessage: { message: { messageContextInfo: { deviceListMetadata: {}, deviceListMetadataVersion: 2, messageSecret: randomBytes(32), supportPayload: JSON.stringify({ version: 2, is_ai_message: true, should_show_system_message: true, ticket_id: randomBytes(16).toString('hex') }) }, eventMessage: { contextInfo: { mentionedJid: [jid], participant: jid, remoteJid: 'status@broadcast' }, isCanceled: e.isCanceled || false, name: e.name, description: e.description, location: e.location || { degreesLatitude: 0, degreesLongitude: 0, name: 'Location' }, joinLink: e.joinLink || '', startTime: typeof e.startTime === 'string' ? parseInt(e.startTime, 10) : e.startTime || Date.now(), endTime: typeof e.endTime === 'string' ? parseInt(e.endTime, 10) : e.endTime || Date.now() + 3600000, extraGuestsAllowed: e.extraGuestsAllowed !== false } } }
288
+ }, { quoted });
289
+ await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
290
+ return msg;
658
291
  }
659
- if (isAudio) {
660
- delete messageContent.text;
661
- delete messageContent.caption;
662
- delete messageContent.font;
663
- delete messageContent.textColor;
292
+
293
+ async handlePollResult(content, jid, quoted) {
294
+ const p = content.pollResultMessage;
295
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
296
+ pollResultSnapshotMessage: { name: p.name, pollVotes: p.pollVotes.map(v => ({ optionName: v.optionName, optionVoteCount: typeof v.optionVoteCount === 'number' ? v.optionVoteCount.toString() : v.optionVoteCount })) }
297
+ }, { userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net', quoted });
298
+ await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
299
+ return msg;
664
300
  }
665
- const font = !isMedia
666
- ? content.font || Math.floor(Math.random() * 9)
667
- : undefined;
668
- const textColor = !isMedia
669
- ? content.textColor || getRandomHexColor()
670
- : undefined;
671
- const backgroundColor =
672
- !isMedia || isAudio
673
- ? content.backgroundColor || getRandomHexColor()
674
- : undefined;
675
- const ptt = isAudio
676
- ? typeof content.ptt === "boolean"
677
- ? content.ptt
678
- : true
679
- : undefined;
680
- const { getUrlInfo } = await import("../Utils/link-preview.js");
681
- const msg = await generateWAMessage(STORIES_JID, messageContent, {
682
- logger: this.config.logger,
683
- userJid,
684
- getUrlInfo: (text) =>
685
- getUrlInfo(text, {
686
- thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
687
- fetchOpts: { timeout: 3000, ...(this.config.options || {}) },
688
- logger: this.config.logger,
689
- uploadImage: this.config.generateHighQualityLinkPreview
690
- ? this.waUploadToServer
691
- : undefined,
692
- }),
693
- upload: this.waUploadToServer,
694
- mediaCache: this.config.mediaCache,
695
- options: this.config.options,
696
- font,
697
- textColor,
698
- backgroundColor,
699
- ptt,
700
- });
701
- await this.relayMessage(STORIES_JID, msg.message, {
702
- messageId: msg.key.id,
703
- statusJidList: uniqueUsers,
704
- additionalNodes: [
705
- {
706
- tag: "meta",
707
- attrs: {},
708
- content: [
709
- {
710
- tag: "mentioned_users",
711
- attrs: {},
712
- content: jids.map((jid) => ({
713
- tag: "to",
714
- attrs: { jid: jidNormalizedUser(jid) },
715
- })),
716
- },
717
- ],
718
- },
719
- ],
720
- });
721
- for (const id of jids) {
722
- try {
723
- const normalizedId = jidNormalizedUser(id);
724
- const isPrivate = isPnUser(normalizedId);
725
- const type = isPrivate
726
- ? "statusMentionMessage"
727
- : "groupStatusMentionMessage";
728
- const protocolMessage = {
729
- [type]: {
730
- message: {
731
- protocolMessage: {
732
- key: msg.key,
733
- type: 25,
734
- },
735
- },
736
- },
737
- messageContextInfo: {
738
- messageSecret: crypto.randomBytes(32),
739
- },
740
- };
741
- const statusMsg = await generateWAMessageFromContent(
742
- normalizedId,
743
- protocolMessage,
744
- {
745
- userJid: jidNormalizedUser(
746
- this.sock.authState?.creds?.me?.id || "",
747
- ),
748
- },
301
+
302
+ /**
303
+ * Group Status V2 — kirim story/status ke grup.
304
+ *
305
+ * Format groupStatusMessage:
306
+ *
307
+ * // Teks biasa
308
+ * { text: 'Halo grup!' }
309
+ *
310
+ * // Foto dengan caption
311
+ * { image: Buffer | { url: '...' }, caption: 'Caption foto' }
312
+ *
313
+ * // Video dengan caption
314
+ * { video: Buffer | { url: '...' }, caption: 'Caption video', gifPlayback?: true }
315
+ *
316
+ * // Audio (voice note)
317
+ * { audio: Buffer | { url: '...' }, ptt: true, seconds: 10 }
318
+ *
319
+ * // Audio biasa (musik)
320
+ * { audio: Buffer | { url: '...' }, ptt: false, mimetype: 'audio/mp4' }
321
+ *
322
+ * // Sticker
323
+ * { sticker: Buffer | { url: '...' } }
324
+ *
325
+ * // Dokumen
326
+ * { document: Buffer | { url: '...' }, mimetype: 'application/pdf', fileName: 'file.pdf', caption: 'Caption' }
327
+ *
328
+ * // Pre-built WAMessage (advanced)
329
+ * { message: { imageMessage: { ... } } }
330
+ *
331
+ * // Raw relay (forward story)
332
+ * { raw: <msgPayload> }
333
+ *
334
+ * Semua mode support field tambahan:
335
+ * backgroundColor?: number (ARGB hex, untuk teks/audio)
336
+ * textArgb?: number
337
+ * font?: number (0-5)
338
+ */
339
+ /**
340
+ * Group Status V2 — kirim story/status ke grup.
341
+ * messageSecret wajib ada supaya WA client bisa decrypt & tampilkan konten.
342
+ *
343
+ * PATCH (v3.2.10): sekarang menyertakan `additionalNodes` via
344
+ * buildInteractiveAdditionalNodes() di SETIAP relayMessage() call. Tanpa ini,
345
+ * node <meta is_vsn2="1"/> (yang sudah punya cabang logic-nya sendiri di
346
+ * Utils/messages.js buildInteractiveAdditionalNodes) tidak pernah benar-benar
347
+ * terkirim ke server, sehingga klien penerima tidak tahu payload ini harus
348
+ * dirender sebagai story/status grup — pesan tetap terkirim & ter-enkripsi
349
+ * normal, tapi tidak pernah muncul sebagai ring status untuk member lain.
350
+ */
351
+ async handleGroupStory(content, jid, quoted) {
352
+ const s = content.groupStatusMessage;
353
+ const secret = randomBytes(32);
354
+ const buildNodes = this.utils.buildInteractiveAdditionalNodes;
355
+
356
+ // Mode 1: raw relay langsung
357
+ if (s.raw) {
358
+ const additionalNodes = buildNodes ? buildNodes(jid, s.raw) : [];
359
+ return await this.relayMessage(jid, s.raw, {
360
+ messageId: this.bail.generateMessageID(),
361
+ additionalNodes
362
+ });
363
+ }
364
+
365
+ // Mode 2: inner WAMessage sudah disiapkan — wrap dengan secret
366
+ if (s.message) {
367
+ const wrapped = {
368
+ groupStatusMessageV2: {
369
+ message: {
370
+ messageContextInfo: {
371
+ messageSecret: secret,
372
+ deviceListMetadata: {},
373
+ deviceListMetadataVersion: 2
374
+ },
375
+ ...s.message
376
+ }
377
+ }
378
+ };
379
+ const additionalNodes = buildNodes ? buildNodes(jid, wrapped) : [];
380
+ return await this.relayMessage(jid, wrapped, {
381
+ messageId: this.bail.generateMessageID(),
382
+ additionalNodes
383
+ });
384
+ }
385
+
386
+ // Mode 3: generate dari media/teks
387
+ let innerMessage = {};
388
+ // PATCH: normalize mentions (terima nomor polos, bukan cuma JID lengkap — biar konsisten
389
+ // sama handleInteractive) dan sisipkan quoted-reply (stanzaId/participant/quotedMessage).
390
+ // Sebelumnya dua-duanya "keisi" secara visual tapi diam-diam gak ke-apply: s.mentions gak
391
+ // pernah dilewatin ke normalizeMentions(), dan param quoted malah belum ada sama sekali di
392
+ // signature function ini padahal messages-send.js (swgc & case 'GROUP_STORY') udah ngoper dia.
393
+ const normalizedMentions = normalizeMentions(s.mentions);
394
+ const quoteCtx = quoted?.key
395
+ ? {
396
+ stanzaId: quoted.key.id,
397
+ participant: quoted.key.participant || quoted.key.remoteJid,
398
+ quotedMessage: quoted.message
399
+ }
400
+ : {};
401
+ const mentionCtx = (normalizedMentions.length || Object.keys(quoteCtx).length)
402
+ ? { contextInfo: { ...quoteCtx, ...(normalizedMentions.length ? { mentionedJid: normalizedMentions } : {}) } }
403
+ : {};
404
+
405
+ if (s.text || (!s.image && !s.video && !s.gif && !s.audio && !s.sticker && !s.document)) {
406
+ // Teks
407
+ innerMessage = {
408
+ extendedTextMessage: {
409
+ text: s.text || s.caption || '',
410
+ ...(typeof s.backgroundColor !== 'undefined' ? { backgroundArgb: s.backgroundColor } : {}),
411
+ ...(typeof s.textArgb !== 'undefined' ? { textArgb: s.textArgb } : {}),
412
+ ...(typeof s.font !== 'undefined' ? { font: s.font } : {}),
413
+ ...mentionCtx
414
+ }
415
+ };
416
+ } else if (s.image) {
417
+ const media = await this.utils.prepareWAMessageMedia(
418
+ { image: s.image },
419
+ { upload: this.waUploadToServer }
420
+ );
421
+ if (s.caption) media.imageMessage.caption = s.caption;
422
+ if (mentionCtx.contextInfo) media.imageMessage.contextInfo = { ...media.imageMessage.contextInfo, ...mentionCtx.contextInfo };
423
+ innerMessage = media;
424
+ } else if (s.card) {
425
+ // Mode: canvas-rendered story card (gradient + title/body/footer text),
426
+ // see lib/Utils/story-card.js. `s.card` accepts the same options as
427
+ // renderStoryCard() — e.g. { title, body, footer, gradient, direction }.
428
+ const cardBuffer = await this.utils.renderStoryCard(s.card);
429
+ const media = await this.utils.prepareWAMessageMedia(
430
+ { image: cardBuffer },
431
+ { upload: this.waUploadToServer }
432
+ );
433
+ if (s.caption) media.imageMessage.caption = s.caption;
434
+ if (mentionCtx.contextInfo) media.imageMessage.contextInfo = { ...media.imageMessage.contextInfo, ...mentionCtx.contextInfo };
435
+ innerMessage = media;
436
+ } else if (s.gif) {
437
+ // Shorthand: { gif: Buffer | { url }, caption? } — dikirim sebagai video looping,
438
+ // sama seperti representasi GIF asli WhatsApp.
439
+ const media = await this.utils.prepareWAMessageMedia(
440
+ { video: s.gif },
441
+ { upload: this.waUploadToServer }
442
+ );
443
+ if (s.caption) media.videoMessage.caption = s.caption;
444
+ media.videoMessage.gifPlayback = true;
445
+ if (mentionCtx.contextInfo) media.videoMessage.contextInfo = { ...media.videoMessage.contextInfo, ...mentionCtx.contextInfo };
446
+ innerMessage = media;
447
+ } else if (s.video) {
448
+ const media = await this.utils.prepareWAMessageMedia(
449
+ { video: s.video },
450
+ { upload: this.waUploadToServer }
451
+ );
452
+ if (s.caption) media.videoMessage.caption = s.caption;
453
+ if (s.gifPlayback) media.videoMessage.gifPlayback = true;
454
+ if (s.seconds) media.videoMessage.seconds = s.seconds;
455
+ if (mentionCtx.contextInfo) media.videoMessage.contextInfo = { ...media.videoMessage.contextInfo, ...mentionCtx.contextInfo };
456
+ innerMessage = media;
457
+ } else if (s.audio) {
458
+ const media = await this.utils.prepareWAMessageMedia(
459
+ {
460
+ audio: s.audio,
461
+ ptt: s.ptt !== false,
462
+ ...(s.seconds ? { seconds: s.seconds } : {}),
463
+ ...(s.mimetype ? { mimetype: s.mimetype } : {})
464
+ },
465
+ {
466
+ upload: this.waUploadToServer,
467
+ // NOTE: backgroundColor harus lewat `options` (argumen ke-2), bukan payload
468
+ // media — prepareWAMessageMedia() cuma hitung backgroundArgb untuk ptt audio
469
+ // kalau options.backgroundColor keisi. Sebelumnya gak pernah diteruskan di sini,
470
+ // jadi backgroundColor pada audio story selalu diam-diam diabaikan.
471
+ ...(typeof s.backgroundColor !== 'undefined' ? { backgroundColor: s.backgroundColor } : {})
472
+ }
473
+ );
474
+ if (mentionCtx.contextInfo) media.audioMessage.contextInfo = { ...media.audioMessage.contextInfo, ...mentionCtx.contextInfo };
475
+ innerMessage = media;
476
+ } else if (s.sticker) {
477
+ const media = await this.utils.prepareWAMessageMedia(
478
+ { sticker: s.sticker },
479
+ { upload: this.waUploadToServer }
480
+ );
481
+ if (mentionCtx.contextInfo) media.stickerMessage.contextInfo = { ...media.stickerMessage.contextInfo, ...mentionCtx.contextInfo };
482
+ innerMessage = media;
483
+ } else if (s.document) {
484
+ const media = await this.utils.prepareWAMessageMedia(
485
+ {
486
+ document: s.document,
487
+ mimetype: s.mimetype || 'application/octet-stream',
488
+ fileName: s.fileName || 'file'
489
+ },
490
+ { upload: this.waUploadToServer }
491
+ );
492
+ if (s.caption && media.documentMessage) media.documentMessage.caption = s.caption;
493
+ if (s.fileName && media.documentMessage) media.documentMessage.fileName = s.fileName;
494
+ if (mentionCtx.contextInfo && media.documentMessage) media.documentMessage.contextInfo = { ...media.documentMessage.contextInfo, ...mentionCtx.contextInfo };
495
+ innerMessage = media;
496
+ } else {
497
+ innerMessage = await this.bail.generateWAMessageContent(s, { upload: this.waUploadToServer });
498
+ }
499
+
500
+ // PATCH V4 (diambil dari Ourin Baileys, kebukti jalan lewat testing user —
501
+ // lihat CHANGELOG): WA butuh contextInfo.isGroupStatus + statusSourceType di
502
+ // level pesan supaya klien nge-render sebagai ring status, bukan cuma nampil
503
+ // sebagai pesan grup biasa. additionalNodes <meta is_vsn2> di bawah TETAP
504
+ // dipertahankan (gak ada bukti itu bikin masalah), tapi contextInfo ini yang
505
+ // di implementasi Ourin kebukti jadi kunci utamanya — dan itu diverifikasi
506
+ // jalan buat foto & video langsung dari testing user, bukan cuma teori.
507
+ const statusMsgKey = Object.keys(innerMessage).find(
508
+ (k) => innerMessage[k] && typeof innerMessage[k] === 'object'
749
509
  );
750
- await this.relayMessage(normalizedId, statusMsg.message, {
751
- additionalNodes: [
752
- {
753
- tag: "meta",
754
- attrs: isPrivate
755
- ? { is_status_mention: "true" }
756
- : { is_group_status_mention: "true" },
757
- },
758
- ],
510
+ if (statusMsgKey) {
511
+ innerMessage[statusMsgKey].contextInfo = innerMessage[statusMsgKey].contextInfo || {};
512
+ innerMessage[statusMsgKey].contextInfo.isGroupStatus = true;
513
+ if (typeof innerMessage[statusMsgKey].contextInfo.statusSourceType === 'undefined') {
514
+ // Nilai ini persis enum StatusSourceType resmi di WAProto.proto:
515
+ // IMAGE=0, VIDEO=1, GIF=2, AUDIO=3, TEXT=4, MUSIC_STANDALONE=5.
516
+ // Implementasi Ourin sendiri cuma isi image/video/audio/text (gif ikut
517
+ // video); di sini gif dipisah ke nilai 2 miliknya sendiri karena memang
518
+ // ada di enum resminya. sticker & document SENGAJA gak diisi — gak ada
519
+ // nilai enum yang cocok buat keduanya (kemungkinan besar memang gak
520
+ // didukung sebagai tipe status asli oleh WhatsApp), sama seperti
521
+ // implementasi Ourin yang jadi rujukan di sini.
522
+ if (s.image || s.card) innerMessage[statusMsgKey].contextInfo.statusSourceType = 0;
523
+ else if (s.gif) innerMessage[statusMsgKey].contextInfo.statusSourceType = 2;
524
+ else if (s.video) innerMessage[statusMsgKey].contextInfo.statusSourceType = 1;
525
+ else if (s.audio) innerMessage[statusMsgKey].contextInfo.statusSourceType = 3;
526
+ else if (statusMsgKey === 'extendedTextMessage') innerMessage[statusMsgKey].contextInfo.statusSourceType = 4;
527
+ }
528
+ }
529
+
530
+ // Wrap dengan messageContextInfo + messageSecret — WAJIB supaya konten bisa ditampilkan
531
+ const wrapped = {
532
+ groupStatusMessageV2: {
533
+ message: {
534
+ messageContextInfo: {
535
+ messageSecret: secret,
536
+ deviceListMetadata: {},
537
+ deviceListMetadataVersion: 2
538
+ },
539
+ ...innerMessage
540
+ }
541
+ }
542
+ };
543
+
544
+ // Ini bagian yang tadinya hilang: <meta is_vsn2="1"/> baru benar-benar
545
+ // terpasang lewat additionalNodes di bawah ini.
546
+ const additionalNodes = buildNodes ? buildNodes(jid, wrapped) : [];
547
+
548
+ return await this.relayMessage(jid, wrapped, {
549
+ messageId: this.bail.generateMessageID(),
550
+ additionalNodes
759
551
  });
760
- await delay(2000);
761
- } catch (error) {
762
- this.config.logger.error(`Error sending to ${id}: ${error}`);
763
- }
764
552
  }
765
- return msg;
766
- }
553
+
554
+ /**
555
+ * Kirim WhatsApp Status (story) beneran ke `status@broadcast`, lengkap dengan
556
+ * statusJidList (siapa aja yang boleh lihat) dan status-mention follow-up
557
+ * (biar penerima yang di-mention dapet notif). Mendukung SEMUA tipe media
558
+ * (text/image/video/gif via video+gifPlayback/audio) — dipilih otomatis dari
559
+ * field yang ada di `content`, sama seperti bawaan generateWAMessage().
560
+ *
561
+ * jids: campuran nomor pribadi & JID grup — kalau grup, semua member-nya
562
+ * otomatis ditambahkan ke daftar penerima status (statusJidList) dan
563
+ * masing-masing dikirimi status-mention.
564
+ */
565
+ async sendStatusWhatsApp(content, jids = []) {
566
+ const { authState, groupMetadata, logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, httpRequestOptions, mediaCache, getUrlInfo } = this.utils;
567
+ const userJid = jidNormalizedUser(authState.creds.me.id);
568
+ const allUsers = new Set([userJid]);
569
+ for (const id of jids) {
570
+ if (isJidGroup(id)) {
571
+ try {
572
+ const metadata = await groupMetadata(id);
573
+ metadata.participants.forEach(p => allUsers.add(jidNormalizedUser(p.id)));
574
+ }
575
+ catch (error) {
576
+ logger?.error(`Error getting metadata for group ${id}: ${error}`);
577
+ }
578
+ }
579
+ else if (isPnUser(id)) {
580
+ allUsers.add(jidNormalizedUser(id));
581
+ }
582
+ }
583
+ const uniqueUsers = Array.from(allUsers);
584
+ const getRandomHexColor = () => '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0');
585
+ const isMedia = !!(content.image || content.video || content.audio);
586
+ const isAudio = !!content.audio;
587
+ const messageContent = { ...content };
588
+ if (isMedia && !isAudio) {
589
+ if (messageContent.text) {
590
+ messageContent.caption = messageContent.text;
591
+ delete messageContent.text;
592
+ }
593
+ delete messageContent.ptt;
594
+ delete messageContent.font;
595
+ delete messageContent.backgroundColor;
596
+ delete messageContent.textColor;
597
+ }
598
+ if (isAudio) {
599
+ delete messageContent.text;
600
+ delete messageContent.caption;
601
+ delete messageContent.font;
602
+ delete messageContent.textColor;
603
+ }
604
+ const font = !isMedia ? (content.font ?? Math.floor(Math.random() * 9)) : undefined;
605
+ const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
606
+ const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
607
+ const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
608
+ const msg = await this.utils.generateWAMessage(STORIES_JID, messageContent, {
609
+ logger,
610
+ userJid,
611
+ getUrlInfo: (text) => getUrlInfo(text, {
612
+ thumbnailWidth: linkPreviewImageThumbnailWidth,
613
+ fetchOpts: { timeout: 3000, ...(httpRequestOptions || {}) },
614
+ logger,
615
+ uploadImage: generateHighQualityLinkPreview ? this.waUploadToServer : undefined
616
+ }),
617
+ upload: this.waUploadToServer,
618
+ mediaCache,
619
+ options: httpRequestOptions,
620
+ font,
621
+ textColor,
622
+ backgroundColor,
623
+ ptt
624
+ });
625
+ await this.relayMessage(STORIES_JID, msg.message, {
626
+ messageId: msg.key.id,
627
+ statusJidList: uniqueUsers,
628
+ additionalNodes: [
629
+ {
630
+ tag: 'meta',
631
+ attrs: {},
632
+ content: [
633
+ {
634
+ tag: 'mentioned_users',
635
+ attrs: {},
636
+ content: jids.map(jid => ({ tag: 'to', attrs: { jid: jidNormalizedUser(jid) } }))
637
+ }
638
+ ]
639
+ }
640
+ ]
641
+ });
642
+ for (const id of jids) {
643
+ try {
644
+ const normalizedId = jidNormalizedUser(id);
645
+ const isPrivate = isPnUser(normalizedId);
646
+ const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
647
+ const protocolMessage = {
648
+ [type]: { message: { protocolMessage: { key: msg.key, type: 25 } } },
649
+ messageContextInfo: { messageSecret: randomBytes(32) }
650
+ };
651
+ const statusMsg = await this.utils.generateWAMessageFromContent(normalizedId, protocolMessage, {
652
+ userJid: jidNormalizedUser(authState?.creds?.me?.id || '')
653
+ });
654
+ await this.relayMessage(normalizedId, statusMsg.message, {
655
+ additionalNodes: [
656
+ {
657
+ tag: 'meta',
658
+ attrs: isPrivate ? { is_status_mention: 'true' } : { is_group_status_mention: 'true' }
659
+ }
660
+ ]
661
+ });
662
+ await delay(2000);
663
+ }
664
+ catch (error) {
665
+ logger?.error(`Error sending to ${id}: ${error}`);
666
+ }
667
+ }
668
+ return msg;
669
+ }
767
670
  }
768
- //# sourceMappingURL=dugong.js.map
671
+
672
+ export default ExtendedMessageBuilder;