keithbaileys 1.0.5 → 1.0.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/README.md +1 -1
- package/lib/Defaults/index.js +8 -2
- package/lib/Socket/business.js +125 -1
- package/lib/Socket/chats.js +78 -0
- package/lib/Socket/communities.js +439 -0
- package/lib/Socket/groups.js +6 -0
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.js +1 -0
- package/lib/Socket/messages-send.js +122 -2
- package/lib/Socket/socket.js +28 -1
- package/lib/Types/Newsletter.js +4 -0
- package/lib/Types/State.js +38 -0
- package/lib/Utils/decode-wa-message.js +4 -0
- package/lib/Utils/index.js +1 -0
- package/lib/Utils/messages-media.js +9 -4
- package/lib/Utils/messages.js +70 -109
- package/lib/Utils/process-message.js +5 -4
- package/lib/Utils/rich-messages.js +1205 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +26 -3
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +26 -0
- package/lib/WAUSync/Protocols/index.js +1 -0
- package/lib/WAUSync/USyncQuery.js +4 -0
- package/lib/WAUSync/USyncUser.js +8 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
## baileys
|
package/lib/Defaults/index.js
CHANGED
|
@@ -72,7 +72,10 @@ exports.MEDIA_PATH_MAP = {
|
|
|
72
72
|
'thumbnail-link': '/mms/image',
|
|
73
73
|
'product-catalog-image': '/product/image',
|
|
74
74
|
'md-app-state': '',
|
|
75
|
-
'md-msg-hist': '/mms/md-app-state'
|
|
75
|
+
'md-msg-hist': '/mms/md-app-state',
|
|
76
|
+
'biz-cover-photo': '/pps/biz-cover-photo',
|
|
77
|
+
'sticker-pack': '/mms/sticker',
|
|
78
|
+
'thumbnail-sticker-pack': '/mms/sticker'
|
|
76
79
|
};
|
|
77
80
|
exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
78
81
|
audio: 'Audio',
|
|
@@ -92,7 +95,10 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
|
|
|
92
95
|
'md-app-state': 'App State',
|
|
93
96
|
'product-catalog-image': '',
|
|
94
97
|
'payment-bg-image': 'Payment Background',
|
|
95
|
-
ptv: 'Video'
|
|
98
|
+
ptv: 'Video',
|
|
99
|
+
'biz-cover-photo': 'Image',
|
|
100
|
+
'sticker-pack': 'Sticker Pack',
|
|
101
|
+
'thumbnail-sticker-pack': 'Sticker Pack'
|
|
96
102
|
};
|
|
97
103
|
exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
|
|
98
104
|
exports.MIN_PREKEY_COUNT = 5;
|
package/lib/Socket/business.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeBusinessSocket = void 0;
|
|
4
4
|
const business_1 = require("../Utils/business");
|
|
5
|
+
const messages_media_1 = require("../Utils/messages-media");
|
|
5
6
|
const WABinary_1 = require("../WABinary");
|
|
6
7
|
const generic_utils_1 = require("../WABinary/generic-utils");
|
|
7
8
|
const messages_recv_1 = require("./messages-recv");
|
|
@@ -246,6 +247,126 @@ const makeBusinessSocket = (config) => {
|
|
|
246
247
|
deleted: +((productCatalogDelNode === null || productCatalogDelNode === void 0 ? void 0 : productCatalogDelNode.attrs.deleted_count) || 0)
|
|
247
248
|
};
|
|
248
249
|
};
|
|
250
|
+
const updateBussinesProfile = async (args) => {
|
|
251
|
+
const node = [];
|
|
252
|
+
const simpleFields = ['address', 'email', 'description'];
|
|
253
|
+
node.push(...simpleFields
|
|
254
|
+
.filter(key => args[key] !== undefined && args[key] !== null)
|
|
255
|
+
.map(key => ({
|
|
256
|
+
tag: key,
|
|
257
|
+
attrs: {},
|
|
258
|
+
content: args[key]
|
|
259
|
+
})));
|
|
260
|
+
if (args.websites !== undefined) {
|
|
261
|
+
node.push(...args.websites.map(website => ({
|
|
262
|
+
tag: 'website',
|
|
263
|
+
attrs: {},
|
|
264
|
+
content: website
|
|
265
|
+
})));
|
|
266
|
+
}
|
|
267
|
+
if (args.hours !== undefined) {
|
|
268
|
+
node.push({
|
|
269
|
+
tag: 'business_hours',
|
|
270
|
+
attrs: { timezone: args.hours.timezone },
|
|
271
|
+
content: args.hours.days.map(dayConfig => {
|
|
272
|
+
const base = {
|
|
273
|
+
tag: 'business_hours_config',
|
|
274
|
+
attrs: {
|
|
275
|
+
day_of_week: dayConfig.day,
|
|
276
|
+
mode: dayConfig.mode
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
if (dayConfig.mode === 'specific_hours') {
|
|
280
|
+
return {
|
|
281
|
+
...base,
|
|
282
|
+
attrs: {
|
|
283
|
+
...base.attrs,
|
|
284
|
+
open_time: dayConfig.openTimeInMinutes,
|
|
285
|
+
close_time: dayConfig.closeTimeInMinutes
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
return base;
|
|
290
|
+
})
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const result = await query({
|
|
294
|
+
tag: 'iq',
|
|
295
|
+
attrs: {
|
|
296
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
297
|
+
type: 'set',
|
|
298
|
+
xmlns: 'w:biz'
|
|
299
|
+
},
|
|
300
|
+
content: [
|
|
301
|
+
{
|
|
302
|
+
tag: 'business_profile',
|
|
303
|
+
attrs: {
|
|
304
|
+
v: '3',
|
|
305
|
+
mutation_type: 'delta'
|
|
306
|
+
},
|
|
307
|
+
content: node
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
});
|
|
311
|
+
return result;
|
|
312
|
+
};
|
|
313
|
+
const updateCoverPhoto = async (photo) => {
|
|
314
|
+
const { fileSha256, filePath } = await (0, messages_media_1.getRawMediaUploadData)(photo, 'biz-cover-photo');
|
|
315
|
+
const fileSha256B64 = fileSha256.toString('base64');
|
|
316
|
+
const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
|
|
317
|
+
fileEncSha256B64: fileSha256B64,
|
|
318
|
+
mediaType: 'biz-cover-photo'
|
|
319
|
+
});
|
|
320
|
+
await query({
|
|
321
|
+
tag: 'iq',
|
|
322
|
+
attrs: {
|
|
323
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
324
|
+
type: 'set',
|
|
325
|
+
xmlns: 'w:biz'
|
|
326
|
+
},
|
|
327
|
+
content: [
|
|
328
|
+
{
|
|
329
|
+
tag: 'business_profile',
|
|
330
|
+
attrs: {
|
|
331
|
+
v: '3',
|
|
332
|
+
mutation_type: 'delta'
|
|
333
|
+
},
|
|
334
|
+
content: [
|
|
335
|
+
{
|
|
336
|
+
tag: 'cover_photo',
|
|
337
|
+
attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
]
|
|
342
|
+
});
|
|
343
|
+
return fbid;
|
|
344
|
+
};
|
|
345
|
+
const removeCoverPhoto = async (id) => {
|
|
346
|
+
return await query({
|
|
347
|
+
tag: 'iq',
|
|
348
|
+
attrs: {
|
|
349
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
350
|
+
type: 'set',
|
|
351
|
+
xmlns: 'w:biz'
|
|
352
|
+
},
|
|
353
|
+
content: [
|
|
354
|
+
{
|
|
355
|
+
tag: 'business_profile',
|
|
356
|
+
attrs: {
|
|
357
|
+
v: '3',
|
|
358
|
+
mutation_type: 'delta'
|
|
359
|
+
},
|
|
360
|
+
content: [
|
|
361
|
+
{
|
|
362
|
+
tag: 'cover_photo',
|
|
363
|
+
attrs: { op: 'delete', id }
|
|
364
|
+
}
|
|
365
|
+
]
|
|
366
|
+
}
|
|
367
|
+
]
|
|
368
|
+
});
|
|
369
|
+
};
|
|
249
370
|
return {
|
|
250
371
|
...sock,
|
|
251
372
|
logger: config.logger,
|
|
@@ -254,7 +375,10 @@ const makeBusinessSocket = (config) => {
|
|
|
254
375
|
getCollections,
|
|
255
376
|
productCreate,
|
|
256
377
|
productDelete,
|
|
257
|
-
productUpdate
|
|
378
|
+
productUpdate,
|
|
379
|
+
updateBussinesProfile,
|
|
380
|
+
updateCoverPhoto,
|
|
381
|
+
removeCoverPhoto
|
|
258
382
|
};
|
|
259
383
|
};
|
|
260
384
|
exports.makeBusinessSocket = makeBusinessSocket;
|
package/lib/Socket/chats.js
CHANGED
|
@@ -135,6 +135,10 @@ const makeChatsSocket = (config) => {
|
|
|
135
135
|
}
|
|
136
136
|
]
|
|
137
137
|
});
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
138
142
|
const botNode = (0, WABinary_1.getBinaryNodeChild)(resp, 'bot');
|
|
139
143
|
const botList = [];
|
|
140
144
|
for (const section of (0, WABinary_1.getBinaryNodeChildren)(botNode, 'section')) {
|
|
@@ -149,6 +153,28 @@ const makeChatsSocket = (config) => {
|
|
|
149
153
|
}
|
|
150
154
|
return botList;
|
|
151
155
|
};
|
|
156
|
+
|
|
157
|
+
const createCallLink = async (type, event, timeoutMs) => {
|
|
158
|
+
const result = await query({
|
|
159
|
+
tag: 'call',
|
|
160
|
+
attrs: {
|
|
161
|
+
id: generateMessageTag(),
|
|
162
|
+
to: '@call'
|
|
163
|
+
},
|
|
164
|
+
content: [
|
|
165
|
+
{
|
|
166
|
+
tag: 'link_create',
|
|
167
|
+
attrs: { media: type },
|
|
168
|
+
content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
}, timeoutMs);
|
|
172
|
+
|
|
173
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'link_create');
|
|
174
|
+
return child === null || child === void 0 ? void 0 : child.attrs.token;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
|
|
152
178
|
const onWhatsApp = async (...jids) => {
|
|
153
179
|
const usyncQuery = new WAUSync_1.USyncQuery().withContactProtocol().withLIDProtocol();
|
|
154
180
|
for (const jid of jids) {
|
|
@@ -737,6 +763,52 @@ const makeChatsSocket = (config) => {
|
|
|
737
763
|
* queries need to be fired on connection open
|
|
738
764
|
* help ensure parity with WA Web
|
|
739
765
|
* */
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
/**
|
|
769
|
+
* Add or Edit Contact
|
|
770
|
+
*/
|
|
771
|
+
const addOrEditContact = (jid, contact) => {
|
|
772
|
+
return chatModify({
|
|
773
|
+
contact
|
|
774
|
+
}, jid);
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Remove Contact
|
|
779
|
+
*/
|
|
780
|
+
const removeContact = (jid) => {
|
|
781
|
+
return chatModify({
|
|
782
|
+
contact: null
|
|
783
|
+
}, jid);
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Add or Edit Quick Reply
|
|
788
|
+
*/
|
|
789
|
+
const addOrEditQuickReply = (quickReply) => {
|
|
790
|
+
return chatModify({
|
|
791
|
+
quickReply
|
|
792
|
+
}, '');
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
/**
|
|
796
|
+
* Remove Quick Reply
|
|
797
|
+
*/
|
|
798
|
+
const removeQuickReply = (timestamp) => {
|
|
799
|
+
return chatModify({
|
|
800
|
+
quickReply: { timestamp, deleted: true }
|
|
801
|
+
}, '');
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Enable/Disable link preview privacy
|
|
806
|
+
*/
|
|
807
|
+
const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
|
|
808
|
+
return chatModify({
|
|
809
|
+
disableLinkPreviews: { isPreviewsDisabled }
|
|
810
|
+
}, '');
|
|
811
|
+
};
|
|
740
812
|
const executeInitQueries = async () => {
|
|
741
813
|
await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
|
|
742
814
|
};
|
|
@@ -840,6 +912,7 @@ const makeChatsSocket = (config) => {
|
|
|
840
912
|
return {
|
|
841
913
|
...sock,
|
|
842
914
|
getBotListV2,
|
|
915
|
+
createCallLink,
|
|
843
916
|
processingMutex,
|
|
844
917
|
fetchPrivacySettings,
|
|
845
918
|
upsertMessage,
|
|
@@ -868,6 +941,11 @@ const makeChatsSocket = (config) => {
|
|
|
868
941
|
getBusinessProfile,
|
|
869
942
|
resyncAppState,
|
|
870
943
|
chatModify,
|
|
944
|
+
addOrEditContact,
|
|
945
|
+
removeContact,
|
|
946
|
+
addOrEditQuickReply,
|
|
947
|
+
removeQuickReply,
|
|
948
|
+
updateDisableLinkPreviewsPrivacy,
|
|
871
949
|
cleanDirtyBits,
|
|
872
950
|
addLabel,
|
|
873
951
|
addChatLabel,
|