@gara31/void-baileys 7.0.0-rc.10
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 +21 -0
- package/WAProto/index.js +117292 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.js +116 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.js +42 -0
- package/lib/Signal/Group/group_cipher.js +109 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +67 -0
- package/lib/Signal/Group/sender-key-message.js +80 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +47 -0
- package/lib/Signal/Group/sender-key-state.js +105 -0
- package/lib/Signal/Group/sender-message-key.js +30 -0
- package/lib/Signal/libsignal.js +416 -0
- package/lib/Signal/lid-mapping.js +189 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.js +61 -0
- package/lib/Socket/business.js +404 -0
- package/lib/Socket/chats.js +1146 -0
- package/lib/Socket/communities.js +505 -0
- package/lib/Socket/groups.js +404 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/messages-recv.js +1600 -0
- package/lib/Socket/messages-send.js +1203 -0
- package/lib/Socket/mex.js +56 -0
- package/lib/Socket/newsletter.js +240 -0
- package/lib/Socket/socket.js +1060 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.js +13 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +32 -0
- package/lib/Utils/auth-utils.js +276 -0
- package/lib/Utils/browser-utils.js +32 -0
- package/lib/Utils/business.js +262 -0
- package/lib/Utils/chat-utils.js +941 -0
- package/lib/Utils/crypto.js +179 -0
- package/lib/Utils/decode-wa-message.js +333 -0
- package/lib/Utils/event-buffer.js +580 -0
- package/lib/Utils/generics.js +436 -0
- package/lib/Utils/history.js +103 -0
- package/lib/Utils/index.js +19 -0
- package/lib/Utils/link-preview.js +105 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.js +56 -0
- package/lib/Utils/make-mutex.js +38 -0
- package/lib/Utils/message-retry-manager.js +181 -0
- package/lib/Utils/messages-media.js +727 -0
- package/lib/Utils/messages.js +1309 -0
- package/lib/Utils/noise-handler.js +162 -0
- package/lib/Utils/pre-key-manager.js +125 -0
- package/lib/Utils/process-message.js +594 -0
- package/lib/Utils/signal.js +194 -0
- package/lib/Utils/use-multi-file-auth-state.js +118 -0
- package/lib/Utils/validate-connection.js +240 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.js +240 -0
- package/lib/WABinary/encode.js +216 -0
- package/lib/WABinary/generic-utils.js +104 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.js +22863 -0
- package/lib/WAM/encode.js +152 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +60 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.js +104 -0
- package/lib/WAUSync/USyncUser.js +23 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.js +11 -0
- package/package.json +31 -0
- package/readme.md +522 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { LRUCache } from "lru-cache";
|
|
2
|
+
import {
|
|
3
|
+
isHostedPnUser,
|
|
4
|
+
isLidUser,
|
|
5
|
+
isPnUser,
|
|
6
|
+
jidDecode,
|
|
7
|
+
jidNormalizedUser,
|
|
8
|
+
WAJIDDomains,
|
|
9
|
+
} from "../WABinary/index.js";
|
|
10
|
+
export class LIDMappingStore {
|
|
11
|
+
constructor(keys, logger, pnToLIDFunc) {
|
|
12
|
+
this.mappingCache = new LRUCache({
|
|
13
|
+
ttl: 3 * 24 * 60 * 60 * 1000, // 7 days
|
|
14
|
+
ttlAutopurge: true,
|
|
15
|
+
updateAgeOnGet: true,
|
|
16
|
+
});
|
|
17
|
+
this.keys = keys;
|
|
18
|
+
this.pnToLIDFunc = pnToLIDFunc;
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Store LID-PN mapping - USER LEVEL
|
|
23
|
+
*/
|
|
24
|
+
async storeLIDPNMappings(pairs) {
|
|
25
|
+
// Validate inputs
|
|
26
|
+
const pairMap = {};
|
|
27
|
+
for (const { lid, pn } of pairs) {
|
|
28
|
+
if (
|
|
29
|
+
!((isLidUser(lid) && isPnUser(pn)) || (isPnUser(lid) && isLidUser(pn)))
|
|
30
|
+
) {
|
|
31
|
+
this.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const lidDecoded = jidDecode(lid);
|
|
35
|
+
const pnDecoded = jidDecode(pn);
|
|
36
|
+
if (!lidDecoded || !pnDecoded) return;
|
|
37
|
+
const pnUser = pnDecoded.user;
|
|
38
|
+
const lidUser = lidDecoded.user;
|
|
39
|
+
let existingLidUser = this.mappingCache.get(`pn:${pnUser}`);
|
|
40
|
+
if (!existingLidUser) {
|
|
41
|
+
this.logger.trace(
|
|
42
|
+
`Cache miss for PN user ${pnUser}; checking database`,
|
|
43
|
+
);
|
|
44
|
+
const stored = await this.keys.get("lid-mapping", [pnUser]);
|
|
45
|
+
existingLidUser = stored[pnUser];
|
|
46
|
+
if (existingLidUser) {
|
|
47
|
+
// Update cache with database value
|
|
48
|
+
this.mappingCache.set(`pn:${pnUser}`, existingLidUser);
|
|
49
|
+
this.mappingCache.set(`lid:${existingLidUser}`, pnUser);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (existingLidUser === lidUser) {
|
|
53
|
+
this.logger.debug(
|
|
54
|
+
{ pnUser, lidUser },
|
|
55
|
+
"LID mapping already exists, skipping",
|
|
56
|
+
);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
pairMap[pnUser] = lidUser;
|
|
60
|
+
}
|
|
61
|
+
this.logger.trace(
|
|
62
|
+
{ pairMap },
|
|
63
|
+
`Storing ${Object.keys(pairMap).length} pn mappings`,
|
|
64
|
+
);
|
|
65
|
+
await this.keys.transaction(async () => {
|
|
66
|
+
for (const [pnUser, lidUser] of Object.entries(pairMap)) {
|
|
67
|
+
await this.keys.set({
|
|
68
|
+
"lid-mapping": {
|
|
69
|
+
[pnUser]: lidUser,
|
|
70
|
+
[`${lidUser}_reverse`]: pnUser,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
this.mappingCache.set(`pn:${pnUser}`, lidUser);
|
|
74
|
+
this.mappingCache.set(`lid:${lidUser}`, pnUser);
|
|
75
|
+
}
|
|
76
|
+
}, "lid-mapping");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get LID for PN - Returns device-specific LID based on user mapping
|
|
80
|
+
*/
|
|
81
|
+
async getLIDForPN(pn) {
|
|
82
|
+
return (await this.getLIDsForPNs([pn]))?.[0]?.lid || null;
|
|
83
|
+
}
|
|
84
|
+
async getLIDsForPNs(pns) {
|
|
85
|
+
const usyncFetch = {};
|
|
86
|
+
// mapped from pn to lid mapping to prevent duplication in results later
|
|
87
|
+
const successfulPairs = {};
|
|
88
|
+
for (const pn of pns) {
|
|
89
|
+
if (!isPnUser(pn) && !isHostedPnUser(pn)) continue;
|
|
90
|
+
const decoded = jidDecode(pn);
|
|
91
|
+
if (!decoded) continue;
|
|
92
|
+
// Check cache first for PN → LID mapping
|
|
93
|
+
const pnUser = decoded.user;
|
|
94
|
+
let lidUser = this.mappingCache.get(`pn:${pnUser}`);
|
|
95
|
+
if (!lidUser) {
|
|
96
|
+
// Cache miss - check database
|
|
97
|
+
const stored = await this.keys.get("lid-mapping", [pnUser]);
|
|
98
|
+
lidUser = stored[pnUser];
|
|
99
|
+
if (lidUser) {
|
|
100
|
+
this.mappingCache.set(`pn:${pnUser}`, lidUser);
|
|
101
|
+
this.mappingCache.set(`lid:${lidUser}`, pnUser);
|
|
102
|
+
} else {
|
|
103
|
+
this.logger.trace(
|
|
104
|
+
`No LID mapping found for PN user ${pnUser}; batch getting from USync`,
|
|
105
|
+
);
|
|
106
|
+
const device = decoded.device || 0;
|
|
107
|
+
let normalizedPn = jidNormalizedUser(pn);
|
|
108
|
+
if (isHostedPnUser(normalizedPn)) {
|
|
109
|
+
normalizedPn = `${pnUser}@s.whatsapp.net`;
|
|
110
|
+
}
|
|
111
|
+
if (!usyncFetch[normalizedPn]) {
|
|
112
|
+
usyncFetch[normalizedPn] = [device];
|
|
113
|
+
} else {
|
|
114
|
+
usyncFetch[normalizedPn]?.push(device);
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
lidUser = lidUser.toString();
|
|
120
|
+
if (!lidUser) {
|
|
121
|
+
this.logger.warn(
|
|
122
|
+
`Invalid or empty LID user for PN ${pn}: lidUser = "${lidUser}"`,
|
|
123
|
+
);
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
// Push the PN device ID to the LID to maintain device separation
|
|
127
|
+
const pnDevice = decoded.device !== undefined ? decoded.device : 0;
|
|
128
|
+
const deviceSpecificLid = `${lidUser}${!!pnDevice ? `:${pnDevice}` : ``}@${decoded.server === "hosted" ? "hosted.lid" : "lid"}`;
|
|
129
|
+
this.logger.trace(
|
|
130
|
+
`getLIDForPN: ${pn} → ${deviceSpecificLid} (user mapping with device ${pnDevice})`,
|
|
131
|
+
);
|
|
132
|
+
successfulPairs[pn] = { lid: deviceSpecificLid, pn };
|
|
133
|
+
}
|
|
134
|
+
if (Object.keys(usyncFetch).length > 0) {
|
|
135
|
+
const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch)); // this function already adds LIDs to mapping
|
|
136
|
+
if (result && result.length > 0) {
|
|
137
|
+
await this.storeLIDPNMappings(result);
|
|
138
|
+
for (const pair of result) {
|
|
139
|
+
const pnDecoded = jidDecode(pair.pn);
|
|
140
|
+
const pnUser = pnDecoded?.user;
|
|
141
|
+
if (!pnUser) continue;
|
|
142
|
+
const lidUser = jidDecode(pair.lid)?.user;
|
|
143
|
+
if (!lidUser) continue;
|
|
144
|
+
for (const device of usyncFetch[pair.pn]) {
|
|
145
|
+
const deviceSpecificLid = `${lidUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted.lid" : "lid"}`;
|
|
146
|
+
this.logger.trace(
|
|
147
|
+
`getLIDForPN: USYNC success for ${pair.pn} → ${deviceSpecificLid} (user mapping with device ${device})`,
|
|
148
|
+
);
|
|
149
|
+
const deviceSpecificPn = `${pnUser}${!!device ? `:${device}` : ``}@${device === 99 ? "hosted" : "s.whatsapp.net"}`;
|
|
150
|
+
successfulPairs[deviceSpecificPn] = {
|
|
151
|
+
lid: deviceSpecificLid,
|
|
152
|
+
pn: deviceSpecificPn,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return Object.values(successfulPairs);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get PN for LID - USER LEVEL with device construction
|
|
164
|
+
*/
|
|
165
|
+
async getPNForLID(lid) {
|
|
166
|
+
if (!isLidUser(lid)) return null;
|
|
167
|
+
const decoded = jidDecode(lid);
|
|
168
|
+
if (!decoded) return null;
|
|
169
|
+
// Check cache first for LID → PN mapping
|
|
170
|
+
const lidUser = decoded.user;
|
|
171
|
+
let pnUser = this.mappingCache.get(`lid:${lidUser}`);
|
|
172
|
+
if (!pnUser || typeof pnUser !== "string") {
|
|
173
|
+
// Cache miss - check database
|
|
174
|
+
const stored = await this.keys.get("lid-mapping", [`${lidUser}_reverse`]);
|
|
175
|
+
pnUser = stored[`${lidUser}_reverse`];
|
|
176
|
+
if (!pnUser || typeof pnUser !== "string") {
|
|
177
|
+
this.logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
this.mappingCache.set(`lid:${lidUser}`, pnUser);
|
|
181
|
+
}
|
|
182
|
+
// Construct device-specific PN JID
|
|
183
|
+
const lidDevice = decoded.device !== undefined ? decoded.device : 0;
|
|
184
|
+
const pnJid = `${pnUser}:${lidDevice}@${decoded.domainType === WAJIDDomains.HOSTED_LID ? "hosted" : "s.whatsapp.net"}`;
|
|
185
|
+
this.logger.trace(`Found reverse mapping: ${lid} → ${pnJid}`);
|
|
186
|
+
return pnJid;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
//# sourceMappingURL=lid-mapping.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { URL } from "url";
|
|
3
|
+
export class AbstractSocketClient extends EventEmitter {
|
|
4
|
+
constructor(url, config) {
|
|
5
|
+
super();
|
|
6
|
+
this.url = url;
|
|
7
|
+
this.config = config;
|
|
8
|
+
this.setMaxListeners(0);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import WebSocket from "ws";
|
|
2
|
+
import { DEFAULT_ORIGIN } from "../../Defaults/index.js";
|
|
3
|
+
import { AbstractSocketClient } from "./types.js";
|
|
4
|
+
export class WebSocketClient extends AbstractSocketClient {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.socket = null;
|
|
8
|
+
}
|
|
9
|
+
get isOpen() {
|
|
10
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
11
|
+
}
|
|
12
|
+
get isClosed() {
|
|
13
|
+
return this.socket === null || this.socket?.readyState === WebSocket.CLOSED;
|
|
14
|
+
}
|
|
15
|
+
get isClosing() {
|
|
16
|
+
return (
|
|
17
|
+
this.socket === null || this.socket?.readyState === WebSocket.CLOSING
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
get isConnecting() {
|
|
21
|
+
return this.socket?.readyState === WebSocket.CONNECTING;
|
|
22
|
+
}
|
|
23
|
+
connect() {
|
|
24
|
+
if (this.socket) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
this.socket = new WebSocket(this.url, {
|
|
28
|
+
origin: DEFAULT_ORIGIN,
|
|
29
|
+
headers: this.config.options?.headers,
|
|
30
|
+
handshakeTimeout: this.config.connectTimeoutMs,
|
|
31
|
+
timeout: this.config.connectTimeoutMs,
|
|
32
|
+
agent: this.config.agent,
|
|
33
|
+
});
|
|
34
|
+
this.socket.setMaxListeners(0);
|
|
35
|
+
const events = [
|
|
36
|
+
"close",
|
|
37
|
+
"error",
|
|
38
|
+
"upgrade",
|
|
39
|
+
"message",
|
|
40
|
+
"open",
|
|
41
|
+
"ping",
|
|
42
|
+
"pong",
|
|
43
|
+
"unexpected-response",
|
|
44
|
+
];
|
|
45
|
+
for (const event of events) {
|
|
46
|
+
this.socket?.on(event, (...args) => this.emit(event, ...args));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
close() {
|
|
50
|
+
if (!this.socket) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
this.socket.close();
|
|
54
|
+
this.socket = null;
|
|
55
|
+
}
|
|
56
|
+
send(str, cb) {
|
|
57
|
+
this.socket?.send(str, cb);
|
|
58
|
+
return Boolean(this.socket);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { getRawMediaUploadData } from "../Utils/index.js";
|
|
2
|
+
import {
|
|
3
|
+
parseCatalogNode,
|
|
4
|
+
parseCollectionsNode,
|
|
5
|
+
parseOrderDetailsNode,
|
|
6
|
+
parseProductNode,
|
|
7
|
+
toProductNode,
|
|
8
|
+
uploadingNecessaryImagesOfProduct,
|
|
9
|
+
} from "../Utils/business.js";
|
|
10
|
+
import { jidNormalizedUser, S_WHATSAPP_NET } from "../WABinary/index.js";
|
|
11
|
+
import { getBinaryNodeChild } from "../WABinary/generic-utils.js";
|
|
12
|
+
import { makeMessagesRecvSocket } from "./messages-recv.js";
|
|
13
|
+
export const makeBusinessSocket = (config) => {
|
|
14
|
+
const sock = makeMessagesRecvSocket(config);
|
|
15
|
+
const { authState, query, waUploadToServer } = sock;
|
|
16
|
+
const updateBussinesProfile = async (args) => {
|
|
17
|
+
const node = [];
|
|
18
|
+
const simpleFields = ["address", "email", "description"];
|
|
19
|
+
node.push(
|
|
20
|
+
...simpleFields
|
|
21
|
+
.filter((key) => args[key])
|
|
22
|
+
.map((key) => ({
|
|
23
|
+
tag: key,
|
|
24
|
+
attrs: {},
|
|
25
|
+
content: args[key],
|
|
26
|
+
})),
|
|
27
|
+
);
|
|
28
|
+
if (args.websites) {
|
|
29
|
+
node.push(
|
|
30
|
+
...args.websites.map((website) => ({
|
|
31
|
+
tag: "website",
|
|
32
|
+
attrs: {},
|
|
33
|
+
content: website,
|
|
34
|
+
})),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (args.hours) {
|
|
38
|
+
node.push({
|
|
39
|
+
tag: "business_hours",
|
|
40
|
+
attrs: { timezone: args.hours.timezone },
|
|
41
|
+
content: args.hours.days.map((config) => {
|
|
42
|
+
const base = {
|
|
43
|
+
tag: "business_hours_config",
|
|
44
|
+
attrs: { day_of_week: config.day, mode: config.mode },
|
|
45
|
+
};
|
|
46
|
+
if (config.mode === "specific_hours") {
|
|
47
|
+
return {
|
|
48
|
+
...base,
|
|
49
|
+
attrs: {
|
|
50
|
+
...base.attrs,
|
|
51
|
+
open_time: config.openTimeInMinutes,
|
|
52
|
+
close_time: config.closeTimeInMinutes,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return base;
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const result = await query({
|
|
61
|
+
tag: "iq",
|
|
62
|
+
attrs: {
|
|
63
|
+
to: S_WHATSAPP_NET,
|
|
64
|
+
type: "set",
|
|
65
|
+
xmlns: "w:biz",
|
|
66
|
+
},
|
|
67
|
+
content: [
|
|
68
|
+
{
|
|
69
|
+
tag: "business_profile",
|
|
70
|
+
attrs: {
|
|
71
|
+
v: "3",
|
|
72
|
+
mutation_type: "delta",
|
|
73
|
+
},
|
|
74
|
+
content: node,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
const updateCoverPhoto = async (photo) => {
|
|
81
|
+
const { fileSha256, filePath } = await getRawMediaUploadData(
|
|
82
|
+
photo,
|
|
83
|
+
"biz-cover-photo",
|
|
84
|
+
);
|
|
85
|
+
const fileSha256B64 = fileSha256.toString("base64");
|
|
86
|
+
const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
|
|
87
|
+
fileEncSha256B64: fileSha256B64,
|
|
88
|
+
mediaType: "biz-cover-photo",
|
|
89
|
+
});
|
|
90
|
+
await query({
|
|
91
|
+
tag: "iq",
|
|
92
|
+
attrs: {
|
|
93
|
+
to: S_WHATSAPP_NET,
|
|
94
|
+
type: "set",
|
|
95
|
+
xmlns: "w:biz",
|
|
96
|
+
},
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
tag: "business_profile",
|
|
100
|
+
attrs: {
|
|
101
|
+
v: "3",
|
|
102
|
+
mutation_type: "delta",
|
|
103
|
+
},
|
|
104
|
+
content: [
|
|
105
|
+
{
|
|
106
|
+
tag: "cover_photo",
|
|
107
|
+
attrs: {
|
|
108
|
+
id: String(fbid),
|
|
109
|
+
op: "update",
|
|
110
|
+
token: meta_hmac,
|
|
111
|
+
ts: String(ts),
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
});
|
|
118
|
+
return fbid;
|
|
119
|
+
};
|
|
120
|
+
const removeCoverPhoto = async (id) => {
|
|
121
|
+
return await query({
|
|
122
|
+
tag: "iq",
|
|
123
|
+
attrs: {
|
|
124
|
+
to: S_WHATSAPP_NET,
|
|
125
|
+
type: "set",
|
|
126
|
+
xmlns: "w:biz",
|
|
127
|
+
},
|
|
128
|
+
content: [
|
|
129
|
+
{
|
|
130
|
+
tag: "business_profile",
|
|
131
|
+
attrs: {
|
|
132
|
+
v: "3",
|
|
133
|
+
mutation_type: "delta",
|
|
134
|
+
},
|
|
135
|
+
content: [
|
|
136
|
+
{
|
|
137
|
+
tag: "cover_photo",
|
|
138
|
+
attrs: { op: "delete", id },
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
const getCatalog = async ({ jid, limit, cursor }) => {
|
|
146
|
+
jid = jid || authState.creds.me?.id;
|
|
147
|
+
jid = jidNormalizedUser(jid);
|
|
148
|
+
const queryParamNodes = [
|
|
149
|
+
{
|
|
150
|
+
tag: "limit",
|
|
151
|
+
attrs: {},
|
|
152
|
+
content: Buffer.from((limit || 10).toString()),
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
tag: "width",
|
|
156
|
+
attrs: {},
|
|
157
|
+
content: Buffer.from("100"),
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
tag: "height",
|
|
161
|
+
attrs: {},
|
|
162
|
+
content: Buffer.from("100"),
|
|
163
|
+
},
|
|
164
|
+
];
|
|
165
|
+
if (cursor) {
|
|
166
|
+
queryParamNodes.push({
|
|
167
|
+
tag: "after",
|
|
168
|
+
attrs: {},
|
|
169
|
+
content: cursor,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const result = await query({
|
|
173
|
+
tag: "iq",
|
|
174
|
+
attrs: {
|
|
175
|
+
to: S_WHATSAPP_NET,
|
|
176
|
+
type: "get",
|
|
177
|
+
xmlns: "w:biz:catalog",
|
|
178
|
+
},
|
|
179
|
+
content: [
|
|
180
|
+
{
|
|
181
|
+
tag: "product_catalog",
|
|
182
|
+
attrs: {
|
|
183
|
+
jid,
|
|
184
|
+
allow_shop_source: "true",
|
|
185
|
+
},
|
|
186
|
+
content: queryParamNodes,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
return parseCatalogNode(result);
|
|
191
|
+
};
|
|
192
|
+
const getCollections = async (jid, limit = 51) => {
|
|
193
|
+
jid = jid || authState.creds.me?.id;
|
|
194
|
+
jid = jidNormalizedUser(jid);
|
|
195
|
+
const result = await query({
|
|
196
|
+
tag: "iq",
|
|
197
|
+
attrs: {
|
|
198
|
+
to: S_WHATSAPP_NET,
|
|
199
|
+
type: "get",
|
|
200
|
+
xmlns: "w:biz:catalog",
|
|
201
|
+
smax_id: "35",
|
|
202
|
+
},
|
|
203
|
+
content: [
|
|
204
|
+
{
|
|
205
|
+
tag: "collections",
|
|
206
|
+
attrs: {
|
|
207
|
+
biz_jid: jid,
|
|
208
|
+
},
|
|
209
|
+
content: [
|
|
210
|
+
{
|
|
211
|
+
tag: "collection_limit",
|
|
212
|
+
attrs: {},
|
|
213
|
+
content: Buffer.from(limit.toString()),
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
tag: "item_limit",
|
|
217
|
+
attrs: {},
|
|
218
|
+
content: Buffer.from(limit.toString()),
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
tag: "width",
|
|
222
|
+
attrs: {},
|
|
223
|
+
content: Buffer.from("100"),
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
tag: "height",
|
|
227
|
+
attrs: {},
|
|
228
|
+
content: Buffer.from("100"),
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
],
|
|
233
|
+
});
|
|
234
|
+
return parseCollectionsNode(result);
|
|
235
|
+
};
|
|
236
|
+
const getOrderDetails = async (orderId, tokenBase64) => {
|
|
237
|
+
const result = await query({
|
|
238
|
+
tag: "iq",
|
|
239
|
+
attrs: {
|
|
240
|
+
to: S_WHATSAPP_NET,
|
|
241
|
+
type: "get",
|
|
242
|
+
xmlns: "fb:thrift_iq",
|
|
243
|
+
smax_id: "5",
|
|
244
|
+
},
|
|
245
|
+
content: [
|
|
246
|
+
{
|
|
247
|
+
tag: "order",
|
|
248
|
+
attrs: {
|
|
249
|
+
op: "get",
|
|
250
|
+
id: orderId,
|
|
251
|
+
},
|
|
252
|
+
content: [
|
|
253
|
+
{
|
|
254
|
+
tag: "image_dimensions",
|
|
255
|
+
attrs: {},
|
|
256
|
+
content: [
|
|
257
|
+
{
|
|
258
|
+
tag: "width",
|
|
259
|
+
attrs: {},
|
|
260
|
+
content: Buffer.from("100"),
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
tag: "height",
|
|
264
|
+
attrs: {},
|
|
265
|
+
content: Buffer.from("100"),
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
tag: "token",
|
|
271
|
+
attrs: {},
|
|
272
|
+
content: Buffer.from(tokenBase64),
|
|
273
|
+
},
|
|
274
|
+
],
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
});
|
|
278
|
+
return parseOrderDetailsNode(result);
|
|
279
|
+
};
|
|
280
|
+
const productUpdate = async (productId, update) => {
|
|
281
|
+
update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
|
|
282
|
+
const editNode = toProductNode(productId, update);
|
|
283
|
+
const result = await query({
|
|
284
|
+
tag: "iq",
|
|
285
|
+
attrs: {
|
|
286
|
+
to: S_WHATSAPP_NET,
|
|
287
|
+
type: "set",
|
|
288
|
+
xmlns: "w:biz:catalog",
|
|
289
|
+
},
|
|
290
|
+
content: [
|
|
291
|
+
{
|
|
292
|
+
tag: "product_catalog_edit",
|
|
293
|
+
attrs: { v: "1" },
|
|
294
|
+
content: [
|
|
295
|
+
editNode,
|
|
296
|
+
{
|
|
297
|
+
tag: "width",
|
|
298
|
+
attrs: {},
|
|
299
|
+
content: "100",
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
tag: "height",
|
|
303
|
+
attrs: {},
|
|
304
|
+
content: "100",
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
},
|
|
308
|
+
],
|
|
309
|
+
});
|
|
310
|
+
const productCatalogEditNode = getBinaryNodeChild(
|
|
311
|
+
result,
|
|
312
|
+
"product_catalog_edit",
|
|
313
|
+
);
|
|
314
|
+
const productNode = getBinaryNodeChild(productCatalogEditNode, "product");
|
|
315
|
+
return parseProductNode(productNode);
|
|
316
|
+
};
|
|
317
|
+
const productCreate = async (create) => {
|
|
318
|
+
// ensure isHidden is defined
|
|
319
|
+
create.isHidden = !!create.isHidden;
|
|
320
|
+
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
|
|
321
|
+
const createNode = toProductNode(undefined, create);
|
|
322
|
+
const result = await query({
|
|
323
|
+
tag: "iq",
|
|
324
|
+
attrs: {
|
|
325
|
+
to: S_WHATSAPP_NET,
|
|
326
|
+
type: "set",
|
|
327
|
+
xmlns: "w:biz:catalog",
|
|
328
|
+
},
|
|
329
|
+
content: [
|
|
330
|
+
{
|
|
331
|
+
tag: "product_catalog_add",
|
|
332
|
+
attrs: { v: "1" },
|
|
333
|
+
content: [
|
|
334
|
+
createNode,
|
|
335
|
+
{
|
|
336
|
+
tag: "width",
|
|
337
|
+
attrs: {},
|
|
338
|
+
content: "100",
|
|
339
|
+
},
|
|
340
|
+
{
|
|
341
|
+
tag: "height",
|
|
342
|
+
attrs: {},
|
|
343
|
+
content: "100",
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
},
|
|
347
|
+
],
|
|
348
|
+
});
|
|
349
|
+
const productCatalogAddNode = getBinaryNodeChild(
|
|
350
|
+
result,
|
|
351
|
+
"product_catalog_add",
|
|
352
|
+
);
|
|
353
|
+
const productNode = getBinaryNodeChild(productCatalogAddNode, "product");
|
|
354
|
+
return parseProductNode(productNode);
|
|
355
|
+
};
|
|
356
|
+
const productDelete = async (productIds) => {
|
|
357
|
+
const result = await query({
|
|
358
|
+
tag: "iq",
|
|
359
|
+
attrs: {
|
|
360
|
+
to: S_WHATSAPP_NET,
|
|
361
|
+
type: "set",
|
|
362
|
+
xmlns: "w:biz:catalog",
|
|
363
|
+
},
|
|
364
|
+
content: [
|
|
365
|
+
{
|
|
366
|
+
tag: "product_catalog_delete",
|
|
367
|
+
attrs: { v: "1" },
|
|
368
|
+
content: productIds.map((id) => ({
|
|
369
|
+
tag: "product",
|
|
370
|
+
attrs: {},
|
|
371
|
+
content: [
|
|
372
|
+
{
|
|
373
|
+
tag: "id",
|
|
374
|
+
attrs: {},
|
|
375
|
+
content: Buffer.from(id),
|
|
376
|
+
},
|
|
377
|
+
],
|
|
378
|
+
})),
|
|
379
|
+
},
|
|
380
|
+
],
|
|
381
|
+
});
|
|
382
|
+
const productCatalogDelNode = getBinaryNodeChild(
|
|
383
|
+
result,
|
|
384
|
+
"product_catalog_delete",
|
|
385
|
+
);
|
|
386
|
+
return {
|
|
387
|
+
deleted: +(productCatalogDelNode?.attrs.deleted_count || 0),
|
|
388
|
+
};
|
|
389
|
+
};
|
|
390
|
+
return {
|
|
391
|
+
...sock,
|
|
392
|
+
logger: config.logger,
|
|
393
|
+
getOrderDetails,
|
|
394
|
+
getCatalog,
|
|
395
|
+
getCollections,
|
|
396
|
+
productCreate,
|
|
397
|
+
productDelete,
|
|
398
|
+
productUpdate,
|
|
399
|
+
updateBussinesProfile,
|
|
400
|
+
updateCoverPhoto,
|
|
401
|
+
removeCoverPhoto,
|
|
402
|
+
};
|
|
403
|
+
};
|
|
404
|
+
//# sourceMappingURL=business.js.map
|