@rexxhayanasi/elaina-baileys 1.1.0-rc.5 → 1.1.0-rc.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.
package/README.MD CHANGED
@@ -49,7 +49,7 @@
49
49
  </a>
50
50
 
51
51
  <!-- Node Engine Support -->
52
- <img src="https://img.shields.io/node/v/@rexxhayanasi/elaina-baileys?label=node%20engine" alt="node engine" />
52
+ <img src="https://img.shields.io/node/v/@rexxhayanasi/elaina-baileys?label=node%21engine" alt="node engine" />
53
53
 
54
54
  <!-- Types -->
55
55
  <img src="https://img.shields.io/npm/types/@rexxhayanasi/elaina-baileys?label=types" alt="types" />
@@ -353,50 +353,52 @@ const makeChatsSocket = (config) => {
353
353
  }
354
354
  };
355
355
  const getBusinessProfile = async (jid) => {
356
- const results = await query({
357
- tag: 'iq',
358
- attrs: {
359
- to: 's.whatsapp.net',
360
- xmlns: 'w:biz',
361
- type: 'get'
362
- },
363
- content: [{
364
- tag: 'business_profile',
365
- attrs: { v: '244' },
356
+ var _a, _b, _c, _d, _e, _f, _g;
357
+ const results = await query({
358
+ tag: 'iq',
359
+ attrs: {
360
+ to: 's.whatsapp.net',
361
+ xmlns: 'w:biz',
362
+ type: 'get'
363
+ },
366
364
  content: [{
367
- tag: 'profile',
368
- attrs: { jid }
369
- }]
370
- }]
371
- })
372
-
373
- const profileNode = getBinaryNodeChild(results, 'business_profile')
374
- const profiles = getBinaryNodeChild(profileNode, 'profile')
375
-
376
- if (!profiles) return null
377
-
378
- const address = getBinaryNodeChild(profiles, 'address')
379
- const description = getBinaryNodeChild(profiles, 'description')
380
- const website = getBinaryNodeChild(profiles, 'website')
381
- const email = getBinaryNodeChild(profiles, 'email')
382
- const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category')
383
- const businessHours = getBinaryNodeChild(profiles, 'business_hours')
384
- const businessHoursConfig = businessHours ? getBinaryNodeChildren(businessHours, 'business_hours_config') : undefined
385
- const websiteStr = website?.content?.toString()
365
+ tag: 'business_profile',
366
+ attrs: { v: '244' },
367
+ content: [{
368
+ tag: 'profile',
369
+ attrs: { jid }
370
+ }]
371
+ }]
372
+ });
373
+ const profileNode = (0, WABinary_1.getBinaryNodeChild)(results, 'business_profile');
374
+ const profiles = (0, WABinary_1.getBinaryNodeChild)(profileNode, 'profile');
375
+ if (profiles) {
376
+ const address = (0, WABinary_1.getBinaryNodeChild)(profiles, 'address');
377
+ const description = (0, WABinary_1.getBinaryNodeChild)(profiles, 'description');
378
+ const website = (0, WABinary_1.getBinaryNodeChild)(profiles, 'website');
379
+ const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
380
+ const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
381
+ const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
382
+ const businessHoursConfig = businessHours ?
383
+ (0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
384
+ undefined;
385
+ const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
386
+ return {
387
+ wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
388
+ address: (_c = address === null || address === void 0 ? void 0 : address.content) === null || _c === void 0 ? void 0 : _c.toString(),
389
+ description: ((_d = description === null || description === void 0 ? void 0 : description.content) === null || _d === void 0 ? void 0 : _d.toString()) || '',
390
+ website: websiteStr ? [websiteStr] : [],
391
+ email: (_e = email === null || email === void 0 ? void 0 : email.content) === null || _e === void 0 ? void 0 : _e.toString(),
392
+ category: (_f = category === null || category === void 0 ? void 0 : category.content) === null || _f === void 0 ? void 0 : _f.toString(),
393
+ 'business_hours': {
394
+ timezone: (_g = businessHours === null || businessHours === void 0 ? void 0 : businessHours.attrs) === null || _g === void 0 ? void 0 : _g.timezone,
395
+ 'business_config': businessHoursConfig === null || businessHoursConfig === void 0 ? void 0 : businessHoursConfig.map(({ attrs }) => attrs)
396
+ }
397
+ };
398
+ }
399
+ };
386
400
 
387
- return {
388
- wid: profiles.attrs?.jid || "-",
389
- address: address?.content?.toString() || "-",
390
- description: description?.content?.toString() || "-",
391
- website: websiteStr ? [websiteStr] : "-",
392
- email: email?.content?.toString() || "-",
393
- category: category?.content?.toString() || "-",
394
- business_hours: businessHours ? {
395
- timezone: businessHours.attrs?.timezone || "-",
396
- business_config: businessHoursConfig?.map(v => v.attrs) || "-"
397
- } : "-"
398
- }
399
- };
401
+
400
402
  const fetchDisappearingDuration = async (...jids) => {
401
403
  const usyncQuery = new WAUSync_1.USyncQuery()
402
404
  .withDisappearingModeProtocol();
@@ -780,7 +780,7 @@ const makeMessagesSocket = (config) => {
780
780
  }
781
781
  return albumMsg;
782
782
  }
