@queenanya/baileys 6.9.2 → 7.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 (59) hide show
  1. package/README.md +56 -13
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.js +5 -2
  4. package/lib/Socket/business.d.ts +46 -8
  5. package/lib/Socket/business.js +1 -0
  6. package/lib/Socket/chats.d.ts +10 -2
  7. package/lib/Socket/chats.js +42 -3
  8. package/lib/Socket/groups.d.ts +17 -3
  9. package/lib/Socket/groups.js +12 -1
  10. package/lib/Socket/index.d.ts +46 -8
  11. package/lib/Socket/messages-recv.d.ts +45 -9
  12. package/lib/Socket/messages-recv.js +184 -22
  13. package/lib/Socket/messages-send.d.ts +40 -6
  14. package/lib/Socket/messages-send.js +153 -37
  15. package/lib/Socket/newsletter.d.ts +140 -0
  16. package/lib/Socket/newsletter.js +249 -0
  17. package/lib/Socket/registration.d.ts +46 -11
  18. package/lib/Socket/socket.js +18 -4
  19. package/lib/Store/make-in-memory-store.d.ts +2 -2
  20. package/lib/Store/make-in-memory-store.js +11 -44
  21. package/lib/Types/Auth.d.ts +1 -0
  22. package/lib/Types/Chat.d.ts +5 -0
  23. package/lib/Types/Events.d.ts +40 -2
  24. package/lib/Types/GroupMetadata.d.ts +3 -1
  25. package/lib/Types/Label.d.ts +11 -0
  26. package/lib/Types/Message.d.ts +39 -27
  27. package/lib/Types/Newsletter.d.ts +79 -0
  28. package/lib/Types/Newsletter.js +18 -0
  29. package/lib/Types/Socket.d.ts +7 -0
  30. package/lib/Types/index.d.ts +9 -0
  31. package/lib/Types/index.js +1 -0
  32. package/lib/Utils/auth-utils.js +1 -0
  33. package/lib/Utils/chat-utils.js +16 -0
  34. package/lib/Utils/crypto.d.ts +1 -1
  35. package/lib/Utils/crypto.js +4 -2
  36. package/lib/Utils/decode-wa-message.d.ts +1 -0
  37. package/lib/Utils/decode-wa-message.js +50 -22
  38. package/lib/Utils/generics.d.ts +30 -10
  39. package/lib/Utils/generics.js +82 -10
  40. package/lib/Utils/history.d.ts +4 -0
  41. package/lib/Utils/history.js +3 -0
  42. package/lib/Utils/logger.d.ts +1 -3
  43. package/lib/Utils/messages-media.d.ts +10 -1
  44. package/lib/Utils/messages-media.js +61 -18
  45. package/lib/Utils/messages.d.ts +2 -1
  46. package/lib/Utils/messages.js +77 -76
  47. package/lib/Utils/noise-handler.d.ts +3 -2
  48. package/lib/Utils/noise-handler.js +18 -5
  49. package/lib/Utils/process-message.d.ts +3 -2
  50. package/lib/Utils/process-message.js +53 -21
  51. package/lib/Utils/signal.js +21 -16
  52. package/lib/Utils/use-multi-file-auth-state.js +16 -3
  53. package/lib/WABinary/decode.d.ts +2 -2
  54. package/lib/WABinary/decode.js +6 -4
  55. package/lib/WABinary/encode.d.ts +1 -2
  56. package/lib/WABinary/encode.js +1 -1
  57. package/lib/WABinary/jid-utils.d.ts +3 -1
  58. package/lib/WABinary/jid-utils.js +4 -1
  59. package/package.json +32 -27
