angularsockets 1.4.4 → 1.4.5

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,481 @@
1
+ /* modified by alip clutch*/
2
+ const WAProto = require('../../WAProto').proto;
3
+ const crypto = require('crypto');
4
+ const Utils_1 = require("../Utils");
5
+
6
+ class yaoii {
7
+ constructor(utils, waUploadToServer, relayMessageFn) {
8
+ this.utils = utils;
9
+ this.relayMessage = relayMessageFn
10
+ this.waUploadToServer = waUploadToServer;
11
+
12
+ this.bail = {
13
+ generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
14
+ generateMessageID: Utils_1.generateMessageID,
15
+ getContentType: (msg) => Object.keys(msg.message || {})[0]
16
+ };
17
+ }
18
+
19
+ detectType(content) {
20
+ if (content.requestPaymentMessage) return 'PAYMENT';
21
+ if (content.productMessage) return 'PRODUCT';
22
+ if (content.interactiveMessage) return 'INTERACTIVE';
23
+ if (content.albumMessage) return 'ALBUM';
24
+ if (content.eventMessage) return 'EVENT';
25
+ if (content.pollResultMessage) return 'POLL_RESULT';
26
+ if (content.groupStatusMessage) return 'GROUP_STORY';
27
+ return null;
28
+ }
29
+
30
+ async handlePayment(content, quoted) {
31
+ const data = content.requestPaymentMessage;
32
+ let notes = {};
33
+
34
+ if (data.sticker?.stickerMessage) {
35
+ notes = {
36
+ stickerMessage: {
37
+ ...data.sticker.stickerMessage,
38
+ contextInfo: {
39
+ stanzaId: quoted?.key?.id,
40
+ participant: quoted?.key?.participant || content.sender,
41
+ quotedMessage: quoted?.message
42
+ }
43
+ }
44
+ };
45
+ } else if (data.note) {
46
+ notes = {
47
+ extendedTextMessage: {
48
+ text: data.note,
49
+ contextInfo: {
50
+ stanzaId: quoted?.key?.id,
51
+ participant: quoted?.key?.participant || content.sender,
52
+ quotedMessage: quoted?.message
53
+ }
54
+ }
55
+ };
56
+ }
57
+
58
+ return {
59
+ requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
60
+ expiryTimestamp: data.expiry || 0,
61
+ amount1000: data.amount || 0,
62
+ currencyCodeIso4217: data.currency || "IDR",
63
+ requestFrom: data.from || "0@s.whatsapp.net",
64
+ noteMessage: notes,
65
+ background: data.background ?? {
66
+ id: "DEFAULT",
67
+ placeholderArgb: 0xFFF0F0F0
68
+ }
69
+ })
70
+ };
71
+ }
72
+
73
+ async handleProduct(content, jid, quoted) {
74
+ const {
75
+ title,
76
+ description,
77
+ thumbnail,
78
+ productId,
79
+ retailerId,
80
+ url,
81
+ body = "",
82
+ footer = "",
83
+ buttons = [],
84
+ priceAmount1000 = null,
85
+ currencyCode = "IDR"
86
+ } = content.productMessage;
87
+
88
+ let productImage;
89
+
90
+ if (Buffer.isBuffer(thumbnail)) {
91
+ const { imageMessage } = await this.utils.generateWAMessageContent(
92
+ { image: thumbnail },
93
+ { upload: this.waUploadToServer }
94
+ );
95
+ productImage = imageMessage;
96
+ } else if (typeof thumbnail === 'object' && thumbnail.url) {
97
+ const { imageMessage } = await this.utils.generateWAMessageContent(
98
+ { image: { url: thumbnail.url }},
99
+ { upload: this.waUploadToServer }
100
+ );
101
+ productImage = imageMessage;
102
+ }
103
+
104
+ return {
105
+ viewOnceMessage: {
106
+ message: {
107
+ interactiveMessage: {
108
+ body: { text: body },
109
+ footer: { text: footer },
110
+ header: {
111
+ title,
112
+ hasMediaAttachment: true,
113
+ productMessage: {
114
+ product: {
115
+ productImage,
116
+ productId,
117
+ title,
118
+ description,
119
+ currencyCode,
120
+ priceAmount1000,
121
+ retailerId,
122
+ url,
123
+ productImageCount: 1
124
+ },
125
+ businessOwnerJid: "0@s.whatsapp.net"
126
+ }
127
+ },
128
+ nativeFlowMessage: { buttons }
129
+ }
130
+ }
131
+ }
132
+ };
133
+ }
134
+
135
+ async handleInteractive(content, jid, quoted) {
136
+ const {
137
+ title,
138
+ footer,
139
+ thumbnail,
140
+ image,
141
+ video,
142
+ document,
143
+ mimetype,
144
+ fileName,
145
+ jpegThumbnail,
146
+ contextInfo,
147
+ externalAdReply,
148
+ buttons = [],
149
+ nativeFlowMessage,
150
+ header
151
+ } = content.interactiveMessage;
152
+
153
+ let media = null;
154
+ let mediaType = null;
155
+
156
+ if (thumbnail) {
157
+ media = await this.utils.prepareWAMessageMedia(
158
+ { image: { url: thumbnail } },
159
+ { upload: this.waUploadToServer }
160
+ );
161
+ mediaType = 'image';
162
+ } else if (image) {
163
+ if (typeof image === 'object' && image.url) {
164
+ media = await this.utils.prepareWAMessageMedia(
165
+ { image: { url: image.url } },
166
+ { upload: this.waUploadToServer }
167
+ );
168
+ } else {
169
+ media = await this.utils.prepareWAMessageMedia(
170
+ { image: image },
171
+ { upload: this.waUploadToServer }
172
+ );
173
+ }
174
+ mediaType = 'image';
175
+ } else if (video) {
176
+ if (typeof video === 'object' && video.url) {
177
+ media = await this.utils.prepareWAMessageMedia(
178
+ { video: { url: video.url } },
179
+ { upload: this.waUploadToServer }
180
+ );
181
+ } else {
182
+ media = await this.utils.prepareWAMessageMedia(
183
+ { video: video },
184
+ { upload: this.waUploadToServer }
185
+ );
186
+ }
187
+ mediaType = 'video';
188
+ } else if (document) {
189
+ let documentPayload = {
190
+ document: document
191
+ };
192
+ if (jpegThumbnail) {
193
+ if (typeof jpegThumbnail === 'object' && jpegThumbnail.url) {
194
+ documentPayload.jpegThumbnail = { url: jpegThumbnail.url };
195
+ } else {
196
+ documentPayload.jpegThumbnail = jpegThumbnail;
197
+ }
198
+ }
199
+
200
+ media = await this.utils.prepareWAMessageMedia(
201
+ documentPayload,
202
+ { upload: this.waUploadToServer }
203
+ );
204
+ if (fileName) {
205
+ media.documentMessage.fileName = fileName;
206
+ }
207
+ if (mimetype) {
208
+ media.documentMessage.mimetype = mimetype;
209
+ }
210
+ mediaType = 'document';
211
+ }
212
+ let interactiveMessage = {
213
+ body: { text: title || "" },
214
+ footer: { text: footer || "" }
215
+ };
216
+ if (buttons && buttons.length > 0) {
217
+ interactiveMessage.nativeFlowMessage = {
218
+ buttons: buttons
219
+ };
220
+ if (nativeFlowMessage) {
221
+ interactiveMessage.nativeFlowMessage = {
222
+ ...interactiveMessage.nativeFlowMessage,
223
+ ...nativeFlowMessage
224
+ };
225
+ }
226
+ } else if (nativeFlowMessage) {
227
+ interactiveMessage.nativeFlowMessage = nativeFlowMessage;
228
+ }
229
+
230
+ if (media) {
231
+ interactiveMessage.header = {
232
+ title: header || "",
233
+ hasMediaAttachment: true,
234
+ ...media
235
+ };
236
+ } else {
237
+ interactiveMessage.header = {
238
+ title: header || "",
239
+ hasMediaAttachment: false
240
+ };
241
+ }
242
+
243
+ let finalContextInfo = {};
244
+ if (contextInfo) {
245
+ finalContextInfo = {
246
+ mentionedJid: contextInfo.mentionedJid || [],
247
+ forwardingScore: contextInfo.forwardingScore || 0,
248
+ isForwarded: contextInfo.isForwarded || false,
249
+ ...contextInfo
250
+ };
251
+ }
252
+
253
+ if (externalAdReply) {
254
+ finalContextInfo.externalAdReply = {
255
+ title: externalAdReply.title || "",
256
+ body: externalAdReply.body || "",
257
+ mediaType: externalAdReply.mediaType || 1,
258
+ thumbnailUrl: externalAdReply.thumbnailUrl || "",
259
+ mediaUrl: externalAdReply.mediaUrl || "",
260
+ sourceUrl: externalAdReply.sourceUrl || "",
261
+ showAdAttribution: externalAdReply.showAdAttribution || false,
262
+ renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
263
+ ...externalAdReply
264
+ };
265
+ }
266
+
267
+ if (Object.keys(finalContextInfo).length > 0) {
268
+ interactiveMessage.contextInfo = finalContextInfo;
269
+ }
270
+ return {
271
+ interactiveMessage: interactiveMessage
272
+ };
273
+ }
274
+
275
+ async handleAlbum(content, jid, quoted) {
276
+ const array = content.albumMessage;
277
+ const album = await this.utils.generateWAMessageFromContent(jid, {
278
+ messageContextInfo: {
279
+ messageSecret: crypto.randomBytes(32),
280
+ },
281
+ albumMessage: {
282
+ expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
283
+ expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
284
+ },
285
+ }, {
286
+ userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
287
+ quoted,
288
+ upload: this.waUploadToServer
289
+ });
290
+
291
+ await this.relayMessage(jid, album.message, {
292
+ messageId: album.key.id,
293
+ });
294
+
295
+ for (let content of array) {
296
+ const img = await this.utils.generateWAMessage(jid, content, {
297
+ upload: this.waUploadToServer,
298
+ });
299
+
300
+ img.message.messageContextInfo = {
301
+ messageSecret: crypto.randomBytes(32),
302
+ messageAssociation: {
303
+ associationType: 1,
304
+ parentMessageKey: album.key,
305
+ },
306
+ participant: "0@s.whatsapp.net",
307
+ remoteJid: "status@broadcast",
308
+ forwardingScore: 99999,
309
+ isForwarded: true,
310
+ mentionedJid: [jid],
311
+ starred: true,
312
+ labels: ["Y", "Important"],
313
+ isHighlighted: true,
314
+ businessMessageForwardInfo: {
315
+ businessOwnerJid: jid,
316
+ },
317
+ dataSharingContext: {
318
+ showMmDisclosure: true,
319
+ },
320
+ };
321
+
322
+ img.message.forwardedNewsletterMessageInfo = {
323
+ newsletterJid: "0@newsletter",
324
+ serverMessageId: 1,
325
+ newsletterName: `WhatsApp`,
326
+ contentType: 1,
327
+ timestamp: new Date().toISOString(),
328
+ senderName: "Alip Clutch",
329
+ content: "Text Message",
330
+ priority: "high",
331
+ status: "sent",
332
+ };
333
+
334
+ img.message.disappearingMode = {
335
+ initiator: 3,
336
+ trigger: 4,
337
+ initiatorDeviceJid: jid,
338
+ initiatedByExternalService: true,
339
+ initiatedByUserDevice: true,
340
+ initiatedBySystem: true,
341
+ initiatedByServer: true,
342
+ initiatedByAdmin: true,
343
+ initiatedByUser: true,
344
+ initiatedByApp: true,
345
+ initiatedByBot: true,
346
+ initiatedByMe: true,
347
+ };
348
+
349
+ await this.relayMessage(jid, img.message, {
350
+ messageId: img.key.id,
351
+ quoted: {
352
+ key: {
353
+ remoteJid: album.key.remoteJid,
354
+ id: album.key.id,
355
+ fromMe: true,
356
+ participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
357
+ },
358
+ message: album.message,
359
+ },
360
+ });
361
+ }
362
+ return album;
363
+ }
364
+
365
+ async handleEvent(content, jid, quoted) {
366
+ const eventData = content.eventMessage;
367
+
368
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
369
+ viewOnceMessage: {
370
+ message: {
371
+ messageContextInfo: {
372
+ deviceListMetadata: {},
373
+ deviceListMetadataVersion: 2,
374
+ messageSecret: crypto.randomBytes(32),
375
+ supportPayload: JSON.stringify({
376
+ version: 2,
377
+ is_ai_message: true,
378
+ should_show_system_message: true,
379
+ ticket_id: crypto.randomBytes(16).toString('hex')
380
+ })
381
+ },
382
+ eventMessage: {
383
+ contextInfo: {
384
+ mentionedJid: [jid],
385
+ participant: jid,
386
+ remoteJid: "status@broadcast",
387
+ forwardedNewsletterMessageInfo: {
388
+ newsletterName: "alip clutch.",
389
+ newsletterJid: "120363401467939056@newsletter",
390
+ serverMessageId: 1
391
+ }
392
+ },
393
+ isCanceled: eventData.isCanceled || false,
394
+ name: eventData.name,
395
+ description: eventData.description,
396
+ location: eventData.location || {
397
+ degreesLatitude: 0,
398
+ degreesLongitude: 0,
399
+ name: "Location"
400
+ },
401
+ joinLink: eventData.joinLink || '',
402
+ startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
403
+ endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
404
+ extraGuestsAllowed: eventData.extraGuestsAllowed !== false
405
+ }
406
+ }
407
+ }
408
+ }, { quoted });
409
+
410
+ await this.relayMessage(jid, msg.message, {
411
+ messageId: msg.key.id
412
+ });
413
+ return msg;
414
+ }
415
+
416
+ async handlePollResult(content, jid, quoted) {
417
+ const pollData = content.pollResultMessage;
418
+
419
+ const msg = await this.utils.generateWAMessageFromContent(jid, {
420
+ pollResultSnapshotMessage: {
421
+ name: pollData.name,
422
+ pollVotes: pollData.pollVotes.map(vote => ({
423
+ optionName: vote.optionName,
424
+ optionVoteCount: typeof vote.optionVoteCount === 'number'
425
+ ? vote.optionVoteCount.toString()
426
+ : vote.optionVoteCount
427
+ }))
428
+ }
429
+ }, {
430
+ userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
431
+ quoted
432
+ });
433
+
434
+ await this.relayMessage(jid, msg.message, {
435
+ messageId: msg.key.id
436
+ });
437
+
438
+ return msg;
439
+ }
440
+
441
+ async handleGroupStory(content, jid, quoted) {
442
+ const storyData = content.groupStatusMessage;
443
+ let waMsgContent;
444
+
445
+ if (storyData.message) {
446
+ waMsgContent = storyData;
447
+ } else {
448
+ if (typeof this.bail?.generateWAMessageContent === "function") {
449
+ waMsgContent = await this.bail.generateWAMessageContent(storyData, {
450
+ upload: this.waUploadToServer
451
+ });
452
+ } else if (typeof this.utils?.generateWAMessageContent === "function") {
453
+ waMsgContent = await this.utils.generateWAMessageContent(storyData, {
454
+ upload: this.waUploadToServer
455
+ });
456
+ } else if (typeof this.utils?.prepareMessageContent === "function") {
457
+ waMsgContent = await this.utils.prepareMessageContent(storyData, {
458
+ upload: this.waUploadToServer
459
+ });
460
+ } else {
461
+ waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
462
+ upload: this.waUploadToServer
463
+ });
464
+ }
465
+ }
466
+
467
+ let msg = {
468
+ message: {
469
+ groupStatusMessageV2: {
470
+ message: waMsgContent.message || waMsgContent
471
+ }
472
+ }
473
+ };
474
+
475
+ return await this.relayMessage(jid, msg.message, {
476
+ messageId: this.bail.generateMessageID()
477
+ });
478
+ }
479
+ }
480
+
481
+ module.exports = yaoii;