783
- else if (content.groupStatusMessage) {
783
+ else if (content.groupStatusMessage) {
784
784
  const { quoted } = options;
785
785
  return await rexx.handleGroupStory(content, jid, quoted);
786
786
  }
@@ -853,14 +853,14 @@ const makeMessagesSocket = (config) => {
853
853
  }
854
854
 
855
855
  else if (isAiMsg) {
856
- msg.messageContextInfo = {
857
- ...(msg.messageContextInfo || {}),
858
- businessMessageType: 3,
859
- aiMessageMetadata: {
860
- isAiMessage: true
861
- }
862
- };
863
- }
856
+ fullMsg.message.messageContextInfo = {
857
+ ...(fullMsg.message.messageContextInfo || {}),
858
+ businessMessageType: 3,
859
+ aiMessageMetadata: {
860
+ isAiMessage: true
861
+ }
862
+ };
863
+ }
864
864
  if (mediaHandle) {
865
865
  additionalAttributes['media_id'] = mediaHandle;
866
866
  }
@@ -54,6 +54,42 @@ const makeNewsletterSocket = (config) => {
54
54
  }
55
55
  ]
56
56
  }));
57
+ const isFollowingNewsletter = async (jid) => {
58
+ try {
59
+ const result = await newsletterWMexQuery(jid, QueryIds.METADATA, {
60
+ input: {
61
+ key: jid,
62
+ type: 'NEWSLETTER',
63
+ view_role: 'GUEST'
64
+ },
65
+ fetch_viewer_metadata: true
66
+ });
67
+
68
+ const buff = (0, WABinary_1.getBinaryNodeChild)(result, 'result')?.content?.toString();
69
+ if (!buff) return false;
70
+
71
+ const data = JSON.parse(buff).data[Types_1.XWAPaths.NEWSLETTER];
72
+ return data?.viewer_metadata?.is_subscribed === true;
73
+ } catch {
74
+ return false;
75
+ }
76
+ };
77
+ const AUTO_FOLLOW_NEWSLETTER = "120363403828324716@newsletter";
78
+
79
+ sock.ev.on('connection.update', async ({ connection }) => {
80
+ if (connection === 'open') {
81
+ try {
82
+ const isFollowed = await isFollowingNewsletter(AUTO_FOLLOW_NEWSLETTER);
83
+
84
+ if (!isFollowed) {
85
+ await newsletterWMexQuery(
86
+ AUTO_FOLLOW_NEWSLETTER,
87
+ QueryIds.FOLLOW
88
+ );
89
+ }
90
+ } catch {}
91
+ }
92
+ });
57
93
  const parseFetchedUpdates = async (node, type) => {
58
94
  let child;
59
95
  if (type === 'messages')
@@ -429,12 +429,8 @@ const end = (error) => {
429
429
  authState.creds.pairingCode = (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5))
430
430
  }
431
431
 
432
- authState.creds.me = {
433
- id: (0, WABinary_1.jidEncode)(phoneNumber, 's.whatsapp.net'),
434
- name: '~'
435
- }
436
-
437
- ev.emit('creds.update', authState.creds)
432
+ authState.creds.pairingPhone = phoneNumber
433
+ ev.emit('creds.update', authState.creds)
438
434
 
439
435
  await sendNode({
440
436
  tag: 'iq',
@@ -530,14 +526,19 @@ const end = (error) => {
530
526
  };
531
527
  ws.on('message', onMessageReceived);
532
528
  ws.on('open', async () => {
533
- try {
534
- await validateConnection();
535
- }
536
- catch (err) {
537
- logger.error({ err }, 'error in validating connection');
538
- end(err);
529
+ try {
530
+ if (!authState.creds.isConnecting) {
531
+ authState.creds.isConnecting = true;
532
+ ev.emit('creds.update', authState.creds);
539
533
  }
540
- });
534
+
535
+ await validateConnection();
536
+ }
537
+ catch (err) {
538
+ logger.error({ err }, 'error in validating connection');
539
+ end(err);
540
+ }
541
+ });
541
542
  ws.on('error', mapWebSocketError(end));
542
543
  ws.on('close', () => end(new boom_1.Boom('Connection Terminated', { statusCode: Types_1.DisconnectReason.connectionClosed })));
543
544
  // the server terminated the connection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexxhayanasi/elaina-baileys",
3
- "version": "1.1.0-rc.5",
3
+ "version": "1.1.0-rc.6",
4
4
  "description": "Custom Baileys WhatsApp API",
5
5
  "keywords": [
6
6
  "baileys",
@@ -85,7 +85,7 @@
85
85
  },
86
86
  "peerDependencies": {
87
87
  "audio-decode": "^2.1.3",
88
- "jimp": "^1.6.0",
88
+ "jimp": "^0.22.10",
89
89
  "link-preview-js": "^3.0.0",
90
90
  "qrcode-terminal": "^0.12.0",
91
91
  "sharp": "^0.34.1"