gifted-baileys 1.5.0 → 1.5.4

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 (120) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1429 -684
  3. package/WAProto/WAProto.proto +969 -88
  4. package/WAProto/index.d.ts +13199 -1260
  5. package/WAProto/index.js +124901 -74525
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +2 -2
  8. package/lib/Defaults/index.js +6 -5
  9. package/lib/Defaults/phonenumber-mcc.json +221 -221
  10. package/lib/Signal/libsignal.js +18 -9
  11. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -2
  12. package/lib/Socket/Client/index.d.ts +2 -3
  13. package/lib/Socket/Client/index.js +2 -3
  14. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -1
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  18. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  19. package/lib/Socket/business.d.ts +64 -29
  20. package/lib/Socket/business.js +1 -0
  21. package/lib/Socket/chats.d.ts +10 -8
  22. package/lib/Socket/chats.js +114 -97
  23. package/lib/Socket/groups.d.ts +10 -8
  24. package/lib/Socket/groups.js +4 -2
  25. package/lib/Socket/index.d.ts +70 -35
  26. package/lib/Socket/messages-recv.d.ts +63 -29
  27. package/lib/Socket/messages-recv.js +374 -155
  28. package/lib/Socket/messages-send.d.ts +48 -12
  29. package/lib/Socket/messages-send.js +445 -87
  30. package/lib/Socket/newsletter.d.ts +132 -0
  31. package/lib/Socket/newsletter.js +236 -0
  32. package/lib/Socket/registration.d.ts +73 -41
  33. package/lib/Socket/registration.js +7 -7
  34. package/lib/Socket/socket.d.ts +2 -0
  35. package/lib/Socket/socket.js +56 -15
  36. package/lib/Socket/usync.d.ts +37 -0
  37. package/lib/Socket/usync.js +70 -0
  38. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  39. package/lib/Store/make-in-memory-store.d.ts +2 -1
  40. package/lib/Store/make-in-memory-store.js +40 -46
  41. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  42. package/lib/Types/Auth.d.ts +2 -1
  43. package/lib/Types/Call.d.ts +1 -1
  44. package/lib/Types/Chat.d.ts +12 -7
  45. package/lib/Types/Events.d.ts +17 -2
  46. package/lib/Types/GroupMetadata.d.ts +6 -2
  47. package/lib/Types/Label.d.ts +11 -0
  48. package/lib/Types/Label.js +1 -1
  49. package/lib/Types/LabelAssociation.js +1 -1
  50. package/lib/Types/Message.d.ts +184 -12
  51. package/lib/Types/Newsletter.d.ts +92 -0
  52. package/lib/Types/Newsletter.js +32 -0
  53. package/lib/Types/Socket.d.ts +7 -2
  54. package/lib/Types/USync.d.ts +25 -0
  55. package/lib/Types/USync.js +2 -0
  56. package/lib/Types/index.d.ts +10 -0
  57. package/lib/Types/index.js +2 -1
  58. package/lib/Utils/auth-utils.js +5 -3
  59. package/lib/Utils/business.d.ts +1 -1
  60. package/lib/Utils/business.js +2 -2
  61. package/lib/Utils/chat-utils.d.ts +11 -12
  62. package/lib/Utils/chat-utils.js +41 -20
  63. package/lib/Utils/crypto.d.ts +15 -16
  64. package/lib/Utils/crypto.js +35 -23
  65. package/lib/Utils/decode-wa-message.d.ts +17 -0
  66. package/lib/Utils/decode-wa-message.js +65 -13
  67. package/lib/Utils/generics.d.ts +11 -17
  68. package/lib/Utils/generics.js +47 -13
  69. package/lib/Utils/history.d.ts +6 -2
  70. package/lib/Utils/history.js +3 -0
  71. package/lib/Utils/link-preview.js +1 -1
  72. package/lib/Utils/logger.d.ts +1 -3
  73. package/lib/Utils/make-mutex.d.ts +2 -2
  74. package/lib/Utils/messages-media.d.ts +31 -25
  75. package/lib/Utils/messages-media.js +95 -53
  76. package/lib/Utils/messages.d.ts +2 -1
  77. package/lib/Utils/messages.js +515 -34
  78. package/lib/Utils/noise-handler.d.ts +6 -6
  79. package/lib/Utils/noise-handler.js +16 -3
  80. package/lib/Utils/process-message.js +4 -3
  81. package/lib/Utils/signal.d.ts +2 -1
  82. package/lib/Utils/signal.js +11 -19
  83. package/lib/Utils/use-multi-file-auth-state.js +11 -3
  84. package/lib/Utils/validate-connection.js +16 -2
  85. package/lib/WABinary/decode.d.ts +1 -2
  86. package/lib/WABinary/decode.js +17 -7
  87. package/lib/WABinary/encode.d.ts +1 -2
  88. package/lib/WABinary/encode.js +33 -17
  89. package/lib/WABinary/generic-utils.d.ts +2 -3
  90. package/lib/WABinary/generic-utils.js +2 -2
  91. package/lib/WABinary/jid-utils.d.ts +4 -2
  92. package/lib/WABinary/jid-utils.js +4 -1
  93. package/lib/WAM/BinaryInfo.d.ts +8 -0
  94. package/lib/WAM/BinaryInfo.js +13 -0
  95. package/lib/WAM/constants.d.ts +38 -0
  96. package/lib/WAM/constants.js +15350 -0
  97. package/lib/WAM/encode.d.ts +2 -0
  98. package/lib/WAM/encode.js +155 -0
  99. package/lib/WAM/index.d.ts +3 -0
  100. package/lib/WAM/index.js +19 -0
  101. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  102. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  103. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  104. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  105. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  106. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  107. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  108. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  109. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  110. package/lib/WAUSync/Protocols/index.js +20 -0
  111. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  112. package/lib/WAUSync/USyncQuery.js +79 -0
  113. package/lib/WAUSync/USyncUser.d.ts +10 -0
  114. package/lib/WAUSync/USyncUser.js +22 -0
  115. package/lib/WAUSync/index.d.ts +3 -0
  116. package/lib/WAUSync/index.js +19 -0
  117. package/lib/gifted +1 -0
  118. package/lib/index.js +2 -0
  119. package/package.json +10 -7
  120. package/lib/index.d.ts +0 -10
