@yannajah/baileys 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/LICENSE +23 -0
  2. package/LICENSE.jexkcode +21 -0
  3. package/README.md +41 -2
  4. package/THIRD_PARTY_NOTICES.md +15 -0
  5. package/WAProto/index.d.ts +16922 -0
  6. package/WAProto/index.js +122451 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/baileys-version.json +3 -0
  9. package/lib/Defaults/index.js +156 -0
  10. package/lib/Defaults/phonenumber-mcc.json +223 -0
  11. package/lib/Signal/Group/ciphertext-message.js +15 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.js +96 -0
  14. package/lib/Signal/Group/index.js +57 -0
  15. package/lib/Signal/Group/keyhelper.js +55 -0
  16. package/lib/Signal/Group/queue-job.js +57 -0
  17. package/lib/Signal/Group/sender-chain-key.js +34 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  19. package/lib/Signal/Group/sender-key-message.js +69 -0
  20. package/lib/Signal/Group/sender-key-name.js +51 -0
  21. package/lib/Signal/Group/sender-key-record.js +53 -0
  22. package/lib/Signal/Group/sender-key-state.js +99 -0
  23. package/lib/Signal/Group/sender-message-key.js +29 -0
  24. package/lib/Signal/libsignal.js +174 -0
  25. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  26. package/lib/Socket/Client/index.js +19 -0
  27. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  28. package/lib/Socket/Client/web-socket-client.js +87 -0
  29. package/lib/Socket/business.js +260 -0
  30. package/lib/Socket/chats.js +1002 -0
  31. package/lib/Socket/clutch-handler.d.ts +27 -0
  32. package/lib/Socket/clutch-handler.js +880 -0
  33. package/lib/Socket/groups.js +317 -0
  34. package/lib/Socket/index.js +97 -0
  35. package/lib/Socket/messages-recv.js +1154 -0
  36. package/lib/Socket/messages-send.js +946 -0
  37. package/lib/Socket/newsletter.js +411 -0
  38. package/lib/Socket/registration.js +166 -0
  39. package/lib/Socket/socket.js +688 -0
  40. package/lib/Socket/usync.js +70 -0
  41. package/lib/Store/index.js +10 -0
  42. package/lib/Store/make-cache-manager-store.js +83 -0
  43. package/lib/Store/make-in-memory-store.js +457 -0
  44. package/lib/Store/make-ordered-dictionary.js +81 -0
  45. package/lib/Store/object-repository.js +27 -0
  46. package/lib/Types/Auth.js +2 -0
  47. package/lib/Types/Call.js +2 -0
  48. package/lib/Types/Chat.js +4 -0
  49. package/lib/Types/Contact.js +2 -0
  50. package/lib/Types/Events.js +2 -0
  51. package/lib/Types/GroupMetadata.js +2 -0
  52. package/lib/Types/Label.js +27 -0
  53. package/lib/Types/LabelAssociation.js +9 -0
  54. package/lib/Types/Message.js +10 -0
  55. package/lib/Types/Mex.d.ts +2 -0
  56. package/lib/Types/Mex.js +98 -0
  57. package/lib/Types/Newsletter.js +41 -0
  58. package/lib/Types/Product.js +2 -0
  59. package/lib/Types/Signal.js +2 -0
  60. package/lib/Types/Socket.js +2 -0
  61. package/lib/Types/State.js +2 -0
  62. package/lib/Types/USync.js +2 -0
  63. package/lib/Types/index.js +43 -0
  64. package/lib/Utils/MessageBuilder.d.ts +215 -0
  65. package/lib/Utils/MessageBuilder.js +4001 -0
  66. package/lib/Utils/a2ui.d.ts +202 -0
  67. package/lib/Utils/a2ui.js +770 -0
  68. package/lib/Utils/auth-utils.js +206 -0
  69. package/lib/Utils/baileys-event-stream.js +63 -0
  70. package/lib/Utils/bot-signature.d.ts +22 -0
  71. package/lib/Utils/bot-signature.js +125 -0
  72. package/lib/Utils/business.js +234 -0
  73. package/lib/Utils/channel-manager.d.ts +39 -0
  74. package/lib/Utils/channel-manager.js +312 -0
  75. package/lib/Utils/chat-utils.js +729 -0
  76. package/lib/Utils/crypto.js +151 -0
  77. package/lib/Utils/decode-wa-message.js +198 -0
  78. package/lib/Utils/event-buffer.js +514 -0
  79. package/lib/Utils/extras.d.ts +449 -0
  80. package/lib/Utils/extras.js +1377 -0
  81. package/lib/Utils/generics.js +574 -0
  82. package/lib/Utils/history.js +96 -0
  83. package/lib/Utils/html-app.d.ts +39 -0
  84. package/lib/Utils/html-app.js +307 -0
  85. package/lib/Utils/index.d.ts +23 -0
  86. package/lib/Utils/index.js +51 -0
  87. package/lib/Utils/link-preview.js +93 -0
  88. package/lib/Utils/logger.js +7 -0
  89. package/lib/Utils/lt-hash.js +51 -0
  90. package/lib/Utils/make-mutex.js +43 -0
  91. package/lib/Utils/message-retry-manager.d.ts +42 -0
  92. package/lib/Utils/message-retry-manager.js +309 -0
  93. package/lib/Utils/messages-media.js +861 -0
  94. package/lib/Utils/messages.js +1085 -0
  95. package/lib/Utils/metaai.d.ts +438 -0
  96. package/lib/Utils/metaai.js +911 -0
  97. package/lib/Utils/mini-app.d.ts +93 -0
  98. package/lib/Utils/mini-app.js +453 -0
  99. package/lib/Utils/modern-messages.d.ts +150 -0
  100. package/lib/Utils/modern-messages.js +498 -0
  101. package/lib/Utils/native-flow.d.ts +14 -0
  102. package/lib/Utils/native-flow.js +122 -0
  103. package/lib/Utils/newsletter-status.d.ts +163 -0
  104. package/lib/Utils/newsletter-status.js +695 -0
  105. package/lib/Utils/noise-handler.js +155 -0
  106. package/lib/Utils/payment-messages.d.ts +59 -0
  107. package/lib/Utils/payment-messages.js +164 -0
  108. package/lib/Utils/process-message.js +334 -0
  109. package/lib/Utils/reporting-utils.d.ts +12 -0
  110. package/lib/Utils/reporting-utils.js +271 -0
  111. package/lib/Utils/scheduled-message.d.ts +82 -0
  112. package/lib/Utils/scheduled-message.js +126 -0
  113. package/lib/Utils/signal.js +153 -0
  114. package/lib/Utils/spr.d.ts +26 -0
  115. package/lib/Utils/spr.js +525 -0
  116. package/lib/Utils/status-stickers.d.ts +78 -0
  117. package/lib/Utils/status-stickers.js +275 -0
  118. package/lib/Utils/telegram-adapter.d.ts +28 -0
  119. package/lib/Utils/telegram-adapter.js +285 -0
  120. package/lib/Utils/use-multi-file-auth-state.js +153 -0
  121. package/lib/Utils/validate-connection.js +235 -0
  122. package/lib/WABinary/constants.js +40 -0
  123. package/lib/WABinary/decode.js +252 -0
  124. package/lib/WABinary/encode.js +265 -0
  125. package/lib/WABinary/generic-utils.js +178 -0
  126. package/lib/WABinary/index.js +21 -0
  127. package/lib/WABinary/jid-utils.js +81 -0
  128. package/lib/WABinary/types.js +2 -0
  129. package/lib/WAM/BinaryInfo.js +13 -0
  130. package/lib/WAM/constants.js +15350 -0
  131. package/lib/WAM/encode.js +155 -0
  132. package/lib/WAM/index.js +19 -0
  133. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  134. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  135. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  136. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  137. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  138. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  139. package/lib/WAUSync/Protocols/index.js +20 -0
  140. package/lib/WAUSync/USyncQuery.js +89 -0
  141. package/lib/WAUSync/USyncUser.js +26 -0
  142. package/lib/WAUSync/index.js +19 -0
  143. package/lib/index.d.ts +20 -0
  144. package/lib/index.js +99 -0
  145. package/package.json +110 -4
