@itsliaaa/baileys 0.1.16-beta.1 → 0.1.16

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.
@@ -429,7 +429,7 @@ export const makeMessagesSocket = (config) => {
429
429
  }
430
430
  return { nodes, shouldIncludeDeviceIdentity };
431
431
  };
432
- const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }) => {
432
+ const relayMessage = async (jid, message, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, addBizAttributes, statusJidList }) => {
433
433
  const meId = authState.creds.me.id;
434
434
  const meLid = authState.creds.me?.lid;
435
435
  const isRetryResend = !!participant?.jid;
@@ -802,8 +802,8 @@ export const makeMessagesSocket = (config) => {
802
802
  stanza.content.push(...additionalNodes);
803
803
  }
804
804
  // Lia@Changes 30-01-26 --- Add Biz Binary Node to support button messages
805
- if (shouldIncludeBizBinaryNode(innerMessage)) {
806
- const bizNode = getBizBinaryNode(innerMessage);
805
+ if (shouldIncludeBizBinaryNode(innerMessage) || addBizAttributes) {
806
+ const bizNode = getBizBinaryNode(innerMessage, addBizAttributes);
807
807
  stanza.content.push(bizNode);
808
808
  }
809
809
  logger.debug({ msgId }, `sending message to ${participants.length} devices`);
@@ -1124,6 +1124,7 @@ export const makeMessagesSocket = (config) => {
1124
1124
  const isPollResultMsg = 'pollResult' in content && !!content.pollResult;
1125
1125
  const isPollUpdateMsg = 'pollUpdate' in content && !!content.pollUpdate;
1126
1126
  const isAiMsg = 'ai' in content && !!content.ai;
1127
+ const isNeedBizAttrs = 'secureMetaServiceLabel' in content && !!content.secureMetaServiceLabel;
1127
1128
  const additionalAttributes = options.additionalAttributes || {};
1128
1129
  const additionalNodes = options.additionalNodes || [];
1129
1130
  // required for delete
@@ -1143,7 +1144,7 @@ export const makeMessagesSocket = (config) => {
1143
1144
  additionalAttributes.edit = '2';
1144
1145
  }
1145
1146
  else if (isPollMsg) {
1146
- if (!isJidNewsletter(jid) && isQuizMsg) {
1147
+ if (!isNewsletter && isQuizMsg) {
1147
1148
  throw new Boom('Quiz are only allowed for newsletter', { statusCode: 400 });
1148
1149
  }
1149
1150
  additionalNodes.push({
@@ -1185,6 +1186,7 @@ export const makeMessagesSocket = (config) => {
1185
1186
  await relayMessage(jid, fullMsg.message, {
1186
1187
  messageId: fullMsg.key.id,
1187
1188
  useCachedGroupMetadata: options.useCachedGroupMetadata,
1189
+ addBizAttributes: isNeedBizAttrs,
1188
1190
  statusJidList: options.statusJidList,
1189
1191
  additionalAttributes,
1190
1192
  additionalNodes
@@ -1219,6 +1221,7 @@ export const makeMessagesSocket = (config) => {
1219
1221
  await relayMessage(jid, albumMsg.message, {
1220
1222
  messageId: albumMsg.key.id,
1221
1223
  useCachedGroupMetadata: options.useCachedGroupMetadata,
1224
+ addBizAttributes: isNeedBizAttrs,
1222
1225
  statusJidList: options.statusJidList,
1223
1226
  additionalAttributes,
1224
1227
  additionalNodes
@@ -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
+ };
@@ -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';
@@ -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}`;
@@ -122,7 +122,7 @@ export const prepareWAMessageMedia = async (message, options) => {
122
122
  return obj;
123
123
  }
124
124
  }
125
- const isNewsletter = !!options.jid && isJidNewsletter(options.jid);
125
+ const isNewsletter = isJidNewsletter(options.jid);
126
126
  const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
127
127
  const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData.jpegThumbnail === 'undefined';
128
128
  const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && typeof uploadData.waveform === 'undefined';
@@ -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
  };
@@ -153,7 +153,8 @@ const MIXED_NATIVE_FLOW = {
153
153
  }
154
154
  ]
155
155
  };
156
- export const getBizBinaryNode = (message) => {
156
+ export const getBizBinaryNode = (message, addBizAttributes) => {
157
+ const bizAttributes = {};
157
158
  const flowMsg = message.interactiveMessage?.nativeFlowMessage;
158
159
  const firstButtonName = flowMsg?.buttons?.[0]?.name;
159
160
  const qualityContent = {
@@ -164,21 +165,25 @@ export const getBizBinaryNode = (message) => {
164
165
  },
165
166
  content: DECISION_SOURCE_CONTENT
166
167
  };
168
+ if (addBizAttributes) {
169
+ bizAttributes.actual_actors = '2';
170
+ bizAttributes.host_storage = '2';
171
+ bizAttributes.privacy_mode_ts = `${Date.now() / 1_000 | 0}`;
172
+ }
167
173
  if (firstButtonName === 'review_and_pay' || firstButtonName === 'payment_info') {
174
+ bizAttributes.native_flow_name = firstButtonName === 'review_and_pay' ?
175
+ 'order_details' :
176
+ firstButtonName;
168
177
  return {
169
178
  tag: 'biz',
170
- attrs: {
171
- native_flow_name: firstButtonName === 'review_and_pay' ?
172
- 'order_details' :
173
- firstButtonName
174
- },
179
+ attrs: bizAttributes,
175
180
  content: [qualityContent]
176
181
  };
177
182
  }
178
183
  if (firstButtonName && FLOWS_MAP[firstButtonName]) {
179
184
  return {
180
185
  tag: 'biz',
181
- attrs: {},
186
+ attrs: bizAttributes,
182
187
  content: [
183
188
  {
184
189
  tag: 'interactive',
@@ -197,7 +202,7 @@ export const getBizBinaryNode = (message) => {
197
202
  if (flowMsg || message.buttonsMessage || message.templateMessage) {
198
203
  return {
199
204
  tag: 'biz',
200
- attrs: {},
205
+ attrs: bizAttributes,
201
206
  content: [
202
207
  MIXED_NATIVE_FLOW,
203
208
  qualityContent
@@ -207,7 +212,7 @@ export const getBizBinaryNode = (message) => {
207
212
  if (message.listMessage) {
208
213
  return {
209
214
  tag: 'biz',
210
- attrs: {},
215
+ attrs: bizAttributes,
211
216
  content: [
212
217
  LIST_TYPE_CONTENT,
213
218
  qualityContent
@@ -216,7 +221,7 @@ export const getBizBinaryNode = (message) => {
216
221
  }
217
222
  return {
218
223
  tag: 'biz',
219
- attrs: {},
224
+ attrs: bizAttributes,
220
225
  content: [qualityContent]
221
226
  };
222
227
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itsliaaa/baileys",
3
- "version": "0.1.16-beta.1",
3
+ "version": "0.1.16",
4
4
  "description": "A simple fork of Baileys for WhatsApp automation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",