@genuxofficial/baileys 1.0.0 → 2.0.0

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.
Files changed (99) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -1
  3. package/WAProto/index.d.ts +19244 -2787
  4. package/WAProto/index.js +138202 -74217
  5. package/engine-requirements.js +10 -0
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +3 -5
  8. package/lib/Defaults/index.js +7 -6
  9. package/lib/Signal/libsignal.js +18 -9
  10. package/lib/Socket/Client/types.d.ts +0 -2
  11. package/lib/Socket/Client/websocket.js +1 -1
  12. package/lib/Socket/business.d.ts +65 -37
  13. package/lib/Socket/chats.d.ts +22 -18
  14. package/lib/Socket/chats.js +110 -6
  15. package/lib/Socket/groups.d.ts +30 -26
  16. package/lib/Socket/groups.js +20 -6
  17. package/lib/Socket/index.d.ts +66 -38
  18. package/lib/Socket/messages-recv.d.ts +63 -33
  19. package/lib/Socket/messages-recv.js +174 -27
  20. package/lib/Socket/messages-send.d.ts +55 -29
  21. package/lib/Socket/messages-send.js +190 -26
  22. package/lib/Socket/newsletter.d.ts +140 -0
  23. package/lib/Socket/newsletter.js +252 -0
  24. package/lib/Socket/socket.d.ts +8 -10
  25. package/lib/Socket/socket.js +26 -13
  26. package/lib/Socket/usync.d.ts +10 -12
  27. package/lib/Socket/usync.js +10 -15
  28. package/lib/Store/index.d.ts +1 -2
  29. package/lib/Store/index.js +1 -3
  30. package/lib/Store/make-in-memory-store.d.ts +1 -1
  31. package/lib/Store/make-in-memory-store.js +14 -5
  32. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  33. package/lib/Types/Auth.d.ts +0 -2
  34. package/lib/Types/Chat.d.ts +7 -0
  35. package/lib/Types/Contact.d.ts +5 -0
  36. package/lib/Types/Events.d.ts +27 -0
  37. package/lib/Types/GroupMetadata.d.ts +7 -0
  38. package/lib/Types/Label.js +1 -1
  39. package/lib/Types/LabelAssociation.js +1 -1
  40. package/lib/Types/Message.d.ts +129 -16
  41. package/lib/Types/Message.js +0 -2
  42. package/lib/Types/Newsletter.d.ts +79 -0
  43. package/lib/Types/Newsletter.js +18 -0
  44. package/lib/Types/Socket.d.ts +8 -5
  45. package/lib/Types/index.d.ts +1 -0
  46. package/lib/Types/index.js +2 -1
  47. package/lib/Utils/auth-utils.d.ts +1 -1
  48. package/lib/Utils/auth-utils.js +6 -7
  49. package/lib/Utils/business.js +2 -2
  50. package/lib/Utils/chat-utils.d.ts +8 -10
  51. package/lib/Utils/chat-utils.js +11 -0
  52. package/lib/Utils/crypto.d.ts +14 -16
  53. package/lib/Utils/crypto.js +40 -26
  54. package/lib/Utils/decode-wa-message.d.ts +5 -3
  55. package/lib/Utils/decode-wa-message.js +171 -29
  56. package/lib/Utils/event-buffer.js +1 -3
  57. package/lib/Utils/generics.d.ts +35 -9
  58. package/lib/Utils/generics.js +93 -27
  59. package/lib/Utils/history.d.ts +2 -2
  60. package/lib/Utils/link-preview.d.ts +1 -1
  61. package/lib/Utils/link-preview.js +17 -7
  62. package/lib/Utils/make-mutex.d.ts +2 -2
  63. package/lib/Utils/make-mutex.js +0 -1
  64. package/lib/Utils/messages-media.d.ts +35 -16
  65. package/lib/Utils/messages-media.js +168 -43
  66. package/lib/Utils/messages.d.ts +6 -9
  67. package/lib/Utils/messages.js +297 -37
  68. package/lib/Utils/noise-handler.d.ts +5 -7
  69. package/lib/Utils/process-message.js +2 -3
  70. package/lib/Utils/use-multi-file-auth-state.js +44 -13
  71. package/lib/Utils/validate-connection.d.ts +2 -2
  72. package/lib/Utils/validate-connection.js +1 -3
  73. package/lib/WABinary/decode.d.ts +2 -4
  74. package/lib/WABinary/decode.js +20 -9
  75. package/lib/WABinary/encode.d.ts +1 -3
  76. package/lib/WABinary/encode.js +30 -12
  77. package/lib/WABinary/generic-utils.d.ts +1 -3
  78. package/lib/WABinary/generic-utils.js +2 -2
  79. package/lib/WABinary/jid-utils.d.ts +9 -4
  80. package/lib/WABinary/jid-utils.js +25 -4
  81. package/lib/WAM/BinaryInfo.d.ts +2 -12
  82. package/lib/WAM/encode.d.ts +1 -3
  83. package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
  84. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +2 -2
  85. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
  86. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -5
  87. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  88. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  89. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  90. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  91. package/lib/WAUSync/USyncQuery.d.ts +2 -0
  92. package/lib/WAUSync/USyncQuery.js +27 -13
  93. package/lib/WAUSync/USyncUser.d.ts +2 -0
  94. package/lib/WAUSync/USyncUser.js +4 -0
  95. package/lib/index.d.ts +2 -1
  96. package/lib/index.js +3 -1
  97. package/package.json +59 -57
  98. package/WAProto/GenerateStatics.sh +0 -4
  99. package/WAProto/WAProto.proto +0 -3344
