@genuxofficial/baileys 3.0.0 → 4.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 (88) hide show
  1. package/WAProto/WAProto.proto +24 -206
  2. package/WAProto/index.d.ts +219 -2233
  3. package/WAProto/index.js +525 -6773
  4. package/WAProto/shizo.x +1 -0
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.d.ts +231 -0
  7. package/lib/Defaults/index.js +17 -1
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Socket/Client/index.d.ts +3 -2
  10. package/lib/Socket/Client/index.js +3 -2
  11. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  12. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  13. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  14. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
  15. package/lib/Socket/business.d.ts +7 -9
  16. package/lib/Socket/chats.d.ts +5 -8
  17. package/lib/Socket/chats.js +8 -38
  18. package/lib/Socket/groups.d.ts +5 -7
  19. package/lib/Socket/groups.js +2 -14
  20. package/lib/Socket/index.d.ts +9 -9
  21. package/lib/Socket/index.js +2 -2
  22. package/lib/Socket/messages-recv.d.ts +8 -10
  23. package/lib/Socket/messages-recv.js +11 -18
  24. package/lib/Socket/messages-send.d.ts +7 -14
  25. package/lib/Socket/messages-send.js +13 -36
  26. package/lib/Socket/newsletter.d.ts +7 -9
  27. package/lib/Socket/newsletter.js +3 -11
  28. package/lib/Socket/registration.d.ts +271 -0
  29. package/lib/Socket/registration.js +166 -0
  30. package/lib/Socket/socket.d.ts +4 -5
  31. package/lib/Socket/socket.js +18 -15
  32. package/lib/Socket/usync.d.ts +4 -4
  33. package/lib/Store/index.d.ts +2 -1
  34. package/lib/Store/index.js +3 -1
  35. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  36. package/lib/Store/make-cache-manager-store.js +83 -0
  37. package/lib/Store/make-in-memory-store.js +10 -8
  38. package/lib/Store/make-ordered-dictionary.js +2 -2
  39. package/lib/Types/Auth.d.ts +6 -0
  40. package/lib/Types/Chat.d.ts +0 -4
  41. package/lib/Types/Contact.d.ts +1 -1
  42. package/lib/Types/GroupMetadata.d.ts +0 -6
  43. package/lib/Types/Message.d.ts +5 -29
  44. package/lib/Types/Message.js +2 -0
  45. package/lib/Types/Socket.d.ts +4 -7
  46. package/lib/Utils/auth-utils.d.ts +1 -1
  47. package/lib/Utils/auth-utils.js +9 -2
  48. package/lib/Utils/business.js +3 -15
  49. package/lib/Utils/chat-utils.d.ts +4 -4
  50. package/lib/Utils/chat-utils.js +2 -1
  51. package/lib/Utils/decode-wa-message.d.ts +2 -4
  52. package/lib/Utils/decode-wa-message.js +24 -145
  53. package/lib/Utils/event-buffer.js +6 -4
  54. package/lib/Utils/generics.d.ts +4 -7
  55. package/lib/Utils/generics.js +17 -9
  56. package/lib/Utils/lt-hash.d.ts +3 -3
  57. package/lib/Utils/lt-hash.js +45 -11
  58. package/lib/Utils/messages-media.d.ts +4 -4
  59. package/lib/Utils/messages-media.js +57 -69
  60. package/lib/Utils/messages.js +39 -33
  61. package/lib/Utils/noise-handler.d.ts +2 -1
  62. package/lib/Utils/noise-handler.js +10 -5
  63. package/lib/Utils/use-multi-file-auth-state.js +11 -48
  64. package/lib/Utils/validate-connection.d.ts +1 -0
  65. package/lib/Utils/validate-connection.js +44 -10
  66. package/lib/WABinary/constants.js +5 -5
  67. package/lib/WABinary/encode.js +10 -23
  68. package/lib/WABinary/generic-utils.d.ts +5 -3
  69. package/lib/WABinary/generic-utils.js +19 -34
  70. package/lib/WABinary/jid-utils.d.ts +2 -11
  71. package/lib/WABinary/jid-utils.js +2 -27
  72. package/lib/WAM/BinaryInfo.d.ts +2 -2
  73. package/lib/WAM/constants.d.ts +2 -3
  74. package/lib/WAM/encode.js +2 -2
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +12 -21
  76. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  77. package/lib/WAUSync/USyncQuery.d.ts +0 -2
  78. package/lib/WAUSync/USyncQuery.js +0 -10
  79. package/lib/WAUSync/USyncUser.d.ts +0 -2
  80. package/lib/WAUSync/USyncUser.js +0 -4
  81. package/package.json +5 -6
  82. package/LICENSE +0 -21
  83. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -25
  84. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
  85. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -8
  86. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
  87. /package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +0 -0
  88. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -28,7 +28,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
