@queenanya/baileys 7.1.1 → 7.1.6

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.
@@ -11,11 +11,11 @@ const Defaults_1 = require("../Defaults");
11
11
  const Utils_1 = require("../Utils");
12
12
  const link_preview_1 = require("../Utils/link-preview");
13
13
  const WABinary_1 = require("../WABinary");
14
- const groups_1 = require("./groups");
14
+ const newsletter_1 = require("./newsletter");
15
15
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
16
16
  const makeMessagesSocket = (config) => {
17
17
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
18
- const sock = (0, groups_1.makeGroupsSocket)(config);
18
+ const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
19
  const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
20
20
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
21
  stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
@@ -77,7 +77,7 @@ const makeMessagesSocket = (config) => {
77
77
  }
78
78
  }
79
79
  if (type) {
80
- node.attrs.type = type;
80
+ node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
81
81
  }
82
82
  const remainingMessageIds = messageIds.slice(1);
83
83
  if (remainingMessageIds.length) {
@@ -256,12 +256,13 @@ const makeMessagesSocket = (config) => {
256
256
  const { user, server } = (0, WABinary_1.jidDecode)(jid);
257
257
  const statusJid = 'status@broadcast';
258
258
  const isGroup = server === 'g.us';
259
+ const isNewsletter = server == 'newsletter';
259
260
  const isStatus = jid === statusJid;
260
261
  const isLid = server === 'lid';
261
262
  msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
262
263
  useUserDevicesCache = useUserDevicesCache !== false;
263
264
  const participants = [];
264
- const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
265
+ const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
265
266
  const binaryNodeContent = [];
266
267
  const devices = [];
267
268
  const meMsg = {
@@ -350,6 +351,15 @@ const makeMessagesSocket = (config) => {
350
351
  });
351
352
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
352
353
  }
354
+ else if (isNewsletter) {
355
+ const patched = await patchMessageBeforeSending(message, []);
356
+ const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
357
+ binaryNodeContent.push({
358
+ tag: 'plaintext',
359
+ attrs: {},
360
+ content: bytes
361
+ });
362
+ }
353
363
  else {
354
364
  const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
355
365
  if (!participant) {
@@ -446,6 +456,35 @@ const makeMessagesSocket = (config) => {
446
456
  });
447
457
  return msgId;
448
458
  };
459
+ const getTypeMessage = (msg) => {
460
+ if (msg.viewOnceMessage) {
461
+ return getTypeMessage(msg.viewOnceMessage.message);
462
+ }
463
+ else if (msg.viewOnceMessageV2) {
464
+ return getTypeMessage(msg.viewOnceMessageV2.message);
465
+ }
466
+ else if (msg.viewOnceMessageV2Extension) {
467
+ return getTypeMessage(msg.viewOnceMessageV2Extension.message);
468
+ }
469
+ else if (msg.ephemeralMessage) {
470
+ return getTypeMessage(msg.ephemeralMessage.message);
471
+ }
472
+ else if (msg.documentWithCaptionMessage) {
473
+ return getTypeMessage(msg.documentWithCaptionMessage.message);
474
+ }
475
+ else if (msg.reactionMessage) {
476
+ return 'reaction';
477
+ }
478
+ else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
479
+ return 'reaction';
480
+ }
481
+ else if (getMediaType(msg)) {
482
+ return 'media';
483
+ }
484
+ else {
485
+ return 'text';
486
+ }
487
+ };
449
488
  const getMediaType = (message) => {
450
489
  if (message.imageMessage) {
451
490
  return 'image';
@@ -618,6 +657,7 @@ const makeMessagesSocket = (config) => {
618
657
  await groupToggleEphemeral(jid, value);
619
658
  }
620
659
  else {
660
+ let mediaHandle;
621
661
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
622
662
  logger,
623
663
  userJid,
@@ -632,7 +672,11 @@ const makeMessagesSocket = (config) => {
632
672
  ? waUploadToServer
633
673
  : undefined
634
674
  }),
635
- upload: waUploadToServer,
675
+ upload: async (readStream, opts) => {
676
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
677
+ mediaHandle = up.handle;
678
+ return up;
679
+ },
636
680
  mediaCache: config.mediaCache,
637
681
  options: config.options,
638
682
  messageId: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
@@ -644,7 +688,7 @@ const makeMessagesSocket = (config) => {
644
688
  // required for delete
645
689
  if (isDeleteMsg) {
646
690
  // if the chat is a group, and I am not the author, then delete the message as an admin
647
- if ((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) {
691
+ if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsletter)(jid)) {
648
692
  additionalAttributes.edit = '8';
649
693
  }
650
694
  else {
@@ -652,7 +696,10 @@ const makeMessagesSocket = (config) => {
652
696
  }
653
697
  }
654
698
  else if (isEditMsg) {
655
- additionalAttributes.edit = '1';
699
+ additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
700
+ }
701
+ if (mediaHandle) {
702
+ additionalAttributes['media_id'] = mediaHandle;
656
703
  }
657
704
  await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
658
705
  if (config.emitOwnEvents) {
@@ -0,0 +1,138 @@
1
+ /// <reference types="node" />
2
+ import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate } from '../Types';
3
+ import { BinaryNode } from '../WABinary';
4
+ export declare const makeNewsletterSocket: (config: SocketConfig) => {
5
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
6
+ duration: string;
7
+ }>;
8
+ newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>;
9
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
10
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
11
+ newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
12
+ newsletterRemovePicture: (jid: string) => Promise<void>;
13
+ newsletterUnfollow: (jid: string) => Promise<void>;
14
+ newsletterFollow: (jid: string) => Promise<void>;
15
+ newsletterUnmute: (jid: string) => Promise<void>;
16
+ newsletterMute: (jid: string) => 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, server_id: 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: "reject" | "approve") => 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 | undefined) => 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").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
50
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>; /**user is Lid, not Jid */
51
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
52
+ groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
53
+ groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_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: () => T | Promise<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 | undefined) => Promise<void>;
67
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
68
+ profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
69
+ onWhatsApp: (...jids: string[]) => Promise<{
70
+ exists: boolean;
71
+ jid: string;
72
+ }[]>;
73
+ fetchBlocklist: () => Promise<string[]>;
74
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
75
+ user: string;
76
+ duration: number;
77
+ setAt: Date;
78
+ }[]>;
79
+ fetchStatus: (jid: string) => Promise<{
80
+ status: string | undefined;
81
+ setAt: Date;
82
+ } | undefined>;
83
+ updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
84
+ removeProfilePicture: (jid: string) => Promise<void>;
85
+ updateProfileStatus: (status: string) => Promise<void>;
86
+ updateProfileName: (name: string) => Promise<void>;
87
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
88
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
89
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
90
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
91
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
92
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
93
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
94
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
95
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
96
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
97
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
98
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
99
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
100
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
101
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
102
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
103
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
104
+ star: (jid: string, messages: {
105
+ id: string;
106
+ fromMe?: boolean | undefined;
107
+ }[], star: boolean) => Promise<void>;
108
+ type: "md";
109
+ ws: any;
110
+ ev: import("../Types").BaileysEventEmitter & {
111
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
112
+ buffer(): void;
113
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
114
+ flush(force?: boolean | undefined): boolean;
115
+ isBuffering(): boolean;
116
+ };
117
+ authState: {
118
+ creds: import("../Types").AuthenticationCreds;
119
+ keys: import("../Types").SignalKeyStoreWithTransaction;
120
+ };
121
+ signalRepository: import("../Types").SignalRepository;
122
+ user: import("../Types").Contact | undefined;
123
+ generateMessageTag: () => string;
124
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
125
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
126
+ waitForSocketOpen: () => Promise<void>;
127
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
128
+ sendNode: (frame: BinaryNode) => Promise<void>;
129
+ logout: (msg?: string | undefined) => Promise<void>;
130
+ end: (error: Error | undefined) => void;
131
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
132
+ uploadPreKeys: (count?: number) => Promise<void>;
133
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
134
+ requestPairingCode: (phoneNumber: string) => Promise<string>;
135
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
136
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
137
+ };
138
+ export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
@@ -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;
@@ -4,7 +4,7 @@ import { KeyPair, SignedKeyPair, SocketConfig } from '../Types';
4
4
  export declare const makeRegistrationSocket: (config: SocketConfig) => {
5
5
  register: (code: string) => Promise<ExistsResponse>;
6
6
  requestRegistrationCode: (registrationOptions?: RegistrationOptions) => Promise<ExistsResponse>;
7
- logger: import("pino").Logger<import("pino").LoggerOptions>;
7
+ logger: import("pino").Logger<never>;
8
8
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
9
9
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
10
10
  products: import("../Types").Product[];
@@ -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,7 @@ 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
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
61
82
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
62
83
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
63
84
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -79,6 +100,11 @@ export declare const makeRegistrationSocket: (config: SocketConfig) => {
79
100
  jid: string;
80
101
  }[]>;
81
102
  fetchBlocklist: () => Promise<string[]>;
103
+ fetchDisappearingDuration: (...jids: string[]) => Promise<{
104
+ user: string;
105
+ duration: number;
106
+ setAt: Date;
107
+ }[]>;
82
108
  fetchStatus: (jid: string) => Promise<{
83
109
  status: string | undefined;
84
110
  setAt: Date;
@@ -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 */
@@ -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
  };