@itsliaaa/baileys 0.1.3 → 0.1.4

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.
@@ -2,7 +2,7 @@ import { proto } from '../../WAProto/index.js';
2
2
  import { makeLibSignalRepository } from '../Signal/libsignal.js';
3
3
  import { Browsers } from '../Utils/browser-utils.js';
4
4
  import logger from '../Utils/logger.js';
5
- const version = [2, 3000, 1034621774];
5
+ const version = [2, 3000, 1033846690];
6
6
  export const UNAUTHORIZED_CODES = [401, 403, 419];
7
7
  export const BIZ_BOT_SUPPORT_PAYLOAD = '{"version":1,"is_ai_message":true,"should_show_system_message":true,"ticket_id":"7004947587700716","citation_items":[],"ticket_locale":"us"}';
8
8
  export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
@@ -1,5 +1,4 @@
1
1
  import NodeCache from '@cacheable/node-cache';
2
- import PQueue from 'p-queue';
3
2
  import { Boom } from '@hapi/boom';
4
3
  import { proto } from '../../WAProto/index.js';
5
4
  import { BIZ_BOT_SUPPORT_PAYLOAD, DEFAULT_CACHE_TTLS, OLD_GROUP_ID_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
@@ -11,10 +10,6 @@ import { getMessageReportingToken, shouldIncludeReportingToken } from '../Utils/
11
10
  import { areJidsSameUser, getBinaryNodeChild, getBinaryNodeChildren, getBizBinaryNode, isHostedLidUser, isHostedPnUser, isJidGroup, isJidNewsletter, isLidUser, isPnUser, jidDecode, jidEncode, jidNormalizedUser, S_WHATSAPP_NET } from '../WABinary/index.js';
12
11
  import { USyncQuery, USyncUser } from '../WAUSync/index.js';
13
12
  import { makeNewsletterSocket } from './newsletter.js';
14
- // Lia@Changes 03-02-26 --- Replace process.nextTick with PQueue for upsertMessage to avoid RSS spike... (i guess (⁠ ⁠◜⁠‿⁠◝⁠ ⁠)⁠♡)
15
- const EMIT_MESSAGE_QUEUE = new PQueue({
16
- concurrency: 1
17
- });
18
13
  export const makeMessagesSocket = (config) => {
19
14
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: httpRequestOptions, patchMessageBeforeSending, cachedGroupMetadata, enableRecentMessageCache, maxMsgRetryCount } = config;
20
15
  const sock = makeNewsletterSocket(config);
@@ -1105,9 +1100,9 @@ export const makeMessagesSocket = (config) => {
1105
1100
  additionalNodes
1106
1101
  });
1107
1102
  if (config.emitOwnEvents) {
1108
- EMIT_MESSAGE_QUEUE.add(() =>
1109
- upsertMessage(fullMsg, 'append')
1110
- );
1103
+ process.nextTick(async () => {
1104
+ await messageMutex.mutex(() => upsertMessage(fullMsg, 'append'));
1105
+ });
1111
1106
  }
1112
1107
  // Lia@Changes 31-01-26 --- Add support for album messages
1113
1108
  // Lia@Note 06-02-26 --- Refactored to reduce high RSS usage (⁠╥⁠﹏⁠╥⁠)
@@ -1139,9 +1134,9 @@ export const makeMessagesSocket = (config) => {
1139
1134
  additionalNodes
1140
1135
  });
1141
1136
  if (config.emitOwnEvents) {
1142
- EMIT_MESSAGE_QUEUE.add(() =>
1143
- upsertMessage(albumMsg, 'append')
1144
- );
1137
+ process.nextTick(async () => {
1138
+ await messageMutex.mutex(() => upsertMessage(albumMsg, 'append'));
1139
+ });
1145
1140
  }
1146
1141
  await delay(delayMs);
1147
1142
  }
