@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.
- package/README.md +56 -14
- package/lib/Defaults/index.js +5 -4
- package/lib/Socket/business.d.ts +31 -3
- package/lib/Socket/chats.d.ts +7 -0
- package/lib/Socket/chats.js +25 -0
- package/lib/Socket/groups.d.ts +15 -2
- package/lib/Socket/groups.js +11 -1
- package/lib/Socket/index.d.ts +31 -3
- package/lib/Socket/messages-recv.d.ts +32 -4
- package/lib/Socket/messages-recv.js +67 -4
- package/lib/Socket/messages-send.d.ts +29 -1
- package/lib/Socket/messages-send.js +61 -9
- package/lib/Socket/newsletter.d.ts +140 -0
- package/lib/Socket/newsletter.js +249 -0
- package/lib/Socket/registration.d.ts +31 -3
- package/lib/Socket/socket.js +2 -1
- package/lib/Types/Chat.d.ts +3 -0
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Message.d.ts +25 -3
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/chat-utils.js +16 -0
- package/lib/Utils/decode-wa-message.js +46 -18
- package/lib/Utils/generics.d.ts +12 -0
- package/lib/Utils/generics.js +26 -6
- package/lib/Utils/messages-media.d.ts +10 -1
- package/lib/Utils/messages-media.js +53 -4
- package/lib/Utils/messages.js +51 -11
- package/lib/Utils/process-message.js +13 -8
- package/lib/Utils/signal.js +0 -5
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +3 -7
- package/lib/WABinary/jid-utils.d.ts +3 -1
- package/lib/WABinary/jid-utils.js +4 -1
- package/package.json +10 -8
|
@@ -17,7 +17,7 @@ const WABinary_1 = require("../WABinary");
|
|
|
17
17
|
const groups_1 = require("./groups");
|
|
18
18
|
const messages_send_1 = require("./messages-send");
|
|
19
19
|
const makeMessagesRecvSocket = (config) => {
|
|
20
|
-
const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
|
|
20
|
+
const { logger, retryRequestDelayMs, maxMsgRetryCount, ignoreMsgLoading, getMessage, shouldIgnoreJid } = config;
|
|
21
21
|
const sock = (0, messages_send_1.makeMessagesSocket)(config);
|
|
22
22
|
const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, } = sock;
|
|
23
23
|
/** this mutex ensures that each retryRequest will wait for the previous one to finish */
|
|
@@ -164,7 +164,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
164
164
|
}
|
|
165
165
|
};
|
|
166
166
|
const handleGroupNotification = (participant, child, msg) => {
|
|
167
|
-
var _a, _b;
|
|
167
|
+
var _a, _b, _c, _d;
|
|
168
168
|
const participantJid = ((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(child, 'participant')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.jid) || participant;
|
|
169
169
|
switch (child === null || child === void 0 ? void 0 : child.tag) {
|
|
170
170
|
case 'create':
|
|
@@ -217,6 +217,11 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
217
217
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
|
|
218
218
|
msg.messageStubParameters = [child.attrs.subject];
|
|
219
219
|
break;
|
|
220
|
+
case 'description':
|
|
221
|
+
const description = (_d = (_c = (0, WABinary_1.getBinaryNodeChild)(child, 'body')) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.toString();
|
|
222
|
+
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION;
|
|
223
|
+
msg.messageStubParameters = description ? [description] : undefined;
|
|
224
|
+
break;
|
|
220
225
|
case 'announcement':
|
|
221
226
|
case 'not_announcement':
|
|
222
227
|
msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE;
|
|
@@ -256,6 +261,50 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
256
261
|
break;
|
|
257
262
|
}
|
|
258
263
|
};
|
|
264
|
+
const handleNewsletterNotification = (id, node) => {
|
|
265
|
+
const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
266
|
+
const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
|
|
267
|
+
const server_id = message.attrs.server_id;
|
|
268
|
+
const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
|
|
269
|
+
const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
|
|
270
|
+
if (reactionsList) {
|
|
271
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
|
|
272
|
+
if (reactions.length === 0) {
|
|
273
|
+
ev.emit('newsletter.reaction', { id, server_id, reaction: { removed: true } });
|
|
274
|
+
}
|
|
275
|
+
reactions.forEach(item => {
|
|
276
|
+
var _a, _b;
|
|
277
|
+
ev.emit('newsletter.reaction', { id, server_id, reaction: { code: (_a = item.attrs) === null || _a === void 0 ? void 0 : _a.code, count: +((_b = item.attrs) === null || _b === void 0 ? void 0 : _b.count) } });
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (viewsList.length) {
|
|
281
|
+
viewsList.forEach(item => {
|
|
282
|
+
ev.emit('newsletter.view', { id, server_id, count: +item.attrs.count });
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const handleMexNewsletterNotification = (id, node) => {
|
|
287
|
+
var _a;
|
|
288
|
+
const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
|
|
289
|
+
const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
|
|
290
|
+
let contentPath;
|
|
291
|
+
if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
|
|
292
|
+
let action;
|
|
293
|
+
if (operation === Types_1.MexOperations.PROMOTE) {
|
|
294
|
+
action = 'promote';
|
|
295
|
+
contentPath = content.data[Types_1.XWAPaths.PROMOTE];
|
|
296
|
+
}
|
|
297
|
+
if (operation === Types_1.MexOperations.DEMOTE) {
|
|
298
|
+
action = 'demote';
|
|
299
|
+
contentPath = content.data[Types_1.XWAPaths.DEMOTE];
|
|
300
|
+
}
|
|
301
|
+
ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
|
|
302
|
+
}
|
|
303
|
+
if (operation === Types_1.MexOperations.UPDATE) {
|
|
304
|
+
contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
|
|
305
|
+
ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
|
|
306
|
+
}
|
|
307
|
+
};
|
|
259
308
|
const processNotification = async (node) => {
|
|
260
309
|
var _a, _b, _c;
|
|
261
310
|
const result = {};
|
|
@@ -276,6 +325,12 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
276
325
|
logger.debug({ jid }, 'got privacy token update');
|
|
277
326
|
}
|
|
278
327
|
break;
|
|
328
|
+
case 'newsletter':
|
|
329
|
+
handleNewsletterNotification(node.attrs.from, child);
|
|
330
|
+
break;
|
|
331
|
+
case 'mex':
|
|
332
|
+
handleMexNewsletterNotification(node.attrs.from, child);
|
|
333
|
+
break;
|
|
279
334
|
case 'w:gp2':
|
|
280
335
|
handleGroupNotification(node.attrs.participant, child, result);
|
|
281
336
|
break;
|
|
@@ -286,6 +341,9 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
286
341
|
case 'encrypt':
|
|
287
342
|
await handleEncryptNotification(node);
|
|
288
343
|
break;
|
|
344
|
+
case 'newsletter':
|
|
345
|
+
// TO DO
|
|
346
|
+
break;
|
|
289
347
|
case 'devices':
|
|
290
348
|
const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
|
|
291
349
|
if ((0, WABinary_1.areJidsSameUser)(child.attrs.jid, authState.creds.me.id)) {
|
|
@@ -304,7 +362,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
304
362
|
const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
|
|
305
363
|
const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
|
|
306
364
|
ev.emit('contacts.update', [{
|
|
307
|
-
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.jid) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
|
365
|
+
id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.jid) || from || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
|
|
308
366
|
imgUrl: setPicture ? 'changed' : 'removed'
|
|
309
367
|
}]);
|
|
310
368
|
if ((0, WABinary_1.isJidGroup)(from)) {
|
|
@@ -573,6 +631,11 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
573
631
|
};
|
|
574
632
|
const handleMessage = async (node) => {
|
|
575
633
|
var _a, _b;
|
|
634
|
+
if (ignoreMsgLoading && node.attrs.offline) {
|
|
635
|
+
logger.debug({ key: node.attrs.key }, 'ignored offline message');
|
|
636
|
+
await sendMessageAck(node);
|
|
637
|
+
return;
|
|
638
|
+
}
|
|
576
639
|
if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
|
|
577
640
|
logger.debug({ key: node.attrs.key }, 'ignored message');
|
|
578
641
|
await sendMessageAck(node);
|
|
@@ -667,7 +730,7 @@ const makeMessagesRecvSocket = (config) => {
|
|
|
667
730
|
await sendMessageAck(node);
|
|
668
731
|
};
|
|
669
732
|
const handleBadAck = async ({ attrs }) => {
|
|
670
|
-
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
|
|
733
|
+
const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, server_id: attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
|
|
671
734
|
// current hypothesis is that if pash is sent in the ack
|
|
672
735
|
// it means -- the message hasn't reached all devices yet
|
|
673
736
|
// we'll retry sending the message here
|
|
@@ -18,6 +18,27 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
18
18
|
}>;
|
|
19
19
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
|
20
20
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
|
21
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
22
|
+
duration: string;
|
|
23
|
+
}>;
|
|
24
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
|
25
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
|
26
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
|
27
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
|
28
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
|
29
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
|
30
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
|
31
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
|
32
|
+
newsletterMute: (jid: string) => Promise<void>;
|
|
33
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
|
34
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
|
35
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
36
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
|
37
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
|
38
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
39
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
|
40
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
41
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
|
21
42
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
|
22
43
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
|
23
44
|
groupLeave: (id: string) => Promise<void>;
|
|
@@ -38,7 +59,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
38
59
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
39
60
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
40
61
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
41
|
-
|
|
62
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
63
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
|
42
64
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
43
65
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
44
66
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
@@ -60,6 +82,11 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
60
82
|
jid: string;
|
|
61
83
|
}[]>;
|
|
62
84
|
fetchBlocklist: () => Promise<string[]>;
|
|
85
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
86
|
+
user: string;
|
|
87
|
+
duration: number;
|
|
88
|
+
setAt: Date;
|
|
89
|
+
}[]>;
|
|
63
90
|
fetchStatus: (jid: string) => Promise<{
|
|
64
91
|
status: string | undefined;
|
|
65
92
|
setAt: Date;
|
|
@@ -81,6 +108,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
|
81
108
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
82
109
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
83
110
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
111
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
84
112
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
85
113
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
86
114
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
@@ -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
|
|
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,
|
|
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
|
-
msgId = msgId || (0, Utils_1.
|
|
262
|
+
msgId = msgId || (0, Utils_1.generateMessageIDV3)((_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';
|
|
@@ -489,6 +528,9 @@ const makeMessagesSocket = (config) => {
|
|
|
489
528
|
else if (message.interactiveResponseMessage) {
|
|
490
529
|
return 'native_flow_response';
|
|
491
530
|
}
|
|
531
|
+
else if (message.groupInviteMessage) {
|
|
532
|
+
return 'url';
|
|
533
|
+
}
|
|
492
534
|
};
|
|
493
535
|
const getButtonType = (message) => {
|
|
494
536
|
if (message.buttonsMessage) {
|
|
@@ -618,6 +660,7 @@ const makeMessagesSocket = (config) => {
|
|
|
618
660
|
await groupToggleEphemeral(jid, value);
|
|
619
661
|
}
|
|
620
662
|
else {
|
|
663
|
+
let mediaHandle;
|
|
621
664
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
|
622
665
|
logger,
|
|
623
666
|
userJid,
|
|
@@ -632,10 +675,16 @@ const makeMessagesSocket = (config) => {
|
|
|
632
675
|
? waUploadToServer
|
|
633
676
|
: undefined
|
|
634
677
|
}),
|
|
635
|
-
upload:
|
|
678
|
+
upload: async (readStream, opts) => {
|
|
679
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
|
680
|
+
mediaHandle = up.handle;
|
|
681
|
+
return up;
|
|
682
|
+
},
|
|
683
|
+
//TODO: CACHE
|
|
684
|
+
getProfilePicUrl: sock.profilePictureUrl,
|
|
636
685
|
mediaCache: config.mediaCache,
|
|
637
686
|
options: config.options,
|
|
638
|
-
messageId: (0, Utils_1.
|
|
687
|
+
messageId: (0, Utils_1.generateMessageIDV3)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
|
|
639
688
|
...options,
|
|
640
689
|
});
|
|
641
690
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
|
@@ -644,7 +693,7 @@ const makeMessagesSocket = (config) => {
|
|
|
644
693
|
// required for delete
|
|
645
694
|
if (isDeleteMsg) {
|
|
646
695
|
// 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)) {
|
|
696
|
+
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
697
|
additionalAttributes.edit = '8';
|
|
649
698
|
}
|
|
650
699
|
else {
|
|
@@ -652,7 +701,10 @@ const makeMessagesSocket = (config) => {
|
|
|
652
701
|
}
|
|
653
702
|
}
|
|
654
703
|
else if (isEditMsg) {
|
|
655
|
-
additionalAttributes.edit = '1';
|
|
704
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
|
705
|
+
}
|
|
706
|
+
if (mediaHandle) {
|
|
707
|
+
additionalAttributes['media_id'] = mediaHandle;
|
|
656
708
|
}
|
|
657
709
|
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, cachedGroupMetadata: options.cachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
|
|
658
710
|
if (config.emitOwnEvents) {
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
50
|
+
groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
|
|
51
|
+
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
|
52
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
53
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
|
54
|
+
groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
|
|
55
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
56
|
+
groupFetchAllParticipating: () => Promise<{
|
|
57
|
+
[_: string]: import("../Types").GroupMetadata;
|
|
58
|
+
}>;
|
|
59
|
+
processingMutex: {
|
|
60
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
|
61
|
+
};
|
|
62
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
63
|
+
[_: string]: string;
|
|
64
|
+
}>;
|
|
65
|
+
upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
|
66
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
|
67
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
|
68
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
|
69
|
+
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
|
70
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
71
|
+
exists: boolean;
|
|
72
|
+
jid: string;
|
|
73
|
+
}[]>;
|
|
74
|
+
fetchBlocklist: () => Promise<string[]>;
|
|
75
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<{
|
|
76
|
+
user: string;
|
|
77
|
+
duration: number;
|
|
78
|
+
setAt: Date;
|
|
79
|
+
}[]>;
|
|
80
|
+
fetchStatus: (jid: string) => Promise<{
|
|
81
|
+
status: string | undefined;
|
|
82
|
+
setAt: Date;
|
|
83
|
+
} | undefined>;
|
|
84
|
+
updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
|
|
85
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
86
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
87
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
88
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
89
|
+
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
|
90
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
91
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
|
92
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
93
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
94
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
|
95
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
|
96
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
97
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
|
|
98
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
99
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
|
100
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
|
101
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
|
102
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
103
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
104
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
105
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
106
|
+
star: (jid: string, messages: {
|
|
107
|
+
id: string;
|
|
108
|
+
fromMe?: boolean | undefined;
|
|
109
|
+
}[], star: boolean) => Promise<void>;
|
|
110
|
+
type: "md";
|
|
111
|
+
ws: any;
|
|
112
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
113
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
114
|
+
buffer(): void;
|
|
115
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
|
|
116
|
+
flush(force?: boolean | undefined): boolean;
|
|
117
|
+
isBuffering(): boolean;
|
|
118
|
+
};
|
|
119
|
+
authState: {
|
|
120
|
+
creds: import("../Types").AuthenticationCreds;
|
|
121
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
122
|
+
};
|
|
123
|
+
signalRepository: import("../Types").SignalRepository;
|
|
124
|
+
user: import("../Types").Contact | undefined;
|
|
125
|
+
generateMessageTag: () => string;
|
|
126
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
|
|
127
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
|
|
128
|
+
waitForSocketOpen: () => Promise<void>;
|
|
129
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
130
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
131
|
+
logout: (msg?: string | undefined) => Promise<void>;
|
|
132
|
+
end: (error: Error | undefined) => void;
|
|
133
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
|
|
134
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
135
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
136
|
+
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
|
137
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
|
138
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
|
139
|
+
};
|
|
140
|
+
export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata;
|