@@ -0,0 +1,132 @@
1
+ import { NewsletterFetchedUpdate, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, SocketConfig, WAMediaUpload } from '../Types';
2
+ import { BinaryNode } from '../WABinary';
3
+ export declare const makeNewsletterSocket: (config: SocketConfig) => {
4
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
5
+ duration: string;
6
+ }>;
7
+ newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>;
8
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
9
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
10
+ newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
11
+ newsletterRemovePicture: (jid: string) => Promise<void>;
12
+ newsletterUnfollow: (jid: string) => Promise<void>;
13
+ newsletterFollow: (jid: string) => Promise<void>;
14
+ newsletterUnmute: (jid: string) => Promise<void>;
15
+ newsletterMute: (jid: string) => Promise<void>;
16
+ newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
17
+ newsletterCreate: (name: string, description: string) => Promise<NewsletterMetadata>;
18
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
19
+ newsletterAdminCount: (jid: string) => Promise<number>;
20
+ /**user is Lid, not Jid */
21
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
22
+ /**user is Lid, not Jid */
23
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
24
+ newsletterDelete: (jid: string) => Promise<void>;
25
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
26
+ newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
27
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>;
28
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>;
29
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
30
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
31
+ groupLeave: (id: string) => Promise<void>;
32
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
33
+ groupRequestParticipantsList: (jid: string) => Promise<{
34
+ [key: string]: string;
35
+ }[]>;
36
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
37
+ status: string;
38
+ jid: string;
39
+ }[]>;
40
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
41
+ status: string;
42
+ jid: string;
43
+ content: BinaryNode;
44
+ }[]>;
45
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
46
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
47
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
48
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
49
+ groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
50
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
51
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
52
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
53
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
54
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
55
+ groupFetchAllParticipating: () => Promise<{
56
+ [_: string]: import("../Types").GroupMetadata;
57
+ }>;
58
+ processingMutex: {
59
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
60
+ };
61
+ fetchPrivacySettings: (force?: boolean) => Promise<{
62
+ [_: string]: string;
63
+ }>;
64
+ upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
65
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
66
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
67
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
68
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
69
+ onWhatsApp: (...jids: string[]) => Promise<{
70
+ exists: boolean;
71
+ jid: string;
72
+ }[]>;
73
+ fetchBlocklist: () => Promise<string[]>;
74
+ fetchStatus: (jid: string) => Promise<{
75
+ status: string | undefined;
76
+ setAt: Date;
77
+ } | undefined>;
78
+ updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
79
+ removeProfilePicture: (jid: string) => Promise<void>;
80
+ updateProfileStatus: (status: string) => Promise<void>;
81
+ updateProfileName: (name: string) => Promise<void>;
82
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
83
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
84
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
85
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
86
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
87
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
88
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
89
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
90
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
91
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
92
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
93
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
94
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
95
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
96
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
97
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
98
+ star: (jid: string, messages: {
99
+ id: string;
100
+ fromMe?: boolean;
101
+ }[], star: boolean) => Promise<void>;
102
+ type: "md";
103
+ ws: any;
104
+ ev: import("../Types").BaileysEventEmitter & {
105
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
106
+ buffer(): void;
107
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
108
+ flush(force?: boolean): boolean;
109
+ isBuffering(): boolean;
110
+ };
111
+ authState: {
112
+ creds: import("../Types").AuthenticationCreds;
113
+ keys: import("../Types").SignalKeyStoreWithTransaction;
114
+ };
115
+ signalRepository: import("../Types").SignalRepository;
116
+ user: import("../Types").Contact | undefined;
117
+ generateMessageTag: () => string;
118
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
119
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
120
+ waitForSocketOpen: () => Promise<void>;
121
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
122
+ sendNode: (frame: BinaryNode) => Promise<void>;
123
+ logout: (msg?: string) => Promise<void>;
124
+ end: (error: Error | undefined) => void;
125
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
126
+ uploadPreKeys: (count?: number) => Promise<void>;
127
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
128
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
129
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
130
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
131
+ };
132
+ export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
@@ -0,0 +1,236 @@
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
+ const makeNewsletterSocket = (config) => {
9
+ const sock = (0, groups_1.makeGroupsSocket)(config);
10
+ const { authState, signalRepository, query, generateMessageTag } = sock;
11
+ const encoder = new TextEncoder();
12
+ const newsletterQuery = async (jid, type, content) => (query({
13
+ tag: 'iq',
14
+ attrs: {
15
+ id: generateMessageTag(),
16
+ type,
17
+ xmlns: 'newsletter',
18
+ to: jid,
19
+ },
20
+ content
21
+ }));
22
+ const newsletterWMexQuery = async (jid, queryId, content) => (query({
23
+ tag: 'iq',
24
+ attrs: {
25
+ id: generateMessageTag(),
26
+ type: 'get',
27
+ xmlns: 'w:mex',
28
+ to: WABinary_1.S_WHATSAPP_NET,
29
+ },
30
+ content: [
31
+ {
32
+ tag: 'query',
33
+ attrs: { 'query_id': queryId },
34
+ content: encoder.encode(JSON.stringify({
35
+ variables: {
36
+ 'newsletter_id': jid,
37
+ ...content
38
+ }
39
+ }))
40
+ }
41
+ ]
42
+ }));
43
+ const parseFetchedUpdates = async (node, type) => {
44
+ let child;
45
+ if (type === 'messages') {
46
+ child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
47
+ }
48
+ else {
49
+ const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
50
+ child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
51
+ }
52
+ return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
53
+ var _a, _b;
54
+ messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
55
+ const views = parseInt(((_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) || '0');
56
+ const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
57
+ const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
58
+ .map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
59
+ const data = {
60
+ 'server_id': messageNode.attrs.server_id,
61
+ views,
62
+ reactions
63
+ };
64
+ if (type === 'messages') {
65
+ const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
66
+ await decrypt();
67
+ data.message = message;
68
+ }
69
+ return data;
70
+ }));
71
+ };
72
+ return {
73
+ ...sock,
74
+ subscribeNewsletterUpdates: async (jid) => {
75
+ var _a;
76
+ const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
77
+ return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
78
+ },
79
+ newsletterReactionMode: async (jid, mode) => {
80
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
81
+ updates: { settings: { 'reaction_codes': { value: mode } } }
82
+ });
83
+ },
84
+ newsletterUpdateDescription: async (jid, description) => {
85
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
86
+ updates: { description: description || '', settings: null }
87
+ });
88
+ },
89
+ newsletterUpdateName: async (jid, name) => {
90
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
91
+ updates: { name, settings: null }
92
+ });
93
+ },
94
+ newsletterUpdatePicture: async (jid, content) => {
95
+ const { img } = await (0, Utils_1.generateProfilePicture)(content);
96
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
97
+ updates: { picture: img.toString('base64'), settings: null }
98
+ });
99
+ },
100
+ newsletterRemovePicture: async (jid) => {
101
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
102
+ updates: { picture: '', settings: null }
103
+ });
104
+ },
105
+ newsletterUnfollow: async (jid) => {
106
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW);
107
+ },
108
+ newsletterFollow: async (jid) => {
109
+ await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW);
110
+ },
111
+ newsletterUnmute: async (jid) => {
112
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE);
113
+ },
114
+ newsletterMute: async (jid) => {
115
+ await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE);
116
+ },
117
+ newsletterAction: async (jid, type) => {
118
+ await newsletterWMexQuery(jid, Types_1.QueryIds[type.toUpperCase()]);
119
+ },
120
+ newsletterCreate: async (name, description) => {
121
+ //TODO: Implement TOS system wide for Meta AI, communities, and here etc.
122
+ /**tos query */
123
+ await query({
124
+ tag: 'iq',
125
+ attrs: {
126
+ to: WABinary_1.S_WHATSAPP_NET,
127
+ xmlns: 'tos',
128
+ id: generateMessageTag(),
129
+ type: 'set'
130
+ },
131
+ content: [
132
+ {
133
+ tag: 'notice',
134
+ attrs: {
135
+ id: '20601218',
136
+ stage: '5'
137
+ },
138
+ content: []
139
+ }
140
+ ]
141
+ });
142
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
143
+ input: { name, description, settings: null }
144
+ });
145
+ return (0, exports.extractNewsletterMetadata)(result, true);
146
+ },
147
+ newsletterMetadata: async (type, key, role) => {
148
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
149
+ input: {
150
+ key,
151
+ type: type.toUpperCase(),
152
+ 'view_role': role || 'GUEST'
153
+ },
154
+ 'fetch_viewer_metadata': true,
155
+ 'fetch_full_image': true,
156
+ 'fetch_creation_time': true
157
+ });
158
+ return (0, exports.extractNewsletterMetadata)(result);
159
+ },
160
+ newsletterAdminCount: async (jid) => {
161
+ var _a, _b;
162
+ const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT);
163
+ 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();
164
+ return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
165
+ },
166
+ /**user is Lid, not Jid */
167
+ newsletterChangeOwner: async (jid, user) => {
168
+ await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
169
+ 'user_id': user
170
+ });
171
+ },
172
+ /**user is Lid, not Jid */
173
+ newsletterDemote: async (jid, user) => {
174
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
175
+ 'user_id': user
176
+ });
177
+ },
178
+ newsletterDelete: async (jid) => {
179
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE);
180
+ },
181
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
182
+ newsletterReactMessage: async (jid, serverId, code) => {
183
+ await query({
184
+ tag: 'message',
185
+ attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', 'server_id': serverId, id: (0, Utils_1.generateMessageID)() },
186
+ content: [{
187
+ tag: 'reaction',
188
+ attrs: code ? { code } : {}
189
+ }]
190
+ });
191
+ },
192
+ newsletterFetchMessages: async (type, key, count, after) => {
193
+ const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
194
+ {
195
+ tag: 'messages',
196
+ attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100' }
197
+ }
198
+ ]);
199
+ return await parseFetchedUpdates(result, 'messages');
200
+ },
201
+ newsletterFetchUpdates: async (jid, count, after, since) => {
202
+ const result = await newsletterQuery(jid, 'get', [
203
+ {
204
+ tag: 'message_updates',
205
+ 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' }
206
+ }
207
+ ]);
208
+ return await parseFetchedUpdates(result, 'updates');
209
+ }
210
+ };
211
+ };
212
+ exports.makeNewsletterSocket = makeNewsletterSocket;
213
+ const extractNewsletterMetadata = (node, isCreate) => {
214
+ var _a, _b, _c, _d, _e, _f, _g;
215
+ 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();
216
+ const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
217
+ const metadata = {
218
+ id: metadataPath.id,
219
+ state: metadataPath.state.type,
220
+ 'creation_time': +metadataPath.thread_metadata.creation_time,
221
+ name: metadataPath.thread_metadata.name.text,
222
+ nameTime: +metadataPath.thread_metadata.name.update_time,
223
+ description: metadataPath.thread_metadata.description.text,
224
+ descriptionTime: +metadataPath.thread_metadata.description.update_time,
225
+ invite: metadataPath.thread_metadata.invite,
226
+ handle: metadataPath.thread_metadata.handle,
227
+ picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
228
+ preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
229
+ 'reaction_codes': (_g = (_f = (_e = metadataPath.thread_metadata) === null || _e === void 0 ? void 0 : _e.settings) === null || _f === void 0 ? void 0 : _f.reaction_codes) === null || _g === void 0 ? void 0 : _g.value,
230
+ subscribers: +metadataPath.thread_metadata.subscribers_count,
231
+ verification: metadataPath.thread_metadata.verification,
232
+ 'viewer_metadata': metadataPath.viewer_metadata
233
+ };
234
+ return metadata;
235
+ };
236
+ exports.extractNewsletterMetadata = extractNewsletterMetadata;
@@ -1,15 +1,15 @@
1
- /// <reference types="node" />
2
- import { AxiosRequestConfig } from 'axios';
1
+ import axios, { AxiosRequestConfig } from 'axios';
3
2
  import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