@@ -761,8 +761,7 @@ export const makeSocket = (config) => {
761
761
  void sendUnifiedSession();
762
762
  if (node.attrs.lid && authState.creds.me?.id) {
763
763
  const myLID = node.attrs.lid;
764
- // Lia@Changes 03-02-26 --- Replaced process.nextTick setImmediate to avoid event-loop starvation
765
- setImmediate(async () => {
764
+ process.nextTick(async () => {
766
765
  try {
767
766
  const myPN = authState.creds.me.id;
768
767
  // Store our own LID-PN mapping
@@ -1,7 +1,7 @@
1
1
  import { Boom } from '@hapi/boom';
2
2
  import { createHash, randomBytes } from 'crypto';
3
3
  import { proto } from '../../WAProto/index.js';
4
- const baileysVersion = [2, 3000, 1034621774];
4
+ const baileysVersion = [2, 3000, 1033846690];
5
5
  import { DisconnectReason } from '../Types/index.js';
6
6
  import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
7
7
  import { sha256 } from './crypto.js';
@@ -560,11 +560,12 @@ const prepareNativeFlowButtons = (message) => {
560
560
  }
561
561
  return {
562
562
  buttons: correctedField.map(button => {
563
+ const buttonText = button.text || button.buttonText;
563
564
  if (hasOptionalProperty(button, 'id') && !!button.id) {
564
565
  return {
565
566
  name: 'quick_reply',
566
567
  buttonParamsJson: JSON.stringify({
567
- display_text: button.text || button.buttonText || '👉🏻 Click',
568
+ display_text: buttonText || '👉🏻 Click',
568
569
  id: button.id
569
570
  })
570
571
  };
@@ -573,7 +574,7 @@ const prepareNativeFlowButtons = (message) => {
573
574
  return {
574
575
  name: 'cta_copy',
575
576
  buttonParamsJson: JSON.stringify({
576
- display_text: button.text || button.buttonText || '📋 Copy',
577
+ display_text: buttonText || '📋 Copy',
577
578
  copy_code: button.copy
578
579
  })
579
580
  };
@@ -582,7 +583,7 @@ const prepareNativeFlowButtons = (message) => {
582
583
  return {
583
584
  name: 'cta_url',
584
585
  buttonParamsJson: JSON.stringify({
585
- display_text: button.text || button.buttonText || '🌐 Visit',
586
+ display_text: buttonText || '🌐 Visit',
586
587
  url: button.url,
587
588
  merchant_url: button.url
588
589
  })
@@ -592,11 +593,21 @@ const prepareNativeFlowButtons = (message) => {
592
593
  return {
593
594
  name: 'cta_call',
594
595
  buttonParamsJson: JSON.stringify({
595
- display_text: button.text || button.buttonText || '📞 Call',
596
+ display_text: buttonText || '📞 Call',
596
597
  phone_number: button.call
597
598
  })
598
599
  };
599
600
  }
601
+ // Lia@Changes 12-03-26 --- Add "single_select" shortcut \⁠(⁠°⁠o⁠°⁠)⁠/
602
+ else if (hasOptionalProperty(button, 'sections') && !!button.sections) {
603
+ return {
604
+ name: 'single_select',
605
+ buttonParamsJson: JSON.stringify({
606
+ title: buttonText || '📋 Select',
607
+ sections: button.sections
608
+ })
609
+ };
610
+ }
600
611
  return button;
601
612
  }),
602
613
  messageParamsJson: JSON.stringify(messageParamsJson),
@@ -679,7 +690,12 @@ export const hasValidCarouselHeader = (message) => {
679
690
  export const generateWAMessageContent = async (message, options) => {
680
691
  var _a, _b;
681
692
  let m = {};
682
- if (hasNonNullishProperty(message, 'text')) {
693
+ // Lia@Changes 30-01-26 --- Add "raw" boolean to send raw messages directly via generateWAMessage()
694
+ if (hasNonNullishProperty(message, 'raw')) {
695
+ delete message.raw;
696
+ return proto.Message.create(message);
697
+ }
698
+ else if (hasNonNullishProperty(message, 'text')) {
683
699
  const extContent = { text: message.text };
684
700
  let urlInfo = message.linkPreview;
685
701
  if (typeof urlInfo === 'undefined') {
@@ -1014,11 +1030,6 @@ export const generateWAMessageContent = async (message, options) => {
1014
1030
  expectedVideoCount: videoCount
1015
1031
  };
1016
1032
  }
1017
- // Lia@Changes 30-01-26 --- Add "raw" boolean to send raw messages directly via generateWAMessage()
1018
- else if (hasNonNullishProperty(message, 'raw')) {
1019
- delete message.raw;
1020
- return proto.Message.create(message);
1021
- }
1022
1033
  else {
1023
1034
  m = await prepareWAMessageMedia(message, options);
1024
1035
  }
@@ -1026,7 +1037,21 @@ export const generateWAMessageContent = async (message, options) => {
1026
1037
  if (hasNonNullishProperty(message, 'buttons')) {
1027
1038
  const buttonsMessage = {
1028
1039
  buttons: message.buttons.map(button => {
1029
- if (hasOptionalProperty(button, 'name')) {
1040
+ // Lia@Changes 12-03-26 --- Add "single_select" shortcut!
1041
+ const buttonText = button.text || button.buttonText
1042
+ if (hasOptionalProperty(button, 'sections')) {
1043
+ return {
1044
+ nativeFlowInfo: {
1045
+ name: 'single_select',
1046
+ paramsJson: JSON.stringify({
1047
+ title: buttonText,
1048
+ sections: button.sections
1049
+ })
1050
+ },
1051
+ type: ButtonType.NATIVE_FLOW
1052
+ };
1053
+ }
1054
+ else if (hasOptionalProperty(button, 'name')) {
1030
1055
  return {
1031
1056
  nativeFlowInfo: {
1032
1057
  name: button.name,
@@ -1035,7 +1060,6 @@ export const generateWAMessageContent = async (message, options) => {
1035
1060
  type: ButtonType.NATIVE_FLOW
1036
1061
  };
1037
1062
  }
1038
- const buttonText = button.text || button.buttonText
1039
1063
  return {
1040
1064
  buttonId: button.id || button.buttonId,
1041
1065
  buttonText: typeof buttonText === 'string' ? { displayText: buttonText } : buttonText,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itsliaaa/baileys",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A simple fork of Baileys for WhatsApp automation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",