@@ -0,0 +1,10 @@
1
+ const major = parseInt(process.versions.node.split('.')[0], 10);
2
+
3
+ if (major < 20) {
4
+ console.error(
5
+ `\n❌ This package requires Node.js 20+ to run reliably.\n` +
6
+ ` You are using Node.js ${process.versions.node}.\n` +
7
+ ` Please upgrade to Node.js 20+ to proceed.\n`
8
+ );
9
+ process.exit(1);
10
+ }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1019707846]
2
+ "version": [2, 3000, 1022982921]
3
3
  }
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { proto } from '../../WAProto';
4
2
  import type { MediaType, SocketConfig } from '../Types';
5
3
  export declare const UNAUTHORIZED_CODES: number[];
@@ -10,8 +8,8 @@ export declare const PHONE_CONNECTION_CB = "CB:Pong";
10
8
  export declare const WA_DEFAULT_EPHEMERAL: number;
11
9
  export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
12
10
  export declare const DICT_VERSION = 2;
13
- export declare const KEY_BUNDLE_TYPE: Buffer;
14
- export declare const NOISE_WA_HEADER: Buffer;
11
+ export declare const KEY_BUNDLE_TYPE: Buffer<ArrayBuffer>;
12
+ export declare const NOISE_WA_HEADER: Buffer<ArrayBuffer>;
15
13
  /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
16
14
  export declare const URL_REGEX: RegExp;
17
15
  export declare const WA_CERT_DETAILS: {
@@ -42,7 +40,7 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
42
40
  'payment-bg-image': string;
43
41
  ptv: string;
44
42
  };
45
- export declare const MEDIA_KEYS: ("ppic" | "product" | "image" | "video" | "sticker" | "audio" | "gif" | "ptt" | "thumbnail-document" | "thumbnail-image" | "thumbnail-link" | "thumbnail-video" | "md-app-state" | "md-msg-hist" | "document" | "product-catalog-image" | "payment-bg-image" | "ptv")[];
43
+ export declare const MEDIA_KEYS: MediaType[];
46
44
  export declare const MIN_PREKEY_COUNT = 5;
47
45
  export declare const INITIAL_PREKEY_COUNT = 30;
