@badzz88/baileys 8.4.6 → 8.4.9

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 (250) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1055 -337
  3. package/WAProto/WAProto.proto +850 -32
  4. package/WAProto/index.d.ts +4913 -25
  5. package/WAProto/index.js +14074 -98
  6. package/package.json +96 -131
  7. package/src/Defaults/index.js +201 -0
  8. package/src/Defaults/phonenumber-mcc.json +223 -0
  9. package/src/Signal/Group/ciphertext-message.js +15 -0
  10. package/src/Signal/Group/group-session-builder.js +92 -0
  11. package/src/Signal/Group/group_cipher.js +89 -0
  12. package/src/Signal/Group/index.js +136 -0
  13. package/src/Signal/Group/keyhelper.js +73 -0
  14. package/src/Signal/Group/sender-chain-key.js +32 -0
  15. package/src/Signal/Group/sender-key-distribution-message.js +66 -0
  16. package/src/Signal/Group/sender-key-message.js +69 -0
  17. package/src/Signal/Group/sender-key-name.js +50 -0
  18. package/src/Signal/Group/sender-key-record.js +44 -0
  19. package/src/Signal/Group/sender-key-state.js +97 -0
  20. package/src/Signal/Group/sender-message-key.js +30 -0
  21. package/src/Signal/libsignal.js +470 -0
  22. package/src/Signal/lid-mapping.js +262 -0
  23. package/src/Socket/Client/index.js +30 -0
  24. package/src/Socket/Client/types.js +13 -0
  25. package/src/Socket/Client/websocket.js +62 -0
  26. package/src/Socket/aigroups.js +240 -0
  27. package/src/Socket/business.js +422 -0
  28. package/src/Socket/chats.js +2374 -0
  29. package/src/Socket/communities.js +580 -0
  30. package/src/Socket/graphql.js +915 -0
  31. package/src/Socket/groups.js +812 -0
  32. package/src/Socket/index.js +37 -0
  33. package/src/Socket/interactive-handler.js +579 -0
  34. package/src/Socket/interop.js +566 -0
  35. package/src/Socket/managed-account.js +214 -0
  36. package/src/Socket/messages-recv.js +3012 -0
  37. package/src/Socket/messages-send.js +2163 -0
  38. package/{lib → src}/Socket/mex.js +11 -5
  39. package/src/Socket/newsletter.js +1057 -0
  40. package/src/Socket/privacy.js +452 -0
  41. package/src/Socket/registration.js +434 -0
  42. package/src/Socket/socket.js +1079 -0
  43. package/src/Socket/text-router.js +67 -0
  44. package/src/Socket/username.js +234 -0
  45. package/src/Store/index.js +36 -0
  46. package/src/Store/make-cache-manager-store.js +90 -0
  47. package/src/Store/make-in-memory-store.js +506 -0
  48. package/src/Store/make-ordered-dictionary.js +81 -0
  49. package/src/Store/object-repository.js +29 -0
  50. package/src/Types/Auth.js +38 -0
  51. package/src/Types/Bussines.js +2 -0
  52. package/src/Types/Call.js +2 -0
  53. package/src/Types/Chat.js +4 -0
  54. package/src/Types/Contact.js +2 -0
  55. package/src/Types/Events.js +2 -0
  56. package/src/Types/GroupMetadata.js +2 -0
  57. package/src/Types/Label.js +27 -0
  58. package/src/Types/LabelAssociation.js +9 -0
  59. package/src/Types/Message.js +95 -0
  60. package/src/Types/Newsletter.js +152 -0
  61. package/src/Types/Product.js +2 -0
  62. package/src/Types/Signal.js +2 -0
  63. package/src/Types/Socket.js +2 -0
  64. package/src/Types/State.js +70 -0
  65. package/src/Types/USync.js +2 -0
  66. package/src/Types/index.js +54 -0
  67. package/src/Utils/auth-utils.js +306 -0
  68. package/src/Utils/browser-utils.js +114 -0
  69. package/src/Utils/business.js +247 -0
  70. package/src/Utils/chat-utils.js +1272 -0
  71. package/src/Utils/consumer-application.js +107 -0
  72. package/src/Utils/crypto.js +125 -0
  73. package/src/Utils/decode-wa-message.js +808 -0
  74. package/src/Utils/event-buffer.js +586 -0
  75. package/src/Utils/generics.js +640 -0
  76. package/src/Utils/group-history.js +60 -0
  77. package/src/Utils/history.js +244 -0
  78. package/src/Utils/identity-change-handler.js +52 -0
  79. package/src/Utils/index.js +53 -0
  80. package/src/Utils/jid-display-normalization.js +218 -0
  81. package/src/Utils/link-preview.js +143 -0
  82. package/src/Utils/logger.js +9 -0
  83. package/src/Utils/lt-hash.js +10 -0
  84. package/src/Utils/make-mutex.js +36 -0
  85. package/src/Utils/message-composer.js +479 -0
  86. package/src/Utils/message-inspect.js +400 -0
  87. package/src/Utils/message-retry-manager.js +231 -0
  88. package/src/Utils/messages-media.js +943 -0
  89. package/src/Utils/messages.js +2490 -0
  90. package/src/Utils/meta-ai-msmsg.js +133 -0
  91. package/src/Utils/noise-handler.js +194 -0
  92. package/src/Utils/offline-node-processor.js +42 -0
  93. package/src/Utils/pre-key-manager.js +107 -0
  94. package/src/Utils/process-message.js +1047 -0
  95. package/src/Utils/reporting-utils.js +262 -0
  96. package/src/Utils/signal.js +192 -0
  97. package/src/Utils/stanza-ack.js +74 -0
  98. package/src/Utils/sync-action-utils.js +54 -0
  99. package/src/Utils/tc-token-utils.js +161 -0
  100. package/src/Utils/use-multi-file-auth-state.js +121 -0
  101. package/src/Utils/validate-connection.js +248 -0
  102. package/src/Utils/voip-rekey.js +22 -0
  103. package/src/WABinary/constants.js +1304 -0
  104. package/src/WABinary/decode.js +377 -0
  105. package/src/WABinary/encode.js +58 -0
  106. package/src/WABinary/generic-utils.js +148 -0
  107. package/src/WABinary/index.js +33 -0
  108. package/src/WABinary/jid-utils.js +374 -0
  109. package/src/WABinary/types.js +2 -0
  110. package/src/WAM/BinaryInfo.js +13 -0
  111. package/src/WAM/constants.js +39486 -0
  112. package/src/WAM/encode.js +142 -0
  113. package/src/WAM/index.js +31 -0
  114. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
  115. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +100 -0
  116. package/src/WAUSync/Protocols/USyncContactProtocol.js +60 -0
  117. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
  118. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  119. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +74 -0
  120. package/src/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
  121. package/src/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  122. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
  123. package/src/WAUSync/Protocols/USyncStatusProtocol.js +44 -0
  124. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  125. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
  126. package/src/WAUSync/Protocols/index.js +40 -0
  127. package/src/WAUSync/USyncBackoff.js +31 -0
  128. package/src/WAUSync/USyncQuery.js +204 -0
  129. package/src/WAUSync/USyncUser.js +58 -0
  130. package/src/WAUSync/index.js +32 -0
  131. package/src/antiban.js +4726 -0
  132. package/{lib → src}/index.js +48 -16
  133. package/lib/Defaults/baileys-version.json +0 -3
  134. package/lib/Defaults/index.js +0 -137
  135. package/lib/Defaults/phonenumber-mcc.json +0 -223
  136. package/lib/Signal/Group/Protocols.js +0 -269
  137. package/lib/Signal/Group/ciphertext-message.js +0 -12
  138. package/lib/Signal/Group/group-session-builder.js +0 -30
  139. package/lib/Signal/Group/group_cipher.js +0 -82
  140. package/lib/Signal/Group/index.js +0 -12
  141. package/lib/Signal/Group/keyhelper.js +0 -18
  142. package/lib/Signal/Group/queue-job.js +0 -57
  143. package/lib/Signal/Group/sender-chain-key.js +0 -26
  144. package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
  145. package/lib/Signal/Group/sender-key-message.js +0 -66
  146. package/lib/Signal/Group/sender-key-name.js +0 -48
  147. package/lib/Signal/Group/sender-key-record.js +0 -41
  148. package/lib/Signal/Group/sender-key-state.js +0 -84
  149. package/lib/Signal/Group/sender-message-key.js +0 -26
  150. package/lib/Signal/libsignal.js +0 -432
  151. package/lib/Signal/lid-mapping.js +0 -277
  152. package/lib/Socket/Client/abstract-socket-client.js +0 -13
  153. package/lib/Socket/Client/index.js +0 -3
  154. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  155. package/lib/Socket/Client/types.js +0 -11
  156. package/lib/Socket/Client/web-socket-client.js +0 -62
  157. package/lib/Socket/Client/websocket.js +0 -54
  158. package/lib/Socket/business.js +0 -379
  159. package/lib/Socket/chats.js +0 -1193
  160. package/lib/Socket/communities.js +0 -431
  161. package/lib/Socket/community.js +0 -392
  162. package/lib/Socket/dugong.js +0 -637
  163. package/lib/Socket/groups.js +0 -374
  164. package/lib/Socket/index.js +0 -12
  165. package/lib/Socket/luxu.js +0 -387
  166. package/lib/Socket/messages-recv.js +0 -1916
  167. package/lib/Socket/messages-send.js +0 -1459
  168. package/lib/Socket/newsletter.js +0 -253
  169. package/lib/Socket/registration.js +0 -167
  170. package/lib/Socket/socket.js +0 -950
  171. package/lib/Socket/username.js +0 -146
  172. package/lib/Socket/usync.js +0 -69
  173. package/lib/Store/index.js +0 -10
  174. package/lib/Store/keyed-db.js +0 -108
  175. package/lib/Store/make-cache-manager-store.js +0 -85
  176. package/lib/Store/make-in-memory-store.js +0 -198
  177. package/lib/Store/make-ordered-dictionary.js +0 -75
  178. package/lib/Store/object-repository.js +0 -32
  179. package/lib/Types/Auth.js +0 -2
  180. package/lib/Types/Bussines.js +0 -2
  181. package/lib/Types/Call.js +0 -2
  182. package/lib/Types/Chat.js +0 -8
  183. package/lib/Types/Contact.js +0 -2
  184. package/lib/Types/Events.js +0 -2
  185. package/lib/Types/GroupMetadata.js +0 -2
  186. package/lib/Types/Label.js +0 -25
  187. package/lib/Types/LabelAssociation.js +0 -7
  188. package/lib/Types/Message.js +0 -11
  189. package/lib/Types/Mex.js +0 -37
  190. package/lib/Types/Newsletter.js +0 -38
  191. package/lib/Types/Product.js +0 -2
  192. package/lib/Types/Signal.js +0 -2
  193. package/lib/Types/Socket.js +0 -3
  194. package/lib/Types/State.js +0 -56
  195. package/lib/Types/USync.js +0 -2
  196. package/lib/Types/index.js +0 -26
  197. package/lib/Utils/auth-utils.js +0 -302
  198. package/lib/Utils/baileys-event-stream.js +0 -63
  199. package/lib/Utils/browser-utils.js +0 -48
  200. package/lib/Utils/business.js +0 -231
  201. package/lib/Utils/chat-utils.js +0 -873
  202. package/lib/Utils/companion-reg-client-utils.js +0 -35
  203. package/lib/Utils/crypto.js +0 -118
  204. package/lib/Utils/decode-wa-message.js +0 -350
  205. package/lib/Utils/event-buffer.js +0 -622
  206. package/lib/Utils/generics.js +0 -399
  207. package/lib/Utils/history.js +0 -134
  208. package/lib/Utils/identity-change-handler.js +0 -50
  209. package/lib/Utils/index.js +0 -23
  210. package/lib/Utils/link-preview.js +0 -85
  211. package/lib/Utils/logger.js +0 -3
  212. package/lib/Utils/lt-hash.js +0 -8
  213. package/lib/Utils/make-mutex.js +0 -33
  214. package/lib/Utils/message-composer.js +0 -273
  215. package/lib/Utils/message-retry-manager.js +0 -265
  216. package/lib/Utils/messages-media.js +0 -788
  217. package/lib/Utils/messages.js +0 -1260
  218. package/lib/Utils/noise-handler.js +0 -201
  219. package/lib/Utils/offline-node-processor.js +0 -40
  220. package/lib/Utils/pre-key-manager.js +0 -106
  221. package/lib/Utils/process-message.js +0 -630
  222. package/lib/Utils/reporting-utils.js +0 -258
  223. package/lib/Utils/signal.js +0 -202
  224. package/lib/Utils/stanza-ack.js +0 -38
  225. package/lib/Utils/sync-action-utils.js +0 -49
  226. package/lib/Utils/tc-token-utils.js +0 -163
  227. package/lib/Utils/use-multi-file-auth-state.js +0 -121
  228. package/lib/Utils/validate-connection.js +0 -204
  229. package/lib/WABinary/constants.js +0 -1301
  230. package/lib/WABinary/decode.js +0 -262
  231. package/lib/WABinary/encode.js +0 -220
  232. package/lib/WABinary/generic-utils.js +0 -204
  233. package/lib/WABinary/index.js +0 -6
  234. package/lib/WABinary/jid-utils.js +0 -98
  235. package/lib/WABinary/types.js +0 -2
  236. package/lib/WAM/BinaryInfo.js +0 -10
  237. package/lib/WAM/constants.js +0 -22853
  238. package/lib/WAM/encode.js +0 -150
  239. package/lib/WAM/index.js +0 -4
  240. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -52
  241. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -54
  242. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
  243. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -38
  244. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
  245. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
  246. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
  247. package/lib/WAUSync/Protocols/index.js +0 -6
  248. package/lib/WAUSync/USyncQuery.js +0 -98
  249. package/lib/WAUSync/USyncUser.js +0 -31
  250. package/lib/WAUSync/index.js +0 -4
