@queenanya/baileys 6.9.5 → 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 (53) hide show
  1. package/README.md +56 -13
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.js +4 -1
  4. package/lib/Socket/business.d.ts +46 -9
  5. package/lib/Socket/chats.d.ts +10 -2
  6. package/lib/Socket/chats.js +40 -1
  7. package/lib/Socket/groups.d.ts +17 -3
  8. package/lib/Socket/groups.js +12 -1
  9. package/lib/Socket/index.d.ts +46 -9
  10. package/lib/Socket/messages-recv.d.ts +45 -9
  11. package/lib/Socket/messages-recv.js +166 -15
  12. package/lib/Socket/messages-send.d.ts +39 -5
  13. package/lib/Socket/messages-send.js +153 -37
  14. package/lib/Socket/newsletter.d.ts +140 -0
  15. package/lib/Socket/newsletter.js +249 -0
  16. package/lib/Socket/registration.d.ts +46 -12
  17. package/lib/Socket/socket.js +4 -3
  18. package/lib/Store/make-in-memory-store.js +5 -1
  19. package/lib/Types/Chat.d.ts +5 -0
  20. package/lib/Types/Events.d.ts +32 -1
  21. package/lib/Types/GroupMetadata.d.ts +1 -1
  22. package/lib/Types/Label.d.ts +11 -0
  23. package/lib/Types/Message.d.ts +39 -27
  24. package/lib/Types/Newsletter.d.ts +79 -0
  25. package/lib/Types/Newsletter.js +18 -0
  26. package/lib/Types/Socket.d.ts +7 -0
  27. package/lib/Types/index.d.ts +9 -0
  28. package/lib/Types/index.js +1 -0
  29. package/lib/Utils/chat-utils.js +16 -0
  30. package/lib/Utils/crypto.d.ts +1 -1
  31. package/lib/Utils/crypto.js +4 -2
  32. package/lib/Utils/decode-wa-message.d.ts +1 -0
  33. package/lib/Utils/decode-wa-message.js +50 -22
  34. package/lib/Utils/generics.d.ts +30 -10
  35. package/lib/Utils/generics.js +82 -10
  36. package/lib/Utils/history.d.ts +4 -0
  37. package/lib/Utils/history.js +3 -0
  38. package/lib/Utils/logger.d.ts +1 -3
  39. package/lib/Utils/messages-media.d.ts +10 -1
  40. package/lib/Utils/messages-media.js +61 -18
  41. package/lib/Utils/messages.js +72 -69
  42. package/lib/Utils/noise-handler.d.ts +1 -1
  43. package/lib/Utils/noise-handler.js +2 -2
  44. package/lib/Utils/process-message.d.ts +3 -2
  45. package/lib/Utils/process-message.js +47 -24
  46. package/lib/Utils/signal.js +21 -16
  47. package/lib/WABinary/decode.d.ts +2 -2
  48. package/lib/WABinary/decode.js +6 -4
  49. package/lib/WABinary/encode.d.ts +1 -2
  50. package/lib/WABinary/encode.js +1 -1
  51. package/lib/WABinary/jid-utils.d.ts +3 -1
  52. package/lib/WABinary/jid-utils.js +4 -1
  53. package/package.json +31 -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,10 +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>;
7
- logger: import("pino").Logger<import("pino").LoggerOptions>;
8
+ logger: import("pino").Logger<never>;
8
9
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
9
10
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
10
11
  products: import("../Types").Product[];
@@ -21,28 +22,53 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
21
22
  sendMessageAck: ({ tag, attrs, content }: import("../WABinary").BinaryNode) => Promise<void>;
22
23
  sendRetryRequest: (node: import("../WABinary").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
23
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>;
24
27
  getPrivacyTokens: (jids: string[]) => Promise<import("../WABinary").BinaryNode>;
25
28
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
26
- 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>;
27
30
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
28
- sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
29
- getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
30
- [key: string]: string;
31
- };
32
- 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>;
33
33
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
34
34
  waUploadToServer: import("../Types").WAMediaUploadFunction;