4
3
  export declare const makeRegistrationSocket: (config: SocketConfig) => {
5
4
  register: (code: string) => Promise<ExistsResponse>;
6
5
  requestRegistrationCode: (registrationOptions?: RegistrationOptions) => Promise<ExistsResponse>;
6
+ logger: Logger;
7
7
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
8
8
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
9
9
  products: import("../Types").Product[];
10
- nextPageCursor: string | undefined;
10
+ nextPageCursor: any;
11
11
  }>;
12
- getCollections: (jid?: string | undefined, limit?: number) => Promise<{
12
+ getCollections: (jid?: string, limit?: number) => Promise<{
13
13
  collections: import("../Types").CatalogCollection[];
14
14
  }>;
15
15
  productCreate: (create: import("../Types").ProductCreate) => Promise<import("../Types").Product>;
@@ -17,36 +17,67 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
17
17
  deleted: number;
18
18
  }>;
19
19
  productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
20
- sendMessageAck: ({ tag, attrs }: import("../WABinary").BinaryNode) => Promise<void>;
20
+ sendMessageAck: ({ tag, attrs, content }: import("../WABinary").BinaryNode, errorCode?: number) => Promise<void>;
21
21
  sendRetryRequest: (node: import("../WABinary").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
22
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
23
+ id: any;
24
+ to: string;
25
+ }>;
22
26
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
27
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number) => Promise<string>;
28
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
23
29
  getPrivacyTokens: (jids: string[]) => Promise<import("../WABinary").BinaryNode>;