@@ -0,0 +1,249 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
4
+ const Types_1 = require("../Types");
5
+ const Utils_1 = require("../Utils");
6
+ const WABinary_1 = require("../WABinary");
7
+ const groups_1 = require("./groups");
8
+ var QueryIds;
9
+ (function (QueryIds) {
10
+ QueryIds["JOB_MUTATION"] = "7150902998257522";
11
+ QueryIds["METADATA"] = "6620195908089573";
12
+ QueryIds["UNFOLLOW"] = "7238632346214362";
13
+ QueryIds["FOLLOW"] = "7871414976211147";
14
+ QueryIds["UNMUTE"] = "7337137176362961";
15
+ QueryIds["MUTE"] = "25151904754424642";
16
+ QueryIds["CREATE"] = "6996806640408138";
17
+ QueryIds["ADMIN_COUNT"] = "7130823597031706";
18
+ QueryIds["CHANGE_OWNER"] = "7341777602580933";
19
+ QueryIds["DELETE"] = "8316537688363079";
20
+ QueryIds["DEMOTE"] = "6551828931592903";
21
+ })(QueryIds || (QueryIds = {}));
22
+ const makeNewsletterSocket = (config) => {
23
+ const sock = (0, groups_1.makeGroupsSocket)(config);
24
+ const { authState, signalRepository, query, generateMessageTag } = sock;
25
+ const encoder = new TextEncoder();
26
+ const newsletterQuery = async (jid, type, content) => (query({
27
+ tag: 'iq',
28
+ attrs: {
29
+ id: generateMessageTag(),
30
+ type,
31
+ xmlns: 'newsletter',
32
+ to: jid,
33
+ },
34
+ content
35
+ }));
36
+ const newsletterWMexQuery = async (jid, query_id, content) => (query({
37
+ tag: 'iq',
38
+ attrs: {
39
+ id: generateMessageTag(),
40
+ type: 'get',
41
+ xmlns: 'w:mex',
42
+ to: WABinary_1.S_WHATSAPP_NET,
43
+ },
44
+ content: [
45
+ {
46
+ tag: 'query',
47
+ attrs: { query_id },
48
+ content: encoder.encode(JSON.stringify({ variables: { newsletter_id: jid, ...content } }))
49
+ }
50
+ ]
51
+ }));
52
+ const parseFetchedUpdates = async (node, type) => {
53
+ let child;
54
+ if (type === 'messages')
55
+ child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
56
+ else {
57
+ const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
58
+ child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
59
+ }
60
+ return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
61
+ var _a, _b;
62
+ messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
63
+ const views = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count;
64
+ const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
65
+ const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
66
+ .map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
67
+ let data;
68
+ if (type === 'messages') {
69
+ const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
70
+ await decrypt();
71
+ data = {
72
+ server_id: messageNode.attrs.server_id,
73
+ views: views ? +views : undefined,
74
+ reactions,
75
+ message
76
+ };
77
+ return data;
78
+ }
79
+ else {
80
+ data = {
81
+ server_id: messageNode.attrs.server_id,
82
+ views: views ? +views : undefined,
83
+ reactions
84
+ };
85
+ return data;
86
+ }
87
+ }));
88
+ };
89
+ return {
90
+ ...sock,
91
+ subscribeNewsletterUpdates: async (jid) => {
92
+ var _a;
93
+ const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
94
+ return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
95
+ },
96
+ newsletterReactionMode: async (jid, mode) => {
97
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
98
+ updates: { settings: { reaction_codes: { value: mode } } }
99
+ });
100
+ },
101
+ newsletterUpdateDescription: async (jid, description) => {
102
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
103
+ updates: { description: description || '', settings: null }
104
+ });
105
+ },
106
+ newsletterUpdateName: async (jid, name) => {
107
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
108
+ updates: { name, settings: null }
109
+ });
110
+ },
111
+ newsletterUpdatePicture: async (jid, content) => {
112
+ const { img } = await (0, Utils_1.generateProfilePicture)(content);
113
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
114
+ updates: { picture: img.toString('base64'), settings: null }
115
+ });
116
+ },
117
+ newsletterRemovePicture: async (jid) => {
118
+ await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
119
+ updates: { picture: '', settings: null }
120
+ });
121
+ },
122
+ newsletterUnfollow: async (jid) => {
123
+ await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
124
+ },
125
+ newsletterFollow: async (jid) => {
126
+ await newsletterWMexQuery(jid, QueryIds.FOLLOW);
127
+ },
128
+ newsletterUnmute: async (jid) => {
129
+ await newsletterWMexQuery(jid, QueryIds.UNMUTE);
130
+ },
131
+ newsletterMute: async (jid) => {
132
+ await newsletterWMexQuery(jid, QueryIds.MUTE);
133
+ },
134
+ newsletterCreate: async (name, description) => {
135
+ /**tos query */
136
+ await query({
137
+ tag: 'iq',
138
+ attrs: {
139
+ to: WABinary_1.S_WHATSAPP_NET,
140
+ xmlns: 'tos',
141
+ id: generateMessageTag(),
142
+ type: 'set'
143
+ },
144
+ content: [
145
+ {
146
+ tag: 'notice',
147
+ attrs: {
148
+ id: '20601218',
149
+ stage: '5'
150
+ },
151
+ content: []
152
+ }
153
+ ]
154
+ });
155
+ const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
156
+ input: { name, description }
157
+ });
158
+ return (0, exports.extractNewsletterMetadata)(result, true);
159
+ },
160
+ newsletterMetadata: async (type, key, role) => {
161
+ const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
162
+ input: {
163
+ key,
164
+ type: type.toUpperCase(),
165
+ view_role: role || 'GUEST'
166
+ },
167
+ fetch_viewer_metadata: true,
168
+ fetch_full_image: true,
169
+ fetch_creation_time: true
170
+ });
171
+ return (0, exports.extractNewsletterMetadata)(result);
172
+ },
173
+ newsletterAdminCount: async (jid) => {
174
+ var _a, _b;
175
+ const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
176
+ const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
177
+ return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
178
+ },
179
+ /**user is Lid, not Jid */
180
+ newsletterChangeOwner: async (jid, user) => {
181
+ await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
182
+ user_id: user
183
+ });
184
+ },
185
+ /**user is Lid, not Jid */
186
+ newsletterDemote: async (jid, user) => {
187
+ await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
188
+ user_id: user
189
+ });
190
+ },
191
+ newsletterDelete: async (jid) => {
192
+ await newsletterWMexQuery(jid, QueryIds.DELETE);
193
+ },
194
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
195
+ newsletterReactMessage: async (jid, server_id, code) => {
196
+ await query({
197
+ tag: 'message',
198
+ attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
199
+ content: [{
200
+ tag: 'reaction',
201
+ attrs: code ? { code } : {}
202
+ }]
203
+ });
204
+ },
205
+ newsletterFetchMessages: async (type, key, count, after) => {
206
+ const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
207
+ {
208
+ tag: 'messages',
209
+ attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
210
+ }
211
+ ]);
212
+ return await parseFetchedUpdates(result, 'messages');
213
+ },
214
+ newsletterFetchUpdates: async (jid, count, after, since) => {
215
+ const result = await newsletterQuery(jid, 'get', [
216
+ {
217
+ tag: 'message_updates',
218
+ attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
219
+ }
220
+ ]);
221
+ return await parseFetchedUpdates(result, 'updates');
222
+ }
223
+ };
224
+ };
225
+ exports.makeNewsletterSocket = makeNewsletterSocket;
226
+ const extractNewsletterMetadata = (node, isCreate) => {
227
+ var _a, _b, _c, _d, _e;
228
+ const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
229
+ const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
230
+ const metadata = {
231
+ id: metadataPath.id,
232
+ state: metadataPath.state.type,
233
+ creation_time: +metadataPath.thread_metadata.creation_time,
234
+ name: metadataPath.thread_metadata.name.text,
235
+ nameTime: +metadataPath.thread_metadata.name.update_time,
236
+ description: metadataPath.thread_metadata.description.text,
237
+ descriptionTime: +metadataPath.thread_metadata.description.update_time,
238
+ invite: metadataPath.thread_metadata.invite,
239
+ handle: metadataPath.thread_metadata.handle,
240
+ picture: metadataPath.thread_metadata.picture.direct_path || null,
241
+ preview: metadataPath.thread_metadata.preview.direct_path || null,
242
+ reaction_codes: (_e = (_d = (_c = metadataPath.thread_metadata) === null || _c === void 0 ? void 0 : _c.settings) === null || _d === void 0 ? void 0 : _d.reaction_codes) === null || _e === void 0 ? void 0 : _e.value,
243
+ subscribers: +metadataPath.thread_metadata.subscribers_count,
244
+ verification: metadataPath.thread_metadata.verification,
245
+ viewer_metadata: metadataPath.viewer_metadata
246
+ };
247
+ return metadata;
248
+ };
249
+ exports.extractNewsletterMetadata = extractNewsletterMetadata;
@@ -1,9 +1,11 @@
1
+ /// <reference types="long" />
1
2
  /// <reference types="node" />