48
46
  export declare const DEFAULT_CACHE_TTLS: {
@@ -33,18 +33,19 @@ exports.PROCESSABLE_HISTORY_TYPES = [
33
33
  ];
34
34
  exports.DEFAULT_CONNECTION_CONFIG = {
35
35
  version: baileys_version_json_1.version,
36
- browser: Utils_1.Browsers.ubuntu('Chrome'),
36
+ browser: Utils_1.Browsers.ubuntu('Firefox'),
37
37
  waWebSocketUrl: 'wss://web.whatsapp.com/ws/chat',
38
38
  connectTimeoutMs: 20000,
39
39
  keepAliveIntervalMs: 30000,
40
40
  logger: logger_1.default.child({ class: 'baileys' }),
41
41
  printQRInTerminal: false,
42
42
  emitOwnEvents: true,
43
- defaultQueryTimeoutMs: 60000,
43
+ defaultQueryTimeoutMs: undefined,
44
44
  customUploadHosts: [],
45
45
  retryRequestDelayMs: 250,
46
46
  maxMsgRetryCount: 5,
47
47
  fireInitQueries: true,
48
+ ignoreMsgLoading: false,
48
49
  auth: undefined,
49
50
  markOnlineOnConnect: true,
50
51
  syncFullHistory: false,
@@ -53,7 +54,7 @@ exports.DEFAULT_CONNECTION_CONFIG = {
53
54
  shouldIgnoreJid: () => false,
54
55
  linkPreviewImageThumbnailWidth: 192,
55
56
  transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
56
- generateHighQualityLinkPreview: false,
57
+ generateHighQualityLinkPreview: true,
57
58
  options: {},
58
59
  appStateMacVerification: {
59
60
  patch: false,
@@ -99,8 +100,8 @@ exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
99
100
  exports.MIN_PREKEY_COUNT = 5;
100
101
  exports.INITIAL_PREKEY_COUNT = 30;
101
102
  exports.DEFAULT_CACHE_TTLS = {
102
- SIGNAL_STORE: 5 * 60,
103
- MSG_RETRY: 60 * 60,
104
- CALL_OFFER: 5 * 60,
103
+ SIGNAL_STORE: 5 * 60, // 5 minutes
104
+ MSG_RETRY: 60 * 60, // 1 hour
105
+ CALL_OFFER: 5 * 60, // 5 minutes
105
106
  USER_DEVICES: 5 * 60, // 5 minutes
106
107
  };
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.makeLibSignalRepository = void 0;
36
+ exports.makeLibSignalRepository = makeLibSignalRepository;
27
37
  const libsignal = __importStar(require("libsignal"));
28
38
  const WASignalGroup_1 = require("../../WASignalGroup");
29
39
  const Utils_1 = require("../Utils");
@@ -91,7 +101,6 @@ function makeLibSignalRepository(auth) {
91
101
  },
92
102
  };
93
103
  }
94
- exports.makeLibSignalRepository = makeLibSignalRepository;
95
104
  const jidToSignalProtocolAddress = (jid) => {
96
105
  const { user, device } = (0, WABinary_1.jidDecode)(jid);
97
106
  return new libsignal.ProtocolAddress(user, device || 0);
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { EventEmitter } from 'events';
4
2
  import { URL } from 'url';
5
3
  import { SocketConfig } from '../../Types';
@@ -38,7 +38,7 @@ class WebSocketClient extends types_1.AbstractSocketClient {
38
38
  headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
39
  handshakeTimeout: this.config.connectTimeoutMs,
40
40
  timeout: this.config.connectTimeoutMs,
41
- agent: this.config.agent,
41
+ agent: this.config.agent
42
42
  });
43
43
  this.socket.setMaxListeners(0);
44
44
  const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
@@ -1,6 +1,3 @@
1
- /// <reference types="long" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
1
  import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types';
5
2
  import { BinaryNode } from '../WABinary';
6
3
  export declare const makeBusinessSocket: (config: SocketConfig) => {
@@ -18,32 +15,57 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
18
15
  deleted: number;
19
16
  }>;
20
17
  productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>;
21
- sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number | undefined) => Promise<void>;
18
+ sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
22
19
  sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
23
20
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
24
- fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAProto.IMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
25
- requestPlaceholderResend: (messageKey: import("../Types").WAProto.IMessageKey) => Promise<string | undefined>;
26
- getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
21
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
22
+ callId: string;
23
+ toJid: string;
24
+ isVideo: boolean;
25
+ }>;
26
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
27
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
28
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
27
29
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
28
30
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
29
31
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
30
- sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
31
- readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
32
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
33
+ getButtonArgs: (message: import("../Types").WAProto.IMessage) => BinaryNode["attrs"];
34
+ readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
32
35
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
33
36
  waUploadToServer: import("../Types").WAMediaUploadFunction;