28
28
  }>;
29
29
  fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
30
30
  requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
31
- getPrivacyTokens: (jids: string[]) => Promise<any>;
31
+ getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
32
32
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
33
33
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
34
34
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
@@ -64,7 +64,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
64
64
  newsletterFollow: (jid: string) => Promise<void>;
65
65
  newsletterUnmute: (jid: string) => Promise<void>;
66
66
  newsletterMute: (jid: string) => Promise<void>;
67
- newsletterCreate: (name: string, description?: string | undefined, picture?: import("../Types").WAMediaUpload | undefined) => Promise<import("../Types").NewsletterMetadata>;
67
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
68
68
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
69
69
  newsletterAdminCount: (jid: string) => Promise<number>;
70
70
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
@@ -94,7 +94,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
94
94
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
95
95
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
96
96
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
97
- groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
97
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
98
98
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
99
99
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
100
100
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -103,7 +103,6 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
103
103
  groupFetchAllParticipating: () => Promise<{
104
104
  [_: string]: import("../Types").GroupMetadata;
105
105
  }>;
106
- getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
107
106
  processingMutex: {
108
107
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
109
108
  };
@@ -115,7 +114,6 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
115
114
  onWhatsApp: (...jids: string[]) => Promise<{
116
115
  jid: string;
117
116
  exists: unknown;
118
- lid: unknown;
119
117
  }[] | undefined>;
120
118
  fetchBlocklist: () => Promise<string[]>;
121
119
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
@@ -148,7 +146,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
148
146
  }[], star: boolean) => Promise<void>;
149
147
  executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
150
148
  type: "md";
151
- ws: import("./Client/websocket").WebSocketClient;
149
+ ws: any;
152
150
  ev: import("../Types").BaileysEventEmitter & {
153
151
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
154
152
  buffer(): void;
@@ -163,8 +161,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
163
161
  signalRepository: import("../Types").SignalRepository;
164
162
  user: import("../Types").Contact | undefined;
165
163
  generateMessageTag: () => string;
166
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
167
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
164
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
165
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
168
166
  waitForSocketOpen: () => Promise<void>;
169
167
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
170
168
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -175,5 +173,5 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
175
173
  uploadPreKeysToServerIfRequired: () => Promise<void>;
176
174
  requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
177
175
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
178
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
176
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
179
177
  };
@@ -2,11 +2,10 @@
2
2
  /// <reference types="node" />
3
3
  import { Boom } from '@hapi/boom';
4
4
  import { proto } from '../../WAProto';