2
3
  import { AxiosRequestConfig } from 'axios';
3
4
  import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
4
5
  export declare const makeRegistrationSocket: (config: SocketConfig) => {
5
6
  register: (code: string) => Promise<ExistsResponse>;
6
7
  requestRegistrationCode: (registrationOptions?: RegistrationOptions) => Promise<ExistsResponse>;
8
+ logger: import("pino").Logger<never>;
7
9
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
8
10
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
9
11
  products: import("../Types").Product[];
@@ -20,28 +22,53 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
20
22
  sendMessageAck: ({ tag, attrs, content }: import("../WABinary").BinaryNode) => Promise<void>;
21
23
  sendRetryRequest: (node: import("../WABinary").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
22
24
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
25
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
26
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
23
27
  getPrivacyTokens: (jids: string[]) => Promise<import("../WABinary").BinaryNode>;
24
28
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
25
- relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
29
+ relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
26
30
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
27
- sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
28
- getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
29
- [key: string]: string;
30
- };
31
- readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
31
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
32
+ readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
32
33
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
33
34
  waUploadToServer: import("../Types").WAMediaUploadFunction;
34
35
  fetchPrivacySettings: (force?: boolean) => Promise<{
35
36
  [_: string]: string;
36
37
  }>;
38
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
39
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
40
+ [key: string]: string;
41
+ } | undefined) => Promise<{
42
+ nodes: import("../WABinary").BinaryNode[];
43
+ shouldIncludeDeviceIdentity: boolean;
44
+ }>;
45
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
37
46
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
38
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 | undefined) => 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) => Promise<import("../Types").NewsletterMetadata>;
61
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => 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 | undefined) => Promise<void>;
67
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
68
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
39
69
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
40
70
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
41
71
  groupLeave: (id: string) => Promise<void>;