34
37
  fetchPrivacySettings: (force?: boolean) => Promise<{
35
38
  [_: string]: string;
36
39
  }>;
37
- sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
38
- createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
39
- [key: string]: string;
40
- } | undefined) => Promise<{
40
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
41
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
41
42
  nodes: BinaryNode[];
42
43
  shouldIncludeDeviceIdentity: boolean;
43
44
  }>;
44
- getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
45
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
45
46
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
46
47
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
48
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
49
+ duration: string;
50
+ }>;
51
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
52
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
53
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
54
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
55
+ newsletterRemovePicture: (jid: string) => Promise<void>;
56
+ newsletterUnfollow: (jid: string) => Promise<void>;
57
+ newsletterFollow: (jid: string) => Promise<void>;
58
+ newsletterUnmute: (jid: string) => Promise<void>;
59
+ newsletterMute: (jid: string) => Promise<void>;
60
+ newsletterCreate: (name: string, description?: string, picture?: import("../Types").WAMediaUpload) => Promise<import("../Types").NewsletterMetadata>;
61
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
62
+ newsletterAdminCount: (jid: string) => Promise<number>;
63
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
64
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
65
+ newsletterDelete: (jid: string) => Promise<void>;
66
+ newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>;
67
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
68
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
47
69
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
48
70
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
49
71
  groupLeave: (id: string) => Promise<void>;
@@ -51,7 +73,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
51
73
  groupRequestParticipantsList: (jid: string) => Promise<{
52
74
  [key: string]: string;
53
75
  }[]>;
54
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
76
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
55
77
  status: string;
56
78
  jid: string;
57
79
  }[]>;
@@ -60,36 +82,40 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
60
82
  jid: string;
61
83
  content: BinaryNode;
62
84
  }[]>;
63
- groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
85
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
64
86
  groupInviteCode: (jid: string) => Promise<string | undefined>;
65
87
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
66
88
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
67
89
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
68
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
90
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
69
91
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
70
92
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
71
- groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
72
- groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
93
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
94
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
73
95
  groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
74
96
  groupFetchAllParticipating: () => Promise<{
75
97
  [_: string]: import("../Types").GroupMetadata;
76
98
  }>;
99
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
77
100
  processingMutex: {
78
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
101
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
79
102
  };
80
103
  upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
81
104
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
82
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
83
- presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
84
- profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
105
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
106
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
107
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
85
108
  onWhatsApp: (...jids: string[]) => Promise<{
86
109
  jid: string;
87
110
  exists: unknown;
111
+ lid: unknown;
88
112
  }[] | undefined>;
89
113
  fetchBlocklist: () => Promise<string[]>;
90
- fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
91
114
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
115
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
92
116
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
117
+ updateProfilePictureFull: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
118
+ updateProfilePictureFull2: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
93
119
  removeProfilePicture: (jid: string) => Promise<void>;
94
120
  updateProfileStatus: (status: string) => Promise<void>;
95
121
  updateProfileName: (name: string) => Promise<void>;
