@genuxofficial/baileys 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/WAProto/WAProto.proto +1385 -96
- package/WAProto/index.d.ts +19244 -2787
- package/WAProto/index.js +138202 -74217
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.js +1 -0
- package/lib/Socket/business.d.ts +47 -17
- package/lib/Socket/chats.d.ts +10 -9
- package/lib/Socket/chats.js +36 -16
- package/lib/Socket/groups.d.ts +12 -11
- package/lib/Socket/groups.js +16 -3
- package/lib/Socket/index.d.ts +52 -22
- package/lib/Socket/messages-recv.d.ts +46 -15
- package/lib/Socket/messages-recv.js +158 -23
- package/lib/Socket/messages-send.d.ts +39 -11
- package/lib/Socket/messages-send.js +188 -22
- package/lib/Socket/newsletter.d.ts +137 -0
- package/lib/Socket/newsletter.js +256 -0
- package/lib/Socket/socket.d.ts +4 -4
- package/lib/Socket/socket.js +25 -12
- package/lib/Socket/usync.d.ts +5 -5
- package/lib/Store/index.d.ts +1 -2
- package/lib/Store/index.js +1 -3
- package/lib/Store/make-in-memory-store.js +14 -5
- package/lib/Types/Chat.d.ts +6 -5
- package/lib/Types/Events.d.ts +27 -0
- package/lib/Types/GroupMetadata.d.ts +6 -0
- package/lib/Types/Label.d.ts +0 -11
- package/lib/Types/Message.d.ts +150 -12
- package/lib/Types/Message.js +0 -2
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Socket.d.ts +8 -3
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/lib/Utils/auth-utils.d.ts +1 -1
- package/lib/Utils/auth-utils.js +3 -4
- package/lib/Utils/business.js +15 -3
- package/lib/Utils/chat-utils.js +0 -16
- package/lib/Utils/crypto.js +6 -4
- package/lib/Utils/decode-wa-message.d.ts +5 -3
- package/lib/Utils/decode-wa-message.js +158 -31
- package/lib/Utils/event-buffer.js +1 -3
- package/lib/Utils/generics.d.ts +3 -2
- package/lib/Utils/generics.js +16 -36
- package/lib/Utils/history.d.ts +2 -2
- package/lib/Utils/link-preview.d.ts +1 -1
- package/lib/Utils/link-preview.js +1 -24
- package/lib/Utils/make-mutex.js +0 -1
- package/lib/Utils/messages-media.d.ts +14 -5
- package/lib/Utils/messages-media.js +130 -69
- package/lib/Utils/messages.d.ts +1 -1
- package/lib/Utils/messages.js +309 -57
- package/lib/Utils/noise-handler.d.ts +1 -1
- package/lib/Utils/process-message.js +0 -1
- package/lib/Utils/use-multi-file-auth-state.js +44 -13
- package/lib/Utils/validate-connection.js +1 -3
- package/lib/WABinary/decode.js +3 -2
- package/lib/WABinary/encode.js +13 -5
- package/lib/WABinary/generic-utils.d.ts +3 -5
- package/lib/WABinary/generic-utils.js +34 -19
- package/lib/WABinary/jid-utils.d.ts +12 -3
- package/lib/WABinary/jid-utils.js +29 -4
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +21 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/USyncQuery.d.ts +2 -0
- package/lib/WAUSync/USyncQuery.js +10 -0
- package/lib/WAUSync/USyncUser.d.ts +2 -0
- package/lib/WAUSync/USyncUser.js +4 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +20 -12
- package/WAProto/GenerateStatics.sh +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -83
@@ -6,34 +6,61 @@ import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptio
|
|
6
6
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
7
7
|
import { USyncQuery } from '../WAUSync';
|
8
8
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
9
|
-
getPrivacyTokens: (jids: string[]) => Promise<
|
9
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
10
10
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
11
11
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
12
12
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
13
13
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
14
|
+
getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
|
14
15
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
15
16
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
16
17
|
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
17
18
|
fetchPrivacySettings: (force?: boolean) => Promise<{
|
18
19
|
[_: string]: string;
|
19
20
|
}>;
|
20
|
-
|
21
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
21
22
|
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
22
23
|
nodes: BinaryNode[];
|
23
24
|
shouldIncludeDeviceIdentity: boolean;
|
24
25
|
}>;
|
25
|
-
|
26
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
26
27
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
27
28
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
29
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
30
|
+
duration: string;
|
31
|
+
}>;
|
32
|
+
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
33
|
+
newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
|
34
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
35
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
36
|
+
newsletterRemovePicture: (jid: string) => Promise<void>;
|
37
|
+
newsletterUnfollow: (jid: string) => Promise<void>;
|
38
|
+
newsletterFollow: (jid: string) => Promise<void>;
|
39
|
+
newsletterUnmute: (jid: string) => Promise<void>;
|
40
|
+
newsletterMute: (jid: string) => Promise<void>;
|
41
|
+
newsletterCreate: (name: string, description?: string | undefined, picture?: import("../Types").WAMediaUpload | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
42
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
43
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
44
|
+
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
45
|
+
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
46
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
47
|
+
newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
|
48
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
49
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
28
50
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
29
51
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
30
52
|
groupLeave: (id: string) => Promise<void>;
|
31
53
|
groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
54
|
+
/**
|
55
|
+
* generic send receipt function
|
56
|
+
* used for receipts of phone call, read, delivery etc.
|
57
|
+
* */
|
32
58
|
groupRequestParticipantsList: (jid: string) => Promise<{
|
33
59
|
[key: string]: string;
|
34
60
|
}[]>;
|
35
61
|
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
|
36
62
|
status: string;
|
63
|
+
/** Correctly bulk send receipts to multiple chats, participants */
|
37
64
|
jid: string;
|
38
65
|
}[]>;
|
39
66
|
groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
|
@@ -46,7 +73,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
46
73
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
47
74
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
48
75
|
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
49
|
-
groupAcceptInviteV4: (key: string |
|
76
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
50
77
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
51
78
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
52
79
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
@@ -55,6 +82,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
55
82
|
groupFetchAllParticipating: () => Promise<{
|
56
83
|
[_: string]: import("../Types").GroupMetadata;
|
57
84
|
}>;
|
85
|
+
getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
|
58
86
|
processingMutex: {
|
59
87
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
60
88
|
};
|
@@ -66,10 +94,11 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
66
94
|
onWhatsApp: (...jids: string[]) => Promise<{
|
67
95
|
jid: string;
|
68
96
|
exists: unknown;
|
97
|
+
lid: unknown;
|
69
98
|
}[] | undefined>;
|
70
99
|
fetchBlocklist: () => Promise<string[]>;
|
71
|
-
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
72
100
|
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
101
|
+
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
73
102
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
74
103
|
removeProfilePicture: (jid: string) => Promise<void>;
|
75
104
|
updateProfileStatus: (status: string) => Promise<void>;
|
@@ -88,7 +117,6 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
88
117
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
89
118
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
90
119
|
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
|
91
|
-
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
|
92
120
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
93
121
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
94
122
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
@@ -99,7 +127,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
99
127
|
}[], star: boolean) => Promise<void>;
|
100
128
|
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
101
129
|
type: "md";
|
102
|
-
ws: import("./Client").WebSocketClient;
|
130
|
+
ws: import("./Client/websocket").WebSocketClient;
|
103
131
|
ev: import("../Types").BaileysEventEmitter & {
|
104
132
|
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
105
133
|
buffer(): void;
|
@@ -114,8 +142,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
114
142
|
signalRepository: import("../Types").SignalRepository;
|
115
143
|
user: import("../Types").Contact | undefined;
|
116
144
|
generateMessageTag: () => string;
|
117
|
-
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<
|
118
|
-
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<
|
145
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
|
146
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
119
147
|
waitForSocketOpen: () => Promise<void>;
|
120
148
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
121
149
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
@@ -124,7 +152,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
124
152
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
125
153
|
uploadPreKeys: (count?: number) => Promise<void>;
|
126
154
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
127
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
155
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
128
156
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
|
129
|
-
sendWAMBuffer: (wamBuffer: Buffer) => Promise<
|
157
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
130
158
|
};
|
@@ -4,18 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
6
|
exports.makeMessagesSocket = void 0;
|
7
|
-
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
8
7
|
const boom_1 = require("@hapi/boom");
|
8
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
9
9
|
const WAProto_1 = require("../../WAProto");
|
10
10
|
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
14
|
const WAUSync_1 = require("../WAUSync");
|
15
|
-
const
|
15
|
+
const newsletter_1 = require("./newsletter");
|
16
|
+
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
16
17
|
const makeMessagesSocket = (config) => {
|
17
18
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, cachedGroupMetadata, } = config;
|
18
|
-
const sock = (0,
|
19
|
+
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
19
20
|
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, sendNode, groupMetadata, groupToggleEphemeral, } = sock;
|
20
21
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
21
22
|
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
@@ -77,7 +78,7 @@ const makeMessagesSocket = (config) => {
|
|
77
78
|
}
|
78
79
|
}
|
79
80
|
if (type) {
|
80
|
-
node.attrs.type = type;
|
81
|
+
node.attrs.type = (0, WABinary_1.isJidNewsletter)(jid) ? 'read-self' : type;
|
81
82
|
}
|
82
83
|
const remainingMessageIds = messageIds.slice(1);
|
83
84
|
if (remainingMessageIds.length) {
|
@@ -225,10 +226,17 @@ const makeMessagesSocket = (config) => {
|
|
225
226
|
return msgId;
|
226
227
|
};
|
227
228
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
228
|
-
|
229
|
-
|
229
|
+
let patched = await patchMessageBeforeSending(message, jids);
|
230
|
+
if (!Array.isArray(patched)) {
|
231
|
+
patched = jids ? jids.map(jid => ({ recipientJid: jid, ...patched })) : [patched];
|
232
|
+
}
|
230
233
|
let shouldIncludeDeviceIdentity = false;
|
231
|
-
const nodes = await Promise.all(
|
234
|
+
const nodes = await Promise.all(patched.map(async (patchedMessageWithJid) => {
|
235
|
+
const { recipientJid: jid, ...patchedMessage } = patchedMessageWithJid;
|
236
|
+
if (!jid) {
|
237
|
+
return {};
|
238
|
+
}
|
239
|
+
const bytes = (0, Utils_1.encodeWAMessage)(patchedMessage);
|
232
240
|
const { type, ciphertext } = await signalRepository
|
233
241
|
.encryptMessage({ jid, data: bytes });
|
234
242
|
if (type === 'pkmsg') {
|
@@ -258,13 +266,14 @@ const makeMessagesSocket = (config) => {
|
|
258
266
|
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
259
267
|
const statusJid = 'status@broadcast';
|
260
268
|
const isGroup = server === 'g.us';
|
269
|
+
const isNewsletter = server == 'newsletter';
|
261
270
|
const isStatus = jid === statusJid;
|
262
271
|
const isLid = server === 'lid';
|
263
272
|
msgId = msgId || (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id);
|
264
273
|
useUserDevicesCache = useUserDevicesCache !== false;
|
265
274
|
useCachedGroupMetadata = useCachedGroupMetadata !== false && !isStatus;
|
266
275
|
const participants = [];
|
267
|
-
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : 's.whatsapp.net') : statusJid;
|
276
|
+
const destinationJid = (!isStatus) ? (0, WABinary_1.jidEncode)(user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net') : statusJid;
|
268
277
|
const binaryNodeContent = [];
|
269
278
|
const devices = [];
|
270
279
|
const meMsg = {
|
@@ -285,7 +294,7 @@ const makeMessagesSocket = (config) => {
|
|
285
294
|
devices.push({ user, device });
|
286
295
|
}
|
287
296
|
await authState.keys.transaction(async () => {
|
288
|
-
var _a, _b, _c, _d, _e;
|
297
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
289
298
|
const mediaType = getMediaType(message);
|
290
299
|
if (mediaType) {
|
291
300
|
extraAttrs['mediatype'] = mediaType;
|
@@ -318,10 +327,20 @@ const makeMessagesSocket = (config) => {
|
|
318
327
|
if (isStatus && statusJidList) {
|
319
328
|
participantsList.push(...statusJidList);
|
320
329
|
}
|
330
|
+
if (!isStatus) {
|
331
|
+
additionalAttributes = {
|
332
|
+
...additionalAttributes,
|
333
|
+
// eslint-disable-next-line camelcase
|
334
|
+
addressing_mode: (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) || 'pn'
|
335
|
+
};
|
336
|
+
}
|
321
337
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
322
338
|
devices.push(...additionalDevices);
|
323
339
|
}
|
324
|
-
const patched = await patchMessageBeforeSending(message
|
340
|
+
const patched = await patchMessageBeforeSending(message);
|
341
|
+
if (Array.isArray(patched)) {
|
342
|
+
throw new boom_1.Boom('Per-jid patching is not supported in groups');
|
343
|
+
}
|
325
344
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
326
345
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
327
346
|
group: destinationJid,
|
@@ -331,7 +350,7 @@ const makeMessagesSocket = (config) => {
|
|
331
350
|
const senderKeyJids = [];
|
332
351
|
// ensure a connection is established with every device
|
333
352
|
for (const { user, device } of devices) {
|
334
|
-
const jid = (0, WABinary_1.jidEncode)(user,
|
353
|
+
const jid = (0, WABinary_1.jidEncode)(user, (groupData === null || groupData === void 0 ? void 0 : groupData.addressingMode) === 'lid' ? 'lid' : 's.whatsapp.net', device);
|
335
354
|
if (!senderKeyMap[jid] || !!participant) {
|
336
355
|
senderKeyJids.push(jid);
|
337
356
|
// store that this person has had the sender keys sent to them
|
@@ -360,6 +379,28 @@ const makeMessagesSocket = (config) => {
|
|
360
379
|
});
|
361
380
|
await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
|
362
381
|
}
|
382
|
+
else if (isNewsletter) {
|
383
|
+
// Message edit
|
384
|
+
if ((_b = message.protocolMessage) === null || _b === void 0 ? void 0 : _b.editedMessage) {
|
385
|
+
msgId = (_c = message.protocolMessage.key) === null || _c === void 0 ? void 0 : _c.id;
|
386
|
+
message = message.protocolMessage.editedMessage;
|
387
|
+
}
|
388
|
+
// Message delete
|
389
|
+
if (((_d = message.protocolMessage) === null || _d === void 0 ? void 0 : _d.type) === WAProto_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
390
|
+
msgId = (_e = message.protocolMessage.key) === null || _e === void 0 ? void 0 : _e.id;
|
391
|
+
message = {};
|
392
|
+
}
|
393
|
+
const patched = await patchMessageBeforeSending(message, []);
|
394
|
+
if (Array.isArray(patched)) {
|
395
|
+
throw new boom_1.Boom('Per-jid patching is not supported in channel');
|
396
|
+
}
|
397
|
+
const bytes = (0, Utils_1.encodeNewsletterMessage)(patched);
|
398
|
+
binaryNodeContent.push({
|
399
|
+
tag: 'plaintext',
|
400
|
+
attrs: mediaType ? { mediatype: mediaType } : {},
|
401
|
+
content: bytes
|
402
|
+
});
|
403
|
+
}
|
363
404
|
else {
|
364
405
|
const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
|
365
406
|
if (!participant) {
|
@@ -377,7 +418,7 @@ const makeMessagesSocket = (config) => {
|
|
377
418
|
const otherJids = [];
|
378
419
|
for (const { user, device } of devices) {
|
379
420
|
const isMe = user === meUser;
|
380
|
-
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((
|
421
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_g = (_f = authState.creds) === null || _f === void 0 ? void 0 : _f.me) === null || _g === void 0 ? void 0 : _g.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
381
422
|
if (isMe) {
|
382
423
|
meJids.push(jid);
|
383
424
|
}
|
@@ -397,7 +438,7 @@ const makeMessagesSocket = (config) => {
|
|
397
438
|
}
|
398
439
|
if (participants.length) {
|
399
440
|
if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer') {
|
400
|
-
const peerNode = (
|
441
|
+
const peerNode = (_j = (_h = participants[0]) === null || _h === void 0 ? void 0 : _h.content) === null || _j === void 0 ? void 0 : _j[0];
|
401
442
|
if (peerNode) {
|
402
443
|
binaryNodeContent.push(peerNode); // push only enc
|
403
444
|
}
|
@@ -414,7 +455,7 @@ const makeMessagesSocket = (config) => {
|
|
414
455
|
tag: 'message',
|
415
456
|
attrs: {
|
416
457
|
id: msgId,
|
417
|
-
type: getMessageType(message),
|
458
|
+
type: isNewsletter ? getTypeMessage(message) : getMessageType(message),
|
418
459
|
...(additionalAttributes || {})
|
419
460
|
},
|
420
461
|
content: binaryNodeContent
|
@@ -446,20 +487,82 @@ const makeMessagesSocket = (config) => {
|
|
446
487
|
});
|
447
488
|
logger.debug({ jid }, 'adding device identity');
|
448
489
|
}
|
490
|
+
const buttonType = getButtonType(message);
|
491
|
+
if (buttonType) {
|
492
|
+
stanza.content.push({
|
493
|
+
tag: 'biz',
|
494
|
+
attrs: {},
|
495
|
+
content: [
|
496
|
+
{
|
497
|
+
tag: buttonType,
|
498
|
+
attrs: getButtonArgs(message),
|
499
|
+
}
|
500
|
+
]
|
501
|
+
});
|
502
|
+
logger.debug({ jid }, 'adding business node');
|
503
|
+
}
|
449
504
|
if (additionalNodes && additionalNodes.length > 0) {
|
450
505
|
stanza.content.push(...additionalNodes);
|
451
506
|
}
|
507
|
+
else {
|
508
|
+
if (((0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidUser)(jid)) && (((_l = (_k = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _k === void 0 ? void 0 : _k.message) === null || _l === void 0 ? void 0 : _l.interactiveMessage) || ((_o = (_m = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _m === void 0 ? void 0 : _m.message) === null || _o === void 0 ? void 0 : _o.interactiveMessage) || ((_q = (_p = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _p === void 0 ? void 0 : _p.message) === null || _q === void 0 ? void 0 : _q.interactiveMessage) || (message === null || message === void 0 ? void 0 : message.interactiveMessage)) || (((_s = (_r = message === null || message === void 0 ? void 0 : message.viewOnceMessage) === null || _r === void 0 ? void 0 : _r.message) === null || _s === void 0 ? void 0 : _s.buttonsMessage) || ((_u = (_t = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2) === null || _t === void 0 ? void 0 : _t.message) === null || _u === void 0 ? void 0 : _u.buttonsMessage) || ((_w = (_v = message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension) === null || _v === void 0 ? void 0 : _v.message) === null || _w === void 0 ? void 0 : _w.buttonsMessage) || (message === null || message === void 0 ? void 0 : message.buttonsMessage))) {
|
509
|
+
stanza.content.push({
|
510
|
+
tag: 'biz',
|
511
|
+
attrs: {},
|
512
|
+
content: [{
|
513
|
+
tag: 'interactive',
|
514
|
+
attrs: {
|
515
|
+
type: 'native_flow',
|
516
|
+
v: '1'
|
517
|
+
},
|
518
|
+
content: [{
|
519
|
+
tag: 'native_flow',
|
520
|
+
attrs: { name: 'quick_reply' }
|
521
|
+
}]
|
522
|
+
}]
|
523
|
+
});
|
524
|
+
}
|
525
|
+
}
|
452
526
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
453
527
|
await sendNode(stanza);
|
454
528
|
});
|
455
529
|
return msgId;
|
456
530
|
};
|
457
531
|
const getMessageType = (message) => {
|
458
|
-
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
|
532
|
+
if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3 || message.pollUpdateMessage) {
|
459
533
|
return 'poll';
|
460
534
|
}
|
461
535
|
return 'text';
|
462
536
|
};
|
537
|
+
const getTypeMessage = (msg) => {
|
538
|
+
if (msg.viewOnceMessage) {
|
539
|
+
return getTypeMessage(msg.viewOnceMessage.message);
|
540
|
+
}
|
541
|
+
else if (msg.viewOnceMessageV2) {
|
542
|
+
return getTypeMessage(msg.viewOnceMessageV2.message);
|
543
|
+
}
|
544
|
+
else if (msg.viewOnceMessageV2Extension) {
|
545
|
+
return getTypeMessage(msg.viewOnceMessageV2Extension.message);
|
546
|
+
}
|
547
|
+
else if (msg.ephemeralMessage) {
|
548
|
+
return getTypeMessage(msg.ephemeralMessage.message);
|
549
|
+
}
|
550
|
+
else if (msg.documentWithCaptionMessage) {
|
551
|
+
return getTypeMessage(msg.documentWithCaptionMessage.message);
|
552
|
+
}
|
553
|
+
else if (msg.reactionMessage) {
|
554
|
+
return 'reaction';
|
555
|
+
}
|
556
|
+
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
557
|
+
return 'poll';
|
558
|
+
}
|
559
|
+
else if (getMediaType(msg)) {
|
560
|
+
return 'media';
|
561
|
+
}
|
562
|
+
else {
|
563
|
+
return 'text';
|
564
|
+
}
|
565
|
+
};
|
463
566
|
const getMediaType = (message) => {
|
464
567
|
if (message.imageMessage) {
|
465
568
|
return 'image';
|
@@ -507,6 +610,39 @@ const makeMessagesSocket = (config) => {
|
|
507
610
|
return 'url';
|
508
611
|
}
|
509
612
|
};
|
613
|
+
const getButtonType = (message) => {
|
614
|
+
if (message.buttonsMessage) {
|
615
|
+
return 'buttons';
|
616
|
+
}
|
617
|
+
else if (message.buttonsResponseMessage) {
|
618
|
+
return 'buttons_response';
|
619
|
+
}
|
620
|
+
else if (message.interactiveResponseMessage) {
|
621
|
+
return 'interactive_response';
|
622
|
+
}
|
623
|
+
else if (message.listMessage) {
|
624
|
+
return 'list';
|
625
|
+
}
|
626
|
+
else if (message.listResponseMessage) {
|
627
|
+
return 'list_response';
|
628
|
+
}
|
629
|
+
};
|
630
|
+
const getButtonArgs = (message) => {
|
631
|
+
if (message.templateMessage) {
|
632
|
+
// TODO: Add attributes
|
633
|
+
return {};
|
634
|
+
}
|
635
|
+
else if (message.listMessage) {
|
636
|
+
const type = message.listMessage.listType;
|
637
|
+
if (!type) {
|
638
|
+
throw new boom_1.Boom('Expected list type inside message');
|
639
|
+
}
|
640
|
+
return { v: '2', type: ListType[type].toLowerCase() };
|
641
|
+
}
|
642
|
+
else {
|
643
|
+
return {};
|
644
|
+
}
|
645
|
+
};
|
510
646
|
const getPrivacyTokens = async (jids) => {
|
511
647
|
const t = (0, Utils_1.unixTimestampSeconds)().toString();
|
512
648
|
const result = await query({
|
@@ -542,13 +678,14 @@ const makeMessagesSocket = (config) => {
|
|
542
678
|
relayMessage,
|
543
679
|
sendReceipt,
|
544
680
|
sendReceipts,
|
681
|
+
getButtonArgs,
|
545
682
|
readMessages,
|
546
683
|
refreshMediaConn,
|
547
684
|
waUploadToServer,
|
548
685
|
fetchPrivacySettings,
|
549
|
-
sendPeerDataOperationMessage,
|
550
|
-
createParticipantNodes,
|
551
686
|
getUSyncDevices,
|
687
|
+
createParticipantNodes,
|
688
|
+
sendPeerDataOperationMessage,
|
552
689
|
updateMediaMessage: async (message) => {
|
553
690
|
const content = (0, Utils_1.assertMediaContent)(message.message);
|
554
691
|
const mediaKey = content.mediaKey;
|
@@ -602,8 +739,12 @@ const makeMessagesSocket = (config) => {
|
|
602
739
|
(disappearingMessagesInChat ? Defaults_1.WA_DEFAULT_EPHEMERAL : 0) :
|
603
740
|
disappearingMessagesInChat;
|
604
741
|
await groupToggleEphemeral(jid, value);
|
742
|
+
if (jid.endsWith('@bot')) {
|
743
|
+
jid = (0, WABinary_1.getBotJid)(jid);
|
744
|
+
}
|
605
745
|
}
|
606
746
|
else {
|
747
|
+
let mediaHandle;
|
607
748
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
608
749
|
logger,
|
609
750
|
userJid,
|
@@ -618,9 +759,13 @@ const makeMessagesSocket = (config) => {
|
|
618
759
|
? waUploadToServer
|
619
760
|
: undefined
|
620
761
|
}),
|
621
|
-
//TODO: CACHE
|
622
762
|
getProfilePicUrl: sock.profilePictureUrl,
|
623
|
-
|
763
|
+
//need update 👉
|
764
|
+
upload: async (encFilePath, opts) => {
|
765
|
+
const up = await waUploadToServer(encFilePath, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
|
766
|
+
mediaHandle = up.handle;
|
767
|
+
return up;
|
768
|
+
},
|
624
769
|
mediaCache: config.mediaCache,
|
625
770
|
options: config.options,
|
626
771
|
messageId: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
|
@@ -629,24 +774,33 @@ const makeMessagesSocket = (config) => {
|
|
629
774
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
630
775
|
const isEditMsg = 'edit' in content && !!content.edit;
|
631
776
|
const isPinMsg = 'pin' in content && !!content.pin;
|
777
|
+
const isKeepMsg = 'keep' in content && content.keep;
|
632
778
|
const isPollMessage = 'poll' in content && !!content.poll;
|
779
|
+
const isAiMsg = 'ai' in content && !!content.ai;
|
633
780
|
const additionalAttributes = {};
|
634
781
|
const additionalNodes = [];
|
635
782
|
// required for delete
|
636
783
|
if (isDeleteMsg) {
|
637
784
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
638
|
-
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)) {
|
785
|
+
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)) {
|
639
786
|
additionalAttributes.edit = '8';
|
640
787
|
}
|
641
788
|
else {
|
642
789
|
additionalAttributes.edit = '7';
|
643
790
|
}
|
791
|
+
// required for edit message
|
644
792
|
}
|
645
793
|
else if (isEditMsg) {
|
646
|
-
additionalAttributes.edit = '1';
|
794
|
+
additionalAttributes.edit = (0, WABinary_1.isJidNewsletter)(jid) ? '3' : '1';
|
795
|
+
// required for pin message
|
647
796
|
}
|
648
797
|
else if (isPinMsg) {
|
649
798
|
additionalAttributes.edit = '2';
|
799
|
+
// required for keep message
|
800
|
+
}
|
801
|
+
else if (isKeepMsg) {
|
802
|
+
additionalAttributes.edit = '6';
|
803
|
+
// required for polling message
|
650
804
|
}
|
651
805
|
else if (isPollMessage) {
|
652
806
|
additionalNodes.push({
|
@@ -655,11 +809,23 @@ const makeMessagesSocket = (config) => {
|
|
655
809
|
polltype: 'creation'
|
656
810
|
},
|
657
811
|
});
|
812
|
+
// required to display AI icon on message
|
813
|
+
}
|
814
|
+
else if (isAiMsg) {
|
815
|
+
additionalNodes.push({
|
816
|
+
attrs: {
|
817
|
+
biz_bot: '1'
|
818
|
+
},
|
819
|
+
tag: "bot"
|
820
|
+
});
|
821
|
+
}
|
822
|
+
if (mediaHandle) {
|
823
|
+
additionalAttributes['media_id'] = mediaHandle;
|
658
824
|
}
|
659
825
|
if ('cachedGroupMetadata' in options) {
|
660
826
|
console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
|
661
827
|
}
|
662
|
-
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList
|
828
|
+
await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, additionalNodes: isAiMsg ? additionalNodes : options.additionalNodes, statusJidList: options.statusJidList });
|
663
829
|
if (config.emitOwnEvents) {
|
664
830
|
process.nextTick(() => {
|
665
831
|
processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
|