@jkt48connect-corp/baileys 7.3.0 → 7.3.2

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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1119 -1407
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.d.ts +7 -9
  5. package/lib/Defaults/index.js +4 -6
  6. package/lib/Socket/Client/index.d.ts +3 -2
  7. package/lib/Socket/Client/index.js +3 -2
  8. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  9. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
  10. package/lib/Socket/business.d.ts +3 -8
  11. package/lib/Socket/chats.d.ts +19 -21
  12. package/lib/Socket/chats.js +48 -51
  13. package/lib/Socket/groups.d.ts +26 -28
  14. package/lib/Socket/groups.js +1 -2
  15. package/lib/Socket/index.d.ts +3 -6
  16. package/lib/Socket/messages-recv.d.ts +3 -8
  17. package/lib/Socket/messages-recv.js +149 -308
  18. package/lib/Socket/messages-send.d.ts +26 -23
  19. package/lib/Socket/messages-send.js +166 -193
  20. package/lib/Socket/newsletter.d.ts +2 -2
  21. package/lib/Socket/newsletter.js +3 -3
  22. package/lib/Socket/registration.d.ts +3 -8
  23. package/lib/Socket/socket.d.ts +6 -8
  24. package/lib/Socket/socket.js +14 -19
  25. package/lib/Store/make-cache-manager-store.d.ts +2 -2
  26. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  27. package/lib/Types/Call.d.ts +1 -1
  28. package/lib/Types/Chat.d.ts +7 -12
  29. package/lib/Types/Events.d.ts +2 -17
  30. package/lib/Types/GroupMetadata.d.ts +1 -3
  31. package/lib/Types/Label.d.ts +0 -11
  32. package/lib/Types/Message.d.ts +328 -324
  33. package/lib/Types/Socket.d.ts +0 -7
  34. package/lib/Types/index.d.ts +0 -9
  35. package/lib/Utils/chat-utils.d.ts +4 -4
  36. package/lib/Utils/chat-utils.js +20 -41
  37. package/lib/Utils/crypto.d.ts +1 -1
  38. package/lib/Utils/crypto.js +2 -4
  39. package/lib/Utils/decode-wa-message.d.ts +0 -17
  40. package/lib/Utils/decode-wa-message.js +14 -42
  41. package/lib/Utils/generics.d.ts +10 -4
  42. package/lib/Utils/generics.js +14 -30
  43. package/lib/Utils/history.d.ts +2 -6
  44. package/lib/Utils/history.js +0 -3
  45. package/lib/Utils/messages.d.ts +1 -0
  46. package/lib/Utils/messages.js +41 -249
  47. package/lib/Utils/signal.d.ts +1 -2
  48. package/lib/Utils/signal.js +19 -11
  49. package/lib/Utils/use-multi-file-auth-state.js +3 -11
  50. package/lib/Utils/validate-connection.d.ts +2 -2
  51. package/lib/Utils/validate-connection.js +1 -1
  52. package/lib/WABinary/encode.d.ts +1 -1
  53. package/lib/WABinary/encode.js +10 -16
  54. package/lib/index.d.ts +11 -0
  55. package/lib/index.js +0 -1
  56. package/lib/index.ts +13 -0
  57. package/package.json +15 -27
  58. package/lib/Socket/Client/types.d.ts +0 -17
  59. package/lib/Socket/Client/types.js +0 -13
  60. package/lib/Socket/usync.d.ts +0 -37
  61. package/lib/Socket/usync.js +0 -70
  62. package/lib/Types/USync.d.ts +0 -25
  63. package/lib/Types/USync.js +0 -2
  64. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  65. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  66. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  67. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  68. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  70. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  71. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  72. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  73. package/lib/WAUSync/Protocols/index.js +0 -20
  74. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  75. package/lib/WAUSync/USyncQuery.js +0 -79
  76. package/lib/WAUSync/USyncUser.d.ts +0 -10
  77. package/lib/WAUSync/USyncUser.js +0 -22
  78. package/lib/WAUSync/index.d.ts +0 -3
  79. package/lib/WAUSync/index.js +0 -19
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1019097045]
2
+ "version": [2, 2413, 1]
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[];
@@ -233,16 +231,16 @@ export declare const DEF_CALLBACK_PREFIX = "CB:";
233
231
  export declare const DEF_TAG_PREFIX = "TAG:";
234
232
  export declare const PHONE_CONNECTION_CB = "CB:Pong";
235
233
  export declare const WA_DEFAULT_EPHEMERAL: number;