@@ -103,10 +129,12 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
103
129
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
104
130
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
105
131
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
106
- getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
132
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
107
133
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
108
134
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
109
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
135
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
136
+ addOrEditContact: (jid: string, contact: import("../Types").ContactAction) => Promise<void>;
137
+ removeContact: (jid: string) => Promise<void>;
110
138
  addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
111
139
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
112
140
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
@@ -114,16 +142,16 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
114
142
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
115
143
  star: (jid: string, messages: {
116
144
  id: string;
117
- fromMe?: boolean | undefined;
145
+ fromMe?: boolean;
118
146
  }[], star: boolean) => Promise<void>;
119
147
  executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
120
148
  type: "md";
121
149
  ws: import("./Client").WebSocketClient;
122
150
  ev: import("../Types").BaileysEventEmitter & {
123
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
151
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
124
152
  buffer(): void;
125
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
126
- flush(force?: boolean | undefined): boolean;
153
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
154
+ flush(force?: boolean): boolean;
127
155
  isBuffering(): boolean;
128
156
  };
129
157
  authState: {
@@ -133,17 +161,17 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
133
161
  signalRepository: import("../Types").SignalRepository;
134
162
  user: import("../Types").Contact | undefined;
135
163
  generateMessageTag: () => string;
136
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
137
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
164
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
165
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
138
166
  waitForSocketOpen: () => Promise<void>;
139
167
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
140
168
  sendNode: (frame: BinaryNode) => Promise<void>;
141
- logout: (msg?: string | undefined) => Promise<void>;
169
+ logout: (msg?: string) => Promise<void>;
142
170
  end: (error: Error | undefined) => void;
143
- onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
171
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
144
172
  uploadPreKeys: (count?: number) => Promise<void>;
145
173
  uploadPreKeysToServerIfRequired: () => Promise<void>;
146
- requestPairingCode: (phoneNumber: string) => Promise<string>;
147
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
148
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
174
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
175
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
176
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
149
177
  };
@@ -1,14 +1,13 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Boom } from '@hapi/boom';
4
2
  import { proto } from '../../WAProto';
