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.
@@ -1,530 +0,0 @@
1
- const WAProto = require('../../WAProto').proto;
2
- const crypto = require('crypto');
3
- const Utils_1 = require("../Utils");
4
-
5
- class RexxHayanasi {
6
- constructor(utils, waUploadToServer, relayMessageFn) {
7
- this.utils = utils;
8
- this.relayMessage = relayMessageFn;
9
- this.waUploadToServer = waUploadToServer;
10
-
11
- this.bail = {
12
- generateWAMessageContent: this.utils.generateWAMessageContent || Utils_1.generateWAMessageContent,
13
- generateMessageID: Utils_1.generateMessageID,
14
- // FIXED: safer getContentType guard
15
- getContentType: (msg) => {
16
- if (!msg || typeof msg !== 'object') return null;
17
- const m = msg.message || {};
18
- if (typeof m !== 'object') return null;
19
- return Object.keys(m)[0] || null;
20
- }
21
- };
22
- }
23
-
24
- detectType(content) {
25
- if (content.requestPaymentMessage) return 'PAYMENT';
26
- if (content.productMessage) return 'PRODUCT';
27
- if (content.interactiveMessage) return 'INTERACTIVE';
28
- if (content.albumMessage) return 'ALBUM';
29
- if (content.eventMessage) return 'EVENT';
30
- if (content.pollResultMessage) return 'POLL_RESULT';
31
- if (content.groupStatusMessage) return 'GROUP_STORY';
32
- return null;
33
- }
34
-
35
- async handlePayment(content, quoted) {
36
- // FIXED: Guard & error handling
37
- const data = content?.requestPaymentMessage;
38
- if (!data) throw new Error('Missing requestPaymentMessage in content');
39
-
40
- try {
41
- let notes = {};
42
-
43
- if (data.sticker?.stickerMessage) {
44
- notes = {
45
- stickerMessage: {
46
- ...data.sticker.stickerMessage,
47
- contextInfo: {
48
- stanzaId: quoted?.key?.id,
49
- participant: quoted?.key?.participant || content.sender,
50
- quotedMessage: quoted?.message
51
- }
52
- }
53
- };
54
- } else if (data.note) {
55
- notes = {
56
- extendedTextMessage: {
57
- text: data.note,
58
- contextInfo: {
59
- stanzaId: quoted?.key?.id,
60
- participant: quoted?.key?.participant || content.sender,
61
- quotedMessage: quoted?.message
62
- }
63
- }
64
- };
65
- }
66
-
67
- return {
68
- requestPaymentMessage: WAProto.Message.RequestPaymentMessage.fromObject({
69
- expiryTimestamp: data.expiry || 0,
70
- amount1000: data.amount || 0,
71
- currencyCodeIso4217: data.currency || "IDR",
72
- requestFrom: data.from || "0@s.whatsapp.net",
73
- noteMessage: notes,
74
- background: data.background ?? {
75
- id: "DEFAULT",
76
- placeholderArgb: 0xFFF0F0F0
77
- }
78
- })
79
- };
80
- } catch (err) {
81
- console.error('handlePayment error:', err);
82
- throw err;
83
- }
84
- }
85
-
86
- async handleProduct(content, jid, quoted) {
87
- try {
88
- const {
89
- title = "",
90
- description = "",
91
- thumbnail,
92
- productId,
93
- retailerId,
94
- url,
95
- body = "",
96
- footer = "",
97
- buttons = [],
98
- priceAmount1000 = null,
99
- currencyCode = "IDR"
100
- } = content.productMessage || {};
101
-
102
- let productImage = null;
103
-
104
- // FIXED: safer handling & fallback
105
- if (thumbnail) {
106
- try {
107
- if (Buffer.isBuffer(thumbnail)) {
108
- const res = await this.utils.generateWAMessageContent(
109
- { image: thumbnail },
110
- { upload: this.waUploadToServer }
111
- );
112
- productImage = res?.imageMessage || res?.message?.imageMessage || null;
113
- } else if (typeof thumbnail === 'object' && thumbnail.url) {
114
- const res = await this.utils.generateWAMessageContent(
115
- { image: { url: thumbnail.url }},
116
- { upload: this.waUploadToServer }
117
- );
118
- productImage = res?.imageMessage || res?.message?.imageMessage || null;
119
- }
120
- } catch (err) {
121
- console.warn('Thumbnail upload failed', err);
122
- }
123
- }
124
-
125
- const product = {
126
- productId,
127
- title,
128
- description,
129
- currencyCode,
130
- priceAmount1000,
131
- retailerId,
132
- url,
133
- productImageCount: productImage ? 1 : 0
134
- };
135
-
136
- if (productImage) product.productImage = productImage;
137
-
138
- return {
139
- viewOnceMessage: {
140
- message: {
141
- interactiveMessage: {
142
- body: { text: body },
143
- footer: { text: footer },
144
- header: {
145
- title,
146
- hasMediaAttachment: !!productImage,
147
- productMessage: {
148
- product,
149
- businessOwnerJid: "0@s.whatsapp.net"
150
- }
151
- },
152
- nativeFlowMessage: { buttons }
153
- }
154
- }
155
- }
156
- };
157
- } catch (err) {
158
- console.error('handleProduct error:', err);
159
- throw err;
160
- }
161
- }
162
-
163
- async handleInteractive(content, jid, quoted) {
164
- try {
165
- const {
166
- title,
167
- footer,
168
- thumbnail,
169
- image,
170
- video,
171
- document,
172
- mimetype,
173
- fileName,
174
- jpegThumbnail,
175
- contextInfo,
176
- externalAdReply,
177
- buttons = [],
178
- nativeFlowMessage,
179
- header
180
- } = content.interactiveMessage || {};
181
-
182
- let media = null;
183
- let mediaType = null;
184
-
185
- if (thumbnail) {
186
- media = await this.utils.prepareWAMessageMedia(
187
- { image: { url: thumbnail } },
188
- { upload: this.waUploadToServer }
189
- );
190
- mediaType = 'image';
191
- } else if (image) {
192
- if (typeof image === 'object' && image.url) {
193
- media = await this.utils.prepareWAMessageMedia(
194
- { image: { url: image.url } },
195
- { upload: this.waUploadToServer }
196
- );
197
- } else {
198
- media = await this.utils.prepareWAMessageMedia(
199
- { image },
200
- { upload: this.waUploadToServer }
201
- );
202
- }
203
- mediaType = 'image';
204
- } else if (video) {
205
- if (typeof video === 'object' && video.url) {
206
- media = await this.utils.prepareWAMessageMedia(
207
- { video: { url: video.url } },
208
- { upload: this.waUploadToServer }
209
- );
210
- } else {
211
- media = await this.utils.prepareWAMessageMedia(
212
- { video },
213
- { upload: this.waUploadToServer }
214
- );
215
- }
216
- mediaType = 'video';
217
- } else if (document) {
218
- let documentPayload = { document };
219
- if (jpegThumbnail) {
220
- if (typeof jpegThumbnail === 'object' && jpegThumbnail.url) {
221
- documentPayload.jpegThumbnail = { url: jpegThumbnail.url };
222
- } else {
223
- documentPayload.jpegThumbnail = jpegThumbnail;
224
- }
225
- }
226
- media = await this.utils.prepareWAMessageMedia(
227
- documentPayload,
228
- { upload: this.waUploadToServer }
229
- );
230
- if (fileName) media.documentMessage.fileName = fileName;
231
- if (mimetype) media.documentMessage.mimetype = mimetype;
232
- mediaType = 'document';
233
- }
234
-
235
- let interactiveMessage = {
236
- body: { text: title || "" },
237
- footer: { text: footer || "" }
238
- };
239
-
240
- if (buttons && buttons.length > 0) {
241
- interactiveMessage.nativeFlowMessage = { buttons };
242
- if (nativeFlowMessage) {
243
- interactiveMessage.nativeFlowMessage = {
244
- ...interactiveMessage.nativeFlowMessage,
245
- ...nativeFlowMessage
246
- };
247
- }
248
- } else if (nativeFlowMessage) {
249
- interactiveMessage.nativeFlowMessage = nativeFlowMessage;
250
- }
251
-
252
- // FIXED: safer header spreading
253
- if (media) {
254
- const headerMedia = {};
255
- if (media.imageMessage) headerMedia.imageMessage = media.imageMessage;
256
- if (media.videoMessage) headerMedia.videoMessage = media.videoMessage;
257
- if (media.documentMessage) headerMedia.documentMessage = media.documentMessage;
258
-
259
- interactiveMessage.header = {
260
- title: header || "",
261
- hasMediaAttachment: true,
262
- ...headerMedia
263
- };
264
- } else {
265
- interactiveMessage.header = {
266
- title: header || "",
267
- hasMediaAttachment: false
268
- };
269
- }
270
-
271
- let finalContextInfo = {};
272
- if (contextInfo) {
273
- finalContextInfo = {
274
- mentionedJid: contextInfo.mentionedJid || [],
275
- forwardingScore: contextInfo.forwardingScore || 0,
276
- isForwarded: contextInfo.isForwarded || false,
277
- ...contextInfo
278
- };
279
- }
280
-
281
- if (externalAdReply) {
282
- finalContextInfo.externalAdReply = {
283
- title: externalAdReply.title || "",
284
- body: externalAdReply.body || "",
285
- mediaType: externalAdReply.mediaType || 1,
286
- thumbnailUrl: externalAdReply.thumbnailUrl || "",
287
- mediaUrl: externalAdReply.mediaUrl || "",
288
- sourceUrl: externalAdReply.sourceUrl || "",
289
- showAdAttribution: externalAdReply.showAdAttribution || false,
290
- renderLargerThumbnail: externalAdReply.renderLargerThumbnail || false,
291
- ...externalAdReply
292
- };
293
- }
294
-
295
- if (Object.keys(finalContextInfo).length > 0) {
296
- interactiveMessage.contextInfo = finalContextInfo;
297
- }
298
-
299
- return { interactiveMessage };
300
- } catch (err) {
301
- console.error('handleInteractive error:', err);
302
- throw err;
303
- }
304
- }
305
-
306
- async handleAlbum(content, jid, quoted) {
307
- try {
308
- const array = Array.isArray(content.albumMessage) ? content.albumMessage : [];
309
- if (array.length === 0) throw new Error('albumMessage harus berupa array dengan isi media');
310
-
311
- const album = await this.utils.generateWAMessageFromContent(jid, {
312
- messageContextInfo: {
313
- messageSecret: crypto.randomBytes(32),
314
- },
315
- albumMessage: {
316
- expectedImageCount: array.filter(a => a.image).length,
317
- expectedVideoCount: array.filter(a => a.video).length,
318
- },
319
- }, {
320
- userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
321
- quoted,
322
- upload: this.waUploadToServer
323
- });
324
-
325
- await this.relayMessage(jid, album.message, { messageId: album.key.id });
326
-
327
- for (let item of array) {
328
- const img = await this.utils.generateWAMessage(jid, item, {
329
- upload: this.waUploadToServer,
330
- });
331
-
332
- img.message.messageContextInfo = {
333
- messageSecret: crypto.randomBytes(32),
334
- messageAssociation: {
335
- associationType: 1,
336
- parentMessageKey: album.key,
337
- },
338
- participant: "0@s.whatsapp.net",
339
- remoteJid: "status@broadcast",
340
- forwardingScore: 99999,
341
- isForwarded: true,
342
- mentionedJid: [jid],
343
- starred: true,
344
- labels: ["Y", "Important"],
345
- isHighlighted: true,
346
- businessMessageForwardInfo: {
347
- businessOwnerJid: jid,
348
- },
349
- dataSharingContext: {
350
- showMmDisclosure: true,
351
- },
352
- };
353
-
354
- img.message.forwardedNewsletterMessageInfo = {
355
- newsletterJid: "0@newsletter",
356
- serverMessageId: 1,
357
- newsletterName: `WhatsApp`,
358
- contentType: 1,
359
- timestamp: new Date().toISOString(),
360
- senderName: "kikyy dugonggg",
361
- content: "Text Message",
362
- priority: "high",
363
- status: "sent",
364
- };
365
-
366
- img.message.disappearingMode = {
367
- initiator: 3,
368
- trigger: 4,
369
- initiatorDeviceJid: jid,
370
- initiatedByExternalService: true,
371
- initiatedByUserDevice: true,
372
- initiatedBySystem: true,
373
- initiatedByServer: true,
374
- initiatedByAdmin: true,
375
- initiatedByUser: true,
376
- initiatedByApp: true,
377
- initiatedByBot: true,
378
- initiatedByMe: true,
379
- };
380
-
381
- await this.relayMessage(jid, img.message, {
382
- messageId: img.key.id,
383
- quoted: {
384
- key: {
385
- remoteJid: album.key.remoteJid,
386
- id: album.key.id,
387
- fromMe: true,
388
- participant: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
389
- },
390
- message: album.message,
391
- },
392
- });
393
- }
394
- return album;
395
- } catch (err) {
396
- console.error('handleAlbum error:', err);
397
- throw err;
398
- }
399
- }
400
-
401
- async handleEvent(content, jid, quoted) {
402
- try {
403
- const eventData = content.eventMessage;
404
- if (!eventData) throw new Error('Missing eventMessage');
405
-
406
- const msg = await this.utils.generateWAMessageFromContent(jid, {
407
- viewOnceMessage: {
408
- message: {
409
- messageContextInfo: {
410
- deviceListMetadata: {},
411
- deviceListMetadataVersion: 2,
412
- messageSecret: crypto.randomBytes(32),
413
- supportPayload: JSON.stringify({
414
- version: 2,
415
- is_ai_message: true,
416
- should_show_system_message: true,
417
- ticket_id: crypto.randomBytes(16).toString('hex')
418
- })
419
- },
420
- eventMessage: {
421
- contextInfo: {
422
- mentionedJid: [jid],
423
- participant: jid,
424
- remoteJid: "status@broadcast",
425
- forwardedNewsletterMessageInfo: {
426
- newsletterName: "shenvn.",
427
- newsletterJid: "120363297591152843@newsletter",
428
- serverMessageId: 1
429
- }
430
- },
431
- isCanceled: eventData.isCanceled || false,
432
- name: eventData.name,
433
- description: eventData.description,
434
- location: eventData.location || {
435
- degreesLatitude: 0,
436
- degreesLongitude: 0,
437
- name: "Location"
438
- },
439
- joinLink: eventData.joinLink || '',
440
- startTime: typeof eventData.startTime === 'string' ? parseInt(eventData.startTime) : eventData.startTime || Date.now(),
441
- endTime: typeof eventData.endTime === 'string' ? parseInt(eventData.endTime) : eventData.endTime || Date.now() + 3600000,
442
- extraGuestsAllowed: eventData.extraGuestsAllowed !== false
443
- }
444
- }
445
- }
446
- }, { quoted });
447
-
448
- await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
449
- return msg;
450
- } catch (err) {
451
- console.error('handleEvent error:', err);
452
- throw err;
453
- }
454
- }
455
-
456
- async handlePollResult(content, jid, quoted) {
457
- try {
458
- const pollData = content.pollResultMessage;
459
- if (!pollData) throw new Error('Missing pollResultMessage');
460
-
461
- const msg = await this.utils.generateWAMessageFromContent(jid, {
462
- pollResultSnapshotMessage: {
463
- name: pollData.name,
464
- pollVotes: (pollData.pollVotes || []).map(vote => ({
465
- optionName: vote.optionName,
466
- optionVoteCount: typeof vote.optionVoteCount === 'number'
467
- ? vote.optionVoteCount.toString()
468
- : vote.optionVoteCount
469
- }))
470
- }
471
- }, {
472
- userJid: this.utils.generateMessageID().split('@')[0] + '@s.whatsapp.net',
473
- quoted
474
- });
475
-
476
- await this.relayMessage(jid, msg.message, { messageId: msg.key.id });
477
- return msg;
478
- } catch (err) {
479
- console.error('handlePollResult error:', err);
480
- throw err;
481
- }
482
- }
483
-
484
- async handleGroupStory(content, jid, quoted) {
485
- try {
486
- const storyData = content.groupStatusMessage;
487
- if (!storyData) throw new Error('Missing groupStatusMessage');
488
-
489
- let waMsgContent;
490
- if (storyData.message) {
491
- waMsgContent = storyData;
492
- } else {
493
- if (typeof this.bail?.generateWAMessageContent === "function") {
494
- waMsgContent = await this.bail.generateWAMessageContent(storyData, {
495
- upload: this.waUploadToServer
496
- });
497
- } else if (typeof this.utils?.generateWAMessageContent === "function") {
498
- waMsgContent = await this.utils.generateWAMessageContent(storyData, {
499
- upload: this.waUploadToServer
500
- });
501
- } else if (typeof this.utils?.prepareMessageContent === "function") {
502
- waMsgContent = await this.utils.prepareMessageContent(storyData, {
503
- upload: this.waUploadToServer
504
- });
505
- } else {
506
- waMsgContent = await Utils_1.generateWAMessageContent(storyData, {
507
- upload: this.waUploadToServer
508
- });
509
- }
510
- }
511
-
512
- let msg = {
513
- message: {
514
- groupStatusMessageV2: {
515
- message: waMsgContent.message || waMsgContent
516
- }
517
- }
518
- };
519
-
520
- return await this.relayMessage(jid, msg.message, {
521
- messageId: this.bail.generateMessageID()
522
- });
523
- } catch (err) {
524
- console.error('handleGroupStory error:', err);
525
- throw err;
526
- }
527
- }
528
- }
529
-
530
- module.exports = RexxHayanasi;
@@ -1,29 +0,0 @@
1
- const { Buffer } = require("buffer")
2
- const fs = require("fs/promises")
3
- const { Readable } = require("stream")
4
- const streamToBuffer = require("./streamToBuffer")
5
-
6
- /**
7
- * Mengonversi berbagai input audio (Buffer, URL, path file, atau Readable stream) menjadi Buffer.
8
- * @param {Buffer|string|Readable} audio Input audio.
9
- * @returns {Promise<Buffer>} Buffer hasil konversi.
10
- */
11
- async function audioToBuffer(audio) {
12
- if (Buffer.isBuffer(audio)) {
13
- return audio
14
- }
15
-
16
- if (typeof audio === "string") {
17
- if (/^https?:\/\//.test(audio)) {
18
- const res = await fetch(audio) // native fetch bawaan Node 20
19
- return Buffer.from(await res.arrayBuffer())
20
- }
21
- return fs.readFile(audio)
22
- }
23
-
24
- if (audio instanceof Readable) {
25
- return streamToBuffer(audio)
26
- }
27
-
28
- throw new TypeError("Unsupported audio input type")
29
- }
@@ -1,15 +0,0 @@
1
- const { Readable } = require("stream");
2
-
3
- /**
4
- * Mengonversi Node.js Readable Stream menjadi Buffer.
5
- * * @param {Readable} stream Aliran data yang dapat dibaca.
6
- * @returns {Promise<Buffer>} Promise yang diselesaikan dengan Buffer berisi semua data dari aliran.
7
- */
8
- async function streamToBuffer(stream) {
9
- const chunks = [];
10
- return new Promise((resolve, reject) => {
11
- stream.on('data', chunk => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
12
- stream.on('end', () => resolve(Buffer.concat(chunks)));
13
- stream.on('error', reject);
14
- });
15
- }
package/lib/index.js.bak DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
-
3
- const chalk = require("chalk");
4
- const gradient = require("gradient-string");
5
-
6
- console.log();
7
- console.log(
8
- chalk.bold.hex('#FFA500')('@rexxhayanasi/elaina-bail') + chalk.bold.cyan('Baileys')
9
- );
10
- console.log(gradient(['magenta', 'cyan'])('> Contact Owner at Baileys Documentation <'));
11
- console.log();
12
-
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
- for (var p in m)
26
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p))
27
- __createBinding(exports, m, p);
28
- };
29
- var __importDefault = (this && this.__importDefault) || function(mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod };
31
- };
32
-
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.proto = exports.makeWASocket = void 0;
35
-
36
- const WAProto_1 = require("../WAProto");
37
- Object.defineProperty(exports, "proto", {
38
- enumerable: true,
39
- get: function() {
40
- return WAProto_1.proto;
41
- }
42
- });
43
-
44
- const Socket_1 = __importDefault(require("./Socket"));
45
- exports.makeWASocket = Socket_1.default;
46
-
47
- __exportStar(require("../WAProto"), exports);
48
- __exportStar(require("./Utils"), exports);
49
- __exportStar(require("./Types"), exports);
50
- __exportStar(require("./Store"), exports);
51
- __exportStar(require("./Defaults"), exports);
52
- __exportStar(require("./WABinary"), exports);
53
- __exportStar(require("./WAM"), exports);
54
- __exportStar(require("./WAUSync"), exports);
55
-
56
- exports.default = Socket_1.default;