Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@adiwajshing/baileys/lib/Socket/business.js
1129 views
1
"use strict";
2
Object.defineProperty(exports, "__esModule", { value: true });
3
exports.makeBusinessSocket = void 0;
4
const business_1 = require("../Utils/business");
5
const WABinary_1 = require("../WABinary");
6
const generic_utils_1 = require("../WABinary/generic-utils");
7
const messages_recv_1 = require("./messages-recv");
8
const makeBusinessSocket = (config) => {
9
const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
10
const { authState, query, waUploadToServer } = sock;
11
const getCatalog = async (jid, limit = 10) => {
12
var _a;
13
jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
14
jid = (0, WABinary_1.jidNormalizedUser)(jid);
15
const result = await query({
16
tag: 'iq',
17
attrs: {
18
to: WABinary_1.S_WHATSAPP_NET,
19
type: 'get',
20
xmlns: 'w:biz:catalog'
21
},
22
content: [
23
{
24
tag: 'product_catalog',
25
attrs: {
26
jid,
27
allow_shop_source: 'true'
28
},
29
content: [
30
{
31
tag: 'limit',
32
attrs: {},
33
content: Buffer.from(limit.toString())
34
},
35
{
36
tag: 'width',
37
attrs: {},
38
content: Buffer.from('100')
39
},
40
{
41
tag: 'height',
42
attrs: {},
43
content: Buffer.from('100')
44
}
45
]
46
}
47
]
48
});
49
return (0, business_1.parseCatalogNode)(result);
50
};
51
const getCollections = async (jid, limit = 51) => {
52
var _a;
53
jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
54
jid = (0, WABinary_1.jidNormalizedUser)(jid);
55
const result = await query({
56
tag: 'iq',
57
attrs: {
58
to: WABinary_1.S_WHATSAPP_NET,
59
type: 'get',
60
xmlns: 'w:biz:catalog',
61
smax_id: '35'
62
},
63
content: [
64
{
65
tag: 'collections',
66
attrs: {
67
biz_jid: jid,
68
},
69
content: [
70
{
71
tag: 'collection_limit',
72
attrs: {},
73
content: Buffer.from(limit.toString())
74
},
75
{
76
tag: 'item_limit',
77
attrs: {},
78
content: Buffer.from(limit.toString())
79
},
80
{
81
tag: 'width',
82
attrs: {},
83
content: Buffer.from('100')
84
},
85
{
86
tag: 'height',
87
attrs: {},
88
content: Buffer.from('100')
89
}
90
]
91
}
92
]
93
});
94
return (0, business_1.parseCollectionsNode)(result);
95
};
96
const getOrderDetails = async (orderId, tokenBase64) => {
97
const result = await query({
98
tag: 'iq',
99
attrs: {
100
to: WABinary_1.S_WHATSAPP_NET,
101
type: 'get',
102
xmlns: 'fb:thrift_iq',
103
smax_id: '5'
104
},
105
content: [
106
{
107
tag: 'order',
108
attrs: {
109
op: 'get',
110
id: orderId
111
},
112
content: [
113
{
114
tag: 'image_dimensions',
115
attrs: {},
116
content: [
117
{
118
tag: 'width',
119
attrs: {},
120
content: Buffer.from('100')
121
},
122
{
123
tag: 'height',
124
attrs: {},
125
content: Buffer.from('100')
126
}
127
]
128
},
129
{
130
tag: 'token',
131
attrs: {},
132
content: Buffer.from(tokenBase64)
133
}
134
]
135
}
136
]
137
});
138
return (0, business_1.parseOrderDetailsNode)(result);
139
};
140
const productUpdate = async (productId, update) => {
141
update = await (0, business_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
142
const editNode = (0, business_1.toProductNode)(productId, update);
143
const result = await query({
144
tag: 'iq',
145
attrs: {
146
to: WABinary_1.S_WHATSAPP_NET,
147
type: 'set',
148
xmlns: 'w:biz:catalog'
149
},
150
content: [
151
{
152
tag: 'product_catalog_edit',
153
attrs: { v: '1' },
154
content: [
155
editNode,
156
{
157
tag: 'width',
158
attrs: {},
159
content: '100'
160
},
161
{
162
tag: 'height',
163
attrs: {},
164
content: '100'
165
}
166
]
167
}
168
]
169
});
170
const productCatalogEditNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_edit');
171
const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogEditNode, 'product');
172
return (0, business_1.parseProductNode)(productNode);
173
};
174
const productCreate = async (create) => {
175
// ensure isHidden is defined
176
create.isHidden = !!create.isHidden;
177
create = await (0, business_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
178
const createNode = (0, business_1.toProductNode)(undefined, create);
179
const result = await query({
180
tag: 'iq',
181
attrs: {
182
to: WABinary_1.S_WHATSAPP_NET,
183
type: 'set',
184
xmlns: 'w:biz:catalog'
185
},
186
content: [
187
{
188
tag: 'product_catalog_add',
189
attrs: { v: '1' },
190
content: [
191
createNode,
192
{
193
tag: 'width',
194
attrs: {},
195
content: '100'
196
},
197
{
198
tag: 'height',
199
attrs: {},
200
content: '100'
201
}
202
]
203
}
204
]
205
});
206
const productCatalogAddNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_add');
207
const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogAddNode, 'product');
208
return (0, business_1.parseProductNode)(productNode);
209
};
210
const productDelete = async (productIds) => {
211
const result = await query({
212
tag: 'iq',
213
attrs: {
214
to: WABinary_1.S_WHATSAPP_NET,
215
type: 'set',
216
xmlns: 'w:biz:catalog'
217
},
218
content: [
219
{
220
tag: 'product_catalog_delete',
221
attrs: { v: '1' },
222
content: productIds.map(id => ({
223
tag: 'product',
224
attrs: {},
225
content: [
226
{
227
tag: 'id',
228
attrs: {},
229
content: Buffer.from(id)
230
}
231
]
232
}))
233
}
234
]
235
});
236
const productCatalogDelNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_delete');
237
return {
238
deleted: +((productCatalogDelNode === null || productCatalogDelNode === void 0 ? void 0 : productCatalogDelNode.attrs.deleted_count) || 0)
239
};
240
};
241
return {
242
...sock,
243
getOrderDetails,
244
getCatalog,
245
getCollections,
246
productCreate,
247
productDelete,
248
productUpdate
249
};
250
};
251
exports.makeBusinessSocket = makeBusinessSocket;
252
253