@itsliaaa/baileys 0.1.16-beta.2 → 0.1.17

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
@@ -585,8 +585,10 @@ sock.sendMessage(jid, {
585
585
  footer: '@itsliaaa/baileys',
586
586
  optionText: '👉🏻 Select Options', // --- Optional, wrap all native flow into a single list
587
587
  optionTitle: '📄 Select Options', // --- Optional
588
- couponText: '🏷️ Newest Coupon!', // --- Optional, add coupon into message
589
- couponCode: '@itsliaaa/baileys', // --- Optional
588
+ offerText: '🏷️ Newest Coupon!', // --- Optional, add an offer into message
589
+ offerCode: '@itsliaaa/baileys', // --- Optional
590
+ offerUrl: 'https://www.npmjs.com/package/@itsliaaa/baileys', // --- Optional
591
+ offerExpiration: Date.now() + 3_600_000, // --- Optional
590
592
  nativeFlow: [{
591
593
  text: '👋🏻 Greeting',
592
594
  id: '#Greeting'
@@ -598,7 +600,7 @@ sock.sendMessage(jid, {
598
600
  copy: '@itsliaaa/baileys'
599
601
  }, {
600
602
  text: '🌐 Source',
601
- url: 'https://www.npmjs.com/package/baileys'
603
+ url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
602
604
  }, {
603
605
  text: '📋 Select',
604
606
  sections: [{
@@ -637,7 +639,7 @@ sock.sendMessage(jid, {
637
639
  footer: '🏷️️ Pinterest',
638
640
  nativeFlow: [{
639
641
  text: '🌐 Source',
640
- url: 'https://www.npmjs.com/package/baileys'
642
+ url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
641
643
  }]
642
644
  }, {
643
645
  image: {
@@ -645,11 +647,13 @@ sock.sendMessage(jid, {
645
647
  },
646
648
  caption: '🖼️ Image 2',
647
649
  footer: '🏷️ Pinterest',
648
- couponText: '🏷️ New Coupon!',
649
- couponCode: '@itsliaaa/baileys',
650
+ offerText: '🏷️ New Coupon!',
651
+ offerCode: '@itsliaaa/baileys',
652
+ offerUrl: 'https://www.npmjs.com/package/@itsliaaa/baileys',
653
+ offerExpiration: Date.now() + 3_600_000,
650
654
  nativeFlow: [{
651
655
  text: '🌐 Source',
652
- url: 'https://www.npmjs.com/package/baileys'
656
+ url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
653
657
  }]
654
658
  }, {
655
659
  image: {
@@ -659,14 +663,16 @@ sock.sendMessage(jid, {
659
663
  footer: '🏷️ Pinterest',
660
664
  optionText: '👉🏻 Select Options',
661
665
  optionTitle: '📄 Select Options',
662
- couponText: '🏷️ New Coupon!',
663
- couponCode: '@itsliaaa/baileys',
666
+ offerText: '🏷️ New Coupon!',
667
+ offerCode: '@itsliaaa/baileys',
668
+ offerUrl: 'https://www.npmjs.com/package/@itsliaaa/baileys',
669
+ offerExpiration: Date.now() + 3_600_000,
664
670
  nativeFlow: [{
665
671
  text: '🛒 Product',
666
672
  id: '#Product'
667
673
  }, {
668
674
  text: '🌐 Source',
669
- url: 'https://www.npmjs.com/package/baileys'
675
+ url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
670
676
  }]
671
677
  }]
672
678
  }, {
@@ -689,7 +695,7 @@ sock.sendMessage(jid, {
689
695
  id: '#Order'
690
696
  }, {
691
697
  text: '🌐 Source',
692
- url: 'https://www.npmjs.com/package/baileys'
698
+ url: 'https://www.npmjs.com/package/@itsliaaa/baileys'
693
699
  }, {
694
700
  text: '📞 Call',
695
701
  call: '628123456789'
@@ -806,7 +812,7 @@ sock.sendMessage(jid, {
806
812
  body: '❓ I dont know',
807
813
  thumbnail: fs.readFileSync('./path/to/image.jpg'), // --- Must in buffer format
808
814
  largeThumbnail: false, // --- Or true for bigger thumbnail
809
- url: 'https://www.npmjs.com/package/baileys' // --- Optional, used for WhatsApp internal thumbnail caching and direct URL
815
+ url: 'https://www.npmjs.com/package/@itsliaaa/baileys' // --- Optional, used for WhatsApp internal thumbnail caching and direct URL
810
816
  }
811
817
  }, {
812
818
  quoted: message
@@ -854,7 +860,7 @@ sock.sendMessage(jid, {
854
860
 
855
861
  ```javascript
856
862
  sock.sendMessage(jid, {
857
- text: 'Just a label!',
863
+ text: '🏷️ Just a label!',
858
864
  secureMetaServiceLabel: true
859
865
  })
860
866
  ```
package/WAProto/index.js CHANGED
@@ -58091,6 +58091,7 @@ export const proto = $root.proto = (() => {
58091
58091
  HistorySyncOnDemandRequest.prototype.onDemandMsgCount = null;
58092
58092
  HistorySyncOnDemandRequest.prototype.oldestMsgTimestampMs = null;
58093
58093
  HistorySyncOnDemandRequest.prototype.accountLid = null;
58094
+ HistorySyncOnDemandRequest.prototype.supportInlineResponse = null;
58094
58095
 
58095
58096
  let $oneOfFields;
58096
58097
 
@@ -58124,6 +58125,11 @@ export const proto = $root.proto = (() => {
58124
58125
  set: $util.oneOfSetter($oneOfFields)
58125
58126
  });
58126
58127
 
58128
+ Object.defineProperty(HistorySyncOnDemandRequest.prototype, "_supportInlineResponse", {
58129
+ get: $util.oneOfGetter($oneOfFields = ["supportInlineResponse"]),
58130
+ set: $util.oneOfSetter($oneOfFields)
58131
+ });
58132
+
58127
58133
  HistorySyncOnDemandRequest.create = function create(properties) {
58128
58134
  return new HistorySyncOnDemandRequest(properties);
58129
58135
  };
@@ -58143,6 +58149,8 @@ export const proto = $root.proto = (() => {
58143
58149
  w.uint32(40).int64(m.oldestMsgTimestampMs);
58144
58150
  if (m.accountLid != null && Object.hasOwnProperty.call(m, "accountLid"))
58145
58151
  w.uint32(50).string(m.accountLid);
58152
+ if (m.supportInlineResponse != null && Object.hasOwnProperty.call(m, "supportInlineResponse"))
58153
+ w.uint32(56).bool(m.supportInlineResponse);
58146
58154
  return w;
58147
58155
  };
58148
58156
 
@@ -58179,6 +58187,10 @@ export const proto = $root.proto = (() => {
58179
58187
  m.accountLid = r.string();
58180
58188
  break;
58181
58189
  }
58190
+ case 7: {
58191
+ m.supportInlineResponse = r.bool();
58192
+ break;
58193
+ }
58182
58194
  default:
58183
58195
  r.skipType(t & 7);
58184
58196
  break;
@@ -58216,6 +58228,9 @@ export const proto = $root.proto = (() => {
58216
58228
  if (d.accountLid != null) {
58217
58229
  m.accountLid = String(d.accountLid);
58218
58230
  }
58231
+ if (d.supportInlineResponse != null) {
58232
+ m.supportInlineResponse = Boolean(d.supportInlineResponse);
58233
+ }
58219
58234
  return m;
58220
58235
  };
58221
58236
 
@@ -58256,6 +58271,11 @@ export const proto = $root.proto = (() => {
58256
58271
  if (o.oneofs)
58257
58272
  d._accountLid = "accountLid";
58258
58273
  }
58274
+ if (m.supportInlineResponse != null && m.hasOwnProperty("supportInlineResponse")) {
58275
+ d.supportInlineResponse = m.supportInlineResponse;
58276
+ if (o.oneofs)
58277
+ d._supportInlineResponse = "supportInlineResponse";
58278
+ }
58259
58279
  return d;
58260
58280
  };
58261
58281
 
@@ -507,7 +507,20 @@ export const makeMessagesSocket = (config) => {
507
507
  return;
508
508
  }
509
509
  // Lia@Changes 02-02-26 --- Add keepInChat, editedMessage, mediaNotifyMessage and pollUpdateMessage
510
- if (innerMessage?.pinInChatMessage || innerMessage?.pollUpdateMessage || innerMessage?.keepInChatMessage || innerMessage?.protocolMessage?.editedMessage || innerMessage?.protocolMessage?.mediaNotifyMessage || innerMessage?.reactionMessage) {
510
+ const isNeedMetaAttrs = innerMessage?.pinInChatMessage || innerMessage?.keepInChatMessage || innerMessage?.reactionMessage
511
+ if (isNeedMetaAttrs) {
512
+ const metaAttrs = {};
513
+ if (innerMessage?.pollUpdateMessage) {
514
+ metaAttrs.polltype = 'vote';
515
+ }
516
+ metaAttrs.content_type = 'add_on';
517
+ binaryNodeContent.push({
518
+ tag: 'meta',
519
+ attrs: metaAttrs,
520
+ content: undefined
521
+ });
522
+ }
523
+ if (isNeedMetaAttrs || innerMessage?.protocolMessage?.editedMessage || innerMessage?.protocolMessage?.mediaNotifyMessage) {
511
524
  extraAttrs['decrypt-fail'] = 'hide'; // todo: expand for reactions and other types
512
525
  }
513
526
  // Lia@Changes 02-02-26 --- Add native_flow_name to extraAttrs when sending interactiveResponseMessage
@@ -1121,8 +1134,6 @@ export const makeMessagesSocket = (config) => {
1121
1134
  const isKeepMsg = 'keep' in content && !!content.keep;
1122
1135
  const isPollMsg = 'poll' in content && !!content.poll;
1123
1136
  const isQuizMsg = 'poll' in content && !!content.poll.pollType;
1124
- const isPollResultMsg = 'pollResult' in content && !!content.pollResult;
1125
- const isPollUpdateMsg = 'pollUpdate' in content && !!content.pollUpdate;
1126
1137
  const isAiMsg = 'ai' in content && !!content.ai;
1127
1138
  const isNeedBizAttrs = 'secureMetaServiceLabel' in content && !!content.secureMetaServiceLabel;
1128
1139
  const additionalAttributes = options.additionalAttributes || {};
@@ -1151,7 +1162,7 @@ export const makeMessagesSocket = (config) => {
1151
1162
  tag: 'meta',
1152
1163
  attrs: {
1153
1164
  // Lia@Note 08-02-26 --- Still a hypothesis regarding PollResult ༎ຶ⁠‿⁠༎ຶ
1154
- polltype: isQuizMsg ? 'quiz_creation' : isPollResultMsg || isPollUpdateMsg ? 'vote' : 'creation',
1165
+ polltype: isQuizMsg ? 'quiz_creation' : 'creation',
1155
1166
  contenttype: isPollMsg && isNewsletter ? 'text' : undefined
1156
1167
  },
1157
1168
  content: undefined
@@ -5,8 +5,7 @@ import { promisify } from 'util';
5
5
  import { proto } from '../../WAProto/index.js';
6
6
  import { DEF_CALLBACK_PREFIX, DEF_TAG_PREFIX, INITIAL_PREKEY_COUNT, MIN_PREKEY_COUNT, MIN_UPLOAD_INTERVAL, NOISE_WA_HEADER, PROCESSABLE_HISTORY_TYPES, TimeMs, UPLOAD_TIMEOUT } from '../Defaults/index.js';
7
7
  import { DisconnectReason } from '../Types/index.js';
8
- import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
9
- import { getPlatformId } from '../Utils/browser-utils.js';
8
+ import { addTransactionCapability, aesEncryptCTR, bindWaitForConnectionUpdate, bytesToCrockford, buildPairingQRData, configureSuccessfulPairing, Curve, derivePairingCodeKey, generateLoginNode, generateMdTagPrefix, generateRegistrationNode, getCompanionPlatformId, getCodeFromWSError, getErrorCodeFromStreamError, getNextPreKeysNode, makeEventBuffer, makeNoiseHandler, promiseTimeout, signedKeyPair, xmppSignedPreKey } from '../Utils/index.js';
10
9
  import { assertNodeErrorFree, binaryNodeToString, encodeBinaryNode, getAllBinaryNodeChildren, getBinaryNodeChild, getBinaryNodeChildren, isLidUser, jidDecode, jidEncode, S_WHATSAPP_NET } from '../WABinary/index.js';
11
10
  import { BinaryInfo } from '../WAM/BinaryInfo.js';
12
11
  import { USyncQuery, USyncUser } from '../WAUSync/index.js';
@@ -629,7 +628,7 @@ export const makeSocket = (config) => {
629
628
  {
630
629
  tag: 'companion_platform_id',
631
630
  attrs: {},
632
- content: getPlatformId(browser[1])
631
+ content: getCompanionPlatformId(browser)
633
632
  },
634
633
  {
635
634
  tag: 'companion_platform_display',
@@ -712,7 +711,7 @@ export const makeSocket = (config) => {
712
711
  return;
713
712
  }
714
713
  const ref = refNode.content.toString('utf-8');
715
- const qr = [ref, noiseKeyB64, identityKeyB64, advB64].join(',');
714
+ const qr = buildPairingQRData(ref, noiseKeyB64, identityKeyB64, advB64, browser);
716
715
  ev.emit('connection.update', { qr });
717
716
  qrTimer = setTimeout(genPairQR, qrMs);
718
717
  qrMs = qrTimeout || 20000; // shorter subsequent qrs
@@ -0,0 +1,32 @@
1
+ export const CompanionWebClientType = {
2
+ UNKNOWN: 0,
3
+ CHROME: 1,
4
+ EDGE: 2,
5
+ FIREFOX: 3,
6
+ IE: 4,
7
+ OPERA: 5,
8
+ SAFARI: 6,
9
+ ELECTRON: 7,
10
+ UWP: 8,
11
+ OTHER_WEB_CLIENT: 9
12
+ };
13
+ const BROWSER_TO_COMPANION_WEB_CLIENT = {
14
+ Chrome: CompanionWebClientType.CHROME,
15
+ Edge: CompanionWebClientType.EDGE,
16
+ Firefox: CompanionWebClientType.FIREFOX,
17
+ IE: CompanionWebClientType.IE,
18
+ Opera: CompanionWebClientType.OPERA,
19
+ Safari: CompanionWebClientType.SAFARI
20
+ };
21
+ export const getCompanionWebClientType = ([os, browserName]) => {
22
+ if (browserName === 'Desktop') {
23
+ return os === 'Windows' ? CompanionWebClientType.UWP : CompanionWebClientType.ELECTRON;
24
+ }
25
+ return BROWSER_TO_COMPANION_WEB_CLIENT[browserName] || CompanionWebClientType.OTHER_WEB_CLIENT;
26
+ };
27
+ export const getCompanionPlatformId = (browser) => {
28
+ return getCompanionWebClientType(browser).toString();
29
+ };
30
+ export const buildPairingQRData = (ref, noiseKeyB64, identityKeyB64, advB64, browser) => {
31
+ return [ref, noiseKeyB64, identityKeyB64, advB64, getCompanionPlatformId(browser)].join(',');
32
+ };
@@ -1,5 +1,5 @@
1
1
  import { Boom } from '@hapi/boom';
2
- import { createHash, randomBytes } from 'crypto';
2
+ import { createHash, randomBytes, randomFillSync } from 'crypto';
3
3
  import { proto } from '../../WAProto/index.js';
4
4
  const baileysVersion = [2, 3000, 1035194821];
5
5
  import { DisconnectReason } from '../Types/index.js';
@@ -132,19 +132,19 @@ export async function promiseTimeout(ms, promise) {
132
132
  // inspired from whatsmeow code
133
133
  // https://github.com/tulir/whatsmeow/blob/64bc969fbe78d31ae0dd443b8d4c80a5d026d07a/send.go#L42
134
134
  export const generateMessageIDV2 = (userId) => {
135
- const data = Buffer.allocUnsafe(8 + 20 + 16);
136
- data.writeBigUInt64BE(BigInt(unixTimestampSeconds()));
135
+ const data = Buffer.allocUnsafe(44);
136
+ data.writeBigUInt64BE(BigInt(Date.now() / 1000 | 0), 0);
137
137
  if (userId) {
138
- const id = jidDecode(userId);
139
- if (id?.user) {
140
- const len = data.write(id.user, 8);
138
+ const userStr = userId.split('@')[0].split(':')[0];
139
+ if (userStr) {
140
+ const len = data.write(userStr, 8);
141
141
  data.write('@c.us', 8 + len);
142
142
  }
143
143
  }
144
- randomBytes(16).copy(data, 28);
144
+ randomFillSync(data, 28, 16);
145
145
  const hash = createHash('sha256').update(data).digest();
146
- const hex = hash.toString('hex').toUpperCase();
147
- const baseId = '3EB0' + hex.substring(0, 18);
146
+ const hex = hash.toString('hex', 0, 9).toUpperCase();
147
+ const baseId = '3EB0' + hex;
148
148
  const pos = 4 + (hash[0] & 15);
149
149
  return baseId.slice(0, pos) + 'STARFALL' + baseId.slice(pos);
150
150
  };
@@ -17,5 +17,6 @@ export * from './event-buffer.js';
17
17
  export * from './process-message.js';
18
18
  export * from './message-retry-manager.js';
19
19
  export * from './browser-utils.js';
20
+ export * from './companion-reg-client-utils.js';
20
21
  export * from './identity-change-handler.js';
21
22
  export * from './stanza-ack.js';
@@ -1,6 +1,6 @@
1
1
  import { LRUCache } from 'lru-cache';
2
2
  /** Number of sent messages to cache in memory for handling retry receipts */
3
- const RECENT_MESSAGES_SIZE = 512;
3
+ const RECENT_MESSAGES_SIZE = 1024;
4
4
  const MESSAGE_KEY_SEPARATOR = '\u0000';
5
5
  /** Timeout for session recreation - 1 hour */
6
6
  const RECREATE_SESSION_TIMEOUT = 60 * 60 * 1000; // 1 hour in milliseconds
@@ -700,7 +700,7 @@ export const getWAUploadToServer = ({ customUploadHosts, fetchAgent, logger, opt
700
700
  logger.debug(`uploading to "${hostname}"`);
701
701
  const auth = encodeURIComponent(uploadInfo.auth);
702
702
  // Lia@Changes 06-02-26 --- Switch media path map for newsletter uploads
703
- const mediaPathMap = (newsletter ? NEWSLETTER_MEDIA_PATH_MAP : undefined) || MEDIA_PATH_MAP
703
+ const mediaPathMap = newsletter ? NEWSLETTER_MEDIA_PATH_MAP : MEDIA_PATH_MAP
704
704
  // Lia@Changes 20-03-26 --- Add server thumb for newsletter media
705
705
  const serverThumb = newsletter ? '&server_thumb_gen=1' : ''
706
706
  const url = `https://${hostname}${mediaPathMap[mediaType]}/${fileEncSha256B64}?auth=${auth}&token=${fileEncSha256B64}${serverThumb}`;
@@ -534,14 +534,14 @@ const prepareNativeFlowButtons = (message) => {
534
534
  const isButtonsFieldArray = Array.isArray(buttons);
535
535
  const correctedField = isButtonsFieldArray ? buttons : buttons.buttons;
536
536
  const messageParamsJson = {};
537
- // Lia@Changes 31-01-26 --- Add coupon and options inside interactive message
538
- if (hasOptionalProperty(message, 'couponCode') && !!message.couponCode) {
537
+ // Lia@Changes 31-01-26 --- Add offer and options inside interactive message
538
+ if (hasOptionalProperty(message, 'offerText') && !!message.offerText) {
539
539
  Object.assign(messageParamsJson, {
540
540
  limited_time_offer: {
541
- text: message.couponText || LIBRARY_NAME,
542
- url: message.couponUrl || DONATE_URL, // Lia@Note 02-02-26 --- Apologies if this feels cheeky, just a fallback
543
- copy_code: message.couponCode,
544
- expiration_time: Date.now() * 2
541
+ text: message.offerText || LIBRARY_NAME,
542
+ url: message.offerUrl || DONATE_URL, // Lia@Note 02-02-26 --- Apologies if this feels cheeky, just a fallback
543
+ copy_code: message.offerCode,
544
+ expiration_time: message.offerExpiration
545
545
  }
546
546
  });
547
547
  }
@@ -560,7 +560,7 @@ const prepareNativeFlowButtons = (message) => {
560
560
  }
561
561
  return {
562
562
  buttons: correctedField.map(button => {
563
- const buttonText = button.text || button.buttonText;
563
+ const buttonText = button.text;
564
564
  if (hasOptionalProperty(button, 'id') && !!button.id) {
565
565
  return {
566
566
  name: 'quick_reply',
@@ -1037,7 +1037,7 @@ export const generateWAMessageContent = async (message, options) => {
1037
1037
  const buttonsMessage = {
1038
1038
  buttons: message.buttons.map(button => {
1039
1039
  // Lia@Changes 12-03-26 --- Add "single_select" shortcut!
1040
- const buttonText = button.text || button.buttonText
1040
+ const buttonText = button.text;
1041
1041
  if (hasOptionalProperty(button, 'sections')) {
1042
1042
  return {
1043
1043
  nativeFlowInfo: {
@@ -1098,11 +1098,12 @@ export const generateWAMessageContent = async (message, options) => {
1098
1098
  else if (hasNonNullishProperty(message, 'templateButtons')) {
1099
1099
  const hydratedTemplate = {
1100
1100
  hydratedButtons: message.templateButtons.map((button, i) => {
1101
+ const buttonText = button.text;
1101
1102
  if (hasOptionalProperty(button, 'id')) {
1102
1103
  return {
1103
1104
  index: i,
1104
1105
  quickReplyButton: {
1105
- displayText: button.text || button.buttonText || '👉🏻 Click',
1106
+ displayText: buttonText || '👉🏻 Click',
1106
1107
  id: button.id
1107
1108
  }
1108
1109
  };
@@ -1111,7 +1112,7 @@ export const generateWAMessageContent = async (message, options) => {
1111
1112
  return {
1112
1113
  index: i,
1113
1114
  urlButton: {
1114
- displayText: button.text || button.buttonText || '🌐 Visit',
1115
+ displayText: buttonText || '🌐 Visit',
1115
1116
  url: button.url
1116
1117
  }
1117
1118
  };
@@ -1120,7 +1121,7 @@ export const generateWAMessageContent = async (message, options) => {
1120
1121
  return {
1121
1122
  index: i,
1122
1123
  callButton: {
1123
- displayText: button.text || button.buttonText || '📞 Call',
1124
+ displayText: buttonText || '📞 Call',
1124
1125
  phoneNumber: button.call
1125
1126
  }
1126
1127
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itsliaaa/baileys",
3
- "version": "0.1.16-beta.2",
3
+ "version": "0.1.17",
4
4
  "description": "A simple fork of Baileys for WhatsApp automation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -48,7 +48,7 @@
48
48
  "p-queue": "^9.1.0",
49
49
  "pino": "^9.6.0",
50
50
  "protobufjs": "^7.5.4",
51
- "whatsapp-rust-bridge": "0.5.3",
51
+ "whatsapp-rust-bridge": "^0.5.3",
52
52
  "ws": "^8.19.0"
53
53
  },
54
54
  "peerDependencies": {