@jkt48connect-corp/baileys 7.3.2 → 7.3.4
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 +459 -143
- package/WAProto/WAProto.proto +227 -2
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +9 -7
- package/lib/Defaults/index.js +6 -4
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +2 -3
- package/lib/Socket/Client/types.d.ts +17 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
- package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
- package/lib/Socket/business.d.ts +8 -3
- package/lib/Socket/chats.d.ts +21 -19
- package/lib/Socket/chats.js +51 -48
- package/lib/Socket/groups.d.ts +28 -26
- package/lib/Socket/groups.js +2 -1
- package/lib/Socket/index.d.ts +6 -3
- package/lib/Socket/messages-recv.d.ts +8 -3
- package/lib/Socket/messages-recv.js +308 -149
- package/lib/Socket/messages-send.d.ts +23 -26
- package/lib/Socket/messages-send.js +193 -166
- package/lib/Socket/newsletter.d.ts +2 -2
- package/lib/Socket/newsletter.js +3 -3
- package/lib/Socket/registration.d.ts +8 -3
- package/lib/Socket/socket.d.ts +8 -6
- package/lib/Socket/socket.js +19 -14
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/make-cache-manager-store.d.ts +2 -2
- package/lib/Store/make-ordered-dictionary.d.ts +1 -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/Message.d.ts +324 -328
- package/lib/Types/Socket.d.ts +7 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +9 -0
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.js +41 -20
- package/lib/Utils/crypto.d.ts +1 -1
- package/lib/Utils/crypto.js +4 -2
- package/lib/Utils/decode-wa-message.d.ts +17 -0
- package/lib/Utils/decode-wa-message.js +42 -14
- package/lib/Utils/generics.d.ts +4 -10
- package/lib/Utils/generics.js +30 -14
- package/lib/Utils/history.d.ts +6 -2
- package/lib/Utils/history.js +3 -0
- package/lib/Utils/messages.d.ts +0 -1
- package/lib/Utils/messages.js +247 -39
- package/lib/Utils/signal.d.ts +2 -1
- package/lib/Utils/signal.js +11 -19
- package/lib/Utils/use-multi-file-auth-state.js +11 -3
- package/lib/Utils/validate-connection.d.ts +2 -2
- package/lib/Utils/validate-connection.js +1 -1
- package/lib/WABinary/encode.d.ts +1 -1
- package/lib/WABinary/encode.js +16 -10
- 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.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +23 -18
- package/LICENSE +0 -21
- package/lib/index.ts +0 -13
@@ -1,31 +1,35 @@
|
|
1
1
|
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
2
|
import { Boom } from '@hapi/boom';
|
4
3
|
import { proto } from '../../WAProto';
|
5
|
-
import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
|
4
|
+
import { AnyMessageContent, Media, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, QueryIds, SocketConfig, WAMessageKey } from '../Types';
|
6
5
|
import { BinaryNode, JidWithDevice } from '../WABinary';
|
6
|
+
import { USyncQuery } from '../WAUSync';
|
7
7
|
export declare const makeMessagesSocket: (config: SocketConfig) => {
|
8
8
|
getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
|
9
9
|
assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
|
10
|
-
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, useUserDevicesCache,
|
10
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
|
11
11
|
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
|
12
12
|
sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
|
13
13
|
getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
|
14
14
|
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
15
15
|
refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
|
16
|
-
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
17
|
-
fetchPrivacySettings: (force?: boolean) => Promise<{
|
18
|
-
[_: string]: string;
|
19
|
-
}>;
|
20
16
|
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
|
17
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
21
18
|
createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
|
22
19
|
nodes: BinaryNode[];
|
23
20
|
shouldIncludeDeviceIdentity: boolean;
|
24
21
|
}>;
|
22
|
+
profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | null | undefined>;
|
23
|
+
waUploadToServer: import("../Types").WAMediaUploadFunction;
|
24
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
25
|
+
[_: string]: string;
|
26
|
+
}>;
|
25
27
|
updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
|
26
28
|
sendStatusMentions: (content: AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
|
27
29
|
sendAlbumMessage: (jid: string, medias: Media[], options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
|
28
30
|
sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
|
31
|
+
newsletterQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
|
32
|
+
newsletterWMexQuery: (jid: string | undefined, queryId: QueryIds, content?: object | undefined) => Promise<BinaryNode>;
|
29
33
|
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
30
34
|
duration: string;
|
31
35
|
}>;
|
@@ -38,15 +42,17 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
38
42
|
newsletterFollow: (jid: string) => Promise<void>;
|
39
43
|
newsletterUnmute: (jid: string) => Promise<void>;
|
40
44
|
newsletterMute: (jid: string) => Promise<void>;
|
45
|
+
newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
|
41
46
|
newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
|
42
47
|
newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
|
43
48
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
44
49
|
newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
|
45
50
|
newsletterDemote: (jid: string, user: string) => Promise<void>;
|
46
51
|
newsletterDelete: (jid: string) => Promise<void>;
|
47
|
-
newsletterReactMessage: (jid: string,
|
52
|
+
newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
|
48
53
|
newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
49
54
|
newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
|
55
|
+
groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
|
50
56
|
groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
|
51
57
|
groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
|
52
58
|
groupLeave: (id: string) => Promise<void>;
|
@@ -67,8 +73,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
67
73
|
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
68
74
|
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
69
75
|
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
70
|
-
|
71
|
-
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
76
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
|
72
77
|
groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
|
73
78
|
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
74
79
|
groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
|
@@ -77,35 +82,27 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
77
82
|
groupFetchAllParticipating: () => Promise<{
|
78
83
|
[_: string]: import("../Types").GroupMetadata;
|
79
84
|
}>;
|
85
|
+
interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
|
80
86
|
processingMutex: {
|
81
87
|
mutex<T>(code: () => T | Promise<T>): Promise<T>;
|
82
88
|
};
|
83
89
|
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
|
84
90
|
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
|
91
|
+
fetchUserLid: (jid: string) => Promise<string | undefined>;
|
85
92
|
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
|
86
93
|
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
|
87
|
-
profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
|
88
94
|
onWhatsApp: (...jids: string[]) => Promise<{
|
89
|
-
exists: boolean;
|
90
95
|
jid: string;
|
91
|
-
|
96
|
+
exists: unknown;
|
97
|
+
}[] | undefined>;
|
92
98
|
fetchBlocklist: () => Promise<string[]>;
|
93
|
-
|
94
|
-
|
95
|
-
duration: number;
|
96
|
-
setAt: Date;
|
97
|
-
}[]>;
|
98
|
-
fetchStatus: (...jids: string[]) => Promise<{
|
99
|
-
user: string;
|
100
|
-
status: string | null;
|
101
|
-
setAt: Date;
|
102
|
-
}[]>;
|
99
|
+
fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
100
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
|
103
101
|
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
|
104
102
|
removeProfilePicture: (jid: string) => Promise<void>;
|
105
103
|
updateProfileStatus: (status: string) => Promise<void>;
|
106
104
|
updateProfileName: (name: string) => Promise<void>;
|
107
105
|
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
108
|
-
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
|
109
106
|
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
110
107
|
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
|
111
108
|
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
|
@@ -125,6 +122,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
125
122
|
id: string;
|
126
123
|
fromMe?: boolean | undefined;
|
127
124
|
}[], star: boolean) => Promise<void>;
|
125
|
+
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
|
128
126
|
type: "md";
|
129
127
|
ws: any;
|
130
128
|
ev: import("../Types").BaileysEventEmitter & {
|
@@ -151,8 +149,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
|
|
151
149
|
onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
|
152
150
|
uploadPreKeys: (count?: number) => Promise<void>;
|
153
151
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
154
|
-
|
155
|
-
interaktiveMeta: (phoneNumber: string) => Promise<string>;
|
152
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
156
153
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
|
157
154
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
158
155
|
};
|
@@ -8,17 +8,19 @@ const boom_1 = require("@hapi/boom");
|
|
8
8
|
const node_cache_1 = __importDefault(require("node-cache"));
|
9
9
|
const WAProto_1 = require("../../WAProto");
|
10
10
|
const Defaults_1 = require("../Defaults");
|
11
|
+
const Types_1 = require("../Types");
|
11
12
|
const Utils_1 = require("../Utils");
|
12
13
|
const link_preview_1 = require("../Utils/link-preview");
|
13
14
|
const WABinary_1 = require("../WABinary");
|
15
|
+
const WAUSync_1 = require("../WAUSync");
|
14
16
|
const newsletter_1 = require("./newsletter");
|
15
17
|
var ListType = WAProto_1.proto.Message.ListMessage.ListType;
|
16
18
|
const makeMessagesSocket = (config) => {
|
17
19
|
const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
|
18
20
|
const sock = (0, newsletter_1.makeNewsletterSocket)(config);
|
19
|
-
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
|
21
|
+
const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupQuery, newsletterWMexQuery, groupToggleEphemeral } = sock;
|
20
22
|
const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
|
21
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
23
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
|
22
24
|
useClones: false
|
23
25
|
});
|
24
26
|
let mediaConn;
|
@@ -109,6 +111,43 @@ const makeMessagesSocket = (config) => {
|
|
109
111
|
const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
|
110
112
|
await sendReceipts(keys, readType);
|
111
113
|
};
|
114
|
+
const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
|
115
|
+
var _a, _b, _c, _d;
|
116
|
+
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
117
|
+
if ((0, WABinary_1.isJidNewsLetter)(jid)) {
|
118
|
+
const node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
119
|
+
input: {
|
120
|
+
key: jid,
|
121
|
+
type: "JID",
|
122
|
+
'view_role': 'GUEST'
|
123
|
+
},
|
124
|
+
'fetch_viewer_metadata': true,
|
125
|
+
'fetch_full_image': true,
|
126
|
+
'fetch_creation_time': true
|
127
|
+
});
|
128
|
+
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
129
|
+
const metadataPath = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER];
|
130
|
+
const pictype = type === 'image' ? 'picture' : 'preview';
|
131
|
+
const directPath = (_c = metadataPath === null || metadataPath === void 0 ? void 0 : metadataPath.thread_metadata[pictype]) === null || _c === void 0 ? void 0 : _c.direct_path;
|
132
|
+
return directPath ? (0, Utils_1.getUrlFromDirectPath)(directPath) : null;
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
const result = await query({
|
136
|
+
tag: 'iq',
|
137
|
+
attrs: {
|
138
|
+
target: jid,
|
139
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
140
|
+
type: 'get',
|
141
|
+
xmlns: 'w:profile:picture'
|
142
|
+
},
|
143
|
+
content: [
|
144
|
+
{ tag: 'picture', attrs: { type, query: 'url' } }
|
145
|
+
]
|
146
|
+
}, timeoutMs);
|
147
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
|
148
|
+
return (_d = child === null || child === void 0 ? void 0 : child.attrs) === null || _d === void 0 ? void 0 : _d.url;
|
149
|
+
}
|
150
|
+
};
|
112
151
|
/** Fetch all the devices we've to send a message to */
|
113
152
|
const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
|
114
153
|
var _a;
|
@@ -116,66 +155,46 @@ const makeMessagesSocket = (config) => {
|
|
116
155
|
if (!useCache) {
|
117
156
|
logger.debug('not using cache for devices');
|
118
157
|
}
|
119
|
-
const
|
158
|
+
const toFetch = [];
|
120
159
|
jids = Array.from(new Set(jids));
|
121
160
|
for (let jid of jids) {
|
122
161
|
const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
|
123
162
|
jid = (0, WABinary_1.jidNormalizedUser)(jid);
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
163
|
+
if (useCache) {
|
164
|
+
const devices = userDevicesCache.get(user);
|
165
|
+
if (devices) {
|
166
|
+
deviceResults.push(...devices);
|
167
|
+
logger.trace({ user }, 'using cache for devices');
|
168
|
+
}
|
169
|
+
else {
|
170
|
+
toFetch.push(jid);
|
171
|
+
}
|
128
172
|
}
|
129
173
|
else {
|
130
|
-
|
174
|
+
toFetch.push(jid);
|
131
175
|
}
|
132
176
|
}
|
133
|
-
if (!
|
177
|
+
if (!toFetch.length) {
|
134
178
|
return deviceResults;
|
135
179
|
}
|
136
|
-
const
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
{
|
155
|
-
tag: 'query',
|
156
|
-
attrs: {},
|
157
|
-
content: [
|
158
|
-
{
|
159
|
-
tag: 'devices',
|
160
|
-
attrs: { version: '2' }
|
161
|
-
}
|
162
|
-
]
|
163
|
-
},
|
164
|
-
{ tag: 'list', attrs: {}, content: users }
|
165
|
-
]
|
166
|
-
},
|
167
|
-
],
|
168
|
-
};
|
169
|
-
const result = await query(iq);
|
170
|
-
const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
|
171
|
-
const deviceMap = {};
|
172
|
-
for (const item of extracted) {
|
173
|
-
deviceMap[item.user] = deviceMap[item.user] || [];
|
174
|
-
deviceMap[item.user].push(item);
|
175
|
-
deviceResults.push(item);
|
176
|
-
}
|
177
|
-
for (const key in deviceMap) {
|
178
|
-
userDevicesCache.set(key, deviceMap[key]);
|
180
|
+
const query = new WAUSync_1.USyncQuery()
|
181
|
+
.withContext('message')
|
182
|
+
.withDeviceProtocol();
|
183
|
+
for (const jid of toFetch) {
|
184
|
+
query.withUser(new WAUSync_1.USyncUser().withId(jid));
|
185
|
+
}
|
186
|
+
const result = await sock.executeUSyncQuery(query);
|
187
|
+
if (result) {
|
188
|
+
const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
|
189
|
+
const deviceMap = {};
|
190
|
+
for (const item of extracted) {
|
191
|
+
deviceMap[item.user] = deviceMap[item.user] || [];
|
192
|
+
deviceMap[item.user].push(item);
|
193
|
+
deviceResults.push(item);
|
194
|
+
}
|
195
|
+
for (const key in deviceMap) {
|
196
|
+
userDevicesCache.set(key, deviceMap[key]);
|
197
|
+
}
|
179
198
|
}
|
180
199
|
return deviceResults;
|
181
200
|
};
|
@@ -222,6 +241,28 @@ const makeMessagesSocket = (config) => {
|
|
222
241
|
}
|
223
242
|
return didFetchNewSession;
|
224
243
|
};
|
244
|
+
const sendPeerDataOperationMessage = async (pdoMessage) => {
|
245
|
+
var _a;
|
246
|
+
//TODO: for later, abstract the logic to send a Peer Message instead of just PDO - useful for App State Key Resync with phone
|
247
|
+
if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
|
248
|
+
throw new boom_1.Boom('Not authenticated');
|
249
|
+
}
|
250
|
+
const protocolMessage = {
|
251
|
+
protocolMessage: {
|
252
|
+
peerDataOperationRequestMessage: pdoMessage,
|
253
|
+
type: WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE
|
254
|
+
}
|
255
|
+
};
|
256
|
+
const meJid = (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id);
|
257
|
+
const msgId = await relayMessage(meJid, protocolMessage, {
|
258
|
+
additionalAttributes: {
|
259
|
+
category: 'peer',
|
260
|
+
// eslint-disable-next-line camelcase
|
261
|
+
push_priority: 'high_force',
|
262
|
+
},
|
263
|
+
});
|
264
|
+
return msgId;
|
265
|
+
};
|
225
266
|
const createParticipantNodes = async (jids, message, extraAttrs) => {
|
226
267
|
const patched = await patchMessageBeforeSending(message, jids);
|
227
268
|
const bytes = (0, Utils_1.encodeWAMessage)(patched);
|
@@ -255,9 +296,9 @@ const makeMessagesSocket = (config) => {
|
|
255
296
|
const { user, server } = (0, WABinary_1.jidDecode)(jid);
|
256
297
|
const statusJid = 'status@broadcast';
|
257
298
|
const isGroup = server === 'g.us';
|
258
|
-
const isPrivate = server === 's.whatsapp.net';
|
259
299
|
const isStatus = jid === statusJid;
|
260
300
|
const isLid = server === 'lid';
|
301
|
+
const isPrivate = server === 's.whatsapp.net';
|
261
302
|
const isNewsletter = server === 'newsletter';
|
262
303
|
msgId = msgId || (0, Utils_1.generateMessageID)();
|
263
304
|
useUserDevicesCache = useUserDevicesCache !== false;
|
@@ -282,7 +323,7 @@ const makeMessagesSocket = (config) => {
|
|
282
323
|
devices.push({ user, device });
|
283
324
|
}
|
284
325
|
await authState.keys.transaction(async () => {
|
285
|
-
var _a, _b, _c, _d, _e, _f
|
326
|
+
var _a, _b, _c, _d, _e, _f;
|
286
327
|
const mediaType = getMediaType(message);
|
287
328
|
if (isGroup || isStatus) {
|
288
329
|
const [groupData, senderKeyMap] = await Promise.all([
|
@@ -447,94 +488,95 @@ const makeMessagesSocket = (config) => {
|
|
447
488
|
});
|
448
489
|
logger.debug({ jid }, 'adding device identity');
|
449
490
|
}
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
491
|
+
if (additionalNodes && additionalNodes.length > 0) {
|
492
|
+
stanza.content.push(...additionalNodes);
|
493
|
+
}
|
494
|
+
const inMsg = (0, Utils_1.normalizeMessageContent)(message) || null;
|
495
|
+
const key = inMsg ? (0, Utils_1.getContentType)(inMsg) : null;
|
496
|
+
if (!isNewsletter && (key === 'interactiveMessage' || key === 'buttonsMessage')) {
|
497
|
+
const nativeNode = {
|
498
|
+
tag: 'biz',
|
499
|
+
attrs: {},
|
500
|
+
content: [{
|
501
|
+
tag: 'interactive',
|
459
502
|
attrs: {
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
} else {
|
464
|
-
stanza.content.push({
|
465
|
-
tag: 'biz',
|
466
|
-
attrs: {},
|
503
|
+
type: 'native_flow',
|
504
|
+
v: '1'
|
505
|
+
},
|
467
506
|
content: [{
|
468
|
-
tag: 'interactive',
|
469
|
-
attrs: {
|
470
|
-
type: 'native_flow',
|
471
|
-
v: '1'
|
472
|
-
},
|
473
|
-
content: [{
|
474
507
|
tag: 'native_flow',
|
475
|
-
attrs: {
|
508
|
+
attrs: {
|
509
|
+
name: 'quick_reply'
|
510
|
+
}
|
476
511
|
}]
|
477
|
-
|
478
|
-
|
479
|
-
|
512
|
+
}]
|
513
|
+
};
|
514
|
+
const resultNativeNode = filterNativeNode(additionalNodes);
|
515
|
+
if (resultNativeNode && additionalNodes && additionalNodes.length > 0) {
|
516
|
+
stanza.content.push(...resultNativeNode);
|
480
517
|
}
|
481
|
-
|
482
|
-
|
483
|
-
if (!stanza.content || !Array.isArray(stanza.content)) {
|
484
|
-
stanza.content = [];
|
485
|
-
}
|
486
|
-
stanza.content.push({
|
487
|
-
tag: "biz",
|
488
|
-
attrs: {},
|
489
|
-
content: [
|
490
|
-
{
|
491
|
-
tag: "list",
|
492
|
-
attrs: {
|
493
|
-
v: "2",
|
494
|
-
type: "product_list"
|
495
|
-
}
|
496
|
-
}
|
497
|
-
]
|
498
|
-
})
|
518
|
+
else {
|
519
|
+
stanza.content.push(nativeNode);
|
499
520
|
}
|
500
|
-
|
501
|
-
/*if (message?.templateMessage) {
|
502
|
-
if (!stanza.content || !Array.isArray(stanza.content)) {
|
503
|
-
stanza.content = [];
|
504
|
-
}
|
505
|
-
stanza.content.push({
|
506
|
-
tag: "hsm",
|
507
|
-
attrs: {
|
508
|
-
category: '',
|
509
|
-
tag: 'AUTHENTICATION'
|
510
|
-
}
|
511
|
-
}, {
|
512
|
-
tag: 'biz',
|
513
|
-
attrs: {}
|
514
|
-
})
|
515
|
-
}*/
|
516
521
|
}
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
522
|
+
if (isPrivate) {
|
523
|
+
const botNode = {
|
524
|
+
tag: 'bot',
|
525
|
+
attrs: { biz_bot: '1' }
|
526
|
+
};
|
527
|
+
const resultBotNode = filterBotNode(additionalNodes);
|
528
|
+
if (resultBotNode && additionalNodes && additionalNodes.length > 0) {
|
529
|
+
stanza.content.push(...resultBotNode);
|
521
530
|
}
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
if (isPrivate && !additionalNodes) {
|
526
|
-
if (!stanza.content || !Array.isArray(stanza.content)) {
|
527
|
-
stanza.content = [];
|
531
|
+
else {
|
532
|
+
stanza.content.push(botNode);
|
528
533
|
}
|
529
|
-
const botsChat = [ { attrs: { biz_bot: '1' }, tag: 'bot' }]
|
530
|
-
stanza.content.push(...botsChat);
|
531
534
|
}
|
532
|
-
|
535
|
+
if (message && message.listMessage) {
|
536
|
+
stanza.content.push({
|
537
|
+
tag: 'biz',
|
538
|
+
attrs: {},
|
539
|
+
content: [
|
540
|
+
{
|
541
|
+
tag: 'list',
|
542
|
+
attrs: getButtonArgs(message)
|
543
|
+
}
|
544
|
+
]
|
545
|
+
});
|
546
|
+
logger.debug({ jid }, 'adding business node');
|
547
|
+
}
|
533
548
|
logger.debug({ msgId }, `sending message to ${participants.length} devices`);
|
534
549
|
await sendNode(stanza);
|
535
550
|
});
|
536
551
|
return msgId;
|
537
552
|
};
|
553
|
+
const filterNativeNode = (nodeContent) => {
|
554
|
+
if (Array.isArray(nodeContent)) {
|
555
|
+
return nodeContent.filter((item) => {
|
556
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
557
|
+
if (item.tag === 'biz' && ((_a = item === null || item === void 0 ? void 0 : item.content[0]) === null || _a === void 0 ? void 0 : _a.tag) === 'interactive' && ((_c = (_b = item === null || item === void 0 ? void 0 : item.content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.type) === 'native_flow' && ((_e = (_d = item === null || item === void 0 ? void 0 : item.content[0]) === null || _d === void 0 ? void 0 : _d.content[0]) === null || _e === void 0 ? void 0 : _e.tag) === 'native_flow' && ((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.content[0]) === null || _f === void 0 ? void 0 : _f.content[0]) === null || _g === void 0 ? void 0 : _g.attrs) === null || _h === void 0 ? void 0 : _h.name) === 'quick_reply') {
|
558
|
+
return false;
|
559
|
+
}
|
560
|
+
return true;
|
561
|
+
});
|
562
|
+
}
|
563
|
+
else {
|
564
|
+
return nodeContent;
|
565
|
+
}
|
566
|
+
};
|
567
|
+
const filterBotNode = (nodeContent) => {
|
568
|
+
if (Array.isArray(nodeContent)) {
|
569
|
+
return nodeContent.filter((item) => {
|
570
|
+
if (item.tag === 'bot' && item.attrs.biz_bot === '1') {
|
571
|
+
return false;
|
572
|
+
}
|
573
|
+
return true;
|
574
|
+
});
|
575
|
+
}
|
576
|
+
else {
|
577
|
+
return nodeContent;
|
578
|
+
}
|
579
|
+
};
|
538
580
|
const getTypeMessage = (msg) => {
|
539
581
|
if (msg.viewOnceMessage) {
|
540
582
|
return getTypeMessage(msg.viewOnceMessage.message);
|
@@ -611,23 +653,6 @@ const makeMessagesSocket = (config) => {
|
|
611
653
|
return 'url';
|
612
654
|
}
|
613
655
|
};
|
614
|
-
const getButtonType = (message) => {
|
615
|
-
if (message.buttonsMessage) {
|
616
|
-
return 'buttons';
|
617
|
-
}
|
618
|
-
else if (message.buttonsResponseMessage) {
|
619
|
-
return 'buttons_response';
|
620
|
-
}
|
621
|
-
else if (message.interactiveResponseMessage) {
|
622
|
-
return 'interactive_response';
|
623
|
-
}
|
624
|
-
else if (message.listMessage) {
|
625
|
-
return 'list';
|
626
|
-
}
|
627
|
-
else if (message.listResponseMessage) {
|
628
|
-
return 'list_response';
|
629
|
-
}
|
630
|
-
};
|
631
656
|
const getButtonArgs = (message) => {
|
632
657
|
if (message.templateMessage) {
|
633
658
|
// TODO: Add attributes
|
@@ -683,7 +708,9 @@ const makeMessagesSocket = (config) => {
|
|
683
708
|
readMessages,
|
684
709
|
refreshMediaConn,
|
685
710
|
getUSyncDevices,
|
711
|
+
sendPeerDataOperationMessage,
|
686
712
|
createParticipantNodes,
|
713
|
+
profilePictureUrl,
|
687
714
|
waUploadToServer,
|
688
715
|
fetchPrivacySettings,
|
689
716
|
updateMediaMessage: async (message) => {
|
@@ -703,7 +730,7 @@ const makeMessagesSocket = (config) => {
|
|
703
730
|
else {
|
704
731
|
try {
|
705
732
|
const media = (0, Utils_1.decryptMediaRetryData)(result.media, mediaKey, result.key.id);
|
706
|
-
if (media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
733
|
+
if (media && media.result !== WAProto_1.proto.MediaRetryNotification.ResultType.SUCCESS) {
|
707
734
|
const resultStr = WAProto_1.proto.MediaRetryNotification.ResultType[media.result];
|
708
735
|
throw new boom_1.Boom(`Media re-upload failed by device (${resultStr})`, { data: media, statusCode: (0, Utils_1.getStatusCodeForMediaRetry)(media.result) || 404 });
|
709
736
|
}
|
@@ -887,7 +914,7 @@ const makeMessagesSocket = (config) => {
|
|
887
914
|
return album;
|
888
915
|
},
|
889
916
|
sendMessage: async (jid, content, options = {}) => {
|
890
|
-
var _a, _b;
|
917
|
+
var _a, _b, _c;
|
891
918
|
const userJid = authState.creds.me.id;
|
892
919
|
if (typeof content === 'object' &&
|
893
920
|
'disappearingMessagesInChat' in content &&
|
@@ -901,9 +928,24 @@ const makeMessagesSocket = (config) => {
|
|
901
928
|
}
|
902
929
|
else {
|
903
930
|
let mediaHandle;
|
931
|
+
const { server } = (0, WABinary_1.jidDecode)(jid);
|
932
|
+
const isGroup = server === 'g.us';
|
933
|
+
let eph;
|
934
|
+
if (isGroup) {
|
935
|
+
const disappearingNode = await groupQuery(jid, 'get', [
|
936
|
+
{
|
937
|
+
tag: 'query',
|
938
|
+
attrs: { request: 'interactive' }
|
939
|
+
}
|
940
|
+
]);
|
941
|
+
const group = (0, WABinary_1.getBinaryNodeChild)(disappearingNode, 'group');
|
942
|
+
const expiration = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral');
|
943
|
+
eph = (_a = expiration === null || expiration === void 0 ? void 0 : expiration.attrs) === null || _a === void 0 ? void 0 : _a.expiration;
|
944
|
+
}
|
904
945
|
const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
|
905
946
|
logger,
|
906
947
|
userJid,
|
948
|
+
ephemeralExpiration: (options.ephemeralExpiration && options.ephemeralExpiration > 0) ? options.ephemeralExpiration : eph,
|
907
949
|
getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
|
908
950
|
thumbnailWidth: linkPreviewImageThumbnailWidth,
|
909
951
|
fetchOpts: {
|
@@ -930,16 +972,12 @@ const makeMessagesSocket = (config) => {
|
|
930
972
|
const isPollMsg = 'poll' in content && !!content.poll;
|
931
973
|
const isEditMsg = 'edit' in content && !!content.edit;
|
932
974
|
const isDeleteMsg = 'delete' in content && !!content.delete;
|
933
|
-
const isButtonsMsg = 'buttons' in content && !!content.buttons;
|
934
|
-
const isListMsg = 'sections' in content && !!content.sections;
|
935
|
-
const isTemplateButtons = 'templateButtons' in content && !!content.templateButtons;
|
936
|
-
const isInteractiveButtons = 'interactiveButtons' in content && !!content.interactiveButtons;
|
937
975
|
const additionalAttributes = {};
|
938
976
|
const additionalNodes = [];
|
939
977
|
// required for delete
|
940
978
|
if (isDeleteMsg) {
|
941
979
|
// if the chat is a group, and I am not the author, then delete the message as an admin
|
942
|
-
if (((0, WABinary_1.isJidGroup)((
|
980
|
+
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)) {
|
943
981
|
additionalAttributes.edit = '8';
|
944
982
|
}
|
945
983
|
else {
|
@@ -952,27 +990,16 @@ const makeMessagesSocket = (config) => {
|
|
952
990
|
else if (isPinMsg) {
|
953
991
|
additionalAttributes.edit = '2';
|
954
992
|
}
|
955
|
-
else if (isKeepMsg) {
|
956
|
-
additionalAttributes.edit = '6';
|
957
|
-
}
|
958
|
-
else if (isButtonsMsg) {
|
959
|
-
}
|
960
|
-
else if (isListMsg) {
|
961
|
-
}
|
962
|
-
else if (isTemplateButtons) {
|
963
|
-
}
|
964
|
-
else if (isInteractiveButtons) {
|
965
|
-
}
|
966
993
|
else if (isAiMsg) {
|
967
994
|
additionalNodes.push({
|
968
995
|
attrs: {
|
969
996
|
biz_bot: '1'
|
970
997
|
},
|
971
|
-
tag:
|
972
|
-
}, {
|
973
|
-
attrs: {},
|
974
|
-
tag: "biz"
|
998
|
+
tag: 'bot'
|
975
999
|
});
|
1000
|
+
if (options.additionalNodes) {
|
1001
|
+
additionalNodes.push(...options.additionalNodes);
|
1002
|
+
}
|
976
1003
|
}
|
977
1004
|
if (mediaHandle) {
|
978
1005
|
additionalAttributes['media_id'] = mediaHandle;
|
@@ -14,7 +14,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
14
14
|
newsletterUnmute: (jid: string) => Promise<void>;
|
15
15
|
newsletterMute: (jid: string) => Promise<void>;
|
16
16
|
newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
|
17
|
-
newsletterCreate: (name: string, description: string
|
17
|
+
newsletterCreate: (name: string, description: string) => Promise<NewsletterMetadata>;
|
18
18
|
newsletterMetadata: (type: "invite" | "jid", key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>;
|
19
19
|
newsletterAdminCount: (jid: string) => Promise<number>;
|
20
20
|
/**user is Lid, not Jid */
|
@@ -125,7 +125,7 @@ export declare const makeNewsletterSocket: (config: SocketConfig) => {
|
|
125
125
|
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
126
126
|
uploadPreKeys: (count?: number) => Promise<void>;
|
127
127
|
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
128
|
-
requestPairingCode: (phoneNumber: string) => Promise<string>;
|
128
|
+
requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
|
129
129
|
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
|
130
130
|
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
|
131
131
|
};
|