@jkt48connect-corp/baileys 7.2.7 → 7.2.8
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/LICENSE +1 -1
- package/README.md +838 -94
- package/WAProto/WAProto.proto +969 -88
- package/WAProto/index.d.ts +13199 -1260
- package/WAProto/index.js +124901 -74525
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +7 -8
- package/lib/Defaults/index.js +5 -3
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Signal/libsignal.js +18 -9
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -1
- package/lib/Socket/business.d.ts +40 -40
- package/lib/Socket/chats.d.ts +13 -14
- package/lib/Socket/groups.d.ts +20 -21
- package/lib/Socket/groups.js +1 -1
- package/lib/Socket/index.d.ts +49 -49
- package/lib/Socket/messages-recv.d.ts +39 -39
- package/lib/Socket/messages-recv.js +310 -151
- package/lib/Socket/messages-send.d.ts +33 -31
- package/lib/Socket/messages-send.js +269 -36
- package/lib/Socket/newsletter.d.ts +24 -25
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +49 -52
- package/lib/Socket/registration.js +7 -7
- package/lib/Socket/socket.d.ts +6 -7
- package/lib/Socket/socket.js +7 -3
- package/lib/Store/make-cache-manager-store.d.ts +1 -0
- package/lib/Store/make-in-memory-store.d.ts +3 -4
- package/lib/Store/make-in-memory-store.js +13 -11
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Types/Auth.d.ts +0 -1
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +12 -7
- package/lib/Types/Events.d.ts +17 -2
- package/lib/Types/GroupMetadata.d.ts +3 -1
- package/lib/Types/Label.d.ts +11 -0
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +164 -13
- package/lib/Types/Newsletter.js +3 -3
- package/lib/Types/Socket.d.ts +7 -2
- package/lib/Types/index.d.ts +9 -0
- package/lib/Types/index.js +1 -1
- package/lib/Utils/auth-utils.js +3 -3
- package/lib/Utils/business.d.ts +1 -1
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +11 -12
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +15 -16
- package/lib/Utils/crypto.js +35 -23
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +43 -15
- package/lib/Utils/generics.d.ts +10 -19
- package/lib/Utils/generics.js +32 -16
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/index.d.ts +0 -1
- package/lib/Utils/index.js +0 -1
- package/lib/Utils/logger.d.ts +1 -3
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +25 -28
- package/lib/Utils/messages-media.js +38 -47
- package/lib/Utils/messages.d.ts +5 -8
- package/lib/Utils/messages.js +430 -12
- package/lib/Utils/noise-handler.d.ts +4 -5
- package/lib/Utils/process-message.js +2 -2
- package/lib/Utils/use-multi-file-auth-state.js +17 -3
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +12 -23
- package/lib/WABinary/decode.d.ts +1 -2
- package/lib/WABinary/decode.js +17 -7
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +33 -17
- package/lib/WABinary/generic-utils.d.ts +2 -3
- package/lib/WABinary/generic-utils.js +2 -2
- package/lib/WABinary/jid-utils.d.ts +1 -1
- package/lib/WAM/BinaryInfo.d.ts +2 -11
- package/lib/WAM/encode.d.ts +1 -2
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -0
- package/lib/WAUSync/USyncQuery.js +79 -0
- package/lib/WAUSync/USyncUser.d.ts +10 -0
- package/lib/WAUSync/USyncUser.js +22 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.js +4 -1
- package/package.json +15 -10
- package/lib/Socket/community.d.ts +0 -219
- package/lib/Socket/community.js +0 -354
- package/lib/Utils/use-single-file-auth-statev2.d.ts +0 -12
- package/lib/Utils/use-single-file-auth-statev2.js +0 -75
- package/lib/index.d.ts +0 -11
@@ -1,7 +1,6 @@
|
|
1
|
-
/// <reference types="node" />
|
2
1
|
import { Boom } from '@hapi/boom';
|
3
2
|
import { proto } from '../../WAProto';
|
4
|
-
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
3
|
+
import { AnyMessageContent, Media, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
5
4
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
6
5
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
7
6
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
@@ -9,11 +8,12 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
9
8
|
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
10
9
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
11
10
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
12
|
-
getButtonArgs: (message: proto.IMessage) => BinaryNode[
|
11
|
+
getButtonArgs: (message: proto.IMessage) => BinaryNode["attrs"];
|
13
12
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
14
13
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
15
14
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
16
|
-
|
15
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
16
|
+
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
|
17
17
|
nodes: BinaryNode[];
|
18
18
|
shouldIncludeDeviceIdentity: boolean;
|
19
19
|
}>;
|
@@ -22,12 +22,14 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
22
22
|
[_: string]: string;
|
23
23
|
}>;
|
24
24
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
25
|
+
sendStatusMentions: (content: AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
|
26
|
+
sendAlbumMessage: (jid: string, medias: Media[], options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
|
25
27
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
26
28
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
27
29
|
duration: string;
|
28
30
|
}>;
|
29
31
|
newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
|
30
|
-
newsletterUpdateDescription: (jid: string, description?: string
|
32
|
+
newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
31
33
|
newsletterUpdateName: (jid: string, name: string) => Promise<void>;
|
32
34
|
newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
33
35
|
newsletterRemovePicture: (jid: string) => Promise<void>;
|
@@ -35,16 +37,16 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
35
37
|
newsletterFollow: (jid: string) => Promise<void>;
|
36
38
|
newsletterUnmute: (jid: string) => Promise<void>;
|
37
39
|
newsletterMute: (jid: string) => Promise<void>;
|
38
|
-
newsletterAction: (jid: string, type: "
|
39
|
-
newsletterCreate: (name: string, description: string
|
40
|
-
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole
|
40
|
+
newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
|
41
|
+
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
42
|
+
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
|
41
43
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
42
44
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
43
45
|
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
44
46
|
newsletterDelete: (jid: string) => Promise<void>;
|
45
|
-
newsletterReactMessage: (jid: string, serverId: string, code?: string
|
46
|
-
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number
|
47
|
-
newsletterFetchUpdates: (jid: string, count: number, after?: number
|
47
|
+
newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
|
48
|
+
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
49
|
+
newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
48
50
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
49
51
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
50
52
|
groupLeave: (id: string) => Promise<void>;
|
@@ -52,7 +54,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
52
54
|
groupRequestParticipantsList: (jid: string) => Promise<{
|
53
55
|
[key: string]: string;
|
54
56
|
}[]>;
|
55
|
-
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "
|
57
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
|
56
58
|
status: string;
|
57
59
|
jid: string;
|
58
60
|
}[]>;
|
@@ -61,27 +63,27 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
61
63
|
jid: string;
|
62
64
|
content: BinaryNode;
|
63
65
|
}[]>;
|
64
|
-
groupUpdateDescription: (jid: string, description?: string
|
66
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
65
67
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
66
68
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
67
69
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
68
70
|
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
69
71
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
70
72
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
71
|
-
groupSettingUpdate: (jid: string, setting: "announcement" | "
|
72
|
-
groupMemberAddMode: (jid: string, mode: "
|
73
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
74
|
+
groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
|
73
75
|
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
74
76
|
groupFetchAllParticipating: () => Promise<{
|
75
77
|
[_: string]: import("../Types").GroupMetadata;
|
76
78
|
}>;
|
77
79
|
processingMutex: {
|
78
|
-
mutex<T>(code: () => T |
|
80
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
79
81
|
};
|
80
82
|
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
81
83
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
82
|
-
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string
|
83
|
-
presenceSubscribe: (toJid: string, tcToken?: Buffer
|
84
|
-
profilePictureUrl: (jid: string, type?: "
|
84
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
|
85
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
86
|
+
profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
|
85
87
|
onWhatsApp: (...jids: string[]) => Promise<{
|
86
88
|
exists: boolean;
|
87
89
|
jid: string;
|
@@ -103,25 +105,25 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
103
105
|
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
|
104
106
|
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
105
107
|
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
106
|
-
getBusinessProfile: (jid: string) => Promise<
|
108
|
+
getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
|
107
109
|
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
108
110
|
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
|
109
|
-
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?:
|
111
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
110
112
|
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
111
113
|
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
112
114
|
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
113
115
|
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
114
116
|
star: (jid: string, messages: {
|
115
117
|
id: string;
|
116
|
-
fromMe?: boolean
|
118
|
+
fromMe?: boolean;
|
117
119
|
}[], star: boolean) => Promise<void>;
|
118
120
|
type: "md";
|
119
121
|
ws: any;
|
120
122
|
ev: import("../Types").BaileysEventEmitter & {
|
121
|
-
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
|
123
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
122
124
|
buffer(): void;
|
123
|
-
createBufferedFunction<A extends any[],
|
124
|
-
flush(force?: boolean
|
125
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
126
|
+
flush(force?: boolean): boolean;
|
125
127
|
isBuffering(): boolean;
|
126
128
|
};
|
127
129
|
authState: {
|
@@ -131,17 +133,17 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
131
133
|
signalRepository: import("../Types").SignalRepository;
|
132
134
|
user: import("../Types").Contact | undefined;
|
133
135
|
generateMessageTag: () => string;
|
134
|
-
query: (node: BinaryNode, timeoutMs?: number
|
135
|
-
waitForMessage: <
|
136
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
|
137
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
|
136
138
|
waitForSocketOpen: () => Promise<void>;
|
137
139
|
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
138
140
|
sendNode: (frame: BinaryNode) => Promise<void>;
|
139
|
-
logout: (msg?: string
|
141
|
+
logout: (msg?: string) => Promise<void>;
|
140
142
|
end: (error: Error | undefined) => void;
|
141
|
-
onUnexpectedError: (err: Error | Boom
|
143
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
142
144
|
uploadPreKeys: (count?: number) => Promise<void>;
|
143
145
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
144
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
145
|
-
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number
|
146
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
147
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
146
148
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
147
149
|
};
|
@@ -18,7 +18,7 @@ const makeMessagesSocket = (config) => {
|
|
18
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
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
21
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
|
22
22
|
useClones: false
|
23
23
|
});
|
24
24
|
let mediaConn;
|
@@ -222,6 +222,28 @@ const makeMessagesSocket = (config) => {
|
|
222
222
|
}
|
223
223
|
return didFetchNewSession;
|
224
224
|
};
|
225
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
226
|
+
var _a;
|
227
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
228
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
229
|
+
throw new boom_1.Boom('Not authenticated');
|
230
|
+
}
|
231
|
+
const protocolMessage = {
|
232
|
+
protocolMessage: {
|
233
|
+
peerDataOperationRequestMessage: pdoMessage,
|
234
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
235
|
+
}
|
236
|
+
};
|
237
|
+
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
238
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
239
|
+
additionalAttributes: {
|
240
|
+
category: 'peer',
|
241
|
+
// eslint-disable-next-line camelcase
|
242
|
+
push_priority: 'high_force',
|
243
|
+
},
|
244
|
+
});
|
245
|
+
return msgId;
|
246
|
+
};
|
225
247
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
226
248
|
const patched = await patchMessageBeforeSending(message, jids);
|
227
249
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
@@ -257,6 +279,7 @@ const makeMessagesSocket = (config) => {
|
|
257
279
|
const isGroup = server === 'g.us';
|
258
280
|
const isStatus = jid === statusJid;
|
259
281
|
const isLid = server === 'lid';
|
282
|
+
const isPrivate = server === 's.whatsapp.net';
|
260
283
|
const isNewsletter = server === 'newsletter';
|
261
284
|
msgId = msgId || (0, Utils_1.generateMessageID)();
|
262
285
|
useUserDevicesCache = useUserDevicesCache !== false;
|
@@ -311,7 +334,7 @@ const makeMessagesSocket = (config) => {
|
|
311
334
|
const additionalDevices = await getUSyncDevices(participantsList, !!useUserDevicesCache, false);
|
312
335
|
devices.push(...additionalDevices);
|
313
336
|
}
|
314
|
-
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : 's.whatsapp.net', d.device)));
|
337
|
+
const patched = await patchMessageBeforeSending(message, devices.map(d => (0, WABinary_1.jidEncode)(d.user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', d.device)));
|
315
338
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
316
339
|
const { ciphertext, senderKeyDistributionMessage } = await signalRepository.encryptGroupMessage({
|
317
340
|
group: destinationJid,
|
@@ -385,7 +408,7 @@ const makeMessagesSocket = (config) => {
|
|
385
408
|
const otherJids = [];
|
386
409
|
for (const { user, device } of devices) {
|
387
410
|
const isMe = user === meUser;
|
388
|
-
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : 's.whatsapp.net', device);
|
411
|
+
const jid = (0, WABinary_1.jidEncode)(isMe && isLid ? ((_f = (_e = authState.creds) === null || _e === void 0 ? void 0 : _e.me) === null || _f === void 0 ? void 0 : _f.lid.split(':')[0]) || user : user, isLid ? 'lid' : isGroup ? 'g.us' : isNewsletter ? 'newsletter' : 's.whatsapp.net', device);
|
389
412
|
if (isMe) {
|
390
413
|
meJids.push(jid);
|
391
414
|
}
|
@@ -449,26 +472,49 @@ const makeMessagesSocket = (config) => {
|
|
449
472
|
if (additionalNodes && additionalNodes.length > 0) {
|
450
473
|
stanza.content.push(...additionalNodes);
|
451
474
|
}
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
475
|
+
const inMsg = (0, Utils_1.normalizeMessageContent)(message) || null;
|
476
|
+
const key = inMsg ? (0, Utils_1.getContentType)(inMsg) : null;
|
477
|
+
if (!isNewsletter && (key === 'interactiveMessage' || key === 'buttonsMessage')) {
|
478
|
+
const nativeNode = {
|
479
|
+
tag: 'biz',
|
480
|
+
attrs: {},
|
481
|
+
content: [{
|
482
|
+
tag: 'interactive',
|
483
|
+
attrs: {
|
484
|
+
type: 'native_flow',
|
485
|
+
v: '1'
|
486
|
+
},
|
487
|
+
content: [{
|
488
|
+
tag: 'native_flow',
|
489
|
+
attrs: {
|
490
|
+
name: 'quick_reply',
|
491
|
+
}
|
492
|
+
}]
|
493
|
+
}]
|
494
|
+
};
|
495
|
+
const resultNativeNode = filterNativeNode(additionalNodes);
|
496
|
+
if (resultNativeNode && additionalNodes && additionalNodes.length > 0) {
|
497
|
+
stanza.content.push(...resultNativeNode);
|
498
|
+
}
|
499
|
+
else {
|
500
|
+
stanza.content.push(nativeNode);
|
501
|
+
}
|
502
|
+
}
|
503
|
+
if (isPrivate) {
|
504
|
+
const botNode = {
|
505
|
+
tag: 'bot',
|
506
|
+
attrs: { biz_bot: '1' }
|
507
|
+
};
|
508
|
+
const resultBotNode = filterBotNode(additionalNodes);
|
509
|
+
if (resultBotNode && additionalNodes && additionalNodes.length > 0) {
|
510
|
+
stanza.content.push(...resultBotNode);
|
511
|
+
}
|
512
|
+
else {
|
513
|
+
stanza.content.push(botNode);
|
469
514
|
}
|
470
515
|
}
|
471
|
-
const
|
516
|
+
const Msg = (0, Utils_1.normalizeMessageContent)(message) || null;
|
517
|
+
const buttonType = getButtonType(Msg);
|
472
518
|
if (buttonType) {
|
473
519
|
stanza.content.push({
|
474
520
|
tag: 'biz',
|
@@ -487,6 +533,32 @@ const makeMessagesSocket = (config) => {
|
|
487
533
|
});
|
488
534
|
return msgId;
|
489
535
|
};
|
536
|
+
const filterNativeNode = (nodeContent) => {
|
537
|
+
if (Array.isArray(nodeContent)) {
|
538
|
+
return nodeContent.filter((item) => {
|
539
|
+
if (item.tag === 'biz' && (item.content && item.content.filter((tag) => { tag.tag === 'interactive' && tag.attrs.type === 'native_flow' && tag.attrs.v === '1'; }))) {
|
540
|
+
return false;
|
541
|
+
}
|
542
|
+
return true;
|
543
|
+
});
|
544
|
+
}
|
545
|
+
else {
|
546
|
+
return nodeContent;
|
547
|
+
}
|
548
|
+
};
|
549
|
+
const filterBotNode = (nodeContent) => {
|
550
|
+
if (Array.isArray(nodeContent)) {
|
551
|
+
return nodeContent.filter((item) => {
|
552
|
+
if (item.tag === 'bot' && item.attrs.biz_bot === '1') {
|
553
|
+
return false;
|
554
|
+
}
|
555
|
+
return true;
|
556
|
+
});
|
557
|
+
}
|
558
|
+
else {
|
559
|
+
return nodeContent;
|
560
|
+
}
|
561
|
+
};
|
490
562
|
const getTypeMessage = (msg) => {
|
491
563
|
if (msg.viewOnceMessage) {
|
492
564
|
return getTypeMessage(msg.viewOnceMessage.message);
|
@@ -507,7 +579,7 @@ const makeMessagesSocket = (config) => {
|
|
507
579
|
return 'reaction';
|
508
580
|
}
|
509
581
|
else if (msg.pollCreationMessage || msg.pollCreationMessageV2 || msg.pollCreationMessageV3 || msg.pollUpdateMessage) {
|
510
|
-
return '
|
582
|
+
return 'poll';
|
511
583
|
}
|
512
584
|
else if (getMediaType(msg)) {
|
513
585
|
return 'media';
|
@@ -559,18 +631,12 @@ const makeMessagesSocket = (config) => {
|
|
559
631
|
else if (message.interactiveResponseMessage) {
|
560
632
|
return 'native_flow_response';
|
561
633
|
}
|
634
|
+
else if (message.groupInviteMessage) {
|
635
|
+
return 'url';
|
636
|
+
}
|
562
637
|
};
|
563
638
|
const getButtonType = (message) => {
|
564
|
-
if (message.
|
565
|
-
return 'buttons';
|
566
|
-
}
|
567
|
-
else if (message.buttonsResponseMessage) {
|
568
|
-
return 'buttons_response';
|
569
|
-
}
|
570
|
-
else if (message.interactiveResponseMessage) {
|
571
|
-
return 'interactive_response';
|
572
|
-
}
|
573
|
-
else if (message.listMessage) {
|
639
|
+
if (message.listMessage) {
|
574
640
|
return 'list';
|
575
641
|
}
|
576
642
|
else if (message.listResponseMessage) {
|
@@ -632,6 +698,7 @@ const makeMessagesSocket = (config) => {
|
|
632
698
|
readMessages,
|
633
699
|
refreshMediaConn,
|
634
700
|
getUSyncDevices,
|
701
|
+
sendPeerDataOperationMessage,
|
635
702
|
createParticipantNodes,
|
636
703
|
waUploadToServer,
|
637
704
|
fetchPrivacySettings,
|
@@ -652,7 +719,7 @@ const makeMessagesSocket = (config) => {
|
|
652
719
|
else {
|
653
720
|
try {
|
654
721
|
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
655
|
-
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
722
|
+
if (media && media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
656
723
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
657
724
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
658
725
|
}
|
@@ -676,6 +743,163 @@ const makeMessagesSocket = (config) => {
|
|
676
743
|
]);
|
677
744
|
return message;
|
678
745
|
},
|
746
|
+
sendStatusMentions: async (content, jids = []) => {
|
747
|
+
const userJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
748
|
+
let allUsers = [];
|
749
|
+
for (const id of jids) {
|
750
|
+
const { user, server } = (0, WABinary_1.jidDecode)(id);
|
751
|
+
const isGroup = server === 'g.us';
|
752
|
+
const isPrivate = server === 's.whatsapp.net';
|
753
|
+
if (isGroup) {
|
754
|
+
let userId = await groupMetadata(id);
|
755
|
+
let participant = await userId.participants;
|
756
|
+
let users = await Promise.all(participant.map(u => (0, WABinary_1.jidNormalizedUser)(u.id)));
|
757
|
+
allUsers = [...allUsers, ...users];
|
758
|
+
}
|
759
|
+
else if (isPrivate) {
|
760
|
+
let users = await Promise.all(jids.map(id => id.replace(/\b\d{18}@.{4}\b/g, '')));
|
761
|
+
allUsers = [...allUsers, ...users];
|
762
|
+
}
|
763
|
+
if (!allUsers.find(user => user.includes(userJid))) {
|
764
|
+
allUsers.push(userJid);
|
765
|
+
}
|
766
|
+
}
|
767
|
+
;
|
768
|
+
const getRandomHexColor = () => {
|
769
|
+
return "#" + Math.floor(Math.random() * 16777215)
|
770
|
+
.toString(16)
|
771
|
+
.padStart(6, "0");
|
772
|
+
};
|
773
|
+
let mediaHandle;
|
774
|
+
let msg = await (0, Utils_1.generateWAMessage)(WABinary_1.STORIES_JID, content, {
|
775
|
+
logger,
|
776
|
+
userJid,
|
777
|
+
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
778
|
+
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
779
|
+
fetchOpts: {
|
780
|
+
timeout: 3000,
|
781
|
+
...axiosOptions || {}
|
782
|
+
},
|
783
|
+
logger,
|
784
|
+
uploadImage: generateHighQualityLinkPreview
|
785
|
+
? waUploadToServer
|
786
|
+
: undefined
|
787
|
+
}),
|
788
|
+
upload: async (readStream, opts) => {
|
789
|
+
const up = await waUploadToServer(readStream, { ...opts });
|
790
|
+
mediaHandle = up.handle;
|
791
|
+
return up;
|
792
|
+
},
|
793
|
+
mediaCache: config.mediaCache,
|
794
|
+
options: config.options,
|
795
|
+
backgroundColor: getRandomHexColor(),
|
796
|
+
font: Math.floor(Math.random() * 9),
|
797
|
+
});
|
798
|
+
await relayMessage(WABinary_1.STORIES_JID, msg.message, {
|
799
|
+
messageId: msg.key.id,
|
800
|
+
statusJidList: allUsers,
|
801
|
+
additionalNodes: [
|
802
|
+
{
|
803
|
+
tag: 'meta',
|
804
|
+
attrs: {},
|
805
|
+
content: [
|
806
|
+
{
|
807
|
+
tag: 'mentioned_users',
|
808
|
+
attrs: {},
|
809
|
+
content: jids.map(jid => ({
|
810
|
+
tag: 'to',
|
811
|
+
attrs: { jid },
|
812
|
+
content: undefined,
|
813
|
+
})),
|
814
|
+
},
|
815
|
+
],
|
816
|
+
},
|
817
|
+
],
|
818
|
+
});
|
819
|
+
jids.forEach(async (id) => {
|
820
|
+
id = (0, WABinary_1.jidNormalizedUser)(id);
|
821
|
+
const { user, server } = (0, WABinary_1.jidDecode)(id);
|
822
|
+
const isPrivate = server === 's.whatsapp.net';
|
823
|
+
let type = isPrivate
|
824
|
+
? 'statusMentionMessage'
|
825
|
+
: 'groupStatusMentionMessage';
|
826
|
+
await relayMessage(id, {
|
827
|
+
[type]: {
|
828
|
+
message: {
|
829
|
+
protocolMessage: {
|
830
|
+
key: msg.key,
|
831
|
+
type: 25,
|
832
|
+
},
|
833
|
+
},
|
834
|
+
},
|
835
|
+
}, {});
|
836
|
+
await (0, Utils_1.delay)(2500);
|
837
|
+
});
|
838
|
+
return msg;
|
839
|
+
},
|
840
|
+
sendAlbumMessage: async (jid, medias, options = {}) => {
|
841
|
+
const userJid = authState.creds.me.id;
|
842
|
+
for (const media of medias) {
|
843
|
+
if (!media.image && !media.video)
|
844
|
+
throw new TypeError(`medias[i] must have image or video property`);
|
845
|
+
}
|
846
|
+
if (medias.length < 2)
|
847
|
+
throw new RangeError("Minimum 2 media");
|
848
|
+
const time = options.delay || 500;
|
849
|
+
delete options.delay;
|
850
|
+
const album = await (0, Utils_1.generateWAMessageFromContent)(jid, {
|
851
|
+
albumMessage: {
|
852
|
+
expectedImageCount: medias.filter(media => media.image).length,
|
853
|
+
expectedVideoCount: medias.filter(media => media.video).length,
|
854
|
+
...options
|
855
|
+
}
|
856
|
+
}, { userJid, ...options });
|
857
|
+
await relayMessage(jid, album.message, { messageId: album.key.id });
|
858
|
+
for (const i in medias) {
|
859
|
+
const media = medias[i];
|
860
|
+
let mediaHandle;
|
861
|
+
let msg;
|
862
|
+
if (media.image) {
|
863
|
+
msg = await (0, Utils_1.generateWAMessage)(jid, {
|
864
|
+
image: media.image,
|
865
|
+
...media,
|
866
|
+
...options
|
867
|
+
}, {
|
868
|
+
userJid,
|
869
|
+
upload: async (readStream, opts) => {
|
870
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
871
|
+
mediaHandle = up.handle;
|
872
|
+
return up;
|
873
|
+
},
|
874
|
+
...options,
|
875
|
+
});
|
876
|
+
}
|
877
|
+
else if (media.video) {
|
878
|
+
msg = await (0, Utils_1.generateWAMessage)(jid, {
|
879
|
+
video: media.video,
|
880
|
+
...media,
|
881
|
+
...options
|
882
|
+
}, {
|
883
|
+
userJid,
|
884
|
+
upload: async (readStream, opts) => {
|
885
|
+
const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsLetter)(jid) });
|
886
|
+
mediaHandle = up.handle;
|
887
|
+
return up;
|
888
|
+
},
|
889
|
+
...options,
|
890
|
+
});
|
891
|
+
}
|
892
|
+
msg.message.messageContextInfo = {
|
893
|
+
messageAssociation: {
|
894
|
+
associationType: 1,
|
895
|
+
parentMessageKey: album.key
|
896
|
+
}
|
897
|
+
};
|
898
|
+
await relayMessage(jid, msg.message, { messageId: msg.key.id });
|
899
|
+
await (0, Utils_1.delay)(time);
|
900
|
+
}
|
901
|
+
return album;
|
902
|
+
},
|
679
903
|
sendMessage: async (jid, content, options = {}) => {
|
680
904
|
var _a, _b;
|
681
905
|
const userJid = authState.creds.me.id;
|
@@ -714,9 +938,12 @@ const makeMessagesSocket = (config) => {
|
|
714
938
|
options: config.options,
|
715
939
|
...options,
|
716
940
|
});
|
717
|
-
const isDeleteMsg = 'delete' in content && !!content.delete;
|
718
|
-
const isEditMsg = 'edit' in content && !!content.edit;
|
719
941
|
const isAiMsg = 'ai' in content && !!content.ai;
|
942
|
+
const isPinMsg = 'pin' in content && !!content.pin;
|
943
|
+
const isKeepMsg = 'keep' in content && content.keep;
|
944
|
+
const isPollMsg = 'poll' in content && !!content.poll;
|
945
|
+
const isEditMsg = 'edit' in content && !!content.edit;
|
946
|
+
const isDeleteMsg = 'delete' in content && !!content.delete;
|
720
947
|
const additionalAttributes = {};
|
721
948
|
const additionalNodes = [];
|
722
949
|
// required for delete
|
@@ -732,13 +959,19 @@ const makeMessagesSocket = (config) => {
|
|
732
959
|
else if (isEditMsg) {
|
733
960
|
additionalAttributes.edit = (0, WABinary_1.isJidNewsLetter)(jid) ? '3' : '1';
|
734
961
|
}
|
962
|
+
else if (isPinMsg) {
|
963
|
+
additionalAttributes.edit = '2';
|
964
|
+
}
|
735
965
|
else if (isAiMsg) {
|
736
966
|
additionalNodes.push({
|
737
967
|
attrs: {
|
738
968
|
biz_bot: '1'
|
739
969
|
},
|
740
|
-
tag:
|
970
|
+
tag: 'bot'
|
741
971
|
});
|
972
|
+
if (options.additionalNodes) {
|
973
|
+
additionalNodes.push(...options.additionalNodes);
|
974
|
+
}
|
742
975
|
}
|
743
976
|
if (mediaHandle) {
|
744
977
|
additionalAttributes['media_id'] = mediaHandle;
|