@queenanya/baileys 7.1.3 → 7.1.7

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 (39) hide show
  1. package/README.md +56 -14
  2. package/lib/Defaults/index.js +5 -4
  3. package/lib/Socket/business.d.ts +31 -3
  4. package/lib/Socket/chats.d.ts +7 -0
  5. package/lib/Socket/chats.js +25 -0
  6. package/lib/Socket/groups.d.ts +15 -2
  7. package/lib/Socket/groups.js +11 -1
  8. package/lib/Socket/index.d.ts +31 -3
  9. package/lib/Socket/messages-recv.d.ts +32 -4
  10. package/lib/Socket/messages-recv.js +67 -4
  11. package/lib/Socket/messages-send.d.ts +29 -1
  12. package/lib/Socket/messages-send.js +61 -9
  13. package/lib/Socket/newsletter.d.ts +140 -0
  14. package/lib/Socket/newsletter.js +249 -0
  15. package/lib/Socket/registration.d.ts +31 -3
  16. package/lib/Socket/socket.js +2 -1
  17. package/lib/Types/Chat.d.ts +3 -0
  18. package/lib/Types/Events.d.ts +27 -0
  19. package/lib/Types/Label.d.ts +11 -0
  20. package/lib/Types/Message.d.ts +25 -3
  21. package/lib/Types/Newsletter.d.ts +79 -0
  22. package/lib/Types/Newsletter.js +18 -0
  23. package/lib/Types/Socket.d.ts +2 -0
  24. package/lib/Types/index.d.ts +2 -0
  25. package/lib/Types/index.js +1 -0
  26. package/lib/Utils/chat-utils.js +16 -0
  27. package/lib/Utils/decode-wa-message.js +46 -18
  28. package/lib/Utils/generics.d.ts +12 -0
  29. package/lib/Utils/generics.js +26 -6
  30. package/lib/Utils/messages-media.d.ts +10 -1
  31. package/lib/Utils/messages-media.js +53 -4
  32. package/lib/Utils/messages.js +51 -11
  33. package/lib/Utils/process-message.js +13 -8
  34. package/lib/Utils/signal.js +0 -5
  35. package/lib/WABinary/encode.d.ts +1 -2
  36. package/lib/WABinary/encode.js +3 -7
  37. package/lib/WABinary/jid-utils.d.ts +3 -1
  38. package/lib/WABinary/jid-utils.js +4 -1
  39. package/package.json +10 -8
@@ -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;
@@ -25,11 +25,11 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
25
25
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
26
26
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
27
27
  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>;
28
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
29
29
  getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
30
30
  [key: string]: string;
31
31
  };
32
- readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => 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<{
@@ -37,6 +37,27 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
37
37
  }>;
38
38
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
39
39
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
40
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
41
+ duration: string;
42
+ }>;
43
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
44
+ newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
45
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
46
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
47
+ newsletterRemovePicture: (jid: string) => Promise<void>;
48
+ newsletterUnfollow: (jid: string) => Promise<void>;
49
+ newsletterFollow: (jid: string) => Promise<void>;
50
+ newsletterUnmute: (jid: string) => Promise<void>;
51
+ newsletterMute: (jid: string) => Promise<void>;
52
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
53
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
54
+ newsletterAdminCount: (jid: string) => Promise<number>;
55
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
56
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
57
+ newsletterDelete: (jid: string) => Promise<void>;
58
+ newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
59
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
60
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
40
61
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
41
62
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
42
63
  groupLeave: (id: string) => Promise<void>;
@@ -57,7 +78,8 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
57
78
  groupInviteCode: (jid: string) => Promise<string | undefined>;
58
79
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
59
80
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
60
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
81
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
82
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
61
83
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
62
84
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
63
85
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -79,6 +101,11 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
79
101
  jid: string;
80
102
  }[]>;
81
103
  fetchBlocklist: () => Promise<string[]>;