5
- import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
3
+ import { BotListInfo, ChatModification, ContactAction, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
6
4
  import { LabelActionBody } from '../Types/Label';
7
5
  import { BinaryNode } from '../WABinary';
8
6
  import { USyncQuery } from '../WAUSync';
9
7
  export declare const makeChatsSocket: (config: SocketConfig) => {
8
+ getBotListV2: () => Promise<BotListInfo[]>;
10
9
  processingMutex: {
11
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
10
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
12
11
  };
13
12
  fetchPrivacySettings: (force?: boolean) => Promise<{
14
13
  [_: string]: string;
@@ -17,19 +16,22 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
17
16
  appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
18
17
  sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
19
18
  presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
20
- profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | undefined>;
19
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
21
20
  onWhatsApp: (...jids: string[]) => Promise<{
22
21
  jid: string;
23
22
  exists: unknown;
23
+ lid: unknown;
24
24
  }[] | undefined>;
25
25
  fetchBlocklist: () => Promise<string[]>;
26
- fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
27
26
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
27
+ fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
28
28
  updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
29
+ updateProfilePictureFull: (jid: string, content: WAMediaUpload) => Promise<void>;
30
+ updateProfilePictureFull2: (jid: string, content: WAMediaUpload) => Promise<void>;
29
31
  removeProfilePicture: (jid: string) => Promise<void>;
30
32
  updateProfileStatus: (status: string) => Promise<void>;
31
33
  updateProfileName: (name: string) => Promise<void>;
32
- updateBlockStatus: (jid: string, action: 'block' | 'unblock') => Promise<void>;
34
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
33
35
  updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>;
34
36
  updateMessagesPrivacy: (value: WAPrivacyMessagesValue) => Promise<void>;
35
37
  updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
@@ -42,7 +44,9 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
42
44
  getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
43
45
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
44
46
  chatModify: (mod: ChatModification, jid: string) => Promise<void>;
45
- cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?: number | string) => Promise<void>;
47
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
48
+ addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>;
49
+ removeContact: (jid: string) => Promise<void>;
46
50
  addLabel: (jid: string, labels: LabelActionBody) => Promise<void>;
47
51
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
48
52
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
@@ -56,10 +60,10 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
56
60
  type: "md";
57
61
  ws: import("./Client").WebSocketClient;
58
62
  ev: import("../Types").BaileysEventEmitter & {
59
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
63
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
60
64
  buffer(): void;
61
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
62
- flush(force?: boolean | undefined): boolean;
65
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
66
+ flush(force?: boolean): boolean;
63
67
  isBuffering(): boolean;
64
68
  };
65
69
  authState: {
@@ -69,17 +73,17 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
69
73
  signalRepository: import("../Types").SignalRepository;
70
74
  user: import("../Types").Contact | undefined;
71
75
  generateMessageTag: () => string;
72
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
73
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
76
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
77
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
74
78
  waitForSocketOpen: () => Promise<void>;
75
79
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
76
80
  sendNode: (frame: BinaryNode) => Promise<void>;
77
- logout: (msg?: string | undefined) => Promise<void>;
81
+ logout: (msg?: string) => Promise<void>;
78
82
  end: (error: Error | undefined) => void;
79
- onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
83
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
80
84
  uploadPreKeys: (count?: number) => Promise<void>;
81
85
  uploadPreKeysToServerIfRequired: () => Promise<void>;
82
- requestPairingCode: (phoneNumber: string) => Promise<string>;
83
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
84
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
86
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
87
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
88
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
85
89
  };
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeChatsSocket = void 0;
7
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
7
  const boom_1 = require("@hapi/boom");
8
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
11
  const Types_1 = require("../Types");
@@ -26,7 +26,7 @@ const makeChatsSocket = (config) => {
26
26
  /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
27
27
  const processingMutex = (0, make_mutex_1.makeMutex)();
28
28
  const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
29
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
29
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
30
30
  useClones: false
31
31
  });
32
32
  if (!config.placeholderResendCache) {
@@ -115,16 +115,46 @@ const makeChatsSocket = (config) => {
115
115
  }]
116
116
  });
117
117
  };
118
+ const getBotListV2 = async () => {
119
+ const resp = await query({
120
+ tag: 'iq',
121
+ attrs: {
122
+ xmlns: 'bot',
123
+ to: WABinary_1.S_WHATSAPP_NET,
124
+ type: 'get'
125
+ },
126
+ content: [{
127
+ tag: 'bot',
128
+ attrs: {
129
+ v: '2'
130
+ }
131
+ }]
132
+ });
133
+ const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
134
+ const botList = [];
135
+ for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
136
+ if (section.attrs.type === 'all') {
137
+ for (const bot of (0, WABinary_1.getBinaryNodeChildren)(section, 'bot')) {
138
+ botList.push({
139
+ jid: bot.attrs.jid,
140
+ personaId: bot.attrs['persona_id']
141
+ });
142
+ }
143
+ }
144
+ }
145
+ return botList;
146
+ };
118
147
  const onWhatsApp = async (...jids) => {
119
148
  const usyncQuery = new WAUSync_1.USyncQuery()
120
- .withContactProtocol();
149
+ .withContactProtocol()
150
+ .withLIDProtocol();
121
151
  for (const jid of jids) {
122
152
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
123
153
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
124
154
  }
125
155
  const results = await sock.executeUSyncQuery(usyncQuery);
126
156
  if (results) {
127
- return results.list.filter((a) => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
157
+ return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
128
158
  }
129
159
  };
130
160
  const fetchStatus = async (...jids) => {
@@ -176,6 +206,59 @@ const makeChatsSocket = (config) => {
176
206
  ]
177
207
  });