24
30
  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>;
31
+ relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
26
32
  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>;
33
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
34
+ getButtonArgs: (message: import("../Types").WAProto.IMessage) => import("../WABinary").BinaryNode["attrs"];
35
+ readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
32
36
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
37
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
38
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
39
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: import("../WABinary").BinaryNode["attrs"]) => Promise<{
40
+ nodes: import("../WABinary").BinaryNode[];
41
+ shouldIncludeDeviceIdentity: boolean;
42
+ }>;
33
43
  waUploadToServer: import("../Types").WAMediaUploadFunction;
34
44
  fetchPrivacySettings: (force?: boolean) => Promise<{
35
45
  [_: string]: string;
36
46
  }>;
37
47
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
48
+ sendStatusMentions: (content: import("../Types").AnyMessageContent, jids?: string[]) => Promise<import("../Types").WAProto.WebMessageInfo>;
49
+ sendAlbumMessage: (jid: string, medias: import("../Types").Media[], options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo>;
38
50
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
51
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
52
+ duration: string;
53
+ }>;
54
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
55
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
56
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
57
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
58
+ newsletterRemovePicture: (jid: string) => Promise<void>;
59
+ newsletterUnfollow: (jid: string) => Promise<void>;
60
+ newsletterFollow: (jid: string) => Promise<void>;
61
+ newsletterUnmute: (jid: string) => Promise<void>;
62
+ newsletterMute: (jid: string) => Promise<void>;
63
+ newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
64
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
65
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
66
+ newsletterAdminCount: (jid: string) => Promise<number>;
67
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
68
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
69
+ newsletterDelete: (jid: string) => Promise<void>;
70
+ newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
71
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
72
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
39
73
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
40
74
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
41
75
  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