5
- import { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
5
+ import { ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
6
6
  import { BinaryNode } from '../WABinary';
7
7
  import { USyncQuery } from '../WAUSync';
8
8
  export declare const makeChatsSocket: (config: SocketConfig) => {
9
- getBotListV2: () => Promise<BotListInfo[]>;
10
9
  processingMutex: {
11
10
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
12
11
  };
@@ -21,7 +20,6 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
21
20
  onWhatsApp: (...jids: string[]) => Promise<{
22
21
  jid: string;
23
22
  exists: unknown;
24
- lid: unknown;
25
23
  }[] | undefined>;
26
24
  fetchBlocklist: () => Promise<string[]>;
27
25
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
@@ -54,7 +52,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
54
52
  }[], star: boolean) => Promise<void>;
55
53
  executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
56
54
  type: "md";
57
- ws: import("./Client/websocket").WebSocketClient;
55
+ ws: any;
58
56
  ev: import("../Types").BaileysEventEmitter & {
59
57
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
60
58
  buffer(): void;
@@ -69,11 +67,10 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
69
67
  signalRepository: import("../Types").SignalRepository;
70
68
  user: import("../Types").Contact | undefined;
71
69
  generateMessageTag: () => string;
72
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
73
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
70
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
71
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
74
72
  waitForSocketOpen: () => Promise<void>;
75
73
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
76
- /** sending non-abt props may fix QR scan fail if server expects */
77
74
  sendNode: (frame: BinaryNode) => Promise<void>;
78
75
  logout: (msg?: string | undefined) => Promise<void>;
79
76
  end: (error: Error | undefined) => void;
@@ -82,5 +79,5 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
82
79
  uploadPreKeysToServerIfRequired: () => Promise<void>;
83
80
  requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
84
81
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
85
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
82
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
86
83
  };
@@ -115,46 +115,16 @@ 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
- };
147
118
  const onWhatsApp = async (...jids) => {
148
119
  const usyncQuery = new WAUSync_1.USyncQuery()
149
- .withContactProtocol()
150
- .withLIDProtocol();
120
+ .withContactProtocol();
151
121
  for (const jid of jids) {
152
122
  const phone = `+${jid.replace('+', '').split('@')[0].split(':')[0]}`;
153
123
  usyncQuery.withUser(new WAUSync_1.USyncUser().withPhone(phone));
154
124
  }
155
125
  const results = await sock.executeUSyncQuery(usyncQuery);
156
126
  if (results) {
157
- return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
127
+ return results.list.filter((a) => !!a.contact).map(({ contact, id }) => ({ jid: id, exists: contact }));
158
128
  }
159
129
  };
160
130
  const fetchStatus = async (...jids) => {
@@ -819,18 +789,18 @@ const makeChatsSocket = (config) => {
819
789
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
820
790
  .catch(error => onUnexpectedError(error, 'presence update requests'));
821
791
  }
822
- if (receivedPendingNotifications && // if we don't have the app state key
792
+ if (receivedPendingNotifications) {
793
+ // if we don't have the app state key
823
794
  // we keep buffering events until we finally have
824
795
  // the key and can sync the messages
825
- // todo scrutinize
826
- !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
827
- ev.buffer();
828
- needToFlushWithAppStateSync = true;
796
+ if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
797
+ ev.buffer();
798
+ needToFlushWithAppStateSync = true;
799
+ }
829
800
  }
830
801
  });
831
802
  return {
832
803
  ...sock,
833
- getBotListV2,
834
804
  processingMutex,
835
805
  fetchPrivacySettings,
836
806
  upsertMessage,
@@ -36,7 +36,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
36
36
  * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
37
37
  * @param inviteMessage the message to accept
38
38
  */
39
- groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
39
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
40
40
  groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
41
41
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
42
42
  groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>;
@@ -45,7 +45,6 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
45
45
  groupFetchAllParticipating: () => Promise<{
46
46
  [_: string]: GroupMetadata;
47
47
  }>;
48
- getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
49
48
  processingMutex: {
50
49
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
51
50
  };
@@ -60,7 +59,6 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
60
59
  onWhatsApp: (...jids: string[]) => Promise<{
61
60
  jid: string;
62
61
  exists: unknown;
63
- lid: unknown;
64
62
  }[] | undefined>;
65
63
  fetchBlocklist: () => Promise<string[]>;
66
64
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
@@ -93,7 +91,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
93
91
  }[], star: boolean) => Promise<void>;
94
92
  executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
95
93
  type: "md";
96
- ws: import("./Client/websocket").WebSocketClient;
94
+ ws: any;
97
95
  ev: import("../Types").BaileysEventEmitter & {
98
96
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
99
97
  buffer(): void;
@@ -108,8 +106,8 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
108
106
  signalRepository: import("../Types").SignalRepository;
109
107
  user: import("../Types").Contact | undefined;
110
108
  generateMessageTag: () => string;
111
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
112
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
109
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
110
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
113
111
  waitForSocketOpen: () => Promise<void>;
114
112
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
115
113
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -120,6 +118,6 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
120
118
  uploadPreKeysToServerIfRequired: () => Promise<void>;
121
119
  requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
122
120
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
123
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
121
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
124
122
  };