35
35
  fetchPrivacySettings: (force?: boolean) => Promise<{
36
36
  [_: string]: string;
37
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[]>;
38
46
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
39
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[]>;
40
69
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
41
70
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
42
71
  groupLeave: (id: string) => Promise<void>;
43
- /** the network code of your mobile network
44
- * @see {@link https://de.wikipedia.org/wiki/Mobile_Network_Code}
45
- */
46
72
  groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
47
73
  groupRequestParticipantsList: (jid: string) => Promise<{
48
74
  [key: string]: string;
@@ -60,7 +86,8 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
60
86
  groupInviteCode: (jid: string) => Promise<string | undefined>;
61
87
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
62
88
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
63
- 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>;
64
91
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
65
92
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
66
93
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -82,6 +109,11 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
82
109
  jid: string;
83
110
  }[]>;
84
111
  fetchBlocklist: () => Promise<string[]>;
112
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
113
+ user: string;
114
+ duration: number;
115
+ setAt: Date;
116
+ }[]>;
85
117
  fetchStatus: (jid: string) => Promise<{
86
118
  status: string | undefined;
87
119
  setAt: Date;
@@ -91,17 +123,19 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
91
123
  updateProfileStatus: (status: string) => Promise<void>;
92
124
  updateProfileName: (name: string) => Promise<void>;
93
125
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
126
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
94
127
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
95
128
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
96
129
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
97
130
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
98
131
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
99
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
132
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
100
133
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
101
134
  getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
102
135
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
103
136
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
104
137
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
138
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
105
139
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
106
140
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
107
141
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -74,7 +74,8 @@ const makeSocket = (config) => {
74
74
  if (logger.level === 'trace') {
75
75
  logger.trace({ xml: (0, WABinary_1.binaryNodeToString)(frame), msg: 'xml send' });
76
76
  }
77
- const buff = (0, WABinary_1.encodeBinaryNode)(frame);
77
+ const node = (0, WABinary_1.encodeBinaryNode)(frame);
78
+ const buff = Buffer.from(node);
78
79
  return sendRawMessage(buff);
79
80
  };
80
81
  /** log & process any unexpected errors */
@@ -403,7 +404,7 @@ const makeSocket = (config) => {
403
404
  {
404
405
  tag: 'companion_platform_id',
405
406
  attrs: {},
406
- content: '49' // Chrome
407
+ content: (0, Utils_1.getPlatformId)(browser[1])
407
408
  },
408
409
  {
409
410
  tag: 'companion_platform_display',
@@ -424,7 +425,7 @@ const makeSocket = (config) => {
424
425
  async function generatePairingKey() {
425
426
  const salt = (0, crypto_1.randomBytes)(32);
426
427
  const randomIv = (0, crypto_1.randomBytes)(16);
427
- const key = (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
428
+ const key = await (0, Utils_1.derivePairingCodeKey)(authState.creds.pairingCode, salt);
428
429
  const ciphered = (0, Utils_1.aesEncryptCTR)(authState.creds.pairingEphemeralKeyPair.public, key, randomIv);
429
430
  return Buffer.concat([salt, randomIv, ciphered]);
430
431
  }
@@ -66,7 +66,11 @@ exports.default = (config) => {
66
66
  ev.on('connection.update', update => {
67
67
  Object.assign(state, update);
68
68
  });
69
- 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
+ }
70
74
  if (isLatest) {
71
75
  chats.clear();
72
76
  for (const id in messages) {
@@ -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
  } | {
@@ -9,6 +9,7 @@ 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': {
@@ -85,6 +90,32 @@ export type BaileysEventMap = {
85
90
  action: RequestJoinAction;
86
91
  method: RequestJoinMethod;
87
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
+ };
88
119
  'blocklist.set': {
89
120
  blocklist: string[];
90
121
  };
@@ -4,7 +4,7 @@ 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
8
  export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
9
9
  export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
10
10
  export interface GroupMetadata {
@@ -10,6 +10,17 @@ export interface Label {
10
10
  /** WhatsApp has 5 predefined labels (New customer, New order & etc) */
11
11
  predefinedId?: string;
12
12
  }
13
+ export interface LabelActionBody {
14
+ id: string;
15
+ /** Label name */
16
+ name?: string;
17
+ /** Label color ID */
18
+ color?: number;
19
+ /** Is label has been deleted */
20
+ deleted?: boolean;
21
+ /** WhatsApp has 5 predefined labels (New customer, New order & etc) */
22
+ predefinedId?: number;
23
+ }
13
24
  /** WhatsApp has 20 predefined colors */
14
25
  export declare enum LabelColor {
15
26
  Color1 = 0,