42
- /** the network code of your mobile network
43
- * @see {@link https://de.wikipedia.org/wiki/Mobile_Network_Code}
44
- */
45
72
  groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
46
73
  groupRequestParticipantsList: (jid: string) => Promise<{
47
74
  [key: string]: string;
@@ -59,7 +86,8 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
59
86
  groupInviteCode: (jid: string) => Promise<string | undefined>;
60
87
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
61
88
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
62
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
89
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
90
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
63
91
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
64
92
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
65
93
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -81,6 +109,11 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
81
109
  jid: string;
82
110
  }[]>;
83
111
  fetchBlocklist: () => Promise<string[]>;
112
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
113
+ user: string;
114
+ duration: number;
115
+ setAt: Date;
116
+ }[]>;
84
117
  fetchStatus: (jid: string) => Promise<{
85
118
  status: string | undefined;
86
119
  setAt: Date;
@@ -90,17 +123,19 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
90
123
  updateProfileStatus: (status: string) => Promise<void>;
91
124
  updateProfileName: (name: string) => Promise<void>;
92
125
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
126
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
93
127
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
94
128
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
95
129
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
96
130
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
97
131
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
98
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
132
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
99
133
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
100
134
  getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
101
135
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
102
136
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
103
137
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
138
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
104
139
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
105
140
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
106
141
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -18,12 +18,16 @@ const Client_1 = require("./Client");
18
18
  * - query phone connection
19
19
  */
20
20
  const makeSocket = (config) => {
21
+ var _a, _b;
21
22
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
22
23
  let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
23
24
  config.mobile = config.mobile || url.protocol === 'tcp:';
24
25
  if (config.mobile && url.protocol !== 'tcp:') {
25
26
  url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
26
27
  }
28
+ if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
+ url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
30
+ }
27
31
  const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
28
32
  ws.connect();
29
33
  const ev = (0, Utils_1.makeEventBuffer)(logger);
@@ -34,7 +38,8 @@ const makeSocket = (config) => {
34
38
  keyPair: ephemeralKeyPair,
35
39
  NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
36
40
  mobile: config.mobile,
37
- logger
41
+ logger,
42
+ routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
38
43
  });