76
  groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
46
77
  groupRequestParticipantsList: (jid: string) => Promise<{
47
78
  [key: string]: string;
48
79
  }[]>;
49
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
80
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
50
81
  status: string;
51
82
  jid: string;
52
83
  }[]>;
@@ -55,27 +86,27 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
55
86
  jid: string;
56
87
  content: import("../WABinary").BinaryNode;
57
88
  }[]>;
58
- groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
89
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
59
90
  groupInviteCode: (jid: string) => Promise<string | undefined>;
60
91
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
61
92
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
62
93
  groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
63
94
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
64
95
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
65
- groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
66
- groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
96
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
97
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
67
98
  groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
68
99
  groupFetchAllParticipating: () => Promise<{
69
100
  [_: string]: import("../Types").GroupMetadata;
70
101
  }>;
71
102
  processingMutex: {
72
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
103
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
73
104
  };
74
105
  upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
75
106
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
76
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
77
- presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
78
- profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
107
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
108
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
109
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
79
110
  onWhatsApp: (...jids: string[]) => Promise<{
80
111
  exists: boolean;
81
112
  jid: string;
@@ -97,25 +128,25 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
97
128
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
98
129
  updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
99
130
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
100
- getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
131
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
101
132
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
102
133
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
103
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
134
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
104
135
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
105
136
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
106
137
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
107
138
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
108
139
  star: (jid: string, messages: {
109
140
  id: string;
110
- fromMe?: boolean | undefined;
141
+ fromMe?: boolean;
111
142
  }[], star: boolean) => Promise<void>;
112
143
  type: "md";
113
144
  ws: any;
114
145
  ev: import("../Types").BaileysEventEmitter & {
115
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
146
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
116
147
  buffer(): void;
117
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
118
- flush(force?: boolean | undefined): boolean;
148
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
149
+ flush(force?: boolean): boolean;
119
150
  isBuffering(): boolean;
120
151
  };
121
152
  authState: {
@@ -125,18 +156,19 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
125
156
  signalRepository: import("../Types").SignalRepository;
126
157
  user: import("../Types").Contact | undefined;
127
158
  generateMessageTag: () => string;
128
- query: (node: import("../WABinary").BinaryNode, timeoutMs?: number | undefined) => Promise<import("../WABinary").BinaryNode>;
129
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
159
+ query: (node: import("../WABinary").BinaryNode, timeoutMs?: number) => Promise<import("../WABinary").BinaryNode>;
160
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
130
161
  waitForSocketOpen: () => Promise<void>;
131
162
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
132
163
  sendNode: (frame: import("../WABinary").BinaryNode) => Promise<void>;
133
- logout: (msg?: string | undefined) => Promise<void>;
164
+ logout: (msg?: string) => Promise<void>;
134
165
  end: (error: Error | undefined) => void;
135
- onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
166
+ onUnexpectedError: (err: Error | axios, msg: string) => void;
136
167
  uploadPreKeys: (count?: number) => Promise<void>;
137
168
  uploadPreKeysToServerIfRequired: () => Promise<void>;
138
- requestPairingCode: (phoneNumber: string) => Promise<string>;
139
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
169
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
170
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
171
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("../WABinary").BinaryNode>;
140
172
  };
141
173
  export interface RegistrationData {
142
174
  registrationId: number;
@@ -180,13 +212,13 @@ export declare function registrationParams(params: RegistrationParams): {
180
212
  lg: string;
181
213
  lc: string;
182
214
  mistyped: string;
183
- authkey: string;
184
- e_regid: string;
215
+ authkey: any;
216
+ e_regid: any;
185
217
  e_keytype: string;
186
- e_ident: string;
218
+ e_ident: any;
187
219
  e_skey_id: string;
188
- e_skey_val: string;
189
- e_skey_sig: string;
220
+ e_skey_val: any;
221
+ e_skey_sig: any;
190
222
  fdid: string;
191
223
  network_ratio_type: string;
192
224
  expid: string;
@@ -195,7 +227,7 @@ export declare function registrationParams(params: RegistrationParams): {
195
227
  pid: string;
196
228
  id: string;
197
229
  backup_token: string;
198
- token: string;
230
+ token: any;
199
231
  fraud_checkpoint_code: string | undefined;
200
232
  };
201
233
  /**
@@ -212,7 +244,7 @@ export declare function mobileRegister(params: RegistrationParams & {
212
244
  /**
213
245
  * Encrypts the given string as AEAD aes-256-gcm with the public whatsapp key and a random keypair.
214
246
  */
215
- export declare function mobileRegisterEncrypt(data: string): string;
247
+ export declare function mobileRegisterEncrypt(data: string): any;
216
248
  export declare function mobileRegisterFetch(path: string, opts?: AxiosRequestConfig): Promise<ExistsResponse>;
217
249
  export interface ExistsResponse {
218
250
  status: 'fail' | 'sent';