125
123
  export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
@@ -69,7 +69,7 @@ const makeGroupsSocket = (config) => {
69
69
  ...sock,
70
70
  groupMetadata,
71
71
  groupCreate: async (subject, participants) => {
72
- const key = (0, Utils_1.generateMessageIDV2)();
72
+ const key = (0, Utils_1.generateMessageID)();
73
73
  const result = await groupQuery('@g.us', 'set', [
74
74
  {
75
75
  tag: 'create',
@@ -163,7 +163,7 @@ const makeGroupsSocket = (config) => {
163
163
  {
164
164
  tag: 'description',
165
165
  attrs: {
166
- ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
166
+ ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
167
167
  ...(prev ? { prev } : {})
168
168
  },
169
169
  content: description ? [
@@ -277,15 +277,9 @@ const extractGroupMetadata = (result) => {
277
277
  const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
278
278
  let desc;
279
279
  let descId;
280
- let descOwner;
281
- let descOwnerPhoneNumber;
282
- let descTime;
283
280
  if (descChild) {
284
281
  desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
285
- descOwner = descChild.attrs.participant;
286
- descOwnerPhoneNumber = descChild.attrs.participant_pn;
287
282
  descId = descChild.attrs.id;
288
- descTime = +descChild.attrs.t;
289
283
  }
290
284
  const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
291
285
  const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
@@ -293,19 +287,14 @@ const extractGroupMetadata = (result) => {
293
287
  const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
294
288
  const metadata = {
295
289
  id: groupId,
296
- addressingMode: group.attrs.addressing_mode,
297
290
  subject: group.attrs.subject,
298
291
  subjectOwner: group.attrs.s_o,
299
- subjectOwnerPhoneNumber: group.attrs.s_o_pn,
300
292
  subjectTime: +group.attrs.s_t,
301
293
  size: groupSize || (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
302
294
  creation: +group.attrs.creation,
303
295
  owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
304
296
  desc,
305
297
  descId,
306
- descOwner,
307
- descOwnerPhoneNumber,
308
- descTime,
309
298
  linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
310
299
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
311
300
  announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
@@ -316,7 +305,6 @@ const extractGroupMetadata = (result) => {
316
305
  participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
317
306
  return {
318
307
  id: attrs.jid,
319
- phoneNumber: attrs.phone_number || attrs.jid,
320
308
  admin: (attrs.type || null),
321
309
  };
322
310
  }),
@@ -3,6 +3,8 @@
3
3
  /// <reference types="node" />
4
4
  import { UserFacingSocketConfig } from '../Types';
5
5
  declare const makeWASocket: (config: UserFacingSocketConfig) => {
6
+ register: (code: string) => Promise<import("./registration").ExistsResponse>;
7
+ requestRegistrationCode: (registrationOptions?: import("./registration").RegistrationOptions | undefined) => Promise<import("./registration").ExistsResponse>;
6
8
  logger: import("../Utils/logger").ILogger;
7
9
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
8
10
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
@@ -27,7 +29,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
27
29
  }>;
28
30
  fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
29
31
  requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
30
- getPrivacyTokens: (jids: string[]) => Promise<any>;
32
+ getPrivacyTokens: (jids: string[]) => Promise<import("../index").BinaryNode>;
31
33
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
32
34
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
33
35
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
@@ -63,7 +65,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
63
65
  newsletterFollow: (jid: string) => Promise<void>;
64
66
  newsletterUnmute: (jid: string) => Promise<void>;
65
67
  newsletterMute: (jid: string) => Promise<void>;
66
- newsletterCreate: (name: string, description?: string | undefined, picture?: import("../Types").WAMediaUpload | undefined) => Promise<import("../Types").NewsletterMetadata>;
68
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
67
69
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
68
70
  newsletterAdminCount: (jid: string) => Promise<number>;
69
71
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
@@ -93,7 +95,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
93
95
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
94
96
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
95
97
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
96
- groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
98
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
97
99
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
98
100
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
99
101
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -102,7 +104,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
102
104
  groupFetchAllParticipating: () => Promise<{
103
105
  [_: string]: import("../Types").GroupMetadata;
104
106
  }>;
105
- getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
106
107
  processingMutex: {
107
108
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
108
109
  };
@@ -114,7 +115,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
114
115
  onWhatsApp: (...jids: string[]) => Promise<{
115
116
  jid: string;
116
117
  exists: unknown;
117
- lid: unknown;
118
118
  }[] | undefined>;
119
119
  fetchBlocklist: () => Promise<string[]>;
120
120
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
@@ -147,7 +147,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
147
147
  }[], star: boolean) => Promise<void>;
148
148
  executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
149
149
  type: "md";
150
- ws: import("./Client/websocket").WebSocketClient;
150
+ ws: any;
151
151
  ev: import("../Types").BaileysEventEmitter & {
152
152
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
153
153
  buffer(): void;
@@ -162,8 +162,8 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
162
162
  signalRepository: import("../Types").SignalRepository;
163
163
  user: import("../Types").Contact | undefined;
164
164
  generateMessageTag: () => string;
165
- query: (node: import("../index").BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
166
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
165
+ query: (node: import("../index").BinaryNode, timeoutMs?: number | undefined) => Promise<import("../index").BinaryNode>;
166
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
167
167
  waitForSocketOpen: () => Promise<void>;
168
168
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
169
169
  sendNode: (frame: import("../index").BinaryNode) => Promise<void>;
@@ -174,6 +174,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
174
174
  uploadPreKeysToServerIfRequired: () => Promise<void>;
175
175
  requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
176
176
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
177
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
177
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("../index").BinaryNode>;
178
178
  };
179
179
  export default makeWASocket;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Defaults_1 = require("../Defaults");
4
- const business_1 = require("./business");
4
+ const registration_1 = require("./registration");
5
5
  // export the last socket layer
6
- const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
6
+ const makeWASocket = (config) => ((0, registration_1.makeRegistrationSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
9
  }));
@@ -15,8 +15,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
15
15
  isVideo: boolean;
16
16
  }>;
17
17
  fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
18
- requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
19
- getPrivacyTokens: (jids: string[]) => Promise<any>;
18
+ requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<'RESOLVED' | string | undefined>;
19
+ getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
20
20
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
21
21
  relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
22
22
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
@@ -52,7 +52,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
52
52
  newsletterFollow: (jid: string) => Promise<void>;
53
53
  newsletterUnmute: (jid: string) => Promise<void>;
54
54
  newsletterMute: (jid: string) => Promise<void>;
55
- newsletterCreate: (name: string, description?: string | undefined, picture?: import("../Types").WAMediaUpload | undefined) => Promise<import("../Types").NewsletterMetadata>;
55
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
56
56
  newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
57
57
  newsletterAdminCount: (jid: string) => Promise<number>;
58
58
  newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
@@ -82,7 +82,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
82
82
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
83
83
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
84
84
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
85
- groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
85
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
86
86
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
87
87
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
88
88
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -91,7 +91,6 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
91
91
  groupFetchAllParticipating: () => Promise<{
92
92
  [_: string]: import("../Types").GroupMetadata;
93
93
  }>;
94
- getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
95
94
  processingMutex: {
96
95
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
97
96
  };
@@ -103,7 +102,6 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
103
102
  onWhatsApp: (...jids: string[]) => Promise<{
104
103
  jid: string;
105
104
  exists: unknown;
106
- lid: unknown;
107
105
  }[] | undefined>;
108
106
  fetchBlocklist: () => Promise<string[]>;
109
107
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
@@ -136,7 +134,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
136
134
  }[], star: boolean) => Promise<void>;
137
135
  executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
138
136
  type: "md";
139
- ws: import("./Client/websocket").WebSocketClient;
137
+ ws: any;
140
138
  ev: import("../Types").BaileysEventEmitter & {
141
139
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
142
140
  buffer(): void;
@@ -151,8 +149,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
151
149
  signalRepository: import("../Types").SignalRepository;
152
150
  user: import("../Types").Contact | undefined;
153
151
  generateMessageTag: () => string;
154
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
155
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
152
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
153
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
156
154
  waitForSocketOpen: () => Promise<void>;
157
155
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
158
156
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -163,5 +161,5 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
163
161
  uploadPreKeysToServerIfRequired: () => Promise<void>;
164
162
  requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
165
163
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
166
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
164
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
167
165
  };
@@ -16,7 +16,7 @@ const WABinary_1 = require("../WABinary");
16
16
  const groups_1 = require("./groups");
17
17
  const messages_send_1 = require("./messages-send");
18
18
  const makeMessagesRecvSocket = (config) => {
19
- const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, ignoreMsgLoading, shouldIgnoreJid } = config;
19
+ const { logger, retryRequestDelayMs, maxMsgRetryCount, ignoreMsgLoading, getMessage, shouldIgnoreJid } = config;
20
20
  const sock = (0, messages_send_1.makeMessagesSocket)(config);
21
21
  const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
22
22
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
@@ -184,8 +184,7 @@ const makeMessagesRecvSocket = (config) => {
184
184
  ]
185
185
  };
186
186
  if (node.attrs.recipient) {
187
- //Fixes problem with retry that is never done when it is @bot
188
- receipt.attrs.recipient = (0, WABinary_1.getBotJid)(node.attrs.recipient);
187
+ receipt.attrs.recipient = node.attrs.recipient;
189
188
  }
190
189
  if (node.attrs.participant) {
191
190
  receipt.attrs.participant = node.attrs.participant;
@@ -562,7 +561,6 @@ const makeMessagesRecvSocket = (config) => {
562
561
  };
563
562
  const sendMessagesAgain = async (key, ids, retryNode) => {
564
563
  var _a;
565
- // todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
566
564
  const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
567
565
  const remoteJid = key.remoteJid;
568
566
  const participant = key.participant || remoteJid;
@@ -575,7 +573,8 @@ const makeMessagesRecvSocket = (config) => {
575
573
  await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
576
574
  }
577
575
  logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
578
- for (const [i, msg] of msgs.entries()) {
576
+ for (let i = 0; i < msgs.length; i++) {
577
+ const msg = msgs[i];
579
578
  if (msg) {
580
579
  updateSendMessageAgainCount(ids[i], participant);
581
580
  const msgRelayOpts = { messageId: ids[i] };
@@ -601,8 +600,7 @@ const makeMessagesRecvSocket = (config) => {
601
600
  const isLid = attrs.from.includes('lid');
602
601
  const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
603
602
  const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
604
- const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender')
605
- && isNodeFromMe);
603
+ const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
606
604
  const key = {
607
605
  remoteJid,
608
606
  id: '',
@@ -722,15 +720,8 @@ const makeMessagesRecvSocket = (config) => {
722
720
  await sendMessageAck(node);
723
721
  return;
724
722
  }
725
- const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
726
- // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
727
- if (encNode && encNode.attrs.type === 'msmsg') {
728
- logger.debug({ key: node.attrs.key }, 'ignored msmsg');
729
- await sendMessageAck(node);
730
- return;
731
- }
732
723
  let response;
733
- if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
724
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !(0, WABinary_1.getBinaryNodeChild)(node, 'enc')) {
734
725
  await sendMessageAck(node);
735
726
  const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
736
727
  response = await requestPlaceholderResend(key);
@@ -744,12 +735,14 @@ const makeMessagesRecvSocket = (config) => {
744
735
  placeholderResendCache.del(node.attrs.id);
745
736
  }
746
737
  }
747
- const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger, getMessage);
738
+ const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
748
739
  if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
749
740
  msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
750
741
  }
751
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
752
- ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
742
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
743
+ if (node.attrs.sender_pn) {
744
+ ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
745
+ }
753
746
  }
754
747
  try {
755
748
  await Promise.all([