39
44
  const { creds } = authState;
40
45
  // add transaction capability
@@ -69,7 +74,8 @@ const makeSocket = (config) => {
69
74
  if (logger.level === 'trace') {
70
75
  logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
71
76
  }
72
- const buff = (0, WABinary_1.encodeBinaryNode)(frame);
77
+ const node = (0, WABinary_1.encodeBinaryNode)(frame);
78
+ const buff = Buffer.from(node);
73
79
  return sendRawMessage(buff);
74
80
  };
75
81
  /** log & process any unexpected errors */
@@ -398,7 +404,7 @@ const makeSocket = (config) => {
398
404
  {
399
405
  tag: 'companion_platform_id',
400
406
  attrs: {},
401
- content: '49' // Chrome
407
+ content: (0, Utils_1.getPlatformId)(browser[1])
402
408
  },
403
409
  {
404
410
  tag: 'companion_platform_display',
@@ -419,7 +425,7 @@ const makeSocket = (config) => {
419
425
  async function generatePairingKey() {
420
426
  const salt = (0, crypto_1.randomBytes)(32);
421
427
  const randomIv = (0, crypto_1.randomBytes)(16);
422
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
428
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
423
429
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
424
430
  return Buffer.concat([salt, randomIv, ciphered]);
425
431
  }
@@ -526,6 +532,14 @@ const makeSocket = (config) => {
526
532
  ws.on('CB:ib,,downgrade_webclient', () => {
527
533
  end(new boom_1.Boom('Multi-device beta not joined', { statusCode: Types_1.DisconnectReason.multideviceMismatch }));
528
534
  });
535
+ ws.on('CB:ib,,edge_routing', (node) => {
536
+ const edgeRoutingNode = (0, WABinary_1.getBinaryNodeChild)(node, 'edge_routing');
537
+ const routingInfo = (0, WABinary_1.getBinaryNodeChild)(edgeRoutingNode, 'routing_info');
538
+ if (routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content) {
539
+ authState.creds.routingInfo = Buffer.from(routingInfo === null || routingInfo === void 0 ? void 0 : routingInfo.content);
540
+ ev.emit('creds.update', authState.creds);
541
+ }
542
+ });
529
543
  let didStartBuffer = false;
530
544
  process.nextTick(() => {
531
545
  var _a;
@@ -17,10 +17,10 @@ export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>
17
17
  export type BaileysInMemoryStoreConfig = {
18
18
  chatKey?: Comparable<Chat, string>;
19
19
  labelAssociationKey?: Comparable<LabelAssociation, string>;
20
- logger: Logger;
20
+ logger?: Logger;
21
21
  socket?: WASocket;
22
22
  };
23
- declare const _default: ({ logger, chatKey, labelAssociationKey, socket }: BaileysInMemoryStoreConfig) => {
23
+ declare const _default: (config: BaileysInMemoryStoreConfig) => {
24
24
  chats: KeyedDB<Chat, string>;
25
25
  contacts: {
26
26
  [_: string]: Contact;
@@ -23,48 +23,11 @@ exports.waLabelAssociationKey = {
23
23
  compare: (k1, k2) => k2.localeCompare(k1)
24
24
  };
25
25
  const makeMessagesDictionary = () => (0, make_ordered_dictionary_1.default)(exports.waMessageID);
26
- const predefinedLabels = Object.freeze({
27
- '1': {
28
- id: '1',
29
- name: 'New customer',
30
- predefinedId: '1',
31
- color: 1,
32
- deleted: false
33
- },
34
- '2': {
35
- id: '2',
36
- name: 'New order',
37
- predefinedId: '2',
38
- color: 2,
39
- deleted: false
40
- },
41
- '3': {
42
- id: '3',
43
- name: 'Pending payment',
44
- predefinedId: '3',
45
- color: 3,
46
- deleted: false
47
- },
48
- '4': {
49
- id: '4',
50
- name: 'Paid',
51
- predefinedId: '4',
52
- color: 4,
53
- deleted: false
54
- },
55
- '5': {
56
- id: '5',
57
- name: 'Order completed',
58
- predefinedId: '5',
59
- color: 5,
60
- deleted: false
61
- }
62
- });
63
- exports.default = ({ logger, chatKey, labelAssociationKey, socket }) => {
64
- // const logger = _logger || DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' })
65
- chatKey = chatKey || (0, exports.waChatKey)(true);
66
- labelAssociationKey = labelAssociationKey || exports.waLabelAssociationKey;
67
- logger = logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
26
+ exports.default = (config) => {
27
+ const socket = config.socket;
28
+ const chatKey = config.chatKey || (0, exports.waChatKey)(true);
29
+ const labelAssociationKey = config.labelAssociationKey || exports.waLabelAssociationKey;
30
+ const logger = config.logger || Defaults_1.DEFAULT_CONNECTION_CONFIG.logger.child({ stream: 'in-mem-store' });
68
31
  const KeyedDB = require('@adiwajshing/keyed-db').default;
69
32
  const chats = new KeyedDB(chatKey, c => c.id);
70
33
  const messages = {};
@@ -72,7 +35,7 @@ exports.default = ({ logger, chatKey, labelAssociationKey, socket }) => {
72
35
  const groupMetadata = {};
73
36
  const presences = {};
74
37
  const state = { connection: 'close' };
75
- const labels = new object_repository_1.ObjectRepository(predefinedLabels);
38
+ const labels = new object_repository_1.ObjectRepository();
76
39
  const labelAssociations = new KeyedDB(labelAssociationKey, labelAssociationKey.key);
77
40
  const assertMessageList = (jid) => {
78
41
  if (!messages[jid]) {
@@ -103,7 +66,11 @@ exports.default = ({ logger, chatKey, labelAssociationKey, socket }) => {
103
66
  ev.on('connection.update', update => {
104
67
  Object.assign(state, update);
105
68
  });
106
- ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest }) => {
69
+ ev.on('messaging-history.set', ({ chats: newChats, contacts: newContacts, messages: newMessages, isLatest, syncType }) => {
70
+ if (syncType === WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
71
+ return; // FOR NOW,
72
+ //TODO: HANDLE
73
+ }
107
74
  if (isLatest) {
108
75
  chats.clear();
109
76
  for (const id in messages) {
@@ -65,6 +65,7 @@ export type AuthenticationCreds = SignalCreds & {
65
65
  registration: RegistrationOptions;
66
66
  pairingCode: string | undefined;
67
67
  lastPropHash: string | undefined;
68
+ routingInfo: Buffer | undefined;
68
69
  };
69
70
  export type SignalDataTypeMap = {
70
71
  'pre-key': KeyPair;
@@ -4,10 +4,13 @@ import type { BufferedEventData } from './Events';
4
4
  import type { ChatLabelAssociationActionBody } from './LabelAssociation';
5
5
  import type { MessageLabelAssociationActionBody } from './LabelAssociation';
6
6
  import type { MinimalMessage } from './Message';
7
+ import type { LabelActionBody } from './Label';
7
8
  /** privacy settings in WhatsApp Web */
8
9
  export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
9
10
  export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
11
+ export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
10
12
  export type WAReadReceiptsValue = 'all' | 'none';
13
+ export type WAPrivacyCallValue = 'all' | 'known';
11
14
  /** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
12
15
  export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
13
16
  export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
@@ -80,6 +83,8 @@ export type ChatModification = {
80
83
  } | {
81
84
  delete: true;
82
85
  lastMessages: LastMessageList;
86
+ } | {
87
+ addLabel: LabelActionBody;
83
88
  } | {
84
89
  addChatLabel: ChatLabelAssociationActionBody;
85
90
  } | {
@@ -4,11 +4,12 @@ import { AuthenticationCreds } from './Auth';
4
4
  import { WACallEvent } from './Call';
5
5
  import { Chat, ChatUpdate, PresenceData } from './Chat';
6
6
  import { Contact } from './Contact';
7
- import { GroupMetadata, ParticipantAction } from './GroupMetadata';
7
+ import { GroupMetadata, ParticipantAction, RequestJoinAction, RequestJoinMethod } from './GroupMetadata';
8
8
  import { Label } from './Label';
9
9
  import { LabelAssociation } from './LabelAssociation';
10
10
  import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
11
11
  import { ConnectionState } from './State';
12
+ import { NewsletterSettingsUpdate, SubscriberAction, NewsletterViewRole } from './Newsletter';
12
13
  export type BaileysEventMap = {
13
14
  /** connection state has been updated -- WS closed, opened, connecting etc. */
14
15
  'connection.update': Partial<ConnectionState>;
@@ -19,7 +20,9 @@ export type BaileysEventMap = {
19
20
  chats: Chat[];
20
21
  contacts: Contact[];
21
22
  messages: WAMessage[];
22
- isLatest: boolean;
23
+ isLatest?: boolean;
24
+ progress?: number | null;
25
+ syncType?: proto.HistorySync.HistorySyncType;
23
26
  };
24
27
  /** upsert chats */
25
28
  'chats.upsert': Chat[];
@@ -58,10 +61,12 @@ export type BaileysEventMap = {
58
61
  /**
59
62
  * add/update the given messages. If they were received while the connection was online,
60
63
  * the update will have type: "notify"
64
+ * if requestId is provided, then the messages was received from the phone due to it being unavailable
61
65
  * */
62
66
  'messages.upsert': {
63
67
  messages: WAMessage[];
64
68
  type: MessageUpsertType;
69
+ requestId?: string;
65
70
  };
66
71
  /** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
67
72
  'messages.reaction': {
@@ -78,6 +83,39 @@ export type BaileysEventMap = {
78
83
  participants: string[];
79
84
  action: ParticipantAction;
80
85
  };
86
+ 'group.join-request': {
87
+ id: string;
88
+ author: string;
89
+ participant: string;
90
+ action: RequestJoinAction;
91
+ method: RequestJoinMethod;
92
+ };
93
+ 'newsletter.reaction': {
94
+ id: string;
95
+ server_id: string;
96
+ reaction: {
97
+ code?: string;
98
+ count?: number;
99
+ removed?: boolean;
100
+ };
101
+ };
102
+ 'newsletter.view': {
103
+ id: string;
104
+ server_id: string;
105
+ count: number;
106
+ };
107
+ /**don't handles subscribe/unsubscribe actions */
108
+ 'newsletter-participants.update': {
109
+ id: string;
110
+ author: string;
111
+ user: string;
112
+ new_role: NewsletterViewRole;
113
+ action: SubscriberAction;
114
+ };
115
+ 'newsletter-settings.update': {
116
+ id: string;
117
+ update: NewsletterSettingsUpdate;
118
+ };
81
119
  'blocklist.set': {
82
120
  blocklist: string[];
83
121
  };
@@ -4,7 +4,9 @@ export type GroupParticipant = (Contact & {
4
4
  isSuperAdmin?: boolean;
5
5
  admin?: 'admin' | 'superadmin' | null;
6
6
  });
7
- export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote';
7
+ export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify';
8
+ export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
9
+ export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
8
10
  export interface GroupMetadata {
9
11
  id: string;
10
12
  owner: string | undefined;