@rexxhayanasi/elaina-baileys 1.1.0-rc.4 → 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.
@@ -24,7 +24,14 @@ const SyncState = {
24
24
  Online: 'online'
25
25
  };
26
26
  const makeChatsSocket = (config) => {
27
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
27
+ const {
28
+ logger,
29
+ markOnlineOnConnect,
30
+ fireInitQueries,
31
+ appStateMacVerification,
32
+ shouldIgnoreJid,
33
+ shouldSyncHistoryMessage,
34
+ relayMessage, } = config;
28
35
  const sock = (0, usync_1.makeUSyncSocket)(config);
29
36
  const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError, } = sock;
30
37
  let privacySettings;
@@ -346,50 +353,52 @@ const makeChatsSocket = (config) => {
346
353
  }
347
354
  };
348
355
  const getBusinessProfile = async (jid) => {
349
- const results = await query({
350
- tag: 'iq',
351
- attrs: {
352
- to: 's.whatsapp.net',
353
- xmlns: 'w:biz',
354
- type: 'get'
355
- },
356
- content: [{
357
- tag: 'business_profile',
358
- 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
+ },
359
364
  content: [{
360
- tag: 'profile',
361
- attrs: { jid }
362
- }]
363
- }]
364
- })
365
-
366
- const profileNode = getBinaryNodeChild(results, 'business_profile')
367
- const profiles = getBinaryNodeChild(profileNode, 'profile')
368
-
369
- if (!profiles) return null
370
-
371
- const address = getBinaryNodeChild(profiles, 'address')
372
- const description = getBinaryNodeChild(profiles, 'description')
373
- const website = getBinaryNodeChild(profiles, 'website')
374
- const email = getBinaryNodeChild(profiles, 'email')
375
- const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category')
376
- const businessHours = getBinaryNodeChild(profiles, 'business_hours')
377
- const businessHoursConfig = businessHours ? getBinaryNodeChildren(businessHours, 'business_hours_config') : undefined
378
- 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
+ };
379
400
 
380
- return {
381
- wid: profiles.attrs?.jid || "-",
382
- address: address?.content?.toString() || "-",
383
- description: description?.content?.toString() || "-",
384
- website: websiteStr ? [websiteStr] : "-",
385
- email: email?.content?.toString() || "-",
386
- category: category?.content?.toString() || "-",
387
- business_hours: businessHours ? {
388
- timezone: businessHours.attrs?.timezone || "-",
389
- business_config: businessHoursConfig?.map(v => v.attrs) || "-"
390
- } : "-"
391
- }
392
- };
401
+
393
402
  const fetchDisappearingDuration = async (...jids) => {
394
403
  const usyncQuery = new WAUSync_1.USyncQuery()
395
404
  .withDisappearingModeProtocol();
@@ -857,6 +866,47 @@ const getBusinessProfile = async (jid) => {
857
866
  const removeContact = (jid) => {
858
867
  return chatModify({ contact: null }, jid);
859
868
  };
869
+
870
+ const addLabelMember = async (jid, label, timestamp = Date.now()) => {
871
+ try {
872
+ return await relayMessage(
873
+ jid,
874
+ {
875
+ protocolMessage: {
876
+ type: 30,
877
+ memberLabel: {
878
+ label,
879
+ labelTimestamp: timestamp
880
+ }
881
+ }
882
+ },
883
+ {}
884
+ )
885
+ } catch (e) {
886
+ logger.error('Failed addLabelMember: ' + e)
887
+ throw e
888
+ }
889
+ }
890
+
891
+ const removeLabelMember = async (jid) => {
892
+ try {
893
+ return await relayMessage(
894
+ jid,
895
+ {
896
+ protocolMessage: {
897
+ type: 30,
898
+ memberLabel: {
899
+ label: ''
900
+ }
901
+ }
902
+ },
903
+ {}
904
+ )
905
+ } catch (e) {
906
+ logger.error('Failed removeLabelMember: ' + e)
907
+ throw e
908
+ }
909
+ }
860
910
  const addLabel = (jid, labels) => {
861
911
  return chatModify({ addLabel: { ...labels } }, jid);
862
912
  };
@@ -1079,7 +1129,9 @@ const getBusinessProfile = async (jid) => {
1079
1129
  removeChatLabel,
1080
1130
  addMessageLabel,
1081
1131
  removeMessageLabel,
1082
- star
1132
+ star,
1133
+ addLabelMember,
1134
+ removeLabelMember
1083
1135
  };
1084
1136
  };
1085
1137
  exports.makeChatsSocket = makeChatsSocket;
@@ -780,10 +780,10 @@ const makeMessagesSocket = (config) => {
780
780
  }
781
781
  return albumMsg;
782
782
  }
783
- else if (rexx.detectType(content) === 'GROUP_STORY') {
784
- const { quoted } = options;
783
+ else if (content.groupStatusMessage) {
784
+ const { quoted } = options;
785
785
  return await rexx.handleGroupStory(content, jid, quoted);
786
- }
786
+ }
787
787
  else {
788
788
  let mediaHandle;
789
789
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
@@ -816,7 +816,7 @@ const makeMessagesSocket = (config) => {
816
816
  const isPinMsg = 'pin' in content && !!content.pin;
817
817
  const isKeepMsg = 'keep' in content && content.keep;
818
818
  const isPollMessage = 'poll' in content && !!content.poll;
819
- const isAiMsg = 'ai' in content && !!content.ai;
819
+ const isAiMsg = content && content.ai === true;
820
820
  const additionalAttributes = {};
821
821
  const additionalNodes = [];
822
822
  // required for delete
@@ -851,14 +851,16 @@ const makeMessagesSocket = (config) => {
851
851
  });
852
852
  // required to display AI icon on message
853
853
  }
854
+
854
855
  else if (isAiMsg) {
855
- additionalNodes.push({
856
- attrs: {
857
- biz_bot: '1'
858
- },
859
- tag: "bot"
860
- });
861
- }
856
+ fullMsg.message.messageContextInfo = {
857
+ ...(fullMsg.message.messageContextInfo || {}),
858
+ businessMessageType: 3,
859
+ aiMessageMetadata: {
860
+ isAiMessage: true
861
+ }
862
+ };
863
+ }
862
864
  if (mediaHandle) {
863
865
  additionalAttributes['media_id'] = mediaHandle;
864
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.4",
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"