236
- export declare const MOBILE_TOKEN: Buffer;
234
+ export declare const MOBILE_TOKEN: any;
237
235
  export declare const MOBILE_REGISTRATION_ENDPOINT = "https://v.whatsapp.net/v2";
238
- export declare const MOBILE_USERAGENT: string;
239
- export declare const REGISTRATION_PUBLIC_KEY: Buffer;
236
+ export declare const MOBILE_USERAGENT = "WhatsApp/2.24.6.77 iOS/15.3.1 Device/Apple-iPhone_7";
237
+ export declare const REGISTRATION_PUBLIC_KEY: any;
240
238
  export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
241
239
  export declare const DICT_VERSION = 2;
242
- export declare const KEY_BUNDLE_TYPE: Buffer;
243
- export declare const NOISE_WA_HEADER: Buffer;
240
+ export declare const KEY_BUNDLE_TYPE: any;
241
+ export declare const NOISE_WA_HEADER: any;
244
242
  export declare const PROTOCOL_VERSION: number[];
245
- export declare const MOBILE_NOISE_HEADER: Buffer;
243
+ export declare const MOBILE_NOISE_HEADER: any;
246
244
  /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
247
245
  export declare const URL_REGEX: RegExp;
248
246
  export declare const WA_CERT_DETAILS: {
@@ -273,7 +271,7 @@ export declare const MEDIA_HKDF_KEY_MAPPING: {
273
271
  'payment-bg-image': string;
274
272
  ptv: string;
275
273
  };
276
- 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")[];
274
+ export declare const MEDIA_KEYS: MediaType[];
277
275
  export declare const MIN_PREKEY_COUNT = 5;
278
276
  export declare const INITIAL_PREKEY_COUNT = 30;
279
277
  export declare const DEFAULT_CACHE_TTLS: {
@@ -44,8 +44,7 @@ exports.PROCESSABLE_HISTORY_TYPES = [
44
44
  WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.INITIAL_BOOTSTRAP,
45
45
  WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.PUSH_NAME,
46
46
  WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.RECENT,
47
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL,
48
- WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.ON_DEMAND,
47
+ WAProto_1.proto.Message.HistorySyncNotification.HistorySyncType.FULL
49
48
  ];
50
49
  exports.DEFAULT_CONNECTION_CONFIG = {
51
50
  version: baileys_version_json_1.version,
@@ -76,7 +75,6 @@ exports.DEFAULT_CONNECTION_CONFIG = {
76
75
  snapshot: false,
77
76
  },
78
77
  getMessage: async () => undefined,
79
- cachedGroupMetadata: async () => undefined,
80
78
  makeSignalRepository: libsignal_1.makeLibSignalRepository
81
79
  };
82
80
  exports.MEDIA_PATH_MAP = {
@@ -114,8 +112,8 @@ exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
114
112
  exports.MIN_PREKEY_COUNT = 5;
115
113
  exports.INITIAL_PREKEY_COUNT = 30;
116
114
  exports.DEFAULT_CACHE_TTLS = {
117
- SIGNAL_STORE: 5 * 60,
118
- MSG_RETRY: 60 * 60,
119
- CALL_OFFER: 5 * 60,
115
+ SIGNAL_STORE: 5 * 60, // 5 minutes
116
+ MSG_RETRY: 60 * 60, // 1 hour
117
+ CALL_OFFER: 5 * 60, // 5 minutes
120
118
  USER_DEVICES: 5 * 60, // 5 minutes
121
119
  };
@@ -1,2 +1,3 @@
1
- export * from './types';
2
- export * from './websocket';
1
+ export * from './abstract-socket-client';
2
+ export * from './mobile-socket-client';
3
+ export * from './web-socket-client';
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./types"), exports);
18
- __exportStar(require("./websocket"), exports);
17
+ __exportStar(require("./abstract-socket-client"), exports);
18
+ __exportStar(require("./mobile-socket-client"), exports);
19
+ __exportStar(require("./web-socket-client"), exports);
@@ -1,5 +1,5 @@
1
1
  import WebSocket from 'ws';
2
- import { AbstractSocketClient } from './types';
2
+ import { AbstractSocketClient } from './abstract-socket-client';
3
3
  export declare class WebSocketClient extends AbstractSocketClient {
4
4
  protected socket: WebSocket | null;
5
5
  get isOpen(): boolean;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WebSocketClient = void 0;
7
7
  const ws_1 = __importDefault(require("ws"));
8
8
  const Defaults_1 = require("../../Defaults");
9
- const types_1 = require("./types");
10
- class WebSocketClient extends types_1.AbstractSocketClient {
9
+ const abstract_socket_client_1 = require("./abstract-socket-client");
10
+ class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
11
11
  constructor() {
12
12
  super(...arguments);
13
13
  this.socket = null;
@@ -15,15 +15,13 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
15
15
  deleted: number;
16
16
  }>;
17
17
  productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>;
18
- sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
18
+ sendMessageAck: ({ tag, attrs, content }: BinaryNode) => Promise<void>;
19
19
  sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
20
20
  offerCall: (toJid: string, isVideo?: boolean) => Promise<{
21
21
  id: any;
22
22
  to: string;
23
23
  }>;
24
24
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
25
- fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number) => Promise<string>;
26
- requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
27
25
  getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
28
26
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
29
27
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
@@ -33,7 +31,6 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
33
31
  readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
34
32
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
35
33
  getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
36
- sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
37
34
  createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
38
35
  nodes: BinaryNode[];
39
36
  shouldIncludeDeviceIdentity: boolean;
@@ -43,8 +40,6 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
43
40
  [_: string]: string;
44
41
  }>;
45
42
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
46
- sendStatusMentions: (content: import("../Types").AnyMessageContent, jids?: string[]) => Promise<import("../Types").WAProto.WebMessageInfo>;
47
- sendAlbumMessage: (jid: string, medias: import("../Types").Media[], options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo>;
48
43
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
49
44
  subscribeNewsletterUpdates: (jid: string) => Promise<{
50
45
  duration: string;
@@ -59,7 +54,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
59
54
  newsletterUnmute: (jid: string) => Promise<void>;
60
55
  newsletterMute: (jid: string) => Promise<void>;
61
56
  newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
62
- newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
57
+ newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<import("../Types").NewsletterMetadata>;
63
58
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
64
59
  newsletterAdminCount: (jid: string) => Promise<number>;
65
60
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
@@ -164,7 +159,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
164
159
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
165
160
  uploadPreKeys: (count?: number) => Promise<void>;
166
161
  uploadPreKeysToServerIfRequired: () => Promise<void>;
167
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
162
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
168
163
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
169
164
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
170
165
  };
@@ -1,34 +1,33 @@
1
- /// <reference types="node" />
2
1
  import { Boom } from '@hapi/boom';
3
2
  import { proto } from '../../WAProto';
4
3
  import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
5
4
  import { BinaryNode } from '../WABinary';
6
- import { USyncQuery } from '../WAUSync';
7
5
  export declare const makeChatsSocket: (config: SocketConfig) => {
8
- interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
9
6
  processingMutex: {
10
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
7
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
11
8
  };
12
9
  fetchPrivacySettings: (force?: boolean) => Promise<{
13
10
  [_: string]: string;
14
11
  }>;
15
12
  upsertMessage: (msg: proto.IWebMessageInfo, type: MessageUpsertType) => Promise<void>;
16
13
  appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
17
- fetchUserLid: (jid: string) => Promise<string | undefined>;
18
14
  sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
19
15
  presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
16
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
20
17
  onWhatsApp: (...jids: string[]) => Promise<{
18
+ exists: boolean;
21
19
  jid: string;
22
- exists: unknown;
23
- }[] | undefined>;
20
+ }[]>;
24
21
  fetchBlocklist: () => Promise<string[]>;
25
- fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
26
- fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
22
+ fetchStatus: (jid: string) => Promise<{
23
+ status: string | undefined;
24
+ setAt: Date;
25
+ } | undefined>;
27
26
  updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
28
27
  removeProfilePicture: (jid: string) => Promise<void>;
29
28
  updateProfileStatus: (status: string) => Promise<void>;
30
29
  updateProfileName: (name: string) => Promise<void>;
31
- updateBlockStatus: (jid: string, action: 'block' | 'unblock') => Promise<void>;
30
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
32
31
  updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>;
33
32
  updateOnlinePrivacy: (value: WAPrivacyOnlineValue) => Promise<void>;
34
33
  updateProfilePicturePrivacy: (value: WAPrivacyValue) => Promise<void>;
@@ -39,7 +38,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
39
38
  getBusinessProfile: (jid: string) => Promise<WABusinessProfile | void>;
40
39
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
41
40
  chatModify: (mod: ChatModification, jid: string) => Promise<void>;
42
- cleanDirtyBits: (type: 'account_sync' | 'groups', fromTimestamp?: number | string) => Promise<void>;
41
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
43
42
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
44
43
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
45
44
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -48,14 +47,13 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
48
47
  id: string;
49
48
  fromMe?: boolean;
50
49
  }[], star: boolean) => Promise<void>;
51
- executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
52
50
  type: "md";
53
51
  ws: any;
54
52
  ev: import("../Types").BaileysEventEmitter & {
55
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
53
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
56
54
  buffer(): void;
57
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
58
- flush(force?: boolean | undefined): boolean;
55
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
56
+ flush(force?: boolean): boolean;
59
57
  isBuffering(): boolean;
60
58
  };
61
59
  authState: {
@@ -65,17 +63,17 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
65
63
  signalRepository: import("../Types").SignalRepository;
66
64
  user: import("../Types").Contact | undefined;
67
65
  generateMessageTag: () => string;
68
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
69
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
66
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
67
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
70
68
  waitForSocketOpen: () => Promise<void>;
71
69
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
72
70
  sendNode: (frame: BinaryNode) => Promise<void>;
73
- logout: (msg?: string | undefined) => Promise<void>;
71
+ logout: (msg?: string) => Promise<void>;
74
72
  end: (error: Error | undefined) => void;
75
- onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
73
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
76
74
  uploadPreKeys: (count?: number) => Promise<void>;
77
75
  uploadPreKeysToServerIfRequired: () => Promise<void>;
78
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
79
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
76
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
77
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
80
78
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
81
79
  };
@@ -12,13 +12,12 @@ const Utils_1 = require("../Utils");
12
12
  const make_mutex_1 = require("../Utils/make-mutex");
13
13
  const process_message_1 = __importDefault(require("../Utils/process-message"));
14
14
  const WABinary_1 = require("../WABinary");
15
- const WAUSync_1 = require("../WAUSync");
16
- const usync_1 = require("./usync");
15
+ const socket_1 = require("./socket");
17
16
  const MAX_SYNC_ATTEMPTS = 2;
18
17
  const makeChatsSocket = (config) => {
19
18
  const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage, } = config;
20
- const sock = (0, usync_1.makeUSyncSocket)(config);
21
- const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError } = sock;
19
+ const sock = (0, socket_1.makeSocket)(config);
20
+ const { ev, ws, authState, generateMessageTag, sendNode, query, onUnexpectedError, } = sock;
22
21
  let privacySettings;
23
22
  let needToFlushWithAppStateSync = false;
24
23
  let pendingAppStateSync = false;
@@ -140,53 +139,35 @@ const makeChatsSocket = (config) => {
140
139
  const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
141
140
  return users;
142
141
  };
143
- const fetchUserLid = async (jid) => {
144
- const [result] = await interactiveQuery([
145
- {
142
+ const onWhatsApp = async (...jids) => {
143
+ const query = { tag: 'contact', attrs: {} };
144
+ const list = jids.map((jid) => {
145
+ // insures only 1 + is there
146
+ const content = `+${jid.replace('+', '')}`;
147
+ return {
146
148
  tag: 'user',
147
- attrs: { jid }
148
- }
149
- ], {
150
- tag: 'lid',
151
- attrs: {}
149
+ attrs: {},
150
+ content: [{
151
+ tag: 'contact',
152
+ attrs: {},
153
+ content,
154
+ }],
155
+ };
152
156
  });
157
+ const results = await interactiveQuery(list, query);
158
+ return results.map(user => {
159
+ const contact = (0, WABinary_1.getBinaryNodeChild)(user, 'contact');
160
+ return { exists: (contact === null || contact === void 0 ? void 0 : contact.attrs.type) === 'in', jid: user.attrs.jid };
161
+ }).filter(item => item.exists);
162
+ };
163
+ const fetchStatus = async (jid) => {
164
+ const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
153
165
  if (result) {
154
- const lid = (0, WABinary_1.getBinaryNodeChild)(result, 'lid');
155
- return lid.attrs.val;
156
- }
157
- };
158
- const onWhatsApp = async (...jids) => {
159
- const usyncQuery = new WAUSync_1.USyncQuery()
160
- .withContactProtocol();
161
- for (const jid of jids) {
162
- const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
163
- usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
164
- }
165
- const results = await sock.executeUSyncQuery(usyncQuery);
166
- if (results) {
167
- return results.list.filter((a) => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
168
- }
169
- };
170
- const fetchStatus = async (...jids) => {
171
- const usyncQuery = new WAUSync_1.USyncQuery()
172
- .withStatusProtocol();
173
- for (const jid of jids) {
174
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
175
- }
176
- const result = await sock.executeUSyncQuery(usyncQuery);
177
- if (result) {
178
- return result.list;
179
- }
180
- };
181
- const fetchDisappearingDuration = async (...jids) => {
182
- const usyncQuery = new WAUSync_1.USyncQuery()
183
- .withDisappearingModeProtocol();
184
- for (const jid of jids) {
185
- usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
186
- }
187
- const result = await sock.executeUSyncQuery(usyncQuery);
188
- if (result) {
189
- return result.list;
166
+ const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
167
+ return {
168
+ status: status === null || status === void 0 ? void 0 : status.content.toString(),
169
+ setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
170
+ };
190
171
  }
191
172
  };
192
173
  /** update the profile picture for yourself or a group */
@@ -477,6 +458,24 @@ const makeChatsSocket = (config) => {
477
458
  * type = "preview" for a low res picture
478
459
  * type = "image for the high res picture"
479
460
  */
461
+ const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
462
+ var _a;
463
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
464
+ const result = await query({
465
+ tag: 'iq',
466
+ attrs: {
467
+ target: jid,
468
+ to: WABinary_1.S_WHATSAPP_NET,
469
+ type: 'get',
470
+ xmlns: 'w:profile:picture'
471
+ },
472
+ content: [
473
+ { tag: 'picture', attrs: { type, query: 'url' } }
474
+ ]
475
+ }, timeoutMs);
476
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
477
+ return (_a = child === null || child === void 0 ? void 0 : child.attrs) === null || _a === void 0 ? void 0 : _a.url;
478
+ };
480
479
  const sendPresenceUpdate = async (type, toJid) => {
481
480
  const me = authState.creds.me;
482
481
  if (type === 'available' || type === 'unavailable') {
@@ -833,18 +832,16 @@ const makeChatsSocket = (config) => {
833
832
  });
834
833
  return {
835
834
  ...sock,
836
- interactiveQuery,
837
835
  processingMutex,
838
836
  fetchPrivacySettings,
839
837
  upsertMessage,
840
838
  appPatch,
841
- fetchUserLid,
842
839
  sendPresenceUpdate,
843
840
  presenceSubscribe,
841
+ profilePictureUrl,
844
842
  onWhatsApp,
845
843
  fetchBlocklist,
846
844
  fetchStatus,
847
- fetchDisappearingDuration,
848
845
  updateProfilePicture,
849
846
  removeProfilePicture,
850
847
  updateProfileStatus,
@@ -1,9 +1,7 @@
1
- /// <reference types="node" />
2
1
  import { proto } from '../../WAProto';
3
2
  import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types';
4
3
  import { BinaryNode } from '../WABinary';
5
4
  export declare const makeGroupsSocket: (config: SocketConfig) => {
6
- groupQuery: (jid: string, type: 'get' | 'set', content: BinaryNode[]) => Promise<BinaryNode>;
7
5
  groupMetadata: (jid: string) => Promise<GroupMetadata>;
8
6
  groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
9
7
  groupLeave: (id: string) => Promise<void>;
@@ -11,7 +9,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
11
9
  groupRequestParticipantsList: (jid: string) => Promise<{
12
10
  [key: string]: string;
13
11
  }[]>;
14
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{
12
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
15
13
  status: string;
16
14
  jid: string;
17
15
  }[]>;
@@ -32,31 +30,32 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
32
30
  groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
33
31
  groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
34
32
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
35
- groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>;
36
- groupMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>;
37
- groupJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>;
33
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
34
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
35
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
38
36
  groupFetchAllParticipating: () => Promise<{
39
37
  [_: string]: GroupMetadata;
40
38
  }>;
41
- interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
42
39
  processingMutex: {
43
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
40
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
44
41
  };
45
42
  fetchPrivacySettings: (force?: boolean) => Promise<{
46
43
  [_: string]: string;
47
44
  }>;
48
45
  upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
49
46
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
50
- fetchUserLid: (jid: string) => Promise<string | undefined>;
51
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
52
- presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
47
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
48
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
49
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
53
50
  onWhatsApp: (...jids: string[]) => Promise<{
51
+ exists: boolean;
54
52
  jid: string;
55
- exists: unknown;
56
- }[] | undefined>;
53
+ }[]>;
57
54
  fetchBlocklist: () => Promise<string[]>;
58
- fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
59
- fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
55
+ fetchStatus: (jid: string) => Promise<{
56
+ status: string | undefined;
57
+ setAt: Date;
58
+ } | undefined>;
60
59
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
61
60
  removeProfilePicture: (jid: string) => Promise<void>;
62
61
  updateProfileStatus: (status: string) => Promise<void>;
@@ -69,26 +68,25 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
69
68
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
70
69
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
71
70
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
72
- getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
71
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
73
72
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
74
73
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
75
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
74
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
76
75
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
77
76
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
78
77
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
79
78
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
80
79
  star: (jid: string, messages: {
81
80
  id: string;
82
- fromMe?: boolean | undefined;
81
+ fromMe?: boolean;
83
82
  }[], star: boolean) => Promise<void>;
84
- executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
85
83
  type: "md";
86
84
  ws: any;
87
85
  ev: import("../Types").BaileysEventEmitter & {
88
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
86
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
89
87
  buffer(): void;
90
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
91
- flush(force?: boolean | undefined): boolean;
88
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
89
+ flush(force?: boolean): boolean;
92
90
  isBuffering(): boolean;
93
91
  };
94
92
  authState: {
@@ -98,18 +96,18 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
98
96
  signalRepository: import("../Types").SignalRepository;
99
97
  user: import("../Types").Contact | undefined;
100
98
  generateMessageTag: () => string;
101
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
102
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
99
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
100
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
103
101
  waitForSocketOpen: () => Promise<void>;
104
102
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
105
103
  sendNode: (frame: BinaryNode) => Promise<void>;
106
- logout: (msg?: string | undefined) => Promise<void>;
104
+ logout: (msg?: string) => Promise<void>;
107
105
  end: (error: Error | undefined) => void;
108
- onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
106
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
109
107
  uploadPreKeys: (count?: number) => Promise<void>;
110
108
  uploadPreKeysToServerIfRequired: () => Promise<void>;
111
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
112
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
109
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
110
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
113
111
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
114
112
  };
115
113
  export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
@@ -67,7 +67,6 @@ const makeGroupsSocket = (config) => {
67
67
  });
68
68
  return {
69
69
  ...sock,
70
- groupQuery,
71
70
  groupMetadata,
72
71
  groupCreate: async (subject, participants) => {
73
72
  const key = (0, Utils_1.generateMessageID)();
@@ -297,7 +296,7 @@ const extractGroupMetadata = (result) => {
297
296
  admin: (attrs.type || null),
298
297
  };
299
298
  }),
300
- ephemeralDuration: eph ? +eph : 0
299
+ ephemeralDuration: eph ? +eph : undefined
301
300
  };
302
301
  return metadata;
303
302
  };
@@ -16,15 +16,13 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
16
16
  deleted: number;
17
17
  }>;
18
18
  productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
19
- sendMessageAck: ({ tag, attrs, content }: import("..").BinaryNode, errorCode?: number) => Promise<void>;
19
+ sendMessageAck: ({ tag, attrs, content }: import("..").BinaryNode) => Promise<void>;
20
20
  sendRetryRequest: (node: import("..").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
21
21
  offerCall: (toJid: string, isVideo?: boolean) => Promise<{
22
22
  id: any;
23
23
  to: string;
24
24
  }>;
25
25
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
26
- fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number) => Promise<string>;
27
- requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
28
26
  getPrivacyTokens: (jids: string[]) => Promise<import("..").BinaryNode>;
29
27
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
30
28
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
@@ -34,7 +32,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
34
32
  readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
35
33
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
36
34
  getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("..").JidWithDevice[]>;
37
- sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
38
35
  createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: import("..").BinaryNode["attrs"]) => Promise<{
39
36
  nodes: import("..").BinaryNode[];
40
37
  shouldIncludeDeviceIdentity: boolean;
@@ -60,7 +57,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
60
57
  newsletterUnmute: (jid: string) => Promise<void>;
61
58
  newsletterMute: (jid: string) => Promise<void>;
62
59
  newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
63
- newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
60
+ newsletterCreate: (name: string, description: string, reaction_codes: string) => Promise<import("../Types").NewsletterMetadata>;
64
61
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
65
62
  newsletterAdminCount: (jid: string) => Promise<number>;
66
63
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
@@ -165,7 +162,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
165
162
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
166
163
  uploadPreKeys: (count?: number) => Promise<void>;
167
164
  uploadPreKeysToServerIfRequired: () => Promise<void>;
168
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
165
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
169
166
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
170
167
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("..").BinaryNode>;
171
168
  };