@elrayyxml/baileys 1.0.2 → 1.0.6

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.
@@ -1,405 +0,0 @@
1
- const WAProto = require('../../WAProto').proto;
2
- const crypto = require('crypto');
3
- const Utils_1 = require("../Utils");
4
-
5
- class elrayyxml {
6
- constructor(utils, waUploadToServer, relayMessageFn, authState) {
7
- this.utils = utils;
8
- this.relayMessage = relayMessageFn;
9
- this.waUploadToServer = waUploadToServer;
10
- this.authState = authState;
11
- }
12
-
13
- getUserJid() {
14
- return this.authState?.creds?.me?.id;
15
- }
16
-
17
- detectType(content) {
18
- if (content.requestPaymentMessage) return 'PAYMENT';
19
- if (content.productMessage) return 'PRODUCT';
20
- if (content.interactiveMessage) return 'INTERACTIVE';
21
- if (content.albumMessage) return 'ALBUM';
22
- if (content.eventMessage) return 'EVENT';
23
- if (content.pollResultMessage) return 'POLL_RESULT';
24
- if (content.groupStatusMessage) return 'GROUP_STORY';
25
- return null;
26
- }
27
-
28
- async handlePayment(content, jid, 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 || this.getUserJid(),
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 || this.getUserJid(),
50
- quotedMessage: quoted?.message
51
- }
52
- }
53
- };
54
- }
55
-
56
- const paymentContent = {
57
- requestPaymentMessage: WAProto.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
- const msg = await Utils_1.generateWAMessageFromContent(jid, paymentContent, {
71
- quoted,
72
- userJid: this.getUserJid()
73
- });
74
-
75
- await this.relayMessage(jid, msg.message, {
76
- messageId: msg.key.id
77
- });
78
-
79
- return msg;
80
- }
81
-
82
- async handleProduct(content, jid, quoted) {
83
- const {
84
- title, description, thumbnail, productId, retailerId, url,
85
- body = "", footer = "", buttons = [], priceAmount1000 = null, currencyCode = "IDR"
86
- } = content.productMessage;
87
-
88
- let productImage;
89
- if (Buffer.isBuffer(thumbnail)) {
90
- const { imageMessage } = await Utils_1.generateWAMessageContent(
91
- { image: thumbnail },
92
- { upload: this.waUploadToServer }
93
- );
94
- productImage = imageMessage;
95
- } else if (typeof thumbnail === 'object' && thumbnail.url) {
96
- const { imageMessage } = await Utils_1.generateWAMessageContent(
97
- { image: { url: thumbnail.url }},
98
- { upload: this.waUploadToServer }
99
- );
100
- productImage = imageMessage;
101
- }
102
-
103
- const productContent = {
104
- viewOnceMessage: {
105
- message: {
106
- interactiveMessage: {
107
- body: { text: body },
108
- footer: { text: footer },
109
- header: {
110
- title,
111
- hasMediaAttachment: true,
112
- productMessage: {
113
- product: {
114
- productImage,
115
- productId,
116
- title,
117
- description,
118
- currencyCode,
119
- priceAmount1000,
120
- retailerId,
121
- url,
122
- productImageCount: 1
123
- },
124
- businessOwnerJid: "0@s.whatsapp.net"
125
- }
126
- },
127
- nativeFlowMessage: { buttons }
128
- }
129
- }
130
- }
131
- };
132
-
133
- const msg = await Utils_1.generateWAMessageFromContent(jid, productContent, {
134
- quoted,
135
- userJid: this.getUserJid()
136
- });
137
-
138
- await this.relayMessage(jid, msg.message, {
139
- messageId: msg.key.id
140
- });
141
-
142
- return msg;
143
- }
144
-
145
- async handleInteractive(content, jid, quoted) {
146
- const {
147
- title, footer, thumbnail, image, video, document, mimetype, fileName,
148
- jpegThumbnail, contextInfo, externalAdReply, buttons = [], nativeFlowMessage, header
149
- } = content.interactiveMessage;
150
-
151
- let media = null;
152
- if (thumbnail) {
153
- media = await this.utils.prepareWAMessageMedia(
154
- { image: { url: thumbnail } },
155
- { upload: this.waUploadToServer }
156
- );
157
- } else if (image) {
158
- if (typeof image === 'object' && image.url) {
159
- media = await this.utils.prepareWAMessageMedia(
160
- { image: { url: image.url } },
161
- { upload: this.waUploadToServer }
162
- );
163
- } else {
164
- media = await this.utils.prepareWAMessageMedia(
165
- { image: image },
166
- { upload: this.waUploadToServer }
167
- );
168
- }
169
- } else if (video) {
170
- if (typeof video === 'object' && video.url) {
171
- media = await this.utils.prepareWAMessageMedia(
172
- { video: { url: video.url } },
173
- { upload: this.waUploadToServer }
174
- );
175
- } else {
176
- media = await this.utils.prepareWAMessageMedia(
177
- { video: video },
178
- { upload: this.waUploadToServer }
179
- );
180
- }
181
- } else if (document) {
182
- let documentPayload = { document: document };
183
- if (jpegThumbnail) {
184
- documentPayload.jpegThumbnail = jpegThumbnail;
185
- }
186
- media = await this.utils.prepareWAMessageMedia(
187
- documentPayload,
188
- { upload: this.waUploadToServer }
189
- );
190
- if (fileName) media.documentMessage.fileName = fileName;
191
- if (mimetype) media.documentMessage.mimetype = mimetype;
192
- }
193
-
194
- let interactiveMessage = {
195
- body: { text: title || "" },
196
- footer: { text: footer || "" }
197
- };
198
-
199
- if (buttons && buttons.length > 0) {
200
- interactiveMessage.nativeFlowMessage = { buttons: buttons };
201
- }
202
- if (nativeFlowMessage) {
203
- interactiveMessage.nativeFlowMessage = {
204
- ...interactiveMessage.nativeFlowMessage,
205
- ...nativeFlowMessage
206
- };
207
- }
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
-
222
- let finalContextInfo = {};
223
- if (contextInfo) {
224
- finalContextInfo = {
225
- mentionedJid: contextInfo.mentionedJid || [],
226
- forwardingScore: contextInfo.forwardingScore || 0,
227
- isForwarded: contextInfo.isForwarded || false,
228
- ...contextInfo
229
- };
230
- }
231
-
232
- if (externalAdReply) {
233
- finalContextInfo.externalAdReply = externalAdReply;
234
- }
235
-
236
- if (Object.keys(finalContextInfo).length > 0) {
237
- interactiveMessage.contextInfo = finalContextInfo;
238
- }
239
-
240
- const interactiveContent = { interactiveMessage: interactiveMessage };
241
-
242
- const msg = await Utils_1.generateWAMessageFromContent(jid, interactiveContent, {
243
- quoted,
244
- userJid: this.getUserJid()
245
- });
246
-
247
- await this.relayMessage(jid, msg.message, {
248
- messageId: msg.key.id
249
- });
250
-
251
- return msg;
252
- }
253
-
254
- async handleAlbum(content, jid, quoted) {
255
- const array = content.albumMessage;
256
-
257
- const albumContent = {
258
- messageContextInfo: {
259
- messageSecret: crypto.randomBytes(32),
260
- },
261
- albumMessage: {
262
- expectedImageCount: array.filter((a) => a.hasOwnProperty("image")).length,
263
- expectedVideoCount: array.filter((a) => a.hasOwnProperty("video")).length,
264
- },
265
- };
266
-
267
- const msg = await Utils_1.generateWAMessageFromContent(jid, albumContent, {
268
- userJid: this.getUserJid(),
269
- quoted,
270
- upload: this.waUploadToServer
271
- });
272
-
273
- await this.relayMessage(jid, msg.message, {
274
- messageId: msg.key.id,
275
- });
276
-
277
- for (let contentItem of array) {
278
- const mediaMsg = await Utils_1.generateWAMessage(jid, contentItem, {
279
- upload: this.waUploadToServer,
280
- userJid: this.getUserJid()
281
- });
282
-
283
- mediaMsg.message.messageContextInfo = {
284
- messageSecret: crypto.randomBytes(32),
285
- messageAssociation: {
286
- associationType: 1,
287
- parentMessageKey: msg.key,
288
- }
289
- };
290
-
291
- await this.relayMessage(jid, mediaMsg.message, {
292
- messageId: mediaMsg.key.id,
293
- quoted: {
294
- key: msg.key,
295
- message: msg.message,
296
- },
297
- });
298
- }
299
-
300
- return msg;
301
- }
302
-
303
- async handleEvent(content, jid, quoted) {
304
- const eventData = content.eventMessage;
305
-
306
- const eventContent = {
307
- viewOnceMessage: {
308
- message: {
309
- messageContextInfo: {
310
- deviceListMetadata: {},
311
- deviceListMetadataVersion: 2,
312
- messageSecret: crypto.randomBytes(32),
313
- },
314
- eventMessage: {
315
- contextInfo: {
316
- mentionedJid: [jid],
317
- },
318
- isCanceled: eventData.isCanceled || false,
319
- name: eventData.name,
320
- description: eventData.description,
321
- location: eventData.location || {
322
- degreesLatitude: 0,
323
- degreesLongitude: 0,
324
- name: "Location"
325
- },
326
- joinLink: eventData.joinLink || '',
327
- startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
328
- endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
329
- extraGuestsAllowed: eventData.extraGuestsAllowed !== false
330
- }
331
- }
332
- }
333
- };
334
-
335
- const msg = await Utils_1.generateWAMessageFromContent(jid, eventContent, {
336
- quoted,
337
- userJid: this.getUserJid()
338
- });
339
-
340
- await this.relayMessage(jid, msg.message, {
341
- messageId: msg.key.id
342
- });
343
-
344
- return msg;
345
- }
346
-
347
- async handlePollResult(content, jid, quoted) {
348
- const pollData = content.pollResultMessage;
349
-
350
- const pollContent = {
351
- pollResultSnapshotMessage: {
352
- name: pollData.name,
353
- pollVotes: pollData.pollVotes.map(vote => ({
354
- optionName: vote.optionName,
355
- optionVoteCount: typeof vote.optionVoteCount === 'number'
356
- ? vote.optionVoteCount.toString()
357
- : vote.optionVoteCount
358
- }))
359
- }
360
- };
361
-
362
- const msg = await Utils_1.generateWAMessageFromContent(jid, pollContent, {
363
- userJid: this.getUserJid(),
364
- quoted
365
- });
366
-
367
- await this.relayMessage(jid, msg.message, {
368
- messageId: msg.key.id
369
- });
370
-
371
- return msg;
372
- }
373
-
374
- async handleGroupStory(content, jid, quoted) {
375
- const storyData = content.groupStatusMessage;
376
-
377
- let waMsgContent;
378
- if (storyData.message) {
379
- waMsgContent = storyData;
380
- } else {
381
- waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
382
- upload: this.waUploadToServer
383
- });
384
- }
385
-
386
- const groupStoryContent = {
387
- groupStatusMessageV2: {
388
- message: waMsgContent.message || waMsgContent
389
- }
390
- };
391
-
392
- const msg = await Utils_1.generateWAMessageFromContent(jid, groupStoryContent, {
393
- userJid: this.getUserJid(),
394
- quoted
395
- });
396
-
397
- await this.relayMessage(jid, msg.message, {
398
- messageId: msg.key.id
399
- });
400
-
401
- return msg;
402
- }
403
- }
404
-
405
- module.exports = elrayyxml;