104
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
105
+ user: string;
106
+ duration: number;
107
+ setAt: Date;
108
+ }[]>;
82
109
  fetchStatus: (jid: string) => Promise<{
83
110
  status: string | undefined;
84
111
  setAt: Date;
@@ -100,6 +127,7 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
100
127
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
101
128
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
102
129
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
130
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
103
131
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
104
132
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
105
133
  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 */
@@ -4,6 +4,7 @@ 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';
@@ -81,6 +82,8 @@ export type ChatModification = {
81
82
  } | {
82
83
  delete: true;
83
84
  lastMessages: LastMessageList;
85
+ } | {
86
+ addLabel: LabelActionBody;
84
87
  } | {
85
88
  addChatLabel: ChatLabelAssociationActionBody;
86
89
  } | {
@@ -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>;
@@ -85,6 +86,32 @@ export type BaileysEventMap = {
85
86
  action: RequestJoinAction;
86
87
  method: RequestJoinMethod;
87
88
  };
89
+ 'newsletter.reaction': {
90
+ id: string;
91
+ server_id: string;
92
+ reaction: {
93
+ code?: string;
94
+ count?: number;
95
+ removed?: boolean;
96
+ };
97
+ };
98
+ 'newsletter.view': {
99
+ id: string;
100
+ server_id: string;
101
+ count: number;
102
+ };
103
+ /**don't handles subscribe/unsubscribe actions */
104
+ 'newsletter-participants.update': {
105
+ id: string;
106
+ author: string;
107
+ user: string;
108
+ new_role: NewsletterViewRole;
109
+ action: SubscriberAction;
110
+ };
111
+ 'newsletter-settings.update': {
112
+ id: string;
113
+ update: NewsletterSettingsUpdate;
114
+ };
88
115
  'blocklist.set': {
89
116
  blocklist: string[];
90
117
  };
@@ -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,
@@ -14,7 +14,9 @@ export type WAMessage = proto.IWebMessageInfo;
14
14
  export type WAMessageContent = proto.IMessage;
15
15
  export type WAContactMessage = proto.Message.IContactMessage;
16
16
  export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
17
- export type WAMessageKey = proto.IMessageKey;
17
+ export type WAMessageKey = proto.IMessageKey & {
18
+ server_id?: string;
19
+ };
18
20
  export type WATextMessage = proto.Message.IExtendedTextMessage;
19
21
  export type WAContextInfo = proto.IContextInfo;
20
22
  export type WALocationMessage = proto.Message.ILocationMessage;
@@ -134,6 +136,13 @@ export type ButtonReplyInfo = {
134
136
  id: string;
135
137
  index: number;
136
138
  };
139
+ export type GroupInviteInfo = {
140
+ inviteCode: string;
141
+ inviteExpiration: number;
142
+ text: string;
143
+ jid: string;
144
+ subject: string;
145
+ };
137
146
  export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
138
147
  productImage: WAMediaUpload;
139
148
  };
@@ -154,8 +163,15 @@ export type AnyRegularMessageContent = (({
154
163
  } | {
155
164
  buttonReply: ButtonReplyInfo;
156
165
  type: 'template' | 'plain';
166
+ } | {
167
+ groupInvite: GroupInviteInfo;
157
168
  } | {
158
169
  listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>;
170
+ } | {
171
+ pin: WAMessageKey;
172
+ time: 86400 | 604800 | 2592000;
173
+ } | {
174
+ unpin: WAMessageKey;
159
175
  } | {
160
176
  product: WASendableProduct;
161
177
  businessOwnerJid?: string;
@@ -214,13 +230,16 @@ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
214
230
  export type MessageGenerationOptionsFromContent = MiscMessageGenerationOptions & {
215
231
  userJid: string;
216
232
  };
217
- export type WAMediaUploadFunction = (readStream: Readable, opts: {
233
+ export type WAMediaUploadFunctionOpts = {
218
234
  fileEncSha256B64: string;
219
235
  mediaType: MediaType;
236
+ newsletter?: boolean;
220
237
  timeoutMs?: number;
221
- }) => Promise<{
238
+ };
239
+ export type WAMediaUploadFunction = (readStream: Readable | Buffer, opts: WAMediaUploadFunctionOpts) => Promise<{
222
240
  mediaUrl: string;
223
241
  directPath: string;
242
+ handle?: string;
224
243
  }>;
225
244
  export type MediaGenerationOptions = {
226
245
  logger?: Logger;
@@ -231,10 +250,13 @@ export type MediaGenerationOptions = {
231
250
  mediaUploadTimeoutMs?: number;
232
251
  options?: AxiosRequestConfig;
233
252
  backgroundColor?: string;
253
+ /** The message is for newsletter? */
254
+ newsletter?: boolean;
234
255
  font?: number;
235
256
  };
236
257
  export type MessageContentGenerationOptions = MediaGenerationOptions & {
237
258
  getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>;
259
+ getProfilePicUrl?: (jid: string, type: 'image' | 'preview') => Promise<string | undefined>;
238
260
  };
239
261
  export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent;
240
262
  /**
@@ -0,0 +1,79 @@
1
+ import { proto } from '../../WAProto';
2
+ export type NewsletterReactionMode = 'ALL' | 'BASIC' | 'NONE';
3
+ export type NewsletterState = 'ACTIVE' | 'GEOSUSPENDED' | 'SUSPENDED';
4
+ export type NewsletterVerification = 'VERIFIED' | 'UNVERIFIED';
5
+ export type NewsletterMute = 'ON' | 'OFF' | 'UNDEFINED';
6
+ export type NewsletterViewRole = 'ADMIN' | 'GUEST' | 'OWNER' | 'SUBSCRIBER';
7
+ export type NewsletterViewerMetadata = {
8
+ mute: NewsletterMute;
9
+ view_role: NewsletterViewRole;
10
+ };
11
+ export type NewsletterMetadata = {
12
+ /**jid of newsletter */
13
+ id: string;
14
+ /**state of newsletter */
15
+ state: NewsletterState;
16
+ /**creation timestamp of newsletter */
17
+ creation_time: number;
18
+ /**name of newsletter */
19
+ name: string;
20
+ /**timestamp of last name modification of newsletter */
21
+ nameTime: number;
22
+ /**description of newsletter */
23
+ description: string;
24
+ /**timestamp of last description modification of newsletter */
25
+ descriptionTime: number;
26
+ /**invite code of newsletter */
27
+ invite: string;
28
+ /**i dont know */
29
+ handle: null;
30
+ /**direct path of picture */
31
+ picture: string | null;
32
+ /**direct path of picture preview (lower quality) */
33
+ preview: string | null;
34
+ /**reaction mode of newsletter */
35
+ reaction_codes?: NewsletterReactionMode;
36
+ /**subscribers count of newsletter */
37
+ subscribers: number;
38
+ /**verification state of newsletter */
39
+ verification: NewsletterVerification;
40
+ /**viewer metadata */
41
+ viewer_metadata: NewsletterViewerMetadata;
42
+ };
43
+ export type SubscriberAction = 'promote' | 'demote';
44
+ export type ReactionModeUpdate = {
45
+ reaction_codes: {
46
+ blocked_codes: null;
47
+ enabled_ts_sec: null;
48
+ value: NewsletterReactionMode;
49
+ };
50
+ };
51
+ /**only exists reaction mode update */
52
+ export type NewsletterSettingsUpdate = ReactionModeUpdate;
53
+ export type NewsletterReaction = {
54
+ count: number;
55
+ code: string;
56
+ };
57
+ export type NewsletterFetchedUpdate = {
58
+ /**id of message in newsletter, starts from 100 */
59
+ server_id: string;
60
+ /**count of views in this message */
61
+ views?: number;
62
+ /**reactions in this message */
63
+ reactions: NewsletterReaction[];
64
+ /**the message, if you requested only updates, you will not receive message */
65
+ message?: proto.IWebMessageInfo;
66
+ };
67
+ export declare enum MexOperations {
68
+ PROMOTE = "NotificationNewsletterAdminPromote",
69
+ DEMOTE = "NotificationNewsletterAdminDemote",
70
+ UPDATE = "NotificationNewsletterUpdate"
71
+ }
72
+ export declare enum XWAPaths {
73
+ PROMOTE = "xwa2_notify_newsletter_admin_promote",
74
+ DEMOTE = "xwa2_notify_newsletter_admin_demote",
75
+ ADMIN_COUNT = "xwa2_newsletter_admin",
76
+ CREATE = "xwa2_newsletter_create",
77
+ NEWSLETTER = "xwa2_newsletter",
78
+ METADATA_UPDATE = "xwa2_notify_newsletter_on_metadata_update"
79
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XWAPaths = exports.MexOperations = void 0;
4
+ var MexOperations;
5
+ (function (MexOperations) {
6
+ MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
7
+ MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
8
+ MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
9
+ })(MexOperations = exports.MexOperations || (exports.MexOperations = {}));
10
+ var XWAPaths;
11
+ (function (XWAPaths) {
12
+ XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
13
+ XWAPaths["DEMOTE"] = "xwa2_notify_newsletter_admin_demote";
14
+ XWAPaths["ADMIN_COUNT"] = "xwa2_newsletter_admin";
15
+ XWAPaths["CREATE"] = "xwa2_newsletter_create";
16
+ XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
+ XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
+ })(XWAPaths = exports.XWAPaths || (exports.XWAPaths = {}));
@@ -75,6 +75,8 @@ export type SocketConfig = {
75
75
  linkPreviewImageThumbnailWidth: number;
76
76
  /** Should Baileys ask the phone for full history, will be received async */
77
77
  syncFullHistory: boolean;
78
+ /** Ignore Message when offline, default is false */
79
+ ignoreMsgLoading: boolean;
78
80
  /** Should baileys fire init queries automatically, default true */
79
81
  fireInitQueries: boolean;
80
82
  /**
@@ -4,6 +4,7 @@ export * from './Chat';
4
4
  export * from './Contact';
5
5
  export * from './State';
6
6
  export * from './Message';
7
+ export * from './Newsletter';
7
8
  export * from './Socket';
8
9
  export * from './Events';
9
10
  export * from './Product';
@@ -14,6 +15,7 @@ import { SocketConfig } from './Socket';
14
15
  export type UserFacingSocketConfig = Partial<SocketConfig> & {
15
16
  auth: AuthenticationState;
16
17
  };
18
+ /** Other Browser Support for Paircode */
17
19
  export type BrowsersMap = {
18
20
  ubuntu(browser: string): [string, string, string];
19
21
  macOS(browser: string): [string, string, string];
@@ -21,6 +21,7 @@ __exportStar(require("./Chat"), exports);
21
21
  __exportStar(require("./Contact"), exports);
22
22
  __exportStar(require("./State"), exports);
23
23
  __exportStar(require("./Message"), exports);
24
+ __exportStar(require("./Newsletter"), exports);
24
25
  __exportStar(require("./Socket"), exports);
25
26
  __exportStar(require("./Events"), exports);
26
27
  __exportStar(require("./Product"), exports);
@@ -491,6 +491,22 @@ const chatModificationToAppPatch = (mod, jid) => {
491
491
  operation: OP.SET,
492
492
  };
493
493
  }
494
+ else if ('addLabel' in mod) {
495
+ patch = {
496
+ syncAction: {
497
+ labelEditAction: {
498
+ name: mod.addLabel.name,
499
+ color: mod.addLabel.color,
500
+ predefinedId: mod.addLabel.predefinedId,
501
+ deleted: mod.addLabel.deleted
502
+ }
503
+ },
504
+ index: ['label_edit', mod.addLabel.id],
505
+ type: 'regular',
506
+ apiVersion: 3,
507
+ operation: OP.SET,
508
+ };
509
+ }
494
510
  else if ('addChatLabel' in mod) {
495
511
  patch = {
496
512
  syncAction: {