@pontalabs/baileys 1.0.11 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +2 -1
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
package/lib/Socket/business.js
CHANGED
|
@@ -1,415 +1,291 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const {
|
|
4
|
+
toProductNode: toProductNode,
|
|
5
|
+
parseCatalogNode: parseCatalogNode,
|
|
6
|
+
parseCollectionsNode: parseCollectionsNode,
|
|
7
|
+
parseOrderDetailsNode: parseOrderDetailsNode,
|
|
8
|
+
getRawMediaUploadData: getRawMediaUploadData,
|
|
9
|
+
uploadingNecessaryImagesOfProduct: uploadingNecessaryImagesOfProduct,
|
|
10
|
+
} = require("../Utils");
|
|
11
|
+
const {
|
|
12
|
+
S_WHATSAPP_NET: S_WHATSAPP_NET,
|
|
13
|
+
jidNormalizedUser: jidNormalizedUser,
|
|
14
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
15
|
+
} = require("../WABinary");
|
|
16
|
+
const { makeMessagesRecvSocket: makeMessagesRecvSocket } = require("./messages-recv");
|
|
11
17
|
const makeBusinessSocket = (config) => {
|
|
12
|
-
const
|
|
13
|
-
const { authState, query, waUploadToServer } =
|
|
14
|
-
|
|
18
|
+
const conn = makeMessagesRecvSocket(config);
|
|
19
|
+
const { authState: authState, query: query, waUploadToServer: waUploadToServer } = conn;
|
|
15
20
|
const updateBussinesProfile = async (args) => {
|
|
16
|
-
const node = []
|
|
17
|
-
const simpleFields = [
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
attrs: {},
|
|
24
|
-
content: args[key]
|
|
25
|
-
})))
|
|
26
|
-
|
|
21
|
+
const node = [];
|
|
22
|
+
const simpleFields = ["address", "email", "description"];
|
|
23
|
+
node.push(
|
|
24
|
+
...simpleFields
|
|
25
|
+
.filter((key) => args[key])
|
|
26
|
+
.map((key) => ({ tag: key, attrs: {}, content: args[key] }))
|
|
27
|
+
);
|
|
27
28
|
if (args.websites) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
node.push(
|
|
30
|
+
...args.websites.map((website) => ({
|
|
31
|
+
tag: "website",
|
|
32
|
+
attrs: {},
|
|
33
|
+
content: website,
|
|
34
|
+
}))
|
|
35
|
+
);
|
|
34
36
|
}
|
|
35
|
-
|
|
36
37
|
if (args.hours) {
|
|
37
|
-
|
|
38
38
|
node.push({
|
|
39
|
-
tag:
|
|
39
|
+
tag: "business_hours",
|
|
40
40
|
attrs: { timezone: args.hours.timezone },
|
|
41
|
-
content: args.hours.days.map(config => {
|
|
41
|
+
content: args.hours.days.map((config) => {
|
|
42
42
|
const base = {
|
|
43
|
-
tag:
|
|
44
|
-
attrs: { day_of_week: config.day, mode: config.mode }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (config.mode === 'specific_hours') {
|
|
43
|
+
tag: "business_hours_config",
|
|
44
|
+
attrs: { day_of_week: config.day, mode: config.mode },
|
|
45
|
+
};
|
|
46
|
+
if (config.mode === "specific_hours") {
|
|
48
47
|
return {
|
|
49
48
|
...base,
|
|
50
49
|
attrs: {
|
|
51
50
|
...base.attrs,
|
|
52
51
|
open_time: config.openTimeInMinutes,
|
|
53
|
-
close_time: config.closeTimeInMinutes
|
|
54
|
-
}
|
|
55
|
-
}
|
|
52
|
+
close_time: config.closeTimeInMinutes,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
})
|
|
56
|
+
return base;
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
61
59
|
}
|
|
62
|
-
|
|
63
60
|
const result = await query({
|
|
64
|
-
tag:
|
|
65
|
-
attrs: {
|
|
66
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
67
|
-
type: 'set',
|
|
68
|
-
xmlns: 'w:biz'
|
|
69
|
-
},
|
|
61
|
+
tag: "iq",
|
|
62
|
+
attrs: { to: S_WHATSAPP_NET, type: "set", xmlns: "w:biz" },
|
|
70
63
|
content: [
|
|
71
64
|
{
|
|
72
|
-
tag:
|
|
73
|
-
attrs: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
return result
|
|
83
|
-
}
|
|
84
|
-
|
|
65
|
+
tag: "business_profile",
|
|
66
|
+
attrs: { v: "3", mutation_type: "delta" },
|
|
67
|
+
content: node,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
return result;
|
|
72
|
+
};
|
|
85
73
|
const updateCoverPhoto = async (photo) => {
|
|
86
|
-
const { fileSha256, filePath } = await
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
const { fileSha256: fileSha256, filePath: filePath } = await getRawMediaUploadData(
|
|
75
|
+
photo,
|
|
76
|
+
"biz-cover-photo"
|
|
77
|
+
);
|
|
78
|
+
const fileSha256B64 = fileSha256.toString("base64");
|
|
79
|
+
const {
|
|
80
|
+
meta_hmac: meta_hmac,
|
|
81
|
+
fbid: fbid,
|
|
82
|
+
ts: ts,
|
|
83
|
+
} = await waUploadToServer(filePath, {
|
|
90
84
|
fileEncSha256B64: fileSha256B64,
|
|
91
|
-
mediaType:
|
|
92
|
-
})
|
|
93
|
-
|
|
85
|
+
mediaType: "biz-cover-photo",
|
|
86
|
+
});
|
|
94
87
|
await query({
|
|
95
|
-
tag:
|
|
96
|
-
attrs: {
|
|
97
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
98
|
-
type: 'set',
|
|
99
|
-
xmlns: 'w:biz'
|
|
100
|
-
},
|
|
88
|
+
tag: "iq",
|
|
89
|
+
attrs: { to: S_WHATSAPP_NET, type: "set", xmlns: "w:biz" },
|
|
101
90
|
content: [
|
|
102
91
|
{
|
|
103
|
-
tag:
|
|
104
|
-
attrs: {
|
|
105
|
-
v: '3',
|
|
106
|
-
mutation_type: 'delta'
|
|
107
|
-
},
|
|
92
|
+
tag: "business_profile",
|
|
93
|
+
attrs: { v: "3", mutation_type: "delta" },
|
|
108
94
|
content: [
|
|
109
95
|
{
|
|
110
|
-
tag:
|
|
111
|
-
attrs: {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
},
|
|
96
|
+
tag: "cover_photo",
|
|
97
|
+
attrs: {
|
|
98
|
+
id: String(fbid),
|
|
99
|
+
op: "update",
|
|
100
|
+
token: meta_hmac,
|
|
101
|
+
ts: String(ts),
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
});
|
|
108
|
+
return fbid;
|
|
109
|
+
};
|
|
110
|
+
const removeCoverPhoto = async (id) =>
|
|
111
|
+
await query({
|
|
112
|
+
tag: "iq",
|
|
113
|
+
attrs: { to: S_WHATSAPP_NET, type: "set", xmlns: "w:biz" },
|
|
129
114
|
content: [
|
|
130
115
|
{
|
|
131
|
-
tag:
|
|
132
|
-
attrs: {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
]
|
|
142
|
-
}
|
|
143
|
-
]
|
|
144
|
-
})
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const getCatalog = async ({ jid, limit, cursor }) => {
|
|
148
|
-
jid = jid || authState.creds.me?.id
|
|
149
|
-
jid = WABinary_1.jidNormalizedUser(jid)
|
|
150
|
-
|
|
116
|
+
tag: "business_profile",
|
|
117
|
+
attrs: { v: "3", mutation_type: "delta" },
|
|
118
|
+
content: [{ tag: "cover_photo", attrs: { op: "delete", id: id } }],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
});
|
|
122
|
+
const getCatalog = async ({ jid: jid, limit: limit, cursor: cursor }) => {
|
|
123
|
+
jid = jid || authState.creds.me?.id;
|
|
124
|
+
jid = jidNormalizedUser(jid);
|
|
151
125
|
const queryParamNodes = [
|
|
152
126
|
{
|
|
153
|
-
tag:
|
|
154
|
-
attrs: {},
|
|
155
|
-
content: Buffer.from((limit || 10).toString())
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
tag: 'width',
|
|
127
|
+
tag: "limit",
|
|
159
128
|
attrs: {},
|
|
160
|
-
content: Buffer.from(
|
|
129
|
+
content: Buffer.from((limit || 10).toString()),
|
|
161
130
|
},
|
|
162
|
-
{
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
content: Buffer.from('100')
|
|
166
|
-
},
|
|
167
|
-
]
|
|
168
|
-
|
|
131
|
+
{ tag: "width", attrs: {}, content: Buffer.from("100") },
|
|
132
|
+
{ tag: "height", attrs: {}, content: Buffer.from("100") },
|
|
133
|
+
];
|
|
169
134
|
if (cursor) {
|
|
170
|
-
queryParamNodes.push({
|
|
171
|
-
tag: 'after',
|
|
172
|
-
attrs: {},
|
|
173
|
-
content: cursor
|
|
174
|
-
})
|
|
135
|
+
queryParamNodes.push({ tag: "after", attrs: {}, content: cursor });
|
|
175
136
|
}
|
|
176
|
-
|
|
177
137
|
const result = await query({
|
|
178
|
-
tag:
|
|
179
|
-
attrs: {
|
|
180
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
181
|
-
type: 'get',
|
|
182
|
-
xmlns: 'w:biz:catalog'
|
|
183
|
-
},
|
|
138
|
+
tag: "iq",
|
|
139
|
+
attrs: { to: S_WHATSAPP_NET, type: "get", xmlns: "w:biz:catalog" },
|
|
184
140
|
content: [
|
|
185
141
|
{
|
|
186
|
-
tag:
|
|
187
|
-
attrs: {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
return business_1.parseCatalogNode(result)
|
|
197
|
-
}
|
|
198
|
-
|
|
142
|
+
tag: "product_catalog",
|
|
143
|
+
attrs: { jid: jid, allow_shop_source: "true" },
|
|
144
|
+
content: queryParamNodes,
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
});
|
|
148
|
+
return parseCatalogNode(result);
|
|
149
|
+
};
|
|
199
150
|
const getCollections = async (jid, limit = 51) => {
|
|
200
|
-
jid = jid || authState.creds.me?.id
|
|
201
|
-
jid =
|
|
202
|
-
|
|
151
|
+
jid = jid || authState.creds.me?.id;
|
|
152
|
+
jid = jidNormalizedUser(jid);
|
|
203
153
|
const result = await query({
|
|
204
|
-
tag:
|
|
154
|
+
tag: "iq",
|
|
205
155
|
attrs: {
|
|
206
|
-
to:
|
|
207
|
-
type:
|
|
208
|
-
xmlns:
|
|
209
|
-
|
|
156
|
+
to: S_WHATSAPP_NET,
|
|
157
|
+
type: "get",
|
|
158
|
+
xmlns: "w:biz:catalog",
|
|
159
|
+
smax_id: "35",
|
|
210
160
|
},
|
|
211
161
|
content: [
|
|
212
162
|
{
|
|
213
|
-
tag:
|
|
214
|
-
attrs: {
|
|
215
|
-
'biz_jid': jid,
|
|
216
|
-
},
|
|
163
|
+
tag: "collections",
|
|
164
|
+
attrs: { biz_jid: jid },
|
|
217
165
|
content: [
|
|
218
166
|
{
|
|
219
|
-
tag:
|
|
220
|
-
attrs: {},
|
|
221
|
-
content: Buffer.from(limit.toString())
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
tag: 'item_limit',
|
|
167
|
+
tag: "collection_limit",
|
|
225
168
|
attrs: {},
|
|
226
|
-
content: Buffer.from(limit.toString())
|
|
169
|
+
content: Buffer.from(limit.toString()),
|
|
227
170
|
},
|
|
228
171
|
{
|
|
229
|
-
tag:
|
|
172
|
+
tag: "item_limit",
|
|
230
173
|
attrs: {},
|
|
231
|
-
content: Buffer.from(
|
|
174
|
+
content: Buffer.from(limit.toString()),
|
|
232
175
|
},
|
|
233
|
-
{
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
})
|
|
242
|
-
|
|
243
|
-
return business_1.parseCollectionsNode(result)
|
|
244
|
-
}
|
|
245
|
-
|
|
176
|
+
{ tag: "width", attrs: {}, content: Buffer.from("100") },
|
|
177
|
+
{ tag: "height", attrs: {}, content: Buffer.from("100") },
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
return parseCollectionsNode(result);
|
|
183
|
+
};
|
|
246
184
|
const getOrderDetails = async (orderId, tokenBase64) => {
|
|
247
185
|
const result = await query({
|
|
248
|
-
tag:
|
|
186
|
+
tag: "iq",
|
|
249
187
|
attrs: {
|
|
250
|
-
to:
|
|
251
|
-
type:
|
|
252
|
-
xmlns:
|
|
253
|
-
|
|
188
|
+
to: S_WHATSAPP_NET,
|
|
189
|
+
type: "get",
|
|
190
|
+
xmlns: "fb:thrift_iq",
|
|
191
|
+
smax_id: "5",
|
|
254
192
|
},
|
|
255
193
|
content: [
|
|
256
194
|
{
|
|
257
|
-
tag:
|
|
258
|
-
attrs: {
|
|
259
|
-
op: 'get',
|
|
260
|
-
id: orderId
|
|
261
|
-
},
|
|
195
|
+
tag: "order",
|
|
196
|
+
attrs: { op: "get", id: orderId },
|
|
262
197
|
content: [
|
|
263
198
|
{
|
|
264
|
-
tag:
|
|
199
|
+
tag: "image_dimensions",
|
|
265
200
|
attrs: {},
|
|
266
201
|
content: [
|
|
267
|
-
{
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
content: Buffer.from('100')
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
tag: 'height',
|
|
274
|
-
attrs: {},
|
|
275
|
-
content: Buffer.from('100')
|
|
276
|
-
}
|
|
277
|
-
]
|
|
202
|
+
{ tag: "width", attrs: {}, content: Buffer.from("100") },
|
|
203
|
+
{ tag: "height", attrs: {}, content: Buffer.from("100") },
|
|
204
|
+
],
|
|
278
205
|
},
|
|
279
|
-
{
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
]
|
|
287
|
-
})
|
|
288
|
-
|
|
289
|
-
return business_1.parseOrderDetailsNode(result)
|
|
290
|
-
}
|
|
291
|
-
|
|
206
|
+
{ tag: "token", attrs: {}, content: Buffer.from(tokenBase64) },
|
|
207
|
+
],
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
return parseOrderDetailsNode(result);
|
|
212
|
+
};
|
|
292
213
|
const productUpdate = async (productId, update) => {
|
|
293
|
-
update = await
|
|
294
|
-
const editNode =
|
|
295
|
-
|
|
214
|
+
update = await uploadingNecessaryImagesOfProduct(update, waUploadToServer);
|
|
215
|
+
const editNode = toProductNode(productId, update);
|
|
296
216
|
const result = await query({
|
|
297
|
-
tag:
|
|
298
|
-
attrs: {
|
|
299
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
300
|
-
type: 'set',
|
|
301
|
-
xmlns: 'w:biz:catalog'
|
|
302
|
-
},
|
|
217
|
+
tag: "iq",
|
|
218
|
+
attrs: { to: S_WHATSAPP_NET, type: "set", xmlns: "w:biz:catalog" },
|
|
303
219
|
content: [
|
|
304
220
|
{
|
|
305
|
-
tag:
|
|
306
|
-
attrs: { v:
|
|
221
|
+
tag: "product_catalog_edit",
|
|
222
|
+
attrs: { v: "1" },
|
|
307
223
|
content: [
|
|
308
224
|
editNode,
|
|
309
|
-
{
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
]
|
|
320
|
-
}
|
|
321
|
-
]
|
|
322
|
-
})
|
|
323
|
-
const productCatalogEditNode = generic_utils_1.getBinaryNodeChild(result, 'product_catalog_edit')
|
|
324
|
-
const productNode = generic_utils_1.getBinaryNodeChild(productCatalogEditNode, 'product')
|
|
325
|
-
return business_1.parseProductNode(productNode)
|
|
326
|
-
}
|
|
327
|
-
|
|
225
|
+
{ tag: "width", attrs: {}, content: "100" },
|
|
226
|
+
{ tag: "height", attrs: {}, content: "100" },
|
|
227
|
+
],
|
|
228
|
+
},
|
|
229
|
+
],
|
|
230
|
+
});
|
|
231
|
+
const productCatalogEditNode = getBinaryNodeChild(result, "product_catalog_edit");
|
|
232
|
+
const productNode = getBinaryNodeChild(productCatalogEditNode, "product");
|
|
233
|
+
return parseProductNode(productNode);
|
|
234
|
+
};
|
|
328
235
|
const productCreate = async (create) => {
|
|
329
|
-
|
|
330
|
-
create
|
|
331
|
-
|
|
332
|
-
const createNode = business_1.toProductNode(undefined, create)
|
|
333
|
-
|
|
236
|
+
create.isHidden = !!create.isHidden;
|
|
237
|
+
create = await uploadingNecessaryImagesOfProduct(create, waUploadToServer);
|
|
238
|
+
const createNode = toProductNode(undefined, create);
|
|
334
239
|
const result = await query({
|
|
335
|
-
tag:
|
|
336
|
-
attrs: {
|
|
337
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
338
|
-
type: 'set',
|
|
339
|
-
xmlns: 'w:biz:catalog'
|
|
340
|
-
},
|
|
240
|
+
tag: "iq",
|
|
241
|
+
attrs: { to: S_WHATSAPP_NET, type: "set", xmlns: "w:biz:catalog" },
|
|
341
242
|
content: [
|
|
342
243
|
{
|
|
343
|
-
tag:
|
|
344
|
-
attrs: { v:
|
|
244
|
+
tag: "product_catalog_add",
|
|
245
|
+
attrs: { v: "1" },
|
|
345
246
|
content: [
|
|
346
247
|
createNode,
|
|
347
|
-
{
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
]
|
|
358
|
-
}
|
|
359
|
-
]
|
|
360
|
-
})
|
|
361
|
-
const productCatalogAddNode = generic_utils_1.getBinaryNodeChild(result, 'product_catalog_add')
|
|
362
|
-
const productNode = generic_utils_1.getBinaryNodeChild(productCatalogAddNode, 'product')
|
|
363
|
-
|
|
364
|
-
return business_1.parseProductNode(productNode)
|
|
365
|
-
}
|
|
366
|
-
|
|
248
|
+
{ tag: "width", attrs: {}, content: "100" },
|
|
249
|
+
{ tag: "height", attrs: {}, content: "100" },
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
});
|
|
254
|
+
const productCatalogAddNode = getBinaryNodeChild(result, "product_catalog_add");
|
|
255
|
+
const productNode = getBinaryNodeChild(productCatalogAddNode, "product");
|
|
256
|
+
return parseProductNode(productNode);
|
|
257
|
+
};
|
|
367
258
|
const productDelete = async (productIds) => {
|
|
368
259
|
const result = await query({
|
|
369
|
-
tag:
|
|
370
|
-
attrs: {
|
|
371
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
372
|
-
type: 'set',
|
|
373
|
-
xmlns: 'w:biz:catalog'
|
|
374
|
-
},
|
|
260
|
+
tag: "iq",
|
|
261
|
+
attrs: { to: S_WHATSAPP_NET, type: "set", xmlns: "w:biz:catalog" },
|
|
375
262
|
content: [
|
|
376
263
|
{
|
|
377
|
-
tag:
|
|
378
|
-
attrs: { v:
|
|
379
|
-
content: productIds.map(id => ({
|
|
380
|
-
tag:
|
|
264
|
+
tag: "product_catalog_delete",
|
|
265
|
+
attrs: { v: "1" },
|
|
266
|
+
content: productIds.map((id) => ({
|
|
267
|
+
tag: "product",
|
|
381
268
|
attrs: {},
|
|
382
|
-
content: [
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
]
|
|
392
|
-
})
|
|
393
|
-
const productCatalogDelNode = generic_utils_1.getBinaryNodeChild(result, 'product_catalog_delete')
|
|
394
|
-
return {
|
|
395
|
-
deleted: +(productCatalogDelNode?.attrs?.deleted_count || 0)
|
|
396
|
-
}
|
|
397
|
-
}
|
|
269
|
+
content: [{ tag: "id", attrs: {}, content: Buffer.from(id) }],
|
|
270
|
+
})),
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
});
|
|
274
|
+
const productCatalogDelNode = getBinaryNodeChild(result, "product_catalog_delete");
|
|
275
|
+
return { deleted: +(productCatalogDelNode?.attrs?.deleted_count || 0) };
|
|
276
|
+
};
|
|
398
277
|
return {
|
|
399
|
-
...
|
|
278
|
+
...conn,
|
|
400
279
|
logger: config.logger,
|
|
401
|
-
getOrderDetails,
|
|
402
|
-
getCatalog,
|
|
403
|
-
getCollections,
|
|
404
|
-
productCreate,
|
|
405
|
-
productDelete,
|
|
406
|
-
productUpdate,
|
|
407
|
-
updateBussinesProfile,
|
|
408
|
-
updateCoverPhoto,
|
|
409
|
-
removeCoverPhoto
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
module.exports = {
|
|
414
|
-
makeBusinessSocket
|
|
415
|
-
}
|
|
280
|
+
getOrderDetails: getOrderDetails,
|
|
281
|
+
getCatalog: getCatalog,
|
|
282
|
+
getCollections: getCollections,
|
|
283
|
+
productCreate: productCreate,
|
|
284
|
+
productDelete: productDelete,
|
|
285
|
+
productUpdate: productUpdate,
|
|
286
|
+
updateBussinesProfile: updateBussinesProfile,
|
|
287
|
+
updateCoverPhoto: updateCoverPhoto,
|
|
288
|
+
removeCoverPhoto: removeCoverPhoto,
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
module.exports = { makeBusinessSocket: makeBusinessSocket };
|