178
208
  };
209
+ /** update the profile picture for yourself or a group as Full */
210
+ const updateProfilePictureFull = async (jid, content) => {
211
+ let targetJid;
212
+ if (!jid) {
213
+ throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
214
+ }
215
+ if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
216
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
217
+ }
218
+ const { img } = await (0, Utils_1.generateProfilePictureFull)(content);
219
+ await query({
220
+ tag: 'iq',
221
+ attrs: {
222
+ target: targetJid,
223
+ to: WABinary_1.S_WHATSAPP_NET,
224
+ type: 'set',
225
+ xmlns: 'w:profile:picture'
226
+ },
227
+ content: [
228
+ {
229
+ tag: 'picture',
230
+ attrs: { type: 'image' },
231
+ content: img
232
+ }
233
+ ]
234
+ });
235
+ };
236
+ const updateProfilePictureFull2 = async (jid, content) => {
237
+ let targetJid;
238
+ if (!jid) {
239
+ throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
240
+ }
241
+ if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
242
+ targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
243
+ }
244
+ const { preview } = await (0, Utils_1.generateProfilePictureFP)(content);
245
+ await query({
246
+ tag: 'iq',
247
+ attrs: {
248
+ target: targetJid,
249
+ to: WABinary_1.S_WHATSAPP_NET,
250
+ type: 'set',
251
+ xmlns: 'w:profile:picture'
252
+ },
253
+ content: [
254
+ {
255
+ tag: 'picture',
256
+ attrs: { type: 'image' },
257
+ content: preview
258
+ }
259
+ ]
260
+ });
261
+ };
179
262
  /** remove the profile picture for yourself or a group */
180
263
  const removeProfilePicture = async (jid) => {
181
264
  let targetJid;
@@ -507,7 +590,7 @@ const makeChatsSocket = (config) => {
507
590
  let presence;
508
591
  const jid = attrs.from;
509
592
  const participant = attrs.participant || attrs.from;
510
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
593
+ if (shouldIgnoreJid(jid) && jid != '@s.whatsapp.net') {
511
594
  return;
512
595
  }
513
596
  if (tag === 'presence') {
@@ -642,6 +725,22 @@ const makeChatsSocket = (config) => {
642
725
  }
643
726
  }, jid);
644
727
  };
728
+ /**
729
+ * Add or Edit Contact
730
+ */
731
+ const addOrEditContact = (jid, contact) => {
732
+ return chatModify({
733
+ contact
734
+ }, jid);
735
+ };
736
+ /**
737
+ * Remove Contact
738
+ */
739
+ const removeContact = (jid) => {
740
+ return chatModify({
741
+ contact: null
742
+ }, jid);
743
+ };
645
744
  /**
646
745
  * Adds label
647
746
  */
@@ -810,6 +909,7 @@ const makeChatsSocket = (config) => {
810
909
  });
811
910
  return {
812
911
  ...sock,
912
+ getBotListV2,
813
913
  processingMutex,
814
914
  fetchPrivacySettings,
815
915
  upsertMessage,
@@ -819,9 +919,11 @@ const makeChatsSocket = (config) => {
819
919
  profilePictureUrl,
820
920
  onWhatsApp,
821
921
  fetchBlocklist,
822
- fetchStatus,
823
922
  fetchDisappearingDuration,
923
+ fetchStatus,
824
924
  updateProfilePicture,
925
+ updateProfilePictureFull,
926
+ updateProfilePictureFull2,
825
927
  removeProfilePicture,
826
928
  updateProfileStatus,
827
929
  updateProfileName,
@@ -839,6 +941,8 @@ const makeChatsSocket = (config) => {
839
941
  resyncAppState,
840
942
  chatModify,
841
943
  cleanDirtyBits,
944
+ addOrEditContact,
945
+ removeContact,
842
946
  addLabel,
843
947
  addChatLabel,
844
948
  removeChatLabel,