@@ -1,637 +0,0 @@
1
- const WAProto = require('../../WAProto').proto;
2
- const crypto = require('crypto');
3
- const Utils_1 = require("../Utils");
4
- const WABinary_1 = require("../WABinary");
5
-
6
- class kikyy {
7
- constructor(utils, waUploadToServer, relayMessageFn, config, sock) {
8
- this.utils = utils;
9
- this.relayMessage = relayMessageFn;
10
- this.waUploadToServer = waUploadToServer;
11
- this.config = config;
12
- this.sock = sock;
13
-
14
- this.bail = {
15
- generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
16
- generateMessageID: Utils_1.generateMessageID,
17
- getContentType: (msg) => Object.keys(msg.message || {})[0]
18
- };
19
- }
20
-
21
- detectType(content) {
22
- if (content.requestPaymentMessage) return 'PAYMENT';
23
- if (content.productMessage) return 'PRODUCT';
24
- if (content.interactiveMessage) return 'INTERACTIVE';
25
- if (content.albumMessage) return 'ALBUM';
26
- if (content.eventMessage) return 'EVENT';
27
- if (content.pollResultMessage) return 'POLL_RESULT';
28
- if (content.groupStatusMessage) return 'GROUP_STORY';
29
- return null;
30
- }
31
-
32
- async handlePayment(content, quoted) {
33
- const data = content.requestPaymentMessage;
34
- let notes = {};
35
-
36
- if (data.sticker?.stickerMessage) {
37
- notes = {
38
- stickerMessage: {
39
- ...data.sticker.stickerMessage,
40
- contextInfo: {
41
- stanzaId: quoted?.key?.id,
42
- participant: quoted?.key?.participant || content.sender,
43
- quotedMessage: quoted?.message
44
- }
45
- }
46
- };
47
- } else if (data.note) {
48
- notes = {
49
- extendedTextMessage: {
50
- text: data.note,
51
- contextInfo: {
52
- stanzaId: quoted?.key?.id,
53
- participant: quoted?.key?.participant || content.sender,
54
- quotedMessage: quoted?.message
55
- }
56
- }
57
- };
58
- }
59
-
60
- return {
61
- requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
62
- expiryTimestamp: data.expiry || 0,
63
- amount1000: data.amount || 0,
64
- currencyCodeIso4217: data.currency || "IDR",
65
- requestFrom: data.from || "0@s.whatsapp.net",
66
- noteMessage: notes,
67
- background: data.background ?? {
68
- id: "DEFAULT",
69
- placeholderArgb: 0xFFF0F0F0
70
- }
71
- })
72
- };
73
- }
74
-
75
- async handleProduct(content, jid, quoted) {
76
- const {
77
- title,
78
- description,
79
- thumbnail,
80
- productId,
81
- retailerId,
82
- url,
83
- body = "",
84
- footer = "",
85
- buttons = [],
86
- priceAmount1000 = null,
87
- currencyCode = "IDR"
88
- } = content.productMessage;
89
-
90
- let productImage;
91
-
92
- if (Buffer.isBuffer(thumbnail)) {
93
- const { imageMessage } = await this.utils.generateWAMessageContent(
94
- { image: thumbnail },
95
- { upload: this.waUploadToServer }
96
- );
97
- productImage = imageMessage;
98
- } else if (typeof thumbnail === 'object' && thumbnail.url) {
99
- const { imageMessage } = await this.utils.generateWAMessageContent(
100
- { image: { url: thumbnail.url }},
101
- { upload: this.waUploadToServer }
102
- );
103
- productImage = imageMessage;
104
- }
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
-
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
-
155
- let media = null;
156
- let mediaType = null;
157
-
158
- if (thumbnail) {
159
- media = await this.utils.prepareWAMessageMedia(
160
- { image: { url: thumbnail } },
161
- { upload: this.waUploadToServer }
162
- );
163
- mediaType = 'image';
164
- } else if (image) {
165
- if (typeof image === 'object' && image.url) {
166
- media = await this.utils.prepareWAMessageMedia(
167
- { image: { url: image.url } },
168
- { upload: this.waUploadToServer }
169
- );
170
- } else {
171
- media = await this.utils.prepareWAMessageMedia(
172
- { image: image },
173
- { upload: this.waUploadToServer }
174
- );
175
- }
176
- mediaType = 'image';
177
- } else if (video) {
178
- if (typeof video === 'object' && video.url) {
179
- media = await this.utils.prepareWAMessageMedia(
180
- { video: { url: video.url } },
181
- { upload: this.waUploadToServer }
182
- );
183
- } else {
184
- media = await this.utils.prepareWAMessageMedia(
185
- { video: video },
186
- { upload: this.waUploadToServer }
187
- );
188
- }
189
- mediaType = 'video';
190
- } else if (document) {
191
- let documentPayload = {
192
- document: document
193
- };
194
- if (jpegThumbnail) {
195
- if (typeof jpegThumbnail === 'object' && jpegThumbnail.url) {
196
- documentPayload.jpegThumbnail = { url: jpegThumbnail.url };
197
- } else {
198
- documentPayload.jpegThumbnail = jpegThumbnail;
199
- }
200
- }
201
-
202
- media = await this.utils.prepareWAMessageMedia(
203
- documentPayload,
204
- { upload: this.waUploadToServer }
205
- );
206
- if (fileName) {
207
- media.documentMessage.fileName = fileName;
208
- }
209
- if (mimetype) {
210
- media.documentMessage.mimetype = mimetype;
211
- }
212
- mediaType = 'document';
213
- }
214
- let interactiveMessage = {
215
- body: { text: title || "" },
216
- footer: { text: footer || "" }
217
- };
218
- if (buttons && buttons.length > 0) {
219
- interactiveMessage.nativeFlowMessage = {
220
- buttons: buttons
221
- };
222
- if (nativeFlowMessage) {
223
- interactiveMessage.nativeFlowMessage = {
224
- ...interactiveMessage.nativeFlowMessage,
225
- ...nativeFlowMessage
226
- };
227
- }
228
- } else if (nativeFlowMessage) {
229
- interactiveMessage.nativeFlowMessage = nativeFlowMessage;
230
- }
231
-
232
- if (media) {
233
- interactiveMessage.header = {
234
- title: header || "",
235
- hasMediaAttachment: true,
236
- ...media
237
- };
238
- } else {
239
- interactiveMessage.header = {
240
- title: header || "",
241
- hasMediaAttachment: false
242
- };
243
- }
244
-
245
- let finalContextInfo = {};
246
- if (contextInfo) {
247
- finalContextInfo = {
248
- mentionedJid: contextInfo.mentionedJid || [],
249
- forwardingScore: contextInfo.forwardingScore || 0,
250
- isForwarded: contextInfo.isForwarded || false,
251
- ...contextInfo
252
- };
253
- }
254
-
255
- if (externalAdReply) {
256
- finalContextInfo.externalAdReply = {
257
- title: externalAdReply.title || "",
258
- body: externalAdReply.body || "",
259
- mediaType: externalAdReply.mediaType || 1,
260
- thumbnailUrl: externalAdReply.thumbnailUrl || "",
261
- mediaUrl: externalAdReply.mediaUrl || "",
262
- sourceUrl: externalAdReply.sourceUrl || "",
263
- showAdAttribution: externalAdReply.showAdAttribution || false,
264
- renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
265
- ...externalAdReply
266
- };
267
- }
268
-
269
- if (Object.keys(finalContextInfo).length > 0) {
270
- interactiveMessage.contextInfo = finalContextInfo;
271
- }
272
- return {
273
- interactiveMessage: interactiveMessage
274
- };
275
- }
276
-
277
- async handleAlbum(content, jid, quoted) {
278
- const array = content.albumMessage;
279
- const album = await this.utils.generateWAMessageFromContent(jid, {
280
- messageContextInfo: {
281
- messageSecret: crypto.randomBytes(32),
282
- },
283
- albumMessage: {
284
- expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
285
- expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
286
- },
287
- }, {
288
- userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
289
- quoted,
290
- upload: this.waUploadToServer
291
- });
292
-
293
- await this.relayMessage(jid, album.message, {
294
- messageId: album.key.id,
295
- });
296
-
297
- for (let content of array) {
298
- const img = await this.utils.generateWAMessage(jid, content, {
299
- upload: this.waUploadToServer,
300
- });
301
-
302
- img.message.messageContextInfo = {
303
- messageSecret: crypto.randomBytes(32),
304
- messageAssociation: {
305
- associationType: 1,
306
- parentMessageKey: album.key,
307
- },
308
- participant: "0@s.whatsapp.net",
309
- remoteJid: "status@broadcast",
310
- forwardingScore: 99999,
311
- isForwarded: true,
312
- mentionedJid: [jid],
313
- starred: true,
314
- labels: ["Y", "Important"],
315
- isHighlighted: true,
316
- businessMessageForwardInfo: {
317
- businessOwnerJid: jid,
318
- },
319
- dataSharingContext: {
320
- showMmDisclosure: true,
321
- },
322
- };
323
-
324
- img.message.forwardedNewsletterMessageInfo = {
325
- newsletterJid: "0@newsletter",
326
- serverMessageId: 1,
327
- newsletterName: `WhatsApp`,
328
- contentType: 1,
329
- timestamp: new Date().toISOString(),
330
- senderName: "kikyy dugonggg",
331
- content: "Text Message",
332
- priority: "high",
333
- status: "sent",
334
- };
335
-
336
- img.message.disappearingMode = {
337
- initiator: 3,
338
- trigger: 4,
339
- initiatorDeviceJid: jid,
340
- initiatedByExternalService: true,
341
- initiatedByUserDevice: true,
342
- initiatedBySystem: true,
343
- initiatedByServer: true,
344
- initiatedByAdmin: true,
345
- initiatedByUser: true,
346
- initiatedByApp: true,
347
- initiatedByBot: true,
348
- initiatedByMe: true,
349
- };
350
-
351
- await this.relayMessage(jid, img.message, {
352
- messageId: img.key.id,
353
- quoted: {
354
- key: {
355
- remoteJid: album.key.remoteJid,
356
- id: album.key.id,
357
- fromMe: true,
358
- participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
359
- },
360
- message: album.message,
361
- },
362
- });
363
- }
364
- return album;
365
- }
366
-
367
- async handleEvent(content, jid, quoted) {
368
- const eventData = content.eventMessage;
369
-
370
- const msg = await this.utils.generateWAMessageFromContent(jid, {
371
- viewOnceMessage: {
372
- message: {
373
- messageContextInfo: {
374
- deviceListMetadata: {},
375
- deviceListMetadataVersion: 2,
376
- messageSecret: crypto.randomBytes(32),
377
- supportPayload: JSON.stringify({
378
- version: 2,
379
- is_ai_message: true,
380
- should_show_system_message: true,
381
- ticket_id: crypto.randomBytes(16).toString('hex')
382
- })
383
- },
384
- eventMessage: {
385
- contextInfo: {
386
- mentionedJid: [jid],
387
- participant: jid,
388
- remoteJid: "status@broadcast",
389
- forwardedNewsletterMessageInfo: {
390
- newsletterName: "shenvn.",
391
- newsletterJid: "120363430179804706@newsletter",
392
- serverMessageId: 1
393
- }
394
- },
395
- isCanceled: eventData.isCanceled || false,
396
- name: eventData.name,
397
- description: eventData.description,
398
- location: eventData.location || {
399
- degreesLatitude: 0,
400
- degreesLongitude: 0,
401
- name: "Location"
402
- },
403
- joinLink: eventData.joinLink || '',
404
- startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
405
- endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
406
- extraGuestsAllowed: eventData.extraGuestsAllowed !== false
407
- }
408
- }
409
- }
410
- }, { quoted });
411
-
412
- await this.relayMessage(jid, msg.message, {
413
- messageId: msg.key.id
414
- });
415
- return msg;
416
- }
417
-
418
- async handlePollResult(content, jid, quoted) {
419
- const pollData = content.pollResultMessage;
420
-
421
- const msg = await this.utils.generateWAMessageFromContent(jid, {
422
- pollResultSnapshotMessage: {
423
- name: pollData.name,
424
- pollVotes: pollData.pollVotes.map(vote => ({
425
- optionName: vote.optionName,
426
- optionVoteCount: typeof vote.optionVoteCount === 'number'
427
- ? vote.optionVoteCount.toString()
428
- : vote.optionVoteCount
429
- }))
430
- }
431
- }, {
432
- userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
433
- quoted
434
- });
435
-
436
- await this.relayMessage(jid, msg.message, {
437
- messageId: msg.key.id
438
- });
439
-
440
- return msg;
441
- }
442
-
443
- async handleGroupStory(content, jid, quoted) {
444
- const storyData = content.groupStatusMessage;
445
- let waMsgContent;
446
-
447
- if (storyData.message) {
448
- waMsgContent = storyData;
449
- } else {
450
- if (typeof this.bail?.generateWAMessageContent === "function") {
451
- waMsgContent = await this.bail.generateWAMessageContent(storyData, {
452
- upload: this.waUploadToServer
453
- });
454
- } else if (typeof this.utils?.generateWAMessageContent === "function") {
455
- waMsgContent = await this.utils.generateWAMessageContent(storyData, {
456
- upload: this.waUploadToServer
457
- });
458
- } else if (typeof this.utils?.prepareMessageContent === "function") {
459
- waMsgContent = await this.utils.prepareMessageContent(storyData, {
460
- upload: this.waUploadToServer
461
- });
462
- } else {
463
- waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
464
- upload: this.waUploadToServer
465
- });
466
- }
467
- }
468
-
469
- let msg = {
470
- message: {
471
- groupStatusMessageV2: {
472
- message: waMsgContent.message || waMsgContent
473
- }
474
- }
475
- };
476
-
477
- return await this.relayMessage(jid, msg.message, {
478
- messageId: this.bail.generateMessageID()
479
- });
480
- }
481
-
482
- async sendStatusWhatsApp(content, jids = []) {
483
- const userJid = WABinary_1.jidNormalizedUser(this.sock.authState.creds.me.id);
484
- let allUsers = new Set();
485
- allUsers.add(userJid);
486
-
487
- for (const id of jids) {
488
- const isGroup = WABinary_1.isJidGroup(id);
489
- const isPrivate = WABinary_1.isJidUser(id);
490
-
491
- if (isGroup) {
492
- try {
493
- const metadata = await this.sock.groupMetadata(id);
494
- const participants = metadata.participants.map(p => WABinary_1.jidNormalizedUser(p.id));
495
- participants.forEach(jid => allUsers.add(jid));
496
- } catch (error) {
497
- this.config.logger.error(`Error getting metadata for group ${id}: ${error}`);
498
- }
499
- } else if (isPrivate) {
500
- allUsers.add(WABinary_1.jidNormalizedUser(id));
501
- }
502
- }
503
-
504
- const uniqueUsers = Array.from(allUsers);
505
- const getRandomHexColor = () => "#" + Math.floor(Math.random() * 16777215).toString(16).padStart(6, "0");
506
-
507
- const isMedia = content.image || content.video || content.audio;
508
- const isAudio = !!content.audio;
509
-
510
- const messageContent = { ...content };
511
-
512
- if (isMedia && !isAudio) {
513
- if (messageContent.text) {
514
- messageContent.caption = messageContent.text;
515
- delete messageContent.text;
516
- }
517
- delete messageContent.ptt;
518
- delete messageContent.font;
519
- delete messageContent.backgroundColor;
520
- delete messageContent.textColor;
521
- }
522
-
523
- if (isAudio) {
524
- delete messageContent.text;
525
- delete messageContent.caption;
526
- delete messageContent.font;
527
- delete messageContent.textColor;
528
- }
529
-
530
- const font = !isMedia ? (content.font || Math.floor(Math.random() * 9)) : undefined;
531
- const textColor = !isMedia ? (content.textColor || getRandomHexColor()) : undefined;
532
- const backgroundColor = (!isMedia || isAudio) ? (content.backgroundColor || getRandomHexColor()) : undefined;
533
- const ptt = isAudio ? (typeof content.ptt === 'boolean' ? content.ptt : true) : undefined;
534
-
535
- let msg;
536
- let mediaHandle;
537
-
538
- try {
539
- const link_preview_1 = require("../Utils/link-preview");
540
-
541
- msg = await Utils_1.generateWAMessage(WABinary_1.STORIES_JID, messageContent, {
542
- logger: this.config.logger,
543
- userJid,
544
- getUrlInfo: text => link_preview_1.getUrlInfo(text, {
545
- thumbnailWidth: this.config.linkPreviewImageThumbnailWidth,
546
- fetchOpts: { timeout: 3000, ...this.config.options || {} },
547
- logger: this.config.logger,
548
- uploadImage: this.config.generateHighQualityLinkPreview ? this.waUploadToServer : undefined
549
- }),
550
- upload: async (encFilePath, opts) => {
551
- const up = await this.waUploadToServer(encFilePath, { ...opts });
552
- mediaHandle = up.handle;
553
- return up;
554
- },
555
- mediaCache: this.config.mediaCache,
556
- options: this.config.options,
557
- font,
558
- textColor,
559
- backgroundColor,
560
- ptt
561
- });
562
- } catch (error) {
563
- this.config.logger.error(`Error generating message: ${error}`);
564
- throw error;
565
- }
566
-
567
- await this.relayMessage(WABinary_1.STORIES_JID, msg.message, {
568
- messageId: msg.key.id,
569
- statusJidList: uniqueUsers,
570
- additionalNodes: [
571
- {
572
- tag: 'meta',
573
- attrs: {},
574
- content: [
575
- {
576
- tag: 'mentioned_users',
577
- attrs: {},
578
- content: jids.map(jid => ({
579
- tag: 'to',
580
- attrs: { jid: WABinary_1.jidNormalizedUser(jid) }
581
- }))
582
- }
583
- ]
584
- }
585
- ]
586
- });
587
-
588
- for (const id of jids) {
589
- try {
590
- const normalizedId = WABinary_1.jidNormalizedUser(id);
591
- const isPrivate = WABinary_1.isJidUser(normalizedId);
592
- const type = isPrivate ? 'statusMentionMessage' : 'groupStatusMentionMessage';
593
-
594
- const protocolMessage = {
595
- [type]: {
596
- message: {
597
- protocolMessage: {
598
- key: msg.key,
599
- type: 25
600
- }
601
- }
602
- },
603
- messageContextInfo: {
604
- messageSecret: crypto.randomBytes(32)
605
- }
606
- };
607
-
608
- const statusMsg = await Utils_1.generateWAMessageFromContent(
609
- normalizedId,
610
- protocolMessage,
611
- {}
612
- );
613
-
614
- await this.relayMessage(
615
- normalizedId,
616
- statusMsg.message,
617
- {
618
- additionalNodes: [{
619
- tag: 'meta',
620
- attrs: isPrivate ?
621
- { is_status_mention: 'true' } :
622
- { is_group_status_mention: 'true' }
623
- }]
624
- }
625
- );
626
-
627
- await Utils_1.delay(2000);
628
- } catch (error) {
629
- this.config.logger.error(`Error sending to ${id}: ${error}`);
630
- }
631
- }
632
-
633
- return msg;
634
- }
635
- }
636
-
637
- module.exports = kikyy;