cuki-bailx 1.1.2 → 1.2.2
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/WAProto/index.js +79296 -118676
- package/engine-requirements.js +1 -1
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +6 -4
- package/lib/Defaults/index.js +102 -78
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +2 -1
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.js +3 -2
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
- package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -12
- package/lib/Socket/business.d.ts +58 -59
- package/lib/Socket/chats.d.ts +27 -29
- package/lib/Socket/chats.js +90 -97
- package/lib/Socket/dugong.d.ts +219 -0
- package/lib/Socket/dugong.js +441 -0
- package/lib/Socket/groups.d.ts +32 -41
- package/lib/Socket/groups.js +5 -20
- package/lib/Socket/index.d.ts +64 -63
- package/lib/Socket/index.js +2 -2
- package/lib/Socket/messages-recv.js +65 -9
- package/lib/Socket/messages-send.d.ts +47 -49
- package/lib/Socket/messages-send.js +312 -379
- package/lib/Socket/newsletter.d.ts +37 -39
- package/lib/Socket/newsletter.js +40 -54
- package/lib/Socket/registration.d.ts +267 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +10 -10
- package/lib/Socket/socket.js +32 -39
- package/lib/Socket/socket.js.bak +630 -0
- package/lib/Socket/usync.d.ts +3 -3
- package/lib/Store/index.d.ts +2 -1
- package/lib/Store/index.js +3 -1
- package/lib/Store/make-cache-manager-store.d.ts +13 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +24 -24
- package/lib/Store/make-in-memory-store.js +11 -13
- package/lib/Store/make-ordered-dictionary.d.ts +1 -1
- package/lib/Store/make-ordered-dictionary.js +2 -2
- package/lib/Types/Auth.d.ts +7 -0
- package/lib/Types/Call.d.ts +1 -1
- package/lib/Types/Chat.d.ts +7 -14
- package/lib/Types/Contact.d.ts +1 -5
- package/lib/Types/Events.d.ts +2 -44
- package/lib/Types/GroupMetadata.d.ts +2 -11
- package/lib/Types/Label.js +1 -1
- package/lib/Types/LabelAssociation.js +1 -1
- package/lib/Types/Message.d.ts +21 -148
- package/lib/Types/Message.js +2 -0
- package/lib/Types/Newsletter.d.ts +13 -0
- package/lib/Types/Newsletter.js +17 -3
- package/lib/Types/Socket.d.ts +9 -17
- package/lib/Types/index.d.ts +1 -8
- package/lib/Types/index.js +2 -2
- package/lib/Utils/auth-utils.d.ts +3 -3
- package/lib/Utils/auth-utils.js +13 -6
- package/lib/Utils/business.js +2 -2
- package/lib/Utils/chat-utils.d.ts +16 -15
- package/lib/Utils/chat-utils.js +35 -36
- package/lib/Utils/crypto.d.ts +16 -15
- package/lib/Utils/crypto.js +29 -71
- package/lib/Utils/decode-wa-message.d.ts +6 -22
- package/lib/Utils/decode-wa-message.js +56 -65
- package/lib/Utils/event-buffer.d.ts +2 -2
- package/lib/Utils/event-buffer.js +7 -11
- package/lib/Utils/generics.d.ts +20 -17
- package/lib/Utils/generics.js +23 -73
- package/lib/Utils/history.d.ts +0 -4
- package/lib/Utils/history.js +6 -4
- package/lib/Utils/link-preview.d.ts +2 -2
- package/lib/Utils/link-preview.js +1 -34
- package/lib/Utils/logger.d.ts +3 -10
- package/lib/Utils/lt-hash.d.ts +2 -2
- package/lib/Utils/lt-hash.js +6 -6
- package/lib/Utils/make-mutex.d.ts +2 -2
- package/lib/Utils/messages-media.d.ts +24 -28
- package/lib/Utils/messages-media.js +115 -263
- package/lib/Utils/messages.d.ts +10 -8
- package/lib/Utils/messages.js +72 -298
- package/lib/Utils/noise-handler.d.ts +12 -10
- package/lib/Utils/noise-handler.js +23 -18
- package/lib/Utils/process-message.d.ts +4 -5
- package/lib/Utils/process-message.js +23 -74
- package/lib/Utils/signal.d.ts +1 -2
- package/lib/Utils/signal.js +35 -37
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +6 -51
- package/lib/Utils/validate-connection.d.ts +4 -3
- package/lib/Utils/validate-connection.js +52 -20
- package/lib/WABinary/constants.d.ts +4 -4
- package/lib/WABinary/constants.js +13 -1276
- package/lib/WABinary/decode.d.ts +4 -3
- package/lib/WABinary/decode.js +13 -26
- package/lib/WABinary/encode.d.ts +2 -1
- package/lib/WABinary/encode.js +17 -39
- package/lib/WABinary/generic-utils.d.ts +3 -1
- package/lib/WABinary/generic-utils.js +85 -2
- package/lib/WABinary/jid-utils.d.ts +5 -10
- package/lib/WABinary/jid-utils.js +5 -26
- package/lib/WAM/BinaryInfo.d.ts +11 -2
- package/lib/WAM/encode.d.ts +2 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +1 -1
- package/lib/index.d.ts +2 -6
- package/lib/index.js +7 -22
- package/lib/index.js.bak +37 -0
- package/package.json +103 -111
- package/LICENSE +0 -21
- package/WAProto/GenerateStatics.sh +0 -4
- package/WAProto/WAProto.proto +0 -4775
- package/WAProto/index.d.ts +0 -55057
- package/WAProto/index.ts.ts +0 -53473
- package/WAProto/p.html +0 -1
- package/lib/WABinary/jid-utils.js.bak +0 -83
- /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
package/lib/Socket/chats.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.makeChatsSocket = void 0;
|
|
7
7
|
const boom_1 = require("@hapi/boom");
|
|
8
|
-
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
9
8
|
const WAProto_1 = require("../../WAProto");
|
|
10
9
|
const Defaults_1 = require("../Defaults");
|
|
11
10
|
const Types_1 = require("../Types");
|
|
@@ -13,6 +12,7 @@ const Utils_1 = require("../Utils");
|
|
|
13
12
|
const make_mutex_1 = require("../Utils/make-mutex");
|
|
14
13
|
const process_message_1 = __importDefault(require("../Utils/process-message"));
|
|
15
14
|
const WABinary_1 = require("../WABinary");
|
|
15
|
+
const socket_1 = require("./socket");
|
|
16
16
|
const WAUSync_1 = require("../WAUSync");
|
|
17
17
|
const usync_1 = require("./usync");
|
|
18
18
|
const MAX_SYNC_ATTEMPTS = 2;
|
|
@@ -25,13 +25,6 @@ const makeChatsSocket = (config) => {
|
|
|
25
25
|
let pendingAppStateSync = false;
|
|
26
26
|
/** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
|
|
27
27
|
const processingMutex = (0, make_mutex_1.makeMutex)();
|
|
28
|
-
const placeholderResendCache = config.placeholderResendCache || new node_cache_1.default({
|
|
29
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
|
|
30
|
-
useClones: false
|
|
31
|
-
});
|
|
32
|
-
if (!config.placeholderResendCache) {
|
|
33
|
-
config.placeholderResendCache = placeholderResendCache;
|
|
34
|
-
}
|
|
35
28
|
/** helper function to fetch the given app state sync key */
|
|
36
29
|
const getAppStateSyncKey = async (keyId) => {
|
|
37
30
|
const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
|
|
@@ -75,12 +68,6 @@ const makeChatsSocket = (config) => {
|
|
|
75
68
|
}]
|
|
76
69
|
});
|
|
77
70
|
};
|
|
78
|
-
const updateMessagesPrivacy = async (value) => {
|
|
79
|
-
await privacyQuery('messages', value);
|
|
80
|
-
};
|
|
81
|
-
const updateCallPrivacy = async (value) => {
|
|
82
|
-
await privacyQuery('calladd', value);
|
|
83
|
-
};
|
|
84
71
|
const updateLastSeenPrivacy = async (value) => {
|
|
85
72
|
await privacyQuery('last', value);
|
|
86
73
|
};
|
|
@@ -115,34 +102,44 @@ const makeChatsSocket = (config) => {
|
|
|
115
102
|
}]
|
|
116
103
|
});
|
|
117
104
|
};
|
|
118
|
-
|
|
119
|
-
|
|
105
|
+
/** helper function to run a generic IQ query */
|
|
106
|
+
const interactiveQuery = async (userNodes, queryNode) => {
|
|
107
|
+
const result = await query({
|
|
120
108
|
tag: 'iq',
|
|
121
109
|
attrs: {
|
|
122
|
-
xmlns: 'bot',
|
|
123
110
|
to: WABinary_1.S_WHATSAPP_NET,
|
|
124
|
-
type: 'get'
|
|
111
|
+
type: 'get',
|
|
112
|
+
xmlns: 'usync',
|
|
125
113
|
},
|
|
126
|
-
content: [
|
|
127
|
-
|
|
114
|
+
content: [
|
|
115
|
+
{
|
|
116
|
+
tag: 'usync',
|
|
128
117
|
attrs: {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
118
|
+
sid: generateMessageTag(),
|
|
119
|
+
mode: 'query',
|
|
120
|
+
last: 'true',
|
|
121
|
+
index: '0',
|
|
122
|
+
context: 'interactive',
|
|
123
|
+
},
|
|
124
|
+
content: [
|
|
125
|
+
{
|
|
126
|
+
tag: 'query',
|
|
127
|
+
attrs: {},
|
|
128
|
+
content: [queryNode]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
tag: 'list',
|
|
132
|
+
attrs: {},
|
|
133
|
+
content: userNodes
|
|
134
|
+
}
|
|
135
|
+
]
|
|
142
136
|
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
137
|
+
],
|
|
138
|
+
});
|
|
139
|
+
const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
|
|
140
|
+
const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
|
|
141
|
+
const users = (0, WABinary_1.getBinaryNodeChildren)(listNode, 'user');
|
|
142
|
+
return users;
|
|
146
143
|
};
|
|
147
144
|
const onWhatsApp = async (...jids) => {
|
|
148
145
|
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
@@ -157,26 +154,14 @@ const makeChatsSocket = (config) => {
|
|
|
157
154
|
return results.list.filter((a) => !!a.contact).map(({ contact, id, lid }) => ({ jid: id, exists: contact, lid }));
|
|
158
155
|
}
|
|
159
156
|
};
|
|
160
|
-
const fetchStatus = async (
|
|
161
|
-
const
|
|
162
|
-
.withStatusProtocol();
|
|
163
|
-
for (const jid of jids) {
|
|
164
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
165
|
-
}
|
|
166
|
-
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
167
|
-
if (result) {
|
|
168
|
-
return result.list;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
const fetchDisappearingDuration = async (...jids) => {
|
|
172
|
-
const usyncQuery = new WAUSync_1.USyncQuery()
|
|
173
|
-
.withDisappearingModeProtocol();
|
|
174
|
-
for (const jid of jids) {
|
|
175
|
-
usyncQuery.withUser(new WAUSync_1.USyncUser().withId(jid));
|
|
176
|
-
}
|
|
177
|
-
const result = await sock.executeUSyncQuery(usyncQuery);
|
|
157
|
+
const fetchStatus = async (jid) => {
|
|
158
|
+
const [result] = await interactiveQuery([{ tag: 'user', attrs: { jid } }], { tag: 'status', attrs: {} });
|
|
178
159
|
if (result) {
|
|
179
|
-
|
|
160
|
+
const status = (0, WABinary_1.getBinaryNodeChild)(result, 'status');
|
|
161
|
+
return {
|
|
162
|
+
status: status === null || status === void 0 ? void 0 : status.content.toString(),
|
|
163
|
+
setAt: new Date(+((status === null || status === void 0 ? void 0 : status.attrs.t) || 0) * 1000)
|
|
164
|
+
};
|
|
180
165
|
}
|
|
181
166
|
};
|
|
182
167
|
/** update the profile picture for yourself or a group */
|
|
@@ -305,9 +290,9 @@ const makeChatsSocket = (config) => {
|
|
|
305
290
|
const email = (0, WABinary_1.getBinaryNodeChild)(profiles, 'email');
|
|
306
291
|
const category = (0, WABinary_1.getBinaryNodeChild)((0, WABinary_1.getBinaryNodeChild)(profiles, 'categories'), 'category');
|
|
307
292
|
const businessHours = (0, WABinary_1.getBinaryNodeChild)(profiles, 'business_hours');
|
|
308
|
-
const businessHoursConfig = businessHours
|
|
309
|
-
|
|
310
|
-
|
|
293
|
+
const businessHoursConfig = businessHours ?
|
|
294
|
+
(0, WABinary_1.getBinaryNodeChildren)(businessHours, 'business_hours_config') :
|
|
295
|
+
undefined;
|
|
311
296
|
const websiteStr = (_a = website === null || website === void 0 ? void 0 : website.content) === null || _a === void 0 ? void 0 : _a.toString();
|
|
312
297
|
return {
|
|
313
298
|
wid: (_b = profiles.attrs) === null || _b === void 0 ? void 0 : _b.jid,
|
|
@@ -416,12 +401,16 @@ const makeChatsSocket = (config) => {
|
|
|
416
401
|
states[name] = newState;
|
|
417
402
|
Object.assign(globalMutationMap, mutationMap);
|
|
418
403
|
logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
|
|
419
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
404
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
405
|
+
[name]: newState
|
|
406
|
+
} });
|
|
420
407
|
}
|
|
421
408
|
// only process if there are syncd patches
|
|
422
409
|
if (patches.length) {
|
|
423
410
|
const { state: newState, mutationMap } = await (0, Utils_1.decodePatches)(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
|
|
424
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
411
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
412
|
+
[name]: newState
|
|
413
|
+
} });
|
|
425
414
|
logger.info(`synced ${name} to v${newState.version}`);
|
|
426
415
|
initialVersionMap[name] = newState.version;
|
|
427
416
|
Object.assign(globalMutationMap, mutationMap);
|
|
@@ -436,11 +425,13 @@ const makeChatsSocket = (config) => {
|
|
|
436
425
|
catch (error) {
|
|
437
426
|
// if retry attempts overshoot
|
|
438
427
|
// or key not found
|
|
439
|
-
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS
|
|
440
|
-
|
|
441
|
-
|
|
428
|
+
const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
|
|
429
|
+
((_a = error.output) === null || _a === void 0 ? void 0 : _a.statusCode) === 404 ||
|
|
430
|
+
error.name === 'TypeError';
|
|
442
431
|
logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
|
|
443
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
432
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
433
|
+
[name]: null
|
|
434
|
+
} });
|
|
444
435
|
// increment number of retries
|
|
445
436
|
attemptsMap[name] = (attemptsMap[name] || 0) + 1;
|
|
446
437
|
if (isIrrecoverableError) {
|
|
@@ -490,7 +481,7 @@ const makeChatsSocket = (config) => {
|
|
|
490
481
|
await sendNode({
|
|
491
482
|
tag: 'presence',
|
|
492
483
|
attrs: {
|
|
493
|
-
name: me.name
|
|
484
|
+
name: me.name,
|
|
494
485
|
type
|
|
495
486
|
}
|
|
496
487
|
});
|
|
@@ -524,22 +515,22 @@ const makeChatsSocket = (config) => {
|
|
|
524
515
|
id: generateMessageTag(),
|
|
525
516
|
type: 'subscribe'
|
|
526
517
|
},
|
|
527
|
-
content: tcToken
|
|
528
|
-
|
|
518
|
+
content: tcToken ?
|
|
519
|
+
[
|
|
529
520
|
{
|
|
530
521
|
tag: 'tctoken',
|
|
531
522
|
attrs: {},
|
|
532
523
|
content: tcToken
|
|
533
524
|
}
|
|
534
|
-
]
|
|
535
|
-
|
|
525
|
+
] :
|
|
526
|
+
undefined
|
|
536
527
|
}));
|
|
537
528
|
const handlePresenceUpdate = ({ tag, attrs, content }) => {
|
|
538
529
|
var _a;
|
|
539
530
|
let presence;
|
|
540
531
|
const jid = attrs.from;
|
|
541
532
|
const participant = attrs.participant || attrs.from;
|
|
542
|
-
if (shouldIgnoreJid(jid) && jid
|
|
533
|
+
if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
|
|
543
534
|
return;
|
|
544
535
|
}
|
|
545
536
|
if (tag === 'presence') {
|
|
@@ -563,7 +554,9 @@ const makeChatsSocket = (config) => {
|
|
|
563
554
|
logger.error({ tag, attrs, content }, 'recv invalid presence node');
|
|
564
555
|
}
|
|
565
556
|
if (presence) {
|
|
566
|
-
ev.emit('presence.update', { id: jid, presences: {
|
|
557
|
+
ev.emit('presence.update', { id: jid, presences: {
|
|
558
|
+
[participant]: presence
|
|
559
|
+
} });
|
|
567
560
|
}
|
|
568
561
|
};
|
|
569
562
|
const appPatch = async (patchCreate) => {
|
|
@@ -614,7 +607,9 @@ const makeChatsSocket = (config) => {
|
|
|
614
607
|
]
|
|
615
608
|
};
|
|
616
609
|
await query(node);
|
|
617
|
-
await authState.keys.set({ 'app-state-sync-version': {
|
|
610
|
+
await authState.keys.set({ 'app-state-sync-version': {
|
|
611
|
+
[name]: state
|
|
612
|
+
} });
|
|
618
613
|
});
|
|
619
614
|
});
|
|
620
615
|
if (config.emitOwnEvents) {
|
|
@@ -627,7 +622,7 @@ const makeChatsSocket = (config) => {
|
|
|
627
622
|
};
|
|
628
623
|
/** sending non-abt props may fix QR scan fail if server expects */
|
|
629
624
|
const fetchProps = async () => {
|
|
630
|
-
var _a, _b
|
|
625
|
+
var _a, _b;
|
|
631
626
|
const resultNode = await query({
|
|
632
627
|
tag: 'iq',
|
|
633
628
|
attrs: {
|
|
@@ -636,19 +631,20 @@ const makeChatsSocket = (config) => {
|
|
|
636
631
|
type: 'get',
|
|
637
632
|
},
|
|
638
633
|
content: [
|
|
639
|
-
{
|
|
634
|
+
{
|
|
635
|
+
tag: 'props',
|
|
636
|
+
attrs: {
|
|
640
637
|
protocol: '2',
|
|
641
638
|
hash: ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.lastPropHash) || ''
|
|
642
|
-
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
643
641
|
]
|
|
644
642
|
});
|
|
645
643
|
const propsNode = (0, WABinary_1.getBinaryNodeChild)(resultNode, 'props');
|
|
646
644
|
let props = {};
|
|
647
645
|
if (propsNode) {
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
ev.emit('creds.update', authState.creds);
|
|
651
|
-
}
|
|
646
|
+
authState.creds.lastPropHash = (_b = propsNode === null || propsNode === void 0 ? void 0 : propsNode.attrs) === null || _b === void 0 ? void 0 : _b.hash;
|
|
647
|
+
ev.emit('creds.update', authState.creds);
|
|
652
648
|
props = (0, WABinary_1.reduceBinaryNodeToDictionary)(propsNode, 'prop');
|
|
653
649
|
}
|
|
654
650
|
logger.debug('fetched props');
|
|
@@ -658,7 +654,7 @@ const makeChatsSocket = (config) => {
|
|
|
658
654
|
* modify a chat -- mark unread, read etc.
|
|
659
655
|
* lastMessages must be sorted in reverse chronologically
|
|
660
656
|
* requires the last messages till the last message received; required for archive & unread
|
|
661
|
-
|
|
657
|
+
*/
|
|
662
658
|
const chatModify = (mod, jid) => {
|
|
663
659
|
const patch = (0, Utils_1.chatModificationToAppPatch)(mod, jid);
|
|
664
660
|
return appPatch(patch);
|
|
@@ -742,25 +738,24 @@ const makeChatsSocket = (config) => {
|
|
|
742
738
|
}
|
|
743
739
|
}
|
|
744
740
|
const historyMsg = (0, Utils_1.getHistoryMsg)(msg.message);
|
|
745
|
-
const shouldProcessHistoryMsg = historyMsg
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
741
|
+
const shouldProcessHistoryMsg = historyMsg ?
|
|
742
|
+
(shouldSyncHistoryMessage(historyMsg) &&
|
|
743
|
+
Defaults_1.PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)) :
|
|
744
|
+
false;
|
|
749
745
|
if (historyMsg && !authState.creds.myAppStateKeyId) {
|
|
750
746
|
logger.warn('skipping app state sync, as myAppStateKeyId is not set');
|
|
751
747
|
pendingAppStateSync = true;
|
|
752
748
|
}
|
|
753
749
|
await Promise.all([
|
|
754
750
|
(async () => {
|
|
755
|
-
if (historyMsg
|
|
756
|
-
|
|
751
|
+
if (historyMsg &&
|
|
752
|
+
authState.creds.myAppStateKeyId) {
|
|
757
753
|
pendingAppStateSync = false;
|
|
758
754
|
await doAppStateSync();
|
|
759
755
|
}
|
|
760
756
|
})(),
|
|
761
757
|
(0, process_message_1.default)(msg, {
|
|
762
758
|
shouldProcessHistoryMsg,
|
|
763
|
-
placeholderResendCache,
|
|
764
759
|
ev,
|
|
765
760
|
creds: authState.creds,
|
|
766
761
|
keyStore: authState.keys,
|
|
@@ -769,8 +764,8 @@ const makeChatsSocket = (config) => {
|
|
|
769
764
|
getMessage: config.getMessage,
|
|
770
765
|
})
|
|
771
766
|
]);
|
|
772
|
-
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare)
|
|
773
|
-
|
|
767
|
+
if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.appStateSyncKeyShare) &&
|
|
768
|
+
pendingAppStateSync) {
|
|
774
769
|
await doAppStateSync();
|
|
775
770
|
pendingAppStateSync = false;
|
|
776
771
|
}
|
|
@@ -821,17 +816,18 @@ const makeChatsSocket = (config) => {
|
|
|
821
816
|
sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
|
|
822
817
|
.catch(error => onUnexpectedError(error, 'presence update requests'));
|
|
823
818
|
}
|
|
824
|
-
if (receivedPendingNotifications
|
|
819
|
+
if (receivedPendingNotifications) {
|
|
820
|
+
// if we don't have the app state key
|
|
825
821
|
// we keep buffering events until we finally have
|
|
826
822
|
// the key and can sync the messages
|
|
827
|
-
!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
|
|
828
|
-
|
|
829
|
-
|
|
823
|
+
if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
|
|
824
|
+
ev.buffer();
|
|
825
|
+
needToFlushWithAppStateSync = true;
|
|
826
|
+
}
|
|
830
827
|
}
|
|
831
828
|
});
|
|
832
829
|
return {
|
|
833
830
|
...sock,
|
|
834
|
-
getBotListV2,
|
|
835
831
|
processingMutex,
|
|
836
832
|
fetchPrivacySettings,
|
|
837
833
|
upsertMessage,
|
|
@@ -841,15 +837,12 @@ const makeChatsSocket = (config) => {
|
|
|
841
837
|
profilePictureUrl,
|
|
842
838
|
onWhatsApp,
|
|
843
839
|
fetchBlocklist,
|
|
844
|
-
fetchDisappearingDuration,
|
|
845
840
|
fetchStatus,
|
|
846
841
|
updateProfilePicture,
|
|
847
842
|
removeProfilePicture,
|
|
848
843
|
updateProfileStatus,
|
|
849
844
|
updateProfileName,
|
|
850
845
|
updateBlockStatus,
|
|
851
|
-
updateCallPrivacy,
|
|
852
|
-
updateMessagesPrivacy,
|
|
853
846
|
updateLastSeenPrivacy,
|
|
854
847
|
updateOnlinePrivacy,
|
|
855
848
|
updateProfilePicturePrivacy,
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// dugong.d.ts
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
|
|
4
|
+
declare namespace kikyy {
|
|
5
|
+
interface MediaUploadOptions {
|
|
6
|
+
fileEncSha256?: Buffer;
|
|
7
|
+
mediaType?: string;
|
|
8
|
+
newsletter?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type WAMediaUploadFunction = (
|
|
12
|
+
stream: Buffer | NodeJS.ReadableStream,
|
|
13
|
+
options?: MediaUploadOptions
|
|
14
|
+
) => Promise<{ url: string; directPath: string }>;
|
|
15
|
+
|
|
16
|
+
interface WAMessageContentGenerationOptions {
|
|
17
|
+
upload?: WAMediaUploadFunction;
|
|
18
|
+
mediaCache?: any;
|
|
19
|
+
options?: any;
|
|
20
|
+
logger?: any;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface StickerMessage {
|
|
24
|
+
url: string;
|
|
25
|
+
fileSha256: Buffer | string;
|
|
26
|
+
fileEncSha256: Buffer | string;
|
|
27
|
+
mediaKey: Buffer | string;
|
|
28
|
+
mimetype: string;
|
|
29
|
+
directPath: string;
|
|
30
|
+
fileLength: number | string;
|
|
31
|
+
mediaKeyTimestamp: number | string;
|
|
32
|
+
isAnimated?: boolean;
|
|
33
|
+
stickerSentTs?: number | string;
|
|
34
|
+
isAvatar?: boolean;
|
|
35
|
+
isAiSticker?: boolean;
|
|
36
|
+
isLottie?: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface PaymentMessage {
|
|
40
|
+
amount: number;
|
|
41
|
+
currency?: string;
|
|
42
|
+
from?: string;
|
|
43
|
+
expiry?: number;
|
|
44
|
+
sticker?: { stickerMessage: StickerMessage };
|
|
45
|
+
note?: string;
|
|
46
|
+
background?: {
|
|
47
|
+
id?: string;
|
|
48
|
+
fileLength?: string;
|
|
49
|
+
width?: number;
|
|
50
|
+
height?: number;
|
|
51
|
+
mimetype?: string;
|
|
52
|
+
placeholderArgb?: number;
|
|
53
|
+
textArgb?: number;
|
|
54
|
+
subtextArgb?: number;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface ProductMessage {
|
|
59
|
+
title: string;
|
|
60
|
+
description: string;
|
|
61
|
+
thumbnail: Buffer | { url: string };
|
|
62
|
+
productId: string;
|
|
63
|
+
retailerId: string;
|
|
64
|
+
url: string;
|
|
65
|
+
body?: string;
|
|
66
|
+
footer?: string;
|
|
67
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
68
|
+
priceAmount1000?: number | null;
|
|
69
|
+
currencyCode?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface InteractiveMessage {
|
|
73
|
+
title: string;
|
|
74
|
+
footer?: string;
|
|
75
|
+
thumbnail?: string;
|
|
76
|
+
image?: string | Buffer | { url: string };
|
|
77
|
+
video?: string | Buffer | { url: string };
|
|
78
|
+
document?: Buffer;
|
|
79
|
+
mimetype?: string;
|
|
80
|
+
fileName?: string;
|
|
81
|
+
jpegThumbnail?: Buffer; // Hanya Buffer saja
|
|
82
|
+
contextInfo?: {
|
|
83
|
+
mentionedJid?: string[];
|
|
84
|
+
forwardingScore?: number;
|
|
85
|
+
isForwarded?: boolean;
|
|
86
|
+
externalAdReply?: {
|
|
87
|
+
title?: string;
|
|
88
|
+
body?: string;
|
|
89
|
+
mediaType?: number;
|
|
90
|
+
thumbnailUrl?: string;
|
|
91
|
+
mediaUrl?: string;
|
|
92
|
+
sourceUrl?: string;
|
|
93
|
+
showAdAttribution?: boolean;
|
|
94
|
+
renderLargerThumbnail?: boolean;
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
};
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
};
|
|
99
|
+
externalAdReply?: {
|
|
100
|
+
title?: string;
|
|
101
|
+
body?: string;
|
|
102
|
+
mediaType?: number;
|
|
103
|
+
thumbnailUrl?: string;
|
|
104
|
+
mediaUrl?: string;
|
|
105
|
+
sourceUrl?: string;
|
|
106
|
+
showAdAttribution?: boolean;
|
|
107
|
+
renderLargerThumbnail?: boolean;
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
};
|
|
110
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
111
|
+
nativeFlowMessage?: {
|
|
112
|
+
messageParamsJson?: string;
|
|
113
|
+
buttons?: proto.Message.InteractiveMessage.INativeFlowButton[];
|
|
114
|
+
[key: string]: any;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
interface AlbumItem {
|
|
119
|
+
image?: { url: string; caption?: string };
|
|
120
|
+
video?: { url: string; caption?: string };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface EventMessageLocation {
|
|
124
|
+
degreesLatitude: number;
|
|
125
|
+
degreesLongitude: number;
|
|
126
|
+
name: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface EventMessage {
|
|
130
|
+
isCanceled?: boolean;
|
|
131
|
+
name: string;
|
|
132
|
+
description: string;
|
|
133
|
+
location?: EventMessageLocation;
|
|
134
|
+
joinLink?: string;
|
|
135
|
+
startTime?: string | number;
|
|
136
|
+
endTime?: string | number;
|
|
137
|
+
extraGuestsAllowed?: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface PollVote {
|
|
141
|
+
optionName: string;
|
|
142
|
+
optionVoteCount: string | number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
interface PollResultMessage {
|
|
146
|
+
name: string;
|
|
147
|
+
pollVotes: PollVote[];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface MessageContent {
|
|
151
|
+
requestPaymentMessage?: PaymentMessage;
|
|
152
|
+
productMessage?: ProductMessage;
|
|
153
|
+
interactiveMessage?: InteractiveMessage;
|
|
154
|
+
albumMessage?: AlbumItem[];
|
|
155
|
+
eventMessage?: EventMessage;
|
|
156
|
+
pollResultMessage?: PollResultMessage;
|
|
157
|
+
sender?: string;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface MessageOptions {
|
|
161
|
+
quoted?: proto.IWebMessageInfo;
|
|
162
|
+
filter?: boolean;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface Utils {
|
|
166
|
+
prepareWAMessageMedia: (media: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
167
|
+
generateWAMessageContent: (content: any, options: WAMessageContentGenerationOptions) => Promise<any>;
|
|
168
|
+
generateWAMessageFromContent: (jid: string, content: any, options?: any) => Promise<any>;
|
|
169
|
+
generateWAMessage: (jid: string, content: any, options?: any) => Promise<any>;
|
|
170
|
+
generateMessageID: () => string;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
declare class kikyy {
|
|
175
|
+
constructor(
|
|
176
|
+
utils: kikyy.Utils,
|
|
177
|
+
waUploadToServer: kikyy.WAMediaUploadFunction,
|
|
178
|
+
relayMessageFn?: (jid: string, content: any, options?: any) => Promise<any>
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
detectType(content: kikyy.MessageContent): 'PAYMENT' | 'PRODUCT' | 'INTERACTIVE' | 'ALBUM' | 'EVENT' | 'POLL_RESULT' | null;
|
|
182
|
+
|
|
183
|
+
handlePayment(
|
|
184
|
+
content: { requestPaymentMessage: kikyy.PaymentMessage },
|
|
185
|
+
quoted?: proto.IWebMessageInfo
|
|
186
|
+
): Promise<{ requestPaymentMessage: proto.Message.RequestPaymentMessage }>;
|
|
187
|
+
|
|
188
|
+
handleProduct(
|
|
189
|
+
content: { productMessage: kikyy.ProductMessage },
|
|
190
|
+
jid: string,
|
|
191
|
+
quoted?: proto.IWebMessageInfo
|
|
192
|
+
): Promise<{ viewOnceMessage: proto.Message.ViewOnceMessage }>;
|
|
193
|
+
|
|
194
|
+
handleInteractive(
|
|
195
|
+
content: { interactiveMessage: kikyy.InteractiveMessage },
|
|
196
|
+
jid: string,
|
|
197
|
+
quoted?: proto.IWebMessageInfo
|
|
198
|
+
): Promise<{ interactiveMessage: proto.Message.InteractiveMessage }>;
|
|
199
|
+
|
|
200
|
+
handleAlbum(
|
|
201
|
+
content: { albumMessage: kikyy.AlbumItem[] },
|
|
202
|
+
jid: string,
|
|
203
|
+
quoted?: proto.IWebMessageInfo
|
|
204
|
+
): Promise<any>;
|
|
205
|
+
|
|
206
|
+
handleEvent(
|
|
207
|
+
content: { eventMessage: kikyy.EventMessage },
|
|
208
|
+
jid: string,
|
|
209
|
+
quoted?: proto.IWebMessageInfo
|
|
210
|
+
): Promise<any>;
|
|
211
|
+
|
|
212
|
+
handlePollResult(
|
|
213
|
+
content: { pollResultMessage: kikyy.PollResultMessage },
|
|
214
|
+
jid: string,
|
|
215
|
+
quoted?: proto.IWebMessageInfo
|
|
216
|
+
): Promise<any>;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export = kikyy;
|