@ruthless-imperium/baileys 1.0.2 → 1.0.3

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.
@@ -0,0 +1,392 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const __def = (m) => (m && m.__esModule) ? m.default : m;
4
+ const __exportStar = (m, e) => { for (const k in m) if (k !== "default" && !Object.prototype.hasOwnProperty.call(e, k)) e[k] = m[k]; };
5
+ const { proto } = require("../../WAProto/index.js");
6
+ const Utils = require("../Utils/index.js");
7
+ const crypto = __def(require("crypto"));
8
+
9
+ class imup {
10
+ constructor(utils, waUploadToServer, relayMessageFn) {
11
+ this.utils = utils
12
+ this.relayMessage = relayMessageFn
13
+ this.waUploadToServer = waUploadToServer
14
+ }
15
+
16
+ detectType(content) {
17
+ if (content.requestPaymentMessage) return 'PAYMENT'
18
+ if (content.productMessage) return 'PRODUCT'
19
+ if (content.albumMessage) return 'ALBUM'
20
+ if (content.eventMessage) return 'EVENT'
21
+ if (content.pollResultMessage) return 'POLL_RESULT'
22
+ if (content.orderMessage) return 'ORDER'
23
+ if (content.groupStatus) return 'GROUP_STATUS'
24
+ if (content.groupLabel) return 'GROUP_LABEL'
25
+ return null
26
+ }
27
+
28
+ async handlePayment(content, quoted) {
29
+ const data = content.requestPaymentMessage
30
+ let notes = {}
31
+
32
+ if (data.sticker?.stickerMessage) {
33
+ notes = {
34
+ stickerMessage: {
35
+ ...data.sticker.stickerMessage,
36
+ contextInfo: {
37
+ stanzaId: quoted?.key?.id,
38
+ participant: quoted?.key?.participant || content.sender,
39
+ quotedMessage: quoted?.message
40
+ }
41
+ }
42
+ }
43
+ } else if (data.note) {
44
+ notes = {
45
+ extendedTextMessage: {
46
+ text: data.note,
47
+ contextInfo: {
48
+ stanzaId: quoted?.key?.id,
49
+ participant: quoted?.key?.participant || content.sender,
50
+ quotedMessage: quoted?.message
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ return {
57
+ requestPaymentMessage: proto.Message.RequestPaymentMessage.fromObject({
58
+ expiryTimestamp: data.expiry || 0,
59
+ amount1000: data.amount || 0,
60
+ currencyCodeIso4217: data.currency || "IDR",
61
+ requestFrom: data.from || "0@s.whatsapp.net",
62
+ noteMessage: notes,
63
+ background: data.background?? {
64
+ id: "DEFAULT",
65
+ placeholderArgb: 0xFFF0F0F0
66
+ }
67
+ })
68
+ }
69
+ }
70
+
71
+ async handleProduct(content, jid, quoted) {
72
+ const {
73
+ title,
74
+ description,
75
+ thumbnail,
76
+ productId,
77
+ retailerId,
78
+ url,
79
+ body = "",
80
+ footer = "",
81
+ buttons = [],
82
+ priceAmount1000 = null,
83
+ currencyCode = "IDR"
84
+ } = content.productMessage
85
+
86
+ let productImage
87
+
88
+ if (Buffer.isBuffer(thumbnail)) {
89
+ const { imageMessage } = await this.utils.generateWAMessageContent(
90
+ { image: thumbnail },
91
+ { upload: this.waUploadToServer }
92
+ )
93
+ productImage = imageMessage
94
+ } else if (typeof thumbnail === 'object' && thumbnail.url) {
95
+ const { imageMessage } = await this.utils.generateWAMessageContent(
96
+ { image: { url: thumbnail.url } },
97
+ { upload: this.waUploadToServer }
98
+ )
99
+ productImage = imageMessage
100
+ }
101
+
102
+ return {
103
+ viewOnceMessage: {
104
+ message: {
105
+ interactiveMessage: {
106
+ body: { text: body },
107
+ footer: { text: footer },
108
+ header: {
109
+ title,
110
+ hasMediaAttachment: true,
111
+ productMessage: {
112
+ product: {
113
+ productImage,
114
+ productId,
115
+ title,
116
+ description,
117
+ currencyCode,
118
+ priceAmount1000,
119
+ retailerId,
120
+ url,
121
+ productImageCount: 1
122
+ },
123
+ businessOwnerJid: "0@s.whatsapp.net"
124
+ }
125
+ },
126
+ nativeFlowMessage: { buttons }
127
+ }
128
+ }
129
+ }
130
+ }
131
+ }
132
+
133
+ async handleAlbum(content, jid, quoted) {
134
+ const array = content.albumMessage
135
+ const album = await this.utils.generateWAMessageFromContent(jid, {
136
+ messageContextInfo: {
137
+ messageSecret: crypto.randomBytes(32),
138
+ },
139
+ albumMessage: {
140
+ expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
141
+ expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
142
+ },
143
+ }, {
144
+ userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
145
+ quoted,
146
+ upload: this.waUploadToServer
147
+ })
148
+
149
+ await this.relayMessage(jid, album.message, {
150
+ messageId: album.key.id,
151
+ })
152
+
153
+ for (let content of array) {
154
+ const img = await this.utils.generateWAMessage(jid, content, {
155
+ upload: this.waUploadToServer,
156
+ })
157
+
158
+ img.message.messageContextInfo = {
159
+ messageSecret: crypto.randomBytes(32),
160
+ messageAssociation: {
161
+ associationType: 1,
162
+ parentMessageKey: album.key,
163
+ },
164
+ participant: "0@s.whatsapp.net",
165
+ remoteJid: "status@broadcast",
166
+ forwardingScore: 99999,
167
+ isForwarded: true,
168
+ mentionedJid: [jid],
169
+ starred: true,
170
+ labels: ["Y", "Important"],
171
+ isHighlighted: true,
172
+ businessMessageForwardInfo: {
173
+ businessOwnerJid: jid,
174
+ },
175
+ dataSharingContext: {
176
+ showMmDisclosure: true,
177
+ },
178
+ }
179
+
180
+ img.message.forwardedNewsletterMessageInfo = {
181
+ newsletterJid: "0@newsletter",
182
+ serverMessageId: 1,
183
+ newsletterName: `WhatsApp`,
184
+ contentType: 1,
185
+ timestamp: new Date().toISOString(),
186
+ senderName: "7-Yuukey",
187
+ contentType: "UPDATE_CARD",
188
+ priority: "high",
189
+ status: "sent",
190
+ }
191
+
192
+ img.message.disappearingMode = {
193
+ initiator: 3,
194
+ trigger: 4,
195
+ initiatorDeviceJid: jid,
196
+ initiatedByExternalService: true,
197
+ initiatedByUserDevice: true,
198
+ initiatedBySystem: true,
199
+ initiatedByServer: true,
200
+ initiatedByAdmin: true,
201
+ initiatedByUser: true,
202
+ initiatedByApp: true,
203
+ initiatedByBot: true,
204
+ initiatedByMe: true,
205
+ }
206
+
207
+ await this.relayMessage(jid, img.message, {
208
+ messageId: img.key.id,
209
+ quoted: {
210
+ key: {
211
+ remoteJid: album.key.remoteJid,
212
+ id: album.key.id,
213
+ fromMe: true,
214
+ participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
215
+ },
216
+ message: album.message,
217
+ },
218
+ })
219
+ }
220
+ return album
221
+ }
222
+
223
+ async handleEvent(content, jid, quoted) {
224
+ const eventData = content.eventMessage
225
+
226
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
227
+ viewOnceMessage: {
228
+ message: {
229
+ messageContextInfo: {
230
+ deviceListMetadata: {},
231
+ deviceListMetadataVersion: 2,
232
+ messageSecret: crypto.randomBytes(32),
233
+ supportPayload: JSON.stringify({
234
+ version: 2,
235
+ is_ai_message: true,
236
+ should_show_system_message: true,
237
+ ticket_id: crypto.randomBytes(16).toString('hex')
238
+ })
239
+ },
240
+ eventMessage: {
241
+ contextInfo: {
242
+ mentionedJid: [jid],
243
+ participant: jid,
244
+ remoteJid: "status@broadcast",
245
+ forwardedNewsletterMessageInfo: {
246
+ newsletterName: "D | 7eppeli-Exloration",
247
+ newsletterJid: "120363421563597486@newsletter",
248
+ serverMessageId: 1
249
+ }
250
+ },
251
+ isCanceled: eventData.isCanceled || false,
252
+ name: eventData.name,
253
+ description: eventData.description,
254
+ location: eventData.location || {
255
+ degreesLatitude: 0,
256
+ degreesLongitude: 0,
257
+ name: "Location"
258
+ },
259
+ joinLink: eventData.joinLink || '',
260
+ startTime: typeof eventData.startTime === 'string'? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
261
+ endTime: typeof eventData.endTime === 'string'? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
262
+ extraGuestsAllowed: eventData.extraGuestsAllowed!== false
263
+ }
264
+ }
265
+ }
266
+ }, { quoted })
267
+
268
+ await this.relayMessage(jid, msg.message, {
269
+ messageId: msg.key.id
270
+ })
271
+ return msg
272
+ }
273
+
274
+ async handlePollResult(content, jid, quoted) {
275
+ const pollData = content.pollResultMessage
276
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
277
+ pollResultSnapshotMessage: {
278
+ name: pollData.name,
279
+ pollVotes: pollData.pollVotes.map(vote => ({
280
+ optionName: vote.optionName,
281
+ optionVoteCount: typeof vote.optionVoteCount === 'number'
282
+ ? vote.optionVoteCount.toString()
283
+ : vote.optionVoteCount
284
+ })),
285
+ contextInfo: {
286
+ isForwarded: true,
287
+ forwardingScore: 1,
288
+ forwardedNewsletterMessageInfo: {
289
+ newsletterName: pollData.newsletter.newsletterName || "120363399602691477@newsletter",
290
+ newsletterJid: pollData.newsletter.newsletterJid || "Newsletter",
291
+ serverMessageId: 1000,
292
+ contentType: "UPDATE"
293
+ }
294
+ }
295
+ }
296
+ }, {
297
+ userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
298
+ quoted
299
+ })
300
+
301
+ await this.relayMessage(jid, msg.message, {
302
+ messageId: msg.key.id
303
+ })
304
+
305
+ return msg
306
+ }
307
+
308
+ async handleOrderMessage(content, jid, quoted) {
309
+ const orderData = content.orderMessage
310
+
311
+ const Haha = await this.utils.generateWAMessageFromContent(jid, {
312
+ orderMessage: {
313
+ orderId: "7EPPELI25022008",
314
+ thumbnail: orderData.thumbnail || null,
315
+ itemCount: orderData.itemCount || 0,
316
+ status: "ACCEPTED",
317
+ surface: "CATALOG",
318
+ message: orderData.message,
319
+ orderTitle: orderData.orderTitle,
320
+ sellerJid: "0@whatsapp.net",
321
+ token: "7EPPELI_EXAMPLE_TOKEN",
322
+ totalAmount1000: orderData.totalAmount1000 || 0,
323
+ totalCurrencyCode: orderData.totalCurrencyCode || "IDR",
324
+ messageVersion: 2
325
+ }
326
+ }, { quoted: quoted })
327
+
328
+ await this.relayMessage(jid, Haha.message, {})
329
+ return Haha
330
+ }
331
+
332
+ async handleGroupStory(content, jid, quoted) {
333
+ const storyData = content.groupStatus
334
+ let messageContent
335
+
336
+ if (storyData.message) {
337
+ messageContent = storyData
338
+ } else {
339
+ if (typeof this.utils?.generateWAMessageContent === "function") {
340
+ messageContent = await this.utils.generateWAMessageContent(storyData, {
341
+ upload: this.waUploadToServer
342
+ })
343
+ } else {
344
+ messageContent = await Utils.generateWAMessageContent(storyData, {
345
+ upload: this.waUploadToServer
346
+ })
347
+ }
348
+ }
349
+
350
+ let msg = {
351
+ message: {
352
+ groupStatusMessageV2: {
353
+ message: messageContent.message || messageContent
354
+ }
355
+ }
356
+ }
357
+
358
+ return await this.relayMessage(jid, msg.message, {
359
+ messageId: this.utils.generateMessageID()
360
+ })
361
+ }
362
+
363
+ async handleGbLabel(content, jid) {
364
+ const x = content.groupLabel
365
+ if (!jid.endsWith('@g.us')) {
366
+ throw new Error('group required!')
367
+ }
368
+
369
+ const msg = this.utils.generateWAMessageFromContent(jid, {
370
+ protocolMessage: {
371
+ type: "GROUP_MEMBER_LABEL_CHANGE",
372
+ memberLabel: {
373
+ label: x.labelText.slice(0, 30)
374
+ }
375
+ }
376
+ }, {})
377
+
378
+ await this.relayMessage(jid, msg.message, {
379
+ additionalNodes: [
380
+ {
381
+ tag: 'meta',
382
+ attrs: {
383
+ tag_reason: 'user_update',
384
+ appdata: 'member_tag'
385
+ },
386
+ content: undefined
387
+ }
388
+ ]
389
+ })
390
+ }
391
+ }
392
+ exports.default = imup;