@@ -0,0 +1,498 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { proto } = require("../../WAProto");
4
+
5
+ const requireObject = (value, name) => {
6
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
7
+ throw new TypeError(`${name} must be an object`)
8
+ }
9
+ return value
10
+ }
11
+
12
+ const requireKey = (value, name = 'key') => {
13
+ requireObject(value, name)
14
+ if (!value.id) {
15
+ throw new TypeError(`${name}.id is required`)
16
+ }
17
+ return value
18
+ }
19
+
20
+ const enumValue = (enumObject, value, fallback) => {
21
+ if (typeof value === 'number') return value
22
+ if (typeof value === 'string') {
23
+ const key = value.trim().toUpperCase()
24
+ if (key in enumObject) return enumObject[key]
25
+ }
26
+ return fallback
27
+ }
28
+
29
+ const STATUS_NOTIFICATION_TYPES = exports.STATUS_NOTIFICATION_TYPES = Object.freeze({
30
+ ...proto.Message.StatusNotificationMessage.StatusNotificationType,
31
+ STATUS_GROUP_STATUS_REPLY: 4
32
+ })
33
+
34
+ const toSeconds = value => value instanceof Date ? Math.floor(value.getTime() / 1000) : value
35
+ const toMilliseconds = value => value instanceof Date ? value.getTime() : value
36
+
37
+ const makeInnerCommentMessage = content => {
38
+ const data = requireObject(content, 'comment.content')
39
+ if (data.raw && typeof data.raw === 'object') return data.raw
40
+ if (typeof data.text === 'string') {
41
+ return {
42
+ extendedTextMessage: proto.Message.ExtendedTextMessage.create({
43
+ text: data.text,
44
+ contextInfo: data.contextInfo
45
+ })
46
+ }
47
+ }
48
+ const keys = Object.keys(data)
49
+ if (keys.some(key => key.endsWith('Message'))) return data
50
+ throw new TypeError('comment.content supports text, raw, or protobuf message fields')
51
+ }
52
+
53
+ const makeQuestionMessage = exports.makeQuestionMessage = input => {
54
+ const data = requireObject(input, 'question')
55
+ if (typeof data.text !== 'string' || !data.text.length) {
56
+ throw new TypeError('question.text is required')
57
+ }
58
+ return {
59
+ questionMessage: proto.Message.FutureProofMessage.create({
60
+ message: {
61
+ extendedTextMessage: proto.Message.ExtendedTextMessage.create({
62
+ text: data.text,
63
+ contextInfo: {
64
+ ...(data.contextInfo || {}),
65
+ isQuestion: true
66
+ }
67
+ })
68
+ }
69
+ })
70
+ }
71
+ }
72
+
73
+ const makeQuestionResponseMessage = exports.makeQuestionResponseMessage = input => {
74
+ const data = requireObject(input, 'questionResponse')
75
+ requireKey(data.key, 'questionResponse.key')
76
+ return {
77
+ questionResponseMessage: proto.Message.QuestionResponseMessage.create({
78
+ key: data.key,
79
+ text: data.text ?? ''
80
+ })
81
+ }
82
+ }
83
+
84
+ const makeQuestionReplyMessage = exports.makeQuestionReplyMessage = input => {
85
+ const data = requireObject(input, 'questionReply')
86
+ if (typeof data.text !== 'string' || !data.text.length) {
87
+ throw new TypeError('questionReply.text is required')
88
+ }
89
+ if (data.serverQuestionId === undefined || data.serverQuestionId === null) {
90
+ throw new TypeError('questionReply.serverQuestionId is required')
91
+ }
92
+ const quoted = {
93
+ serverQuestionId: Number(data.serverQuestionId)
94
+ }
95
+ if (data.quotedQuestion) quoted.quotedQuestion = data.quotedQuestion
96
+ if (data.quotedResponse) quoted.quotedResponse = data.quotedResponse
97
+ return {
98
+ questionReplyMessage: proto.Message.FutureProofMessage.create({
99
+ message: {
100
+ extendedTextMessage: proto.Message.ExtendedTextMessage.create({
101
+ text: data.text,
102
+ contextInfo: {
103
+ ...(data.contextInfo || {}),
104
+ questionReplyQuotedMessage: quoted
105
+ }
106
+ })
107
+ }
108
+ })
109
+ }
110
+ }
111
+
112
+ const makeStatusQuestionAnswerMessage = exports.makeStatusQuestionAnswerMessage = input => {
113
+ const data = requireObject(input, 'statusQuestionAnswer')
114
+ requireKey(data.key, 'statusQuestionAnswer.key')
115
+ return {
116
+ statusQuestionAnswerMessage: proto.Message.StatusQuestionAnswerMessage.create({
117
+ key: data.key,
118
+ text: data.text ?? ''
119
+ })
120
+ }
121
+ }
122
+
123
+ const makeStatusQuotedMessage = exports.makeStatusQuotedMessage = input => {
124
+ const data = requireObject(input, 'statusQuoted')
125
+ requireKey(data.originalStatusId, 'statusQuoted.originalStatusId')
126
+ const type = enumValue(
127
+ proto.Message.StatusQuotedMessage.StatusQuotedMessageType,
128
+ data.type,
129
+ proto.Message.StatusQuotedMessage.StatusQuotedMessageType.QUESTION_ANSWER
130
+ )
131
+ return {
132
+ statusQuotedMessage: proto.Message.StatusQuotedMessage.create({
133
+ type,
134
+ text: data.text,
135
+ thumbnail: data.thumbnail,
136
+ originalStatusId: data.originalStatusId
137
+ })
138
+ }
139
+ }
140
+
141
+ const makeStatusStickerInteractionMessage = exports.makeStatusStickerInteractionMessage = input => {
142
+ const data = requireObject(input, 'statusStickerInteraction')
143
+ requireKey(data.key, 'statusStickerInteraction.key')
144
+ if (!data.stickerKey) {
145
+ throw new TypeError('statusStickerInteraction.stickerKey is required')
146
+ }
147
+ const type = enumValue(
148
+ proto.Message.StatusStickerInteractionMessage.StatusStickerType,
149
+ data.type,
150
+ proto.Message.StatusStickerInteractionMessage.StatusStickerType.REACTION
151
+ )
152
+ return {
153
+ statusStickerInteractionMessage: proto.Message.StatusStickerInteractionMessage.create({
154
+ key: data.key,
155
+ stickerKey: data.stickerKey,
156
+ type
157
+ })
158
+ }
159
+ }
160
+
161
+ const makeStatusNotificationMessage = exports.makeStatusNotificationMessage = input => {
162
+ const data = requireObject(input, 'statusNotification')
163
+ requireKey(data.responseMessageKey, 'statusNotification.responseMessageKey')
164
+ requireKey(data.originalMessageKey, 'statusNotification.originalMessageKey')
165
+ const type = enumValue(
166
+ STATUS_NOTIFICATION_TYPES,
167
+ data.type,
168
+ STATUS_NOTIFICATION_TYPES.UNKNOWN
169
+ )
170
+ return {
171
+ statusNotificationMessage: proto.Message.StatusNotificationMessage.create({
172
+ responseMessageKey: data.responseMessageKey,
173
+ originalMessageKey: data.originalMessageKey,
174
+ type
175
+ })
176
+ }
177
+ }
178
+
179
+ const makeNewsletterAdminInviteMessage = exports.makeNewsletterAdminInviteMessage = input => {
180
+ const data = requireObject(input, 'newsletterAdminInvite')
181
+ if (!data.newsletterJid) {
182
+ throw new TypeError('newsletterAdminInvite.newsletterJid is required')
183
+ }
184
+ return {
185
+ newsletterAdminInviteMessage: proto.Message.NewsletterAdminInviteMessage.create({
186
+ newsletterJid: data.newsletterJid,
187
+ newsletterName: data.newsletterName,
188
+ jpegThumbnail: data.jpegThumbnail,
189
+ caption: data.caption,
190
+ inviteExpiration: data.inviteExpiration,
191
+ contextInfo: data.contextInfo
192
+ })
193
+ }
194
+ }
195
+
196
+ const makeNewsletterFollowerInviteMessage = exports.makeNewsletterFollowerInviteMessage = input => {
197
+ const data = requireObject(input, 'newsletterFollowerInvite')
198
+ if (!data.newsletterJid) {
199
+ throw new TypeError('newsletterFollowerInvite.newsletterJid is required')
200
+ }
201
+ return {
202
+ newsletterFollowerInviteMessageV2: proto.Message.NewsletterFollowerInviteMessage.create({
203
+ newsletterJid: data.newsletterJid,
204
+ newsletterName: data.newsletterName,
205
+ jpegThumbnail: data.jpegThumbnail,
206
+ caption: data.caption,
207
+ contextInfo: data.contextInfo
208
+ })
209
+ }
210
+ }
211
+
212
+ const makePollAddOptionMessage = exports.makePollAddOptionMessage = input => {
213
+ const data = requireObject(input, 'pollAddOption')
214
+ requireKey(data.pollCreationMessageKey, 'pollAddOption.pollCreationMessageKey')
215
+ const addOption = typeof data.option === 'string'
216
+ ? { optionName: data.option }
217
+ : data.addOption || data.option
218
+ if (!addOption?.optionName) {
219
+ throw new TypeError('pollAddOption.option is required')
220
+ }
221
+ return {
222
+ pollAddOptionMessage: proto.Message.PollAddOptionMessage.create({
223
+ pollCreationMessageKey: data.pollCreationMessageKey,
224
+ addOption,
225
+ metadata: data.metadata
226
+ })
227
+ }
228
+ }
229
+
230
+ const makeCommentMessage = exports.makeCommentMessage = input => {
231
+ const data = requireObject(input, 'comment')
232
+ requireKey(data.targetMessageKey, 'comment.targetMessageKey')
233
+ const message = data.message || (data.content ? makeInnerCommentMessage(data.content) : null)
234
+ requireObject(message, 'comment.message')
235
+ return {
236
+ commentMessage: proto.Message.CommentMessage.create({
237
+ message,
238
+ targetMessageKey: data.targetMessageKey
239
+ })
240
+ }
241
+ }
242
+
243
+ const makeEventInviteMessage = exports.makeEventInviteMessage = input => {
244
+ const data = requireObject(input, 'eventInvite')
245
+ if (!data.eventId) {
246
+ throw new TypeError('eventInvite.eventId is required')
247
+ }
248
+ return {
249
+ eventInviteMessage: proto.Message.EventInviteMessage.create({
250
+ contextInfo: data.contextInfo,
251
+ eventId: data.eventId,
252
+ eventTitle: data.eventTitle,
253
+ jpegThumbnail: data.jpegThumbnail,
254
+ startTime: toSeconds(data.startTime),
255
+ caption: data.caption,
256
+ isCanceled: data.isCanceled,
257
+ endTime: toSeconds(data.endTime),
258
+ callLink: data.callLink
259
+ })
260
+ }
261
+ }
262
+
263
+ const makeScheduledCallCreationMessage = exports.makeScheduledCallCreationMessage = input => {
264
+ const data = requireObject(input, 'scheduledCall')
265
+ if (!data.scheduledTimestampMs) {
266
+ throw new TypeError('scheduledCall.scheduledTimestampMs is required')
267
+ }
268
+ const callType = enumValue(
269
+ proto.Message.ScheduledCallCreationMessage.CallType,
270
+ data.callType,
271
+ proto.Message.ScheduledCallCreationMessage.CallType.UNKNOWN
272
+ )
273
+ return {
274
+ scheduledCallCreationMessage: proto.Message.ScheduledCallCreationMessage.create({
275
+ scheduledTimestampMs: toMilliseconds(data.scheduledTimestampMs),
276
+ callType,
277
+ title: data.title
278
+ })
279
+ }
280
+ }
281
+
282
+ const makeScheduledCallEditMessage = exports.makeScheduledCallEditMessage = input => {
283
+ const data = requireObject(input, 'scheduledCallEdit')
284
+ requireKey(data.key, 'scheduledCallEdit.key')
285
+ const editType = enumValue(
286
+ proto.Message.ScheduledCallEditMessage.EditType,
287
+ data.editType,
288
+ proto.Message.ScheduledCallEditMessage.EditType.CANCEL
289
+ )
290
+ return {
291
+ scheduledCallEditMessage: proto.Message.ScheduledCallEditMessage.create({
292
+ key: data.key,
293
+ editType
294
+ })
295
+ }
296
+ }
297
+
298
+ const makeGroupStatusReactionMessage = exports.makeGroupStatusReactionMessage = input => {
299
+ const data = requireObject(input, 'groupStatusReaction')
300
+ requireKey(data.key, 'groupStatusReaction.key')
301
+ return {
302
+ groupStatusMessageV2: proto.Message.FutureProofMessage.create({
303
+ message: {
304
+ reactionMessage: proto.Message.ReactionMessage.create({
305
+ key: data.key,
306
+ text: data.text ?? '',
307
+ groupingKey: data.groupingKey,
308
+ senderTimestampMs: data.senderTimestampMs || Date.now()
309
+ })
310
+ }
311
+ })
312
+ }
313
+ }
314
+
315
+ const makeNewsletterStatusAttribution = exports.makeNewsletterStatusAttribution = input => {
316
+ const data = requireObject(input, 'newsletterStatus')
317
+ if (!data.newsletterJid) {
318
+ throw new TypeError('newsletterStatus.newsletterJid is required')
319
+ }
320
+ if (data.messageId === undefined || data.messageId === null) {
321
+ throw new TypeError('newsletterStatus.messageId is required')
322
+ }
323
+ return proto.StatusAttribution.create({
324
+ type: proto.StatusAttribution.Type.NEWSLETTER_STATUS,
325
+ actionUrl: data.actionUrl,
326
+ statusReshare: {
327
+ source: proto.StatusAttribution.StatusReshare.Source.CHANNEL_RESHARE,
328
+ metadata: {
329
+ duration: data.duration,
330
+ channelJid: data.newsletterJid,
331
+ channelMessageId: Number(data.messageId),
332
+ hasMultipleReshares: data.hasMultipleReshares ?? false
333
+ }
334
+ }
335
+ })
336
+ }
337
+
338
+ const makeGroupStatusAttribution = exports.makeGroupStatusAttribution = input => {
339
+ const data = requireObject(input, 'groupStatusAttribution')
340
+ if (!data.authorJid) {
341
+ throw new TypeError('groupStatusAttribution.authorJid is required')
342
+ }
343
+ return proto.StatusAttribution.create({
344
+ type: proto.StatusAttribution.Type.GROUP_STATUS,
345
+ actionUrl: data.actionUrl,
346
+ groupStatus: {
347
+ authorJid: data.authorJid
348
+ }
349
+ })
350
+ }
351
+
352
+ const STATUS_AUDIENCE_DEFAULT_LIST_NAME = exports.STATUS_AUDIENCE_DEFAULT_LIST_NAME = 'Close friends'
353
+ const STATUS_AUDIENCE_DEFAULT_EMOJI = exports.STATUS_AUDIENCE_DEFAULT_EMOJI = '⭐'
354
+
355
+ const makeStatusAudienceMetadata = exports.makeStatusAudienceMetadata = input => {
356
+ const data = typeof input === 'string' ? { listName: input } : requireObject(input, 'statusAudience')
357
+ const audienceType = enumValue(
358
+ proto.ContextInfo.StatusAudienceMetadata.AudienceType,
359
+ data.audienceType,
360
+ proto.ContextInfo.StatusAudienceMetadata.AudienceType.CLOSE_FRIENDS
361
+ )
362
+ const listName = data.listName === undefined ? STATUS_AUDIENCE_DEFAULT_LIST_NAME : String(data.listName)
363
+ const listEmoji = data.listEmoji === undefined ? STATUS_AUDIENCE_DEFAULT_EMOJI : String(data.listEmoji)
364
+ return proto.ContextInfo.StatusAudienceMetadata.create({
365
+ audienceType,
366
+ listName,
367
+ listEmoji
368
+ })
369
+ }
370
+
371
+ const makeMessageAssociation = exports.makeMessageAssociation = input => {
372
+ const data = requireObject(input, 'messageAssociation')
373
+ const parentMessageKey = data.parentMessageKey ?? data.key
374
+ requireKey(parentMessageKey, 'messageAssociation.parentMessageKey')
375
+ const associationType = enumValue(
376
+ proto.MessageAssociation.AssociationType,
377
+ data.associationType ?? data.type,
378
+ proto.MessageAssociation.AssociationType.UNKNOWN
379
+ )
380
+ return proto.MessageAssociation.create({
381
+ associationType,
382
+ parentMessageKey,
383
+ messageIndex: data.messageIndex
384
+ })
385
+ }
386
+
387
+ const makeStatusAddYoursAssociation = exports.makeStatusAddYoursAssociation = input => {
388
+ const data = input && typeof input === 'object' && !Array.isArray(input) && input.id
389
+ ? { key: input }
390
+ : requireObject(input, 'addYours')
391
+ const parentMessageKey = data.key ?? data.parentMessageKey
392
+ requireKey(parentMessageKey, 'addYours.key')
393
+ const associationType = enumValue(
394
+ proto.MessageAssociation.AssociationType,
395
+ data.type ?? data.associationType,
396
+ proto.MessageAssociation.AssociationType.STATUS_ADD_YOURS
397
+ )
398
+ return proto.MessageAssociation.create({
399
+ associationType,
400
+ parentMessageKey,
401
+ messageIndex: data.messageIndex
402
+ })
403
+ }
404
+
405
+ const makeStatusMentionMessage = exports.makeStatusMentionMessage = input => {
406
+ const data = requireObject(input, 'statusMention')
407
+ requireKey(data.key, 'statusMention.key')
408
+ const field = data.group ? 'groupStatusMentionMessage' : 'statusMentionMessage'
409
+ return {
410
+ [field]: proto.Message.FutureProofMessage.create({
411
+ message: {
412
+ protocolMessage: proto.Message.ProtocolMessage.create({
413
+ key: data.key,
414
+ type: proto.Message.ProtocolMessage.Type.STATUS_MENTION_MESSAGE
415
+ })
416
+ }
417
+ })
418
+ }
419
+ }
420
+
421
+ const modernBuilders = [
422
+ ['question', makeQuestionMessage],
423
+ ['questionReply', makeQuestionReplyMessage],
424
+ ['questionResponse', makeQuestionResponseMessage],
425
+ ['statusQuestionAnswer', makeStatusQuestionAnswerMessage],
426
+ ['statusQuoted', makeStatusQuotedMessage],
427
+ ['statusStickerInteraction', makeStatusStickerInteractionMessage],
428
+ ['statusNotification', makeStatusNotificationMessage],
429
+ ['newsletterAdminInvite', makeNewsletterAdminInviteMessage],
430
+ ['newsletterFollowerInvite', makeNewsletterFollowerInviteMessage],
431
+ ['pollAddOption', makePollAddOptionMessage],
432
+ ['comment', makeCommentMessage],
433
+ ['eventInvite', makeEventInviteMessage],
434
+ ['scheduledCall', makeScheduledCallCreationMessage],
435
+ ['scheduledCallEdit', makeScheduledCallEditMessage],
436
+ ['groupStatusReaction', makeGroupStatusReactionMessage],
437
+ ['statusMention', makeStatusMentionMessage]
438
+ ]
439
+
440
+ const prepareModernMessageContent = exports.prepareModernMessageContent = content => {
441
+ if (!content || typeof content !== 'object' || Array.isArray(content)) return content
442
+ let output = { ...content }
443
+ const attributions = Array.isArray(output.contextInfo?.statusAttributions)
444
+ ? [...output.contextInfo.statusAttributions]
445
+ : []
446
+ if (output.newsletterStatus) {
447
+ attributions.push(makeNewsletterStatusAttribution(output.newsletterStatus))
448
+ delete output.newsletterStatus
449
+ }
450
+ if (output.groupStatusAttribution) {
451
+ attributions.push(makeGroupStatusAttribution(output.groupStatusAttribution))
452
+ delete output.groupStatusAttribution
453
+ }
454
+ if (Array.isArray(output.statusAttributions)) {
455
+ attributions.push(...output.statusAttributions)
456
+ delete output.statusAttributions
457
+ }
458
+ const carried = []
459
+ const audience = output.statusAudience
460
+ if (audience !== undefined && audience !== null) {
461
+ carried.push('statusAudience')
462
+ output.contextInfo = {
463
+ ...(output.contextInfo || {}),
464
+ statusAudienceMetadata: makeStatusAudienceMetadata(audience)
465
+ }
466
+ delete output.statusAudience
467
+ }
468
+ if (attributions.length) {
469
+ output.contextInfo = {
470
+ ...(output.contextInfo || {}),
471
+ statusAttributions: attributions
472
+ }
473
+ }
474
+ if (output.addYours !== undefined && output.addYours !== null) {
475
+ carried.push('addYours')
476
+ output.messageAssociation = makeStatusAddYoursAssociation(output.addYours)
477
+ delete output.addYours
478
+ }
479
+ else if (output.messageAssociation !== undefined && output.messageAssociation !== null) {
480
+ carried.push('messageAssociation')
481
+ output.messageAssociation = makeMessageAssociation(output.messageAssociation)
482
+ }
483
+ for (const [key, builder] of modernBuilders) {
484
+ if (output[key] !== undefined && output[key] !== null) {
485
+ if (carried.length) {
486
+ throw new TypeError(
487
+ `${carried.join(' and ')} cannot be combined with ${key}: ${key} builds its own message and keeps no room for them. `
488
+ + 'Build it with the low-level makers and generateWAMessageFromContent instead.'
489
+ )
490
+ }
491
+ return {
492
+ raw: true,
493
+ ...builder(output[key])
494
+ }
495
+ }
496
+ }
497
+ return output
498
+ }
@@ -0,0 +1,14 @@
1
+ export const NATIVE_FLOW_NAMES: readonly string[];
2
+ export const WEB_SUPPORTED_INTERACTIVE_FLOWS: readonly string[];
3
+ export const NATIVE_FLOW_BUTTON_LIMIT: {
4
+ readonly quickReply: 10;
5
+ readonly other: 3;
6
+ };
7
+ export const getNativeFlowNameByButtonName: (name: string) => string | undefined;
8
+ export const isWebSupportedButtonName: (name: string) => boolean;
9
+ export const checkNativeFlowButtons: (buttons: any[]) => {
10
+ ok: boolean;
11
+ limit: number;
12
+ problems: string[];
13
+ unsupported: string[];
14
+ };
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkNativeFlowButtons = exports.isWebSupportedButtonName = exports.getNativeFlowNameByButtonName = exports.NATIVE_FLOW_BUTTON_LIMIT = exports.WEB_SUPPORTED_INTERACTIVE_FLOWS = exports.NATIVE_FLOW_NAMES = void 0;
4
+
5
+ exports.NATIVE_FLOW_NAMES = Object.freeze([
6
+ 'booking_confirmation',
7
+ 'order_details',
8
+ 'order_status',
9
+ 'payment_status',
10
+ 'payment_method',
11
+ 'payment_reminder',
12
+ 'message_with_link',
13
+ 'message_with_link_status',
14
+ 'quick_reply',
15
+ 'cta_call',
16
+ 'cta_url',
17
+ 'cta_catalog',
18
+ 'catalog_message',
19
+ 'payment_info',
20
+ 'cta_copy',
21
+ 'mixed',
22
+ 'galaxy_message',
23
+ 'cta_app',
24
+ 'call_permission_request',
25
+ 'payment_request',
26
+ 'api_signup',
27
+ 'inapp_signup',
28
+ 'form_message',
29
+ 'menu_options',
30
+ 'a2ui_reply_action',
31
+ 'address_message',
32
+ 'mpm'
33
+ ]);
34
+
35
+ const BUTTON_NAME_TO_FLOW = Object.freeze({
36
+ review_and_pay: 'order_details',
37
+ payment_info: 'payment_info',
38
+ review_order: 'order_status',
39
+ order_status: 'order_status',
40
+ payment_status: 'payment_status',
41
+ payment_method: 'payment_method',
42
+ open_webview: 'message_with_link',
43
+ message_with_link_status: 'message_with_link_status',
44
+ cta_url: 'cta_url',
45
+ cta_call: 'cta_call',
46
+ quick_reply: 'quick_reply',
47
+ catalog_message: 'catalog_message',
48
+ cta_catalog: 'cta_catalog',
49
+ cta_copy: 'cta_copy',
50
+ galaxy_message: 'galaxy_message',
51
+ payment_reminder: 'payment_reminder',
52
+ booking_confirmation: 'booking_confirmation',
53
+ call_permission_request: 'call_permission_request',
54
+ payment_request: 'payment_request',
55
+ api_signup: 'api_signup',
56
+ inapp_signup: 'inapp_signup',
57
+ cta_app: 'cta_app',
58
+ form_message: 'form_message',
59
+ address_message: 'address_message',
60
+ mpm: 'mpm'
61
+ });
62
+
63
+ exports.WEB_SUPPORTED_INTERACTIVE_FLOWS = Object.freeze([
64
+ 'quick_reply',
65
+ 'cta_call',
66
+ 'cta_url',
67
+ 'cta_catalog',
68
+ 'catalog_message',
69
+ 'cta_copy',
70
+ 'galaxy_message',
71
+ 'order_status',
72
+ 'payment_reminder',
73
+ 'booking_confirmation',
74
+ 'payment_request',
75
+ 'api_signup',
76
+ 'inapp_signup',
77
+ 'cta_app',
78
+ 'form_message'
79
+ ]);
80
+
81
+ exports.NATIVE_FLOW_BUTTON_LIMIT = Object.freeze({
82
+ quickReply: 10,
83
+ other: 3
84
+ });
85
+
86
+ const getNativeFlowNameByButtonName = (name) => BUTTON_NAME_TO_FLOW[name];
87
+ exports.getNativeFlowNameByButtonName = getNativeFlowNameByButtonName;
88
+
89
+ const isWebSupportedButtonName = (name) => {
90
+ const flow = getNativeFlowNameByButtonName(name);
91
+ return flow !== undefined && exports.WEB_SUPPORTED_INTERACTIVE_FLOWS.includes(flow);
92
+ };
93
+ exports.isWebSupportedButtonName = isWebSupportedButtonName;
94
+
95
+ const checkNativeFlowButtons = (buttons) => {
96
+ const list = (Array.isArray(buttons) ? buttons : []).map(button => (typeof button === 'string' ? { name: button } : button));
97
+ const problems = [];
98
+
99
+ if (!list.length) {
100
+ return { ok: true, limit: exports.NATIVE_FLOW_BUTTON_LIMIT.other, problems, unsupported: [] };
101
+ }
102
+
103
+ const firstIsQuickReply = list[0]?.name === 'quick_reply';
104
+ const limit = firstIsQuickReply ? exports.NATIVE_FLOW_BUTTON_LIMIT.quickReply : exports.NATIVE_FLOW_BUTTON_LIMIT.other;
105
+
106
+ if (list.length > limit) {
107
+ problems.push(`WhatsApp Web renders at most ${limit} buttons when the first one is ${firstIsQuickReply ? 'quick_reply' : 'not quick_reply'}, got ${list.length}`);
108
+ }
109
+
110
+ const unsupported = [...new Set(list.map(button => button?.name).filter(name => !isWebSupportedButtonName(name)))];
111
+ for (const name of unsupported) {
112
+ problems.push(`"${name}" is not a native flow WhatsApp Web or iOS can render, only Android shows it`);
113
+ }
114
+
115
+ const mixesKinds = list.slice(1).some(button => (button?.name === 'quick_reply') !== firstIsQuickReply);
116
+ if (mixesKinds) {
117
+ problems.push('quick_reply buttons cannot be mixed with other button types in one message');
118
+ }
119
+
120
+ return { ok: problems.length === 0, limit, problems, unsupported };
121
+ };
122
+ exports.checkNativeFlowButtons = checkNativeFlowButtons;