@vinzsocket/baileys 2.8.10 → 2.8.30

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.
Files changed (83) hide show
  1. package/lib/Defaults/index.js +75 -73
  2. package/lib/Signal/Group/ciphertext-message.js +9 -9
  3. package/lib/Signal/Group/group-session-builder.js +21 -21
  4. package/lib/Signal/Group/group_cipher.js +79 -81
  5. package/lib/Signal/Group/index.js +2 -2
  6. package/lib/Signal/Group/keyhelper.js +9 -9
  7. package/lib/Signal/Group/queue-job.js +43 -46
  8. package/lib/Signal/Group/sender-chain-key.js +24 -25
  9. package/lib/Signal/Group/sender-key-distribution-message.js +50 -58
  10. package/lib/Signal/Group/sender-key-message.js +55 -60
  11. package/lib/Signal/Group/sender-key-name.js +38 -39
  12. package/lib/Signal/Group/sender-key-record.js +39 -41
  13. package/lib/Signal/Group/sender-key-state.js +85 -89
  14. package/lib/Signal/Group/sender-message-key.js +22 -22
  15. package/lib/Signal/libsignal.js +387 -292
  16. package/lib/Signal/lid-mapping.js +98 -93
  17. package/lib/Socket/Client/types.js +6 -6
  18. package/lib/Socket/Client/websocket.js +44 -44
  19. package/lib/Socket/business.js +350 -365
  20. package/lib/Socket/chats.js +1019 -914
  21. package/lib/Socket/communities.js +454 -376
  22. package/lib/Socket/groups.js +378 -310
  23. package/lib/Socket/index.js +11 -11
  24. package/lib/Socket/messages-recv.js +1355 -1182
  25. package/lib/Socket/messages-send.js +1224 -1081
  26. package/lib/Socket/mex.js +40 -34
  27. package/lib/Socket/newsletter.js +212 -169
  28. package/lib/Socket/socket.js +896 -757
  29. package/lib/Store/index.js +1 -1
  30. package/lib/Store/make-cache-manager-store.js +75 -79
  31. package/lib/Store/make-in-memory-store.js +450 -389
  32. package/lib/Store/make-ordered-dictionary.js +73 -76
  33. package/lib/Store/object-repository.js +24 -22
  34. package/lib/Types/Chat.js +1 -7
  35. package/lib/Types/Label.js +20 -20
  36. package/lib/Types/LabelAssociation.js +2 -2
  37. package/lib/Types/Message.js +2 -2
  38. package/lib/Types/Newsletter.js +24 -24
  39. package/lib/Types/Socket.js +1 -1
  40. package/lib/Types/State.js +8 -8
  41. package/lib/Types/index.js +10 -10
  42. package/lib/Utils/auth-utils.js +408 -401
  43. package/lib/Utils/baileys-event-stream.js +44 -35
  44. package/lib/Utils/business.js +200 -197
  45. package/lib/Utils/chat-utils.js +775 -708
  46. package/lib/Utils/crypto.js +97 -85
  47. package/lib/Utils/decode-wa-message.js +240 -227
  48. package/lib/Utils/event-buffer.js +547 -518
  49. package/lib/Utils/extended-messages.js +250 -203
  50. package/lib/Utils/generics.js +300 -289
  51. package/lib/Utils/history.js +76 -69
  52. package/lib/Utils/lid-resolver.js +47 -42
  53. package/lib/Utils/link-preview.js +75 -65
  54. package/lib/Utils/logger.js +3 -1
  55. package/lib/Utils/lt-hash.js +38 -34
  56. package/lib/Utils/make-mutex.js +32 -34
  57. package/lib/Utils/mention.js +79 -86
  58. package/lib/Utils/message-retry-manager.js +148 -136
  59. package/lib/Utils/messages-media.js +652 -562
  60. package/lib/Utils/messages.js +753 -707
  61. package/lib/Utils/noise-handler.js +156 -135
  62. package/lib/Utils/process-message.js +404 -341
  63. package/lib/Utils/signal.js +180 -118
  64. package/lib/Utils/use-multi-file-auth-state.js +87 -91
  65. package/lib/Utils/validate-connection.js +167 -142
  66. package/lib/WABinary/constants.js +28 -1293
  67. package/lib/WABinary/decode.js +220 -218
  68. package/lib/WABinary/encode.js +199 -201
  69. package/lib/WABinary/generic-utils.js +80 -77
  70. package/lib/WABinary/jid-utils.js +41 -35
  71. package/lib/WAM/BinaryInfo.js +7 -7
  72. package/lib/WAM/constants.js +1 -15241
  73. package/lib/WAM/encode.js +124 -131
  74. package/lib/WAUSync/Protocols/USyncContactProtocol.js +23 -23
  75. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +51 -47
  76. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -22
  77. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -32
  78. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -19
  79. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -43
  80. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +17 -17
  81. package/lib/WAUSync/USyncQuery.js +82 -84
  82. package/lib/WAUSync/USyncUser.js +20 -20
  83. package/package.json +4 -2
@@ -11,949 +11,1054 @@ import { getBinaryNodeChild, getBinaryNodeChildren, jidDecode, jidNormalizedUser
11
11
  import { USyncQuery, USyncUser } from '../WAUSync/index.js';
12
12
  import { makeSocket } from './socket.js';
13
13
  const MAX_SYNC_ATTEMPTS = 2;
14
- export const makeChatsSocket = (config) => {
15
- const { logger, markOnlineOnConnect, fireInitQueries, appStateMacVerification, shouldIgnoreJid, shouldSyncHistoryMessage } = config;
16
- const sock = makeSocket(config);
17
- const { ev, ws, authState, generateMessageTag, sendNode, query, signalRepository, onUnexpectedError } = sock;
18
- let privacySettings;
19
- let syncState = SyncState.Connecting;
20
- /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
21
- const processingMutex = makeMutex();
22
- // Timeout for AwaitingInitialSync state
23
- let awaitingSyncTimeout;
24
- const placeholderResendCache = config.placeholderResendCache ||
25
- new NodeCache({
26
- stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
27
- useClones: false
28
- });
29
- if (!config.placeholderResendCache) {
30
- config.placeholderResendCache = placeholderResendCache;
14
+ export const makeChatsSocket = config => {
15
+ const {
16
+ logger,
17
+ markOnlineOnConnect,
18
+ fireInitQueries,
19
+ appStateMacVerification,
20
+ shouldIgnoreJid,
21
+ shouldSyncHistoryMessage
22
+ } = config;
23
+ const sock = makeSocket(config);
24
+ const {
25
+ ev,
26
+ ws,
27
+ authState,
28
+ generateMessageTag,
29
+ sendNode,
30
+ query,
31
+ signalRepository,
32
+ onUnexpectedError
33
+ } = sock;
34
+ let privacySettings;
35
+ let syncState = SyncState.Connecting;
36
+ /** this mutex ensures that the notifications (receipts, messages etc.) are processed in order */
37
+ const processingMutex = makeMutex();
38
+ // Timeout for AwaitingInitialSync state
39
+ let awaitingSyncTimeout;
40
+ const placeholderResendCache = config.placeholderResendCache || new NodeCache({
41
+ stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
42
+ // 1 hour
43
+ useClones: false
44
+ });
45
+ if (!config.placeholderResendCache) {
46
+ config.placeholderResendCache = placeholderResendCache;
47
+ }
48
+ /** helper function to fetch the given app state sync key */
49
+ const getAppStateSyncKey = async keyId => {
50
+ const {
51
+ [keyId]: key
52
+ } = await authState.keys.get('app-state-sync-key', [keyId]);
53
+ return key;
54
+ };
55
+ const fetchPrivacySettings = async (force = false) => {
56
+ if (!privacySettings || force) {
57
+ const {
58
+ content
59
+ } = await query({
60
+ tag: 'iq',
61
+ attrs: {
62
+ xmlns: 'privacy',
63
+ to: S_WHATSAPP_NET,
64
+ type: 'get'
65
+ },
66
+ content: [{
67
+ tag: 'privacy',
68
+ attrs: {}
69
+ }]
70
+ });
71
+ privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
31
72
  }
32
- /** helper function to fetch the given app state sync key */
33
- const getAppStateSyncKey = async (keyId) => {
34
- const { [keyId]: key } = await authState.keys.get('app-state-sync-key', [keyId]);
35
- return key;
36
- };
37
- const fetchPrivacySettings = async (force = false) => {
38
- if (!privacySettings || force) {
39
- const { content } = await query({
40
- tag: 'iq',
41
- attrs: {
42
- xmlns: 'privacy',
43
- to: S_WHATSAPP_NET,
44
- type: 'get'
45
- },
46
- content: [{ tag: 'privacy', attrs: {} }]
47
- });
48
- privacySettings = reduceBinaryNodeToDictionary(content?.[0], 'category');
49
- }
50
- return privacySettings;
51
- };
52
- /** helper function to run a privacy IQ query */
53
- const privacyQuery = async (name, value) => {
54
- await query({
55
- tag: 'iq',
56
- attrs: {
57
- xmlns: 'privacy',
58
- to: S_WHATSAPP_NET,
59
- type: 'set'
60
- },
61
- content: [
62
- {
63
- tag: 'privacy',
64
- attrs: {},
65
- content: [
66
- {
67
- tag: 'category',
68
- attrs: { name, value }
69
- }
70
- ]
71
- }
72
- ]
73
- });
74
- };
75
- const updateMessagesPrivacy = async (value) => {
76
- await privacyQuery('messages', value);
77
- };
78
- const updateCallPrivacy = async (value) => {
79
- await privacyQuery('calladd', value);
80
- };
81
- const updateLastSeenPrivacy = async (value) => {
82
- await privacyQuery('last', value);
83
- };
84
- const updateOnlinePrivacy = async (value) => {
85
- await privacyQuery('online', value);
86
- };
87
- const updateProfilePicturePrivacy = async (value) => {
88
- await privacyQuery('profile', value);
89
- };
90
- const updateStatusPrivacy = async (value) => {
91
- await privacyQuery('status', value);
92
- };
93
- const updateReadReceiptsPrivacy = async (value) => {
94
- await privacyQuery('readreceipts', value);
95
- };
96
- const updateGroupsAddPrivacy = async (value) => {
97
- await privacyQuery('groupadd', value);
98
- };
99
- const updateDefaultDisappearingMode = async (duration) => {
100
- await query({
101
- tag: 'iq',
102
- attrs: {
103
- xmlns: 'disappearing_mode',
104
- to: S_WHATSAPP_NET,
105
- type: 'set'
106
- },
107
- content: [
108
- {
109
- tag: 'disappearing_mode',
110
- attrs: {
111
- duration: duration.toString()
112
- }
113
- }
114
- ]
115
- });
116
- };
117
- const getBotListV2 = async () => {
118
- const resp = await query({
119
- tag: 'iq',
120
- attrs: {
121
- xmlns: 'bot',
122
- to: S_WHATSAPP_NET,
123
- type: 'get'
124
- },
125
- content: [
126
- {
127
- tag: 'bot',
128
- attrs: {
129
- v: '2'
130
- }
131
- }
132
- ]
133
- });
134
- const botNode = getBinaryNodeChild(resp, 'bot');
135
- const botList = [];
136
- for (const section of getBinaryNodeChildren(botNode, 'section')) {
137
- if (section.attrs.type === 'all') {
138
- for (const bot of getBinaryNodeChildren(section, 'bot')) {
139
- botList.push({
140
- jid: bot.attrs.jid,
141
- personaId: bot.attrs['persona_id']
142
- });
143
- }
144
- }
145
- }
146
- return botList;
147
- };
148
- const fetchStatus = async (...jids) => {
149
- const usyncQuery = new USyncQuery().withStatusProtocol();
150
- for (const jid of jids) {
151
- usyncQuery.withUser(new USyncUser().withId(jid));
152
- }
153
- const result = await sock.executeUSyncQuery(usyncQuery);
154
- if (result) {
155
- return result.list;
73
+ return privacySettings;
74
+ };
75
+ /** helper function to run a privacy IQ query */
76
+ const privacyQuery = async (name, value) => {
77
+ await query({
78
+ tag: 'iq',
79
+ attrs: {
80
+ xmlns: 'privacy',
81
+ to: S_WHATSAPP_NET,
82
+ type: 'set'
83
+ },
84
+ content: [{
85
+ tag: 'privacy',
86
+ attrs: {},
87
+ content: [{
88
+ tag: 'category',
89
+ attrs: {
90
+ name,
91
+ value
92
+ }
93
+ }]
94
+ }]
95
+ });
96
+ };
97
+ const updateMessagesPrivacy = async value => {
98
+ await privacyQuery('messages', value);
99
+ };
100
+ const updateCallPrivacy = async value => {
101
+ await privacyQuery('calladd', value);
102
+ };
103
+ const updateLastSeenPrivacy = async value => {
104
+ await privacyQuery('last', value);
105
+ };
106
+ const updateOnlinePrivacy = async value => {
107
+ await privacyQuery('online', value);
108
+ };
109
+ const updateProfilePicturePrivacy = async value => {
110
+ await privacyQuery('profile', value);
111
+ };
112
+ const updateStatusPrivacy = async value => {
113
+ await privacyQuery('status', value);
114
+ };
115
+ const updateReadReceiptsPrivacy = async value => {
116
+ await privacyQuery('readreceipts', value);
117
+ };
118
+ const updateGroupsAddPrivacy = async value => {
119
+ await privacyQuery('groupadd', value);
120
+ };
121
+ const updateDefaultDisappearingMode = async duration => {
122
+ await query({
123
+ tag: 'iq',
124
+ attrs: {
125
+ xmlns: 'disappearing_mode',
126
+ to: S_WHATSAPP_NET,
127
+ type: 'set'
128
+ },
129
+ content: [{
130
+ tag: 'disappearing_mode',
131
+ attrs: {
132
+ duration: duration.toString()
156
133
  }
157
- };
158
- const fetchDisappearingDuration = async (...jids) => {
159
- const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
160
- for (const jid of jids) {
161
- usyncQuery.withUser(new USyncUser().withId(jid));
134
+ }]
135
+ });
136
+ };
137
+ const getBotListV2 = async () => {
138
+ const resp = await query({
139
+ tag: 'iq',
140
+ attrs: {
141
+ xmlns: 'bot',
142
+ to: S_WHATSAPP_NET,
143
+ type: 'get'
144
+ },
145
+ content: [{
146
+ tag: 'bot',
147
+ attrs: {
148
+ v: '2'
162
149
  }
163
- const result = await sock.executeUSyncQuery(usyncQuery);
164
- if (result) {
165
- return result.list;
150
+ }]
151
+ });
152
+ const botNode = getBinaryNodeChild(resp, 'bot');
153
+ const botList = [];
154
+ for (const section of getBinaryNodeChildren(botNode, 'section')) {
155
+ if (section.attrs.type === 'all') {
156
+ for (const bot of getBinaryNodeChildren(section, 'bot')) {
157
+ botList.push({
158
+ jid: bot.attrs.jid,
159
+ personaId: bot.attrs['persona_id']
160
+ });
166
161
  }
167
- };
168
- /** update the profile picture for yourself or a group */
169
- const updateProfilePicture = async (jid, content, dimensions) => {
170
- let targetJid;
171
- if (!jid) {
172
- throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
162
+ }
163
+ }
164
+ return botList;
165
+ };
166
+ const fetchStatus = async (...jids) => {
167
+ const usyncQuery = new USyncQuery().withStatusProtocol();
168
+ for (const jid of jids) {
169
+ usyncQuery.withUser(new USyncUser().withId(jid));
170
+ }
171
+ const result = await sock.executeUSyncQuery(usyncQuery);
172
+ if (result) {
173
+ return result.list;
174
+ }
175
+ };
176
+ const fetchDisappearingDuration = async (...jids) => {
177
+ const usyncQuery = new USyncQuery().withDisappearingModeProtocol();
178
+ for (const jid of jids) {
179
+ usyncQuery.withUser(new USyncUser().withId(jid));
180
+ }
181
+ const result = await sock.executeUSyncQuery(usyncQuery);
182
+ if (result) {
183
+ return result.list;
184
+ }
185
+ };
186
+ /** update the profile picture for yourself or a group */
187
+ const updateProfilePicture = async (jid, content, dimensions) => {
188
+ let targetJid;
189
+ if (!jid) {
190
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
191
+ }
192
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
193
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
194
+ } else {
195
+ targetJid = undefined;
196
+ }
197
+ const {
198
+ img
199
+ } = await generateProfilePicture(content, dimensions);
200
+ await query({
201
+ tag: 'iq',
202
+ attrs: {
203
+ to: S_WHATSAPP_NET,
204
+ type: 'set',
205
+ xmlns: 'w:profile:picture',
206
+ ...(targetJid ? {
207
+ target: targetJid
208
+ } : {})
209
+ },
210
+ content: [{
211
+ tag: 'picture',
212
+ attrs: {
213
+ type: 'image'
214
+ },
215
+ content: img
216
+ }]
217
+ });
218
+ };
219
+ /** remove the profile picture for yourself or a group */
220
+ const removeProfilePicture = async jid => {
221
+ let targetJid;
222
+ if (!jid) {
223
+ throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
224
+ }
225
+ if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
226
+ targetJid = jidNormalizedUser(jid); // in case it is someone other than us
227
+ } else {
228
+ targetJid = undefined;
229
+ }
230
+ await query({
231
+ tag: 'iq',
232
+ attrs: {
233
+ to: S_WHATSAPP_NET,
234
+ type: 'set',
235
+ xmlns: 'w:profile:picture',
236
+ ...(targetJid ? {
237
+ target: targetJid
238
+ } : {})
239
+ }
240
+ });
241
+ };
242
+ /** update the profile status for yourself */
243
+ const updateProfileStatus = async status => {
244
+ await query({
245
+ tag: 'iq',
246
+ attrs: {
247
+ to: S_WHATSAPP_NET,
248
+ type: 'set',
249
+ xmlns: 'status'
250
+ },
251
+ content: [{
252
+ tag: 'status',
253
+ attrs: {},
254
+ content: Buffer.from(status, 'utf-8')
255
+ }]
256
+ });
257
+ };
258
+ const updateProfileName = async name => {
259
+ await chatModify({
260
+ pushNameSetting: name
261
+ }, '');
262
+ };
263
+ const fetchBlocklist = async () => {
264
+ const result = await query({
265
+ tag: 'iq',
266
+ attrs: {
267
+ xmlns: 'blocklist',
268
+ to: S_WHATSAPP_NET,
269
+ type: 'get'
270
+ }
271
+ });
272
+ const listNode = getBinaryNodeChild(result, 'list');
273
+ return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
274
+ };
275
+ const updateBlockStatus = async (jid, action) => {
276
+ await query({
277
+ tag: 'iq',
278
+ attrs: {
279
+ xmlns: 'blocklist',
280
+ to: S_WHATSAPP_NET,
281
+ type: 'set'
282
+ },
283
+ content: [{
284
+ tag: 'item',
285
+ attrs: {
286
+ action,
287
+ jid
173
288
  }
174
- if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
175
- targetJid = jidNormalizedUser(jid); // in case it is someone other than us
289
+ }]
290
+ });
291
+ };
292
+ const getBusinessProfile = async jid => {
293
+ const results = await query({
294
+ tag: 'iq',
295
+ attrs: {
296
+ to: 's.whatsapp.net',
297
+ xmlns: 'w:biz',
298
+ type: 'get'
299
+ },
300
+ content: [{
301
+ tag: 'business_profile',
302
+ attrs: {
303
+ v: '244'
304
+ },
305
+ content: [{
306
+ tag: 'profile',
307
+ attrs: {
308
+ jid
309
+ }
310
+ }]
311
+ }]
312
+ });
313
+ const profileNode = getBinaryNodeChild(results, 'business_profile');
314
+ const profiles = getBinaryNodeChild(profileNode, 'profile');
315
+ if (profiles) {
316
+ const address = getBinaryNodeChild(profiles, 'address');
317
+ const description = getBinaryNodeChild(profiles, 'description');
318
+ const website = getBinaryNodeChild(profiles, 'website');
319
+ const email = getBinaryNodeChild(profiles, 'email');
320
+ const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
321
+ const businessHours = getBinaryNodeChild(profiles, 'business_hours');
322
+ const businessHoursConfig = businessHours ? getBinaryNodeChildren(businessHours, 'business_hours_config') : undefined;
323
+ const websiteStr = website?.content?.toString();
324
+ return {
325
+ wid: profiles.attrs?.jid,
326
+ address: address?.content?.toString(),
327
+ description: description?.content?.toString() || '',
328
+ website: websiteStr ? [websiteStr] : [],
329
+ email: email?.content?.toString(),
330
+ category: category?.content?.toString(),
331
+ business_hours: {
332
+ timezone: businessHours?.attrs?.timezone,
333
+ business_config: businessHoursConfig?.map(({
334
+ attrs
335
+ }) => attrs)
176
336
  }
177
- else {
178
- targetJid = undefined;
337
+ };
338
+ }
339
+ };
340
+ const cleanDirtyBits = async (type, fromTimestamp) => {
341
+ logger.info({
342
+ fromTimestamp
343
+ }, 'clean dirty bits ' + type);
344
+ await sendNode({
345
+ tag: 'iq',
346
+ attrs: {
347
+ to: S_WHATSAPP_NET,
348
+ type: 'set',
349
+ xmlns: 'urn:xmpp:whatsapp:dirty',
350
+ id: generateMessageTag()
351
+ },
352
+ content: [{
353
+ tag: 'clean',
354
+ attrs: {
355
+ type,
356
+ ...(fromTimestamp ? {
357
+ timestamp: fromTimestamp.toString()
358
+ } : null)
179
359
  }
180
- const { img } = await generateProfilePicture(content, dimensions);
181
- await query({
182
- tag: 'iq',
183
- attrs: {
184
- to: S_WHATSAPP_NET,
185
- type: 'set',
186
- xmlns: 'w:profile:picture',
187
- ...(targetJid ? { target: targetJid } : {})
188
- },
189
- content: [
190
- {
191
- tag: 'picture',
192
- attrs: { type: 'image' },
193
- content: img
194
- }
195
- ]
196
- });
360
+ }]
361
+ });
362
+ };
363
+ const newAppStateChunkHandler = isInitialSync => {
364
+ return {
365
+ onMutation(mutation) {
366
+ processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? {
367
+ accountSettings: authState.creds.accountSettings
368
+ } : undefined, logger);
369
+ }
197
370
  };
198
- /** remove the profile picture for yourself or a group */
199
- const removeProfilePicture = async (jid) => {
200
- let targetJid;
201
- if (!jid) {
202
- throw new Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
203
- }
204
- if (jidNormalizedUser(jid) !== jidNormalizedUser(authState.creds.me.id)) {
205
- targetJid = jidNormalizedUser(jid); // in case it is someone other than us
206
- }
207
- else {
208
- targetJid = undefined;
209
- }
210
- await query({
211
- tag: 'iq',
212
- attrs: {
213
- to: S_WHATSAPP_NET,
214
- type: 'set',
215
- xmlns: 'w:profile:picture',
216
- ...(targetJid ? { target: targetJid } : {})
371
+ };
372
+ const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
373
+ // we use this to determine which events to fire
374
+ // otherwise when we resync from scratch -- all notifications will fire
375
+ const initialVersionMap = {};
376
+ const globalMutationMap = {};
377
+ await authState.keys.transaction(async () => {
378
+ const collectionsToHandle = new Set(collections);
379
+ // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
380
+ const attemptsMap = {};
381
+ // keep executing till all collections are done
382
+ // sometimes a single patch request will not return all the patches (God knows why)
383
+ // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
384
+ while (collectionsToHandle.size) {
385
+ const states = {};
386
+ const nodes = [];
387
+ for (const name of collectionsToHandle) {
388
+ const result = await authState.keys.get('app-state-sync-version', [name]);
389
+ let state = result[name];
390
+ if (state) {
391
+ if (typeof initialVersionMap[name] === 'undefined') {
392
+ initialVersionMap[name] = state.version;
217
393
  }
218
- });
219
- };
220
- /** update the profile status for yourself */
221
- const updateProfileStatus = async (status) => {
222
- await query({
223
- tag: 'iq',
224
- attrs: {
225
- to: S_WHATSAPP_NET,
226
- type: 'set',
227
- xmlns: 'status'
228
- },
229
- content: [
230
- {
231
- tag: 'status',
232
- attrs: {},
233
- content: Buffer.from(status, 'utf-8')
234
- }
235
- ]
236
- });
237
- };
238
- const updateProfileName = async (name) => {
239
- await chatModify({ pushNameSetting: name }, '');
240
- };
241
- const fetchBlocklist = async () => {
242
- const result = await query({
243
- tag: 'iq',
394
+ } else {
395
+ state = newLTHashState();
396
+ }
397
+ states[name] = state;
398
+ logger.info(`resyncing ${name} from v${state.version}`);
399
+ nodes.push({
400
+ tag: 'collection',
244
401
  attrs: {
245
- xmlns: 'blocklist',
246
- to: S_WHATSAPP_NET,
247
- type: 'get'
402
+ name,
403
+ version: state.version.toString(),
404
+ // return snapshot if being synced from scratch
405
+ return_snapshot: (!state.version).toString()
248
406
  }
249
- });
250
- const listNode = getBinaryNodeChild(result, 'list');
251
- return getBinaryNodeChildren(listNode, 'item').map(n => n.attrs.jid);
252
- };
253
- const updateBlockStatus = async (jid, action) => {
254
- await query({
255
- tag: 'iq',
256
- attrs: {
257
- xmlns: 'blocklist',
258
- to: S_WHATSAPP_NET,
259
- type: 'set'
260
- },
261
- content: [
262
- {
263
- tag: 'item',
264
- attrs: {
265
- action,
266
- jid
267
- }
268
- }
269
- ]
270
- });
271
- };
272
- const getBusinessProfile = async (jid) => {
273
- const results = await query({
274
- tag: 'iq',
275
- attrs: {
276
- to: 's.whatsapp.net',
277
- xmlns: 'w:biz',
278
- type: 'get'
279
- },
280
- content: [
281
- {
282
- tag: 'business_profile',
283
- attrs: { v: '244' },
284
- content: [
285
- {
286
- tag: 'profile',
287
- attrs: { jid }
288
- }
289
- ]
290
- }
291
- ]
292
- });
293
- const profileNode = getBinaryNodeChild(results, 'business_profile');
294
- const profiles = getBinaryNodeChild(profileNode, 'profile');
295
- if (profiles) {
296
- const address = getBinaryNodeChild(profiles, 'address');
297
- const description = getBinaryNodeChild(profiles, 'description');
298
- const website = getBinaryNodeChild(profiles, 'website');
299
- const email = getBinaryNodeChild(profiles, 'email');
300
- const category = getBinaryNodeChild(getBinaryNodeChild(profiles, 'categories'), 'category');
301
- const businessHours = getBinaryNodeChild(profiles, 'business_hours');
302
- const businessHoursConfig = businessHours
303
- ? getBinaryNodeChildren(businessHours, 'business_hours_config')
304
- : undefined;
305
- const websiteStr = website?.content?.toString();
306
- return {
307
- wid: profiles.attrs?.jid,
308
- address: address?.content?.toString(),
309
- description: description?.content?.toString() || '',
310
- website: websiteStr ? [websiteStr] : [],
311
- email: email?.content?.toString(),
312
- category: category?.content?.toString(),
313
- business_hours: {
314
- timezone: businessHours?.attrs?.timezone,
315
- business_config: businessHoursConfig?.map(({ attrs }) => attrs)
316
- }
317
- };
407
+ });
318
408
  }
319
- };
320
- const cleanDirtyBits = async (type, fromTimestamp) => {
321
- logger.info({ fromTimestamp }, 'clean dirty bits ' + type);
322
- await sendNode({
323
- tag: 'iq',
324
- attrs: {
325
- to: S_WHATSAPP_NET,
326
- type: 'set',
327
- xmlns: 'urn:xmpp:whatsapp:dirty',
328
- id: generateMessageTag()
329
- },
330
- content: [
331
- {
332
- tag: 'clean',
333
- attrs: {
334
- type,
335
- ...(fromTimestamp ? { timestamp: fromTimestamp.toString() } : null)
336
- }
337
- }
338
- ]
409
+ const result = await query({
410
+ tag: 'iq',
411
+ attrs: {
412
+ to: S_WHATSAPP_NET,
413
+ xmlns: 'w:sync:app:state',
414
+ type: 'set'
415
+ },
416
+ content: [{
417
+ tag: 'sync',
418
+ attrs: {},
419
+ content: nodes
420
+ }]
339
421
  });
340
- };
341
- const newAppStateChunkHandler = (isInitialSync) => {
342
- return {
343
- onMutation(mutation) {
344
- processSyncAction(mutation, ev, authState.creds.me, isInitialSync ? { accountSettings: authState.creds.accountSettings } : undefined, logger);
345
- }
346
- };
347
- };
348
- const resyncAppState = ev.createBufferedFunction(async (collections, isInitialSync) => {
349
- // we use this to determine which events to fire
350
- // otherwise when we resync from scratch -- all notifications will fire
351
- const initialVersionMap = {};
352
- const globalMutationMap = {};
353
- await authState.keys.transaction(async () => {
354
- const collectionsToHandle = new Set(collections);
355
- // in case something goes wrong -- ensure we don't enter a loop that cannot be exited from
356
- const attemptsMap = {};
357
- // keep executing till all collections are done
358
- // sometimes a single patch request will not return all the patches (God knows why)
359
- // so we fetch till they're all done (this is determined by the "has_more_patches" flag)
360
- while (collectionsToHandle.size) {
361
- const states = {};
362
- const nodes = [];
363
- for (const name of collectionsToHandle) {
364
- const result = await authState.keys.get('app-state-sync-version', [name]);
365
- let state = result[name];
366
- if (state) {
367
- if (typeof initialVersionMap[name] === 'undefined') {
368
- initialVersionMap[name] = state.version;
369
- }
370
- }
371
- else {
372
- state = newLTHashState();
373
- }
374
- states[name] = state;
375
- logger.info(`resyncing ${name} from v${state.version}`);
376
- nodes.push({
377
- tag: 'collection',
378
- attrs: {
379
- name,
380
- version: state.version.toString(),
381
- // return snapshot if being synced from scratch
382
- return_snapshot: (!state.version).toString()
383
- }
384
- });
385
- }
386
- const result = await query({
387
- tag: 'iq',
388
- attrs: {
389
- to: S_WHATSAPP_NET,
390
- xmlns: 'w:sync:app:state',
391
- type: 'set'
392
- },
393
- content: [
394
- {
395
- tag: 'sync',
396
- attrs: {},
397
- content: nodes
398
- }
399
- ]
400
- });
401
- // extract from binary node
402
- const decoded = await extractSyncdPatches(result, config?.options);
403
- for (const key in decoded) {
404
- const name = key;
405
- const { patches, hasMorePatches, snapshot } = decoded[name];
406
- try {
407
- if (snapshot) {
408
- const { state: newState, mutationMap } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
409
- states[name] = newState;
410
- Object.assign(globalMutationMap, mutationMap);
411
- logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
412
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
413
- }
414
- // only process if there are syncd patches
415
- if (patches.length) {
416
- const { state: newState, mutationMap } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
417
- await authState.keys.set({ 'app-state-sync-version': { [name]: newState } });
418
- logger.info(`synced ${name} to v${newState.version}`);
419
- initialVersionMap[name] = newState.version;
420
- Object.assign(globalMutationMap, mutationMap);
421
- }
422
- if (hasMorePatches) {
423
- logger.info(`${name} has more patches...`);
424
- }
425
- else {
426
- // collection is done with sync
427
- collectionsToHandle.delete(name);
428
- }
429
- }
430
- catch (error) {
431
- // if retry attempts overshoot
432
- // or key not found
433
- const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS ||
434
- error.output?.statusCode === 404 ||
435
- error.name === 'TypeError';
436
- logger.info({ name, error: error.stack }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
437
- await authState.keys.set({ 'app-state-sync-version': { [name]: null } });
438
- // increment number of retries
439
- attemptsMap[name] = (attemptsMap[name] || 0) + 1;
440
- if (isIrrecoverableError) {
441
- // stop retrying
442
- collectionsToHandle.delete(name);
443
- }
444
- }
422
+ // extract from binary node
423
+ const decoded = await extractSyncdPatches(result, config?.options);
424
+ for (const key in decoded) {
425
+ const name = key;
426
+ const {
427
+ patches,
428
+ hasMorePatches,
429
+ snapshot
430
+ } = decoded[name];
431
+ try {
432
+ if (snapshot) {
433
+ const {
434
+ state: newState,
435
+ mutationMap
436
+ } = await decodeSyncdSnapshot(name, snapshot, getAppStateSyncKey, initialVersionMap[name], appStateMacVerification.snapshot);
437
+ states[name] = newState;
438
+ Object.assign(globalMutationMap, mutationMap);
439
+ logger.info(`restored state of ${name} from snapshot to v${newState.version} with mutations`);
440
+ await authState.keys.set({
441
+ 'app-state-sync-version': {
442
+ [name]: newState
445
443
  }
444
+ });
446
445
  }
447
- }, authState?.creds?.me?.id || 'resync-app-state');
448
- const { onMutation } = newAppStateChunkHandler(isInitialSync);
449
- for (const key in globalMutationMap) {
450
- onMutation(globalMutationMap[key]);
451
- }
452
- });
453
- /**
454
- * fetch the profile picture of a user/group
455
- * type = "preview" for a low res picture
456
- * type = "image for the high res picture"
457
- */
458
- const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
459
- jid = jidNormalizedUser(jid);
460
- const result = await query({
461
- tag: 'iq',
462
- attrs: {
463
- target: jid,
464
- to: S_WHATSAPP_NET,
465
- type: 'get',
466
- xmlns: 'w:profile:picture'
467
- },
468
- content: [{ tag: 'picture', attrs: { type, query: 'url' } }]
469
- }, timeoutMs);
470
- const child = getBinaryNodeChild(result, 'picture');
471
- return child?.attrs?.url;
472
- };
473
- const createCallLink = async (type, event, timeoutMs) => {
474
- const result = await query({
475
- tag: 'call',
476
- attrs: {
477
- id: generateMessageTag(),
478
- to: '@call'
479
- },
480
- content: [
481
- {
482
- tag: 'link_create',
483
- attrs: { media: type },
484
- content: event ? [{ tag: 'event', attrs: { start_time: String(event.startTime) } }] : undefined
446
+ // only process if there are syncd patches
447
+ if (patches.length) {
448
+ const {
449
+ state: newState,
450
+ mutationMap
451
+ } = await decodePatches(name, patches, states[name], getAppStateSyncKey, config.options, initialVersionMap[name], logger, appStateMacVerification.patch);
452
+ await authState.keys.set({
453
+ 'app-state-sync-version': {
454
+ [name]: newState
485
455
  }
486
- ]
487
- }, timeoutMs);
488
- const child = getBinaryNodeChild(result, 'link_create');
489
- return child?.attrs?.token;
490
- };
491
- const sendPresenceUpdate = async (type, toJid) => {
492
- const me = authState.creds.me;
493
- if (type === 'available' || type === 'unavailable') {
494
- if (!me.name) {
495
- logger.warn('no name present, ignoring presence update request...');
496
- return;
456
+ });
457
+ logger.info(`synced ${name} to v${newState.version}`);
458
+ initialVersionMap[name] = newState.version;
459
+ Object.assign(globalMutationMap, mutationMap);
497
460
  }
498
- ev.emit('connection.update', { isOnline: type === 'available' });
499
- await sendNode({
500
- tag: 'presence',
501
- attrs: {
502
- name: me.name.replace(/@/g, ''),
503
- type
504
- }
461
+ if (hasMorePatches) {
462
+ logger.info(`${name} has more patches...`);
463
+ } else {
464
+ // collection is done with sync
465
+ collectionsToHandle.delete(name);
466
+ }
467
+ } catch (error) {
468
+ // if retry attempts overshoot
469
+ // or key not found
470
+ const isIrrecoverableError = attemptsMap[name] >= MAX_SYNC_ATTEMPTS || error.output?.statusCode === 404 || error.name === 'TypeError';
471
+ logger.info({
472
+ name,
473
+ error: error.stack
474
+ }, `failed to sync state from version${isIrrecoverableError ? '' : ', removing and trying from scratch'}`);
475
+ await authState.keys.set({
476
+ 'app-state-sync-version': {
477
+ [name]: null
478
+ }
505
479
  });
480
+ // increment number of retries
481
+ attemptsMap[name] = (attemptsMap[name] || 0) + 1;
482
+ if (isIrrecoverableError) {
483
+ // stop retrying
484
+ collectionsToHandle.delete(name);
485
+ }
486
+ }
506
487
  }
507
- else {
508
- const { server } = jidDecode(toJid);
509
- const isLid = server === 'lid';
510
- await sendNode({
511
- tag: 'chatstate',
512
- attrs: {
513
- from: isLid ? me.lid : me.id,
514
- to: toJid
515
- },
516
- content: [
517
- {
518
- tag: type === 'recording' ? 'composing' : type,
519
- attrs: type === 'recording' ? { media: 'audio' } : {}
520
- }
521
- ]
522
- });
488
+ }
489
+ }, authState?.creds?.me?.id || 'resync-app-state');
490
+ const {
491
+ onMutation
492
+ } = newAppStateChunkHandler(isInitialSync);
493
+ for (const key in globalMutationMap) {
494
+ onMutation(globalMutationMap[key]);
495
+ }
496
+ });
497
+ /**
498
+ * fetch the profile picture of a user/group
499
+ * type = "preview" for a low res picture
500
+ * type = "image for the high res picture"
501
+ */
502
+ const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
503
+ jid = jidNormalizedUser(jid);
504
+ const result = await query({
505
+ tag: 'iq',
506
+ attrs: {
507
+ target: jid,
508
+ to: S_WHATSAPP_NET,
509
+ type: 'get',
510
+ xmlns: 'w:profile:picture'
511
+ },
512
+ content: [{
513
+ tag: 'picture',
514
+ attrs: {
515
+ type,
516
+ query: 'url'
523
517
  }
524
- };
525
- /**
526
- * @param toJid the jid to subscribe to
527
- * @param tcToken token for subscription, use if present
528
- */
529
- const presenceSubscribe = (toJid, tcToken) => sendNode({
530
- tag: 'presence',
518
+ }]
519
+ }, timeoutMs);
520
+ const child = getBinaryNodeChild(result, 'picture');
521
+ return child?.attrs?.url;
522
+ };
523
+ const createCallLink = async (type, event, timeoutMs) => {
524
+ const result = await query({
525
+ tag: 'call',
526
+ attrs: {
527
+ id: generateMessageTag(),
528
+ to: '@call'
529
+ },
530
+ content: [{
531
+ tag: 'link_create',
531
532
  attrs: {
532
- to: toJid,
533
- id: generateMessageTag(),
534
- type: 'subscribe'
533
+ media: type
535
534
  },
536
- content: tcToken
537
- ? [
538
- {
539
- tag: 'tctoken',
540
- attrs: {},
541
- content: tcToken
542
- }
543
- ]
544
- : undefined
545
- });
546
- const handlePresenceUpdate = ({ tag, attrs, content }) => {
547
- let presence;
548
- const jid = attrs.from;
549
- const participant = attrs.participant || attrs.from;
550
- if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
551
- return;
552
- }
553
- if (tag === 'presence') {
554
- presence = {
555
- lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
556
- lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
557
- };
558
- }
559
- else if (Array.isArray(content)) {
560
- const [firstChild] = content;
561
- let type = firstChild.tag;
562
- if (type === 'paused') {
563
- type = 'available';
564
- }
565
- if (firstChild.attrs?.media === 'audio') {
566
- type = 'recording';
567
- }
568
- presence = { lastKnownPresence: type };
569
- }
570
- else {
571
- logger.error({ tag, attrs, content }, 'recv invalid presence node');
572
- }
573
- if (presence) {
574
- ev.emit('presence.update', { id: jid, presences: { [participant]: presence } });
575
- }
576
- };
577
- const appPatch = async (patchCreate) => {
578
- const name = patchCreate.type;
579
- const myAppStateKeyId = authState.creds.myAppStateKeyId;
580
- if (!myAppStateKeyId) {
581
- throw new Boom('App state key not present!', { statusCode: 400 });
582
- }
583
- let initial;
584
- let encodeResult;
585
- await processingMutex.mutex(async () => {
586
- await authState.keys.transaction(async () => {
587
- logger.debug({ patch: patchCreate }, 'applying app patch');
588
- await resyncAppState([name], false);
589
- const { [name]: currentSyncVersion } = await authState.keys.get('app-state-sync-version', [name]);
590
- initial = currentSyncVersion || newLTHashState();
591
- encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
592
- const { patch, state } = encodeResult;
593
- const node = {
594
- tag: 'iq',
595
- attrs: {
596
- to: S_WHATSAPP_NET,
597
- type: 'set',
598
- xmlns: 'w:sync:app:state'
599
- },
600
- content: [
601
- {
602
- tag: 'sync',
603
- attrs: {},
604
- content: [
605
- {
606
- tag: 'collection',
607
- attrs: {
608
- name,
609
- version: (state.version - 1).toString(),
610
- return_snapshot: 'false'
611
- },
612
- content: [
613
- {
614
- tag: 'patch',
615
- attrs: {},
616
- content: proto.SyncdPatch.encode(patch).finish()
617
- }
618
- ]
619
- }
620
- ]
621
- }
622
- ]
623
- };
624
- await query(node);
625
- await authState.keys.set({ 'app-state-sync-version': { [name]: state } });
626
- }, authState?.creds?.me?.id || 'app-patch');
627
- });
628
- if (config.emitOwnEvents) {
629
- const { onMutation } = newAppStateChunkHandler(false);
630
- const { mutationMap } = await decodePatches(name, [{ ...encodeResult.patch, version: { version: encodeResult.state.version } }], initial, getAppStateSyncKey, config.options, undefined, logger);
631
- for (const key in mutationMap) {
632
- onMutation(mutationMap[key]);
633
- }
634
- }
635
- };
636
- /** sending non-abt props may fix QR scan fail if server expects */
637
- const fetchProps = async () => {
638
- const resultNode = await query({
639
- tag: 'iq',
640
- attrs: {
641
- to: S_WHATSAPP_NET,
642
- xmlns: 'w',
643
- type: 'get'
644
- },
645
- content: [
646
- {
647
- tag: 'props',
648
- attrs: {
649
- protocol: '2',
650
- hash: authState?.creds?.lastPropHash || ''
651
- }
652
- }
653
- ]
654
- });
655
- const propsNode = getBinaryNodeChild(resultNode, 'props');
656
- let props = {};
657
- if (propsNode) {
658
- if (propsNode.attrs?.hash) {
659
- // on some clients, the hash is returning as undefined
660
- authState.creds.lastPropHash = propsNode?.attrs?.hash;
661
- ev.emit('creds.update', authState.creds);
662
- }
663
- props = reduceBinaryNodeToDictionary(propsNode, 'prop');
664
- }
665
- logger.debug('fetched props');
666
- return props;
667
- };
668
- /**
669
- * modify a chat -- mark unread, read etc.
670
- * lastMessages must be sorted in reverse chronologically
671
- * requires the last messages till the last message received; required for archive & unread
672
- */
673
- const chatModify = (mod, jid) => {
674
- const patch = chatModificationToAppPatch(mod, jid);
675
- return appPatch(patch);
676
- };
677
- /**
678
- * Enable/Disable link preview privacy, not related to baileys link preview generation
679
- */
680
- const updateDisableLinkPreviewsPrivacy = (isPreviewsDisabled) => {
681
- return chatModify({
682
- disableLinkPreviews: { isPreviewsDisabled }
683
- }, '');
684
- };
685
- /**
686
- * Star or Unstar a message
687
- */
688
- const star = (jid, messages, star) => {
689
- return chatModify({
690
- star: {
691
- messages,
692
- star
693
- }
694
- }, jid);
695
- };
696
- /**
697
- * Add or Edit Contact
698
- */
699
- const addOrEditContact = (jid, contact) => {
700
- return chatModify({
701
- contact
702
- }, jid);
703
- };
704
- /**
705
- * Remove Contact
706
- */
707
- const removeContact = (jid) => {
708
- return chatModify({
709
- contact: null
710
- }, jid);
711
- };
712
- /**
713
- * Adds label
714
- */
715
- const addLabel = (jid, labels) => {
716
- return chatModify({
717
- addLabel: {
718
- ...labels
719
- }
720
- }, jid);
721
- };
722
- /**
723
- * Adds label for the chats
724
- */
725
- const addChatLabel = (jid, labelId) => {
726
- return chatModify({
727
- addChatLabel: {
728
- labelId
729
- }
730
- }, jid);
731
- };
732
- /**
733
- * Removes label for the chat
734
- */
735
- const removeChatLabel = (jid, labelId) => {
736
- return chatModify({
737
- removeChatLabel: {
738
- labelId
739
- }
740
- }, jid);
741
- };
742
- /**
743
- * Adds label for the message
744
- */
745
- const addMessageLabel = (jid, messageId, labelId) => {
746
- return chatModify({
747
- addMessageLabel: {
748
- messageId,
749
- labelId
750
- }
751
- }, jid);
752
- };
753
- /**
754
- * Removes label for the message
755
- */
756
- const removeMessageLabel = (jid, messageId, labelId) => {
757
- return chatModify({
758
- removeMessageLabel: {
759
- messageId,
760
- labelId
761
- }
762
- }, jid);
763
- };
764
- /**
765
- * Add or Edit Quick Reply
766
- */
767
- const addOrEditQuickReply = (quickReply) => {
768
- return chatModify({
769
- quickReply
770
- }, '');
771
- };
772
- /**
773
- * Remove Quick Reply
774
- */
775
- const removeQuickReply = (timestamp) => {
776
- return chatModify({
777
- quickReply: { timestamp, deleted: true }
778
- }, '');
779
- };
780
- /**
781
- * queries need to be fired on connection open
782
- * help ensure parity with WA Web
783
- * */
784
- const executeInitQueries = async () => {
785
- await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
786
- };
787
- const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
788
- ev.emit('messages.upsert', { messages: [msg], type });
789
- if (!!msg.pushName) {
790
- let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
791
- jid = jidNormalizedUser(jid);
792
- if (!msg.key.fromMe) {
793
- ev.emit('contacts.update', [{ id: jid, notify: msg.pushName, verifiedName: msg.verifiedBizName }]);
794
- }
795
- // update our pushname too
796
- if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
797
- ev.emit('creds.update', { me: { ...authState.creds.me, name: msg.pushName } });
798
- }
535
+ content: event ? [{
536
+ tag: 'event',
537
+ attrs: {
538
+ start_time: String(event.startTime)
539
+ }
540
+ }] : undefined
541
+ }]
542
+ }, timeoutMs);
543
+ const child = getBinaryNodeChild(result, 'link_create');
544
+ return child?.attrs?.token;
545
+ };
546
+ const sendPresenceUpdate = async (type, toJid) => {
547
+ const me = authState.creds.me;
548
+ if (type === 'available' || type === 'unavailable') {
549
+ if (!me.name) {
550
+ logger.warn('no name present, ignoring presence update request...');
551
+ return;
552
+ }
553
+ ev.emit('connection.update', {
554
+ isOnline: type === 'available'
555
+ });
556
+ await sendNode({
557
+ tag: 'presence',
558
+ attrs: {
559
+ name: me.name.replace(/@/g, ''),
560
+ type
799
561
  }
800
- const historyMsg = getHistoryMsg(msg.message);
801
- const shouldProcessHistoryMsg = historyMsg
802
- ? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType)
803
- : false;
804
- // State machine: decide on sync and flush
805
- if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
806
- if (awaitingSyncTimeout) {
807
- clearTimeout(awaitingSyncTimeout);
808
- awaitingSyncTimeout = undefined;
809
- }
810
- if (shouldProcessHistoryMsg) {
811
- syncState = SyncState.Syncing;
812
- logger.info('Transitioned to Syncing state');
813
- // Let doAppStateSync handle the final flush after it's done
814
- }
815
- else {
816
- syncState = SyncState.Online;
817
- logger.info('History sync skipped, transitioning to Online state and flushing buffer');
818
- ev.flush();
819
- }
562
+ });
563
+ } else {
564
+ const {
565
+ server
566
+ } = jidDecode(toJid);
567
+ const isLid = server === 'lid';
568
+ await sendNode({
569
+ tag: 'chatstate',
570
+ attrs: {
571
+ from: isLid ? me.lid : me.id,
572
+ to: toJid
573
+ },
574
+ content: [{
575
+ tag: type === 'recording' ? 'composing' : type,
576
+ attrs: type === 'recording' ? {
577
+ media: 'audio'
578
+ } : {}
579
+ }]
580
+ });
581
+ }
582
+ };
583
+ /**
584
+ * @param toJid the jid to subscribe to
585
+ * @param tcToken token for subscription, use if present
586
+ */
587
+ const presenceSubscribe = (toJid, tcToken) => sendNode({
588
+ tag: 'presence',
589
+ attrs: {
590
+ to: toJid,
591
+ id: generateMessageTag(),
592
+ type: 'subscribe'
593
+ },
594
+ content: tcToken ? [{
595
+ tag: 'tctoken',
596
+ attrs: {},
597
+ content: tcToken
598
+ }] : undefined
599
+ });
600
+ const handlePresenceUpdate = ({
601
+ tag,
602
+ attrs,
603
+ content
604
+ }) => {
605
+ let presence;
606
+ const jid = attrs.from;
607
+ const participant = attrs.participant || attrs.from;
608
+ if (shouldIgnoreJid(jid) && jid !== '@s.whatsapp.net') {
609
+ return;
610
+ }
611
+ if (tag === 'presence') {
612
+ presence = {
613
+ lastKnownPresence: attrs.type === 'unavailable' ? 'unavailable' : 'available',
614
+ lastSeen: attrs.last && attrs.last !== 'deny' ? +attrs.last : undefined
615
+ };
616
+ } else if (Array.isArray(content)) {
617
+ const [firstChild] = content;
618
+ let type = firstChild.tag;
619
+ if (type === 'paused') {
620
+ type = 'available';
621
+ }
622
+ if (firstChild.attrs?.media === 'audio') {
623
+ type = 'recording';
624
+ }
625
+ presence = {
626
+ lastKnownPresence: type
627
+ };
628
+ } else {
629
+ logger.error({
630
+ tag,
631
+ attrs,
632
+ content
633
+ }, 'recv invalid presence node');
634
+ }
635
+ if (presence) {
636
+ ev.emit('presence.update', {
637
+ id: jid,
638
+ presences: {
639
+ [participant]: presence
820
640
  }
821
- const doAppStateSync = async () => {
822
- if (syncState === SyncState.Syncing) {
823
- logger.info('Doing app state sync');
824
- await resyncAppState(ALL_WA_PATCH_NAMES, true);
825
- // Sync is complete, go online and flush everything
826
- syncState = SyncState.Online;
827
- logger.info('App state sync complete, transitioning to Online state and flushing buffer');
828
- ev.flush();
829
- const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
830
- ev.emit('creds.update', { accountSyncCounter });
831
- }
641
+ });
642
+ }
643
+ };
644
+ const appPatch = async patchCreate => {
645
+ const name = patchCreate.type;
646
+ const myAppStateKeyId = authState.creds.myAppStateKeyId;
647
+ if (!myAppStateKeyId) {
648
+ throw new Boom('App state key not present!', {
649
+ statusCode: 400
650
+ });
651
+ }
652
+ let initial;
653
+ let encodeResult;
654
+ await processingMutex.mutex(async () => {
655
+ await authState.keys.transaction(async () => {
656
+ logger.debug({
657
+ patch: patchCreate
658
+ }, 'applying app patch');
659
+ await resyncAppState([name], false);
660
+ const {
661
+ [name]: currentSyncVersion
662
+ } = await authState.keys.get('app-state-sync-version', [name]);
663
+ initial = currentSyncVersion || newLTHashState();
664
+ encodeResult = await encodeSyncdPatch(patchCreate, myAppStateKeyId, initial, getAppStateSyncKey);
665
+ const {
666
+ patch,
667
+ state
668
+ } = encodeResult;
669
+ const node = {
670
+ tag: 'iq',
671
+ attrs: {
672
+ to: S_WHATSAPP_NET,
673
+ type: 'set',
674
+ xmlns: 'w:sync:app:state'
675
+ },
676
+ content: [{
677
+ tag: 'sync',
678
+ attrs: {},
679
+ content: [{
680
+ tag: 'collection',
681
+ attrs: {
682
+ name,
683
+ version: (state.version - 1).toString(),
684
+ return_snapshot: 'false'
685
+ },
686
+ content: [{
687
+ tag: 'patch',
688
+ attrs: {},
689
+ content: proto.SyncdPatch.encode(patch).finish()
690
+ }]
691
+ }]
692
+ }]
832
693
  };
833
- await Promise.all([
834
- (async () => {
835
- if (shouldProcessHistoryMsg) {
836
- await doAppStateSync();
837
- }
838
- })(),
839
- processMessage(msg, {
840
- signalRepository,
841
- shouldProcessHistoryMsg,
842
- placeholderResendCache,
843
- ev,
844
- creds: authState.creds,
845
- keyStore: authState.keys,
846
- logger,
847
- options: config.options
848
- })
849
- ]);
850
- // If the app state key arrives and we are waiting to sync, trigger the sync now.
851
- if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
852
- logger.info('App state sync key arrived, triggering app state sync');
853
- await doAppStateSync();
854
- }
855
- });
856
- ws.on('CB:presence', handlePresenceUpdate);
857
- ws.on('CB:chatstate', handlePresenceUpdate);
858
- ws.on('CB:ib,,dirty', async (node) => {
859
- const { attrs } = getBinaryNodeChild(node, 'dirty');
860
- const type = attrs.type;
861
- switch (type) {
862
- case 'account_sync':
863
- if (attrs.timestamp) {
864
- let { lastAccountSyncTimestamp } = authState.creds;
865
- if (lastAccountSyncTimestamp) {
866
- await cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
867
- }
868
- lastAccountSyncTimestamp = +attrs.timestamp;
869
- ev.emit('creds.update', { lastAccountSyncTimestamp });
870
- }
871
- break;
872
- case 'groups':
873
- // handled in groups.ts
874
- break;
875
- default:
876
- logger.info({ node }, 'received unknown sync');
877
- break;
878
- }
694
+ await query(node);
695
+ await authState.keys.set({
696
+ 'app-state-sync-version': {
697
+ [name]: state
698
+ }
699
+ });
700
+ }, authState?.creds?.me?.id || 'app-patch');
879
701
  });
880
- ev.on('connection.update', ({ connection, receivedPendingNotifications }) => {
881
- if (connection === 'open') {
882
- if (fireInitQueries) {
883
- executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
884
- }
885
- sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
886
- }
887
- if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
888
- return;
702
+ if (config.emitOwnEvents) {
703
+ const {
704
+ onMutation
705
+ } = newAppStateChunkHandler(false);
706
+ const {
707
+ mutationMap
708
+ } = await decodePatches(name, [{
709
+ ...encodeResult.patch,
710
+ version: {
711
+ version: encodeResult.state.version
889
712
  }
890
- syncState = SyncState.AwaitingInitialSync;
891
- logger.info('Connection is now AwaitingInitialSync, buffering events');
892
- ev.buffer();
893
- const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.create({
894
- syncType: proto.HistorySync.HistorySyncType.RECENT
895
- }));
896
- if (!willSyncHistory) {
897
- logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
898
- syncState = SyncState.Online;
899
- setTimeout(() => ev.flush(), 0);
900
- return;
901
- }
902
- logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
903
- if (awaitingSyncTimeout) {
904
- clearTimeout(awaitingSyncTimeout);
713
+ }], initial, getAppStateSyncKey, config.options, undefined, logger);
714
+ for (const key in mutationMap) {
715
+ onMutation(mutationMap[key]);
716
+ }
717
+ }
718
+ };
719
+ /** sending non-abt props may fix QR scan fail if server expects */
720
+ const fetchProps = async () => {
721
+ const resultNode = await query({
722
+ tag: 'iq',
723
+ attrs: {
724
+ to: S_WHATSAPP_NET,
725
+ xmlns: 'w',
726
+ type: 'get'
727
+ },
728
+ content: [{
729
+ tag: 'props',
730
+ attrs: {
731
+ protocol: '2',
732
+ hash: authState?.creds?.lastPropHash || ''
905
733
  }
906
- awaitingSyncTimeout = setTimeout(() => {
907
- if (syncState === SyncState.AwaitingInitialSync) {
908
- logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
909
- syncState = SyncState.Online;
910
- ev.flush();
911
- }
912
- }, 20000);
734
+ }]
913
735
  });
914
- return {
915
- ...sock,
916
- createCallLink,
917
- getBotListV2,
918
- processingMutex,
919
- fetchPrivacySettings,
920
- upsertMessage,
921
- appPatch,
922
- sendPresenceUpdate,
923
- presenceSubscribe,
924
- profilePictureUrl,
925
- fetchBlocklist,
926
- fetchStatus,
927
- fetchDisappearingDuration,
928
- updateProfilePicture,
929
- removeProfilePicture,
930
- updateProfileStatus,
931
- updateProfileName,
932
- updateBlockStatus,
933
- updateDisableLinkPreviewsPrivacy,
934
- updateCallPrivacy,
935
- updateMessagesPrivacy,
936
- updateLastSeenPrivacy,
937
- updateOnlinePrivacy,
938
- updateProfilePicturePrivacy,
939
- updateStatusPrivacy,
940
- updateReadReceiptsPrivacy,
941
- updateGroupsAddPrivacy,
942
- updateDefaultDisappearingMode,
943
- getBusinessProfile,
944
- resyncAppState,
945
- chatModify,
946
- cleanDirtyBits,
947
- addOrEditContact,
948
- removeContact,
949
- addLabel,
950
- addChatLabel,
951
- removeChatLabel,
952
- addMessageLabel,
953
- removeMessageLabel,
954
- star,
955
- addOrEditQuickReply,
956
- removeQuickReply
736
+ const propsNode = getBinaryNodeChild(resultNode, 'props');
737
+ let props = {};
738
+ if (propsNode) {
739
+ if (propsNode.attrs?.hash) {
740
+ // on some clients, the hash is returning as undefined
741
+ authState.creds.lastPropHash = propsNode?.attrs?.hash;
742
+ ev.emit('creds.update', authState.creds);
743
+ }
744
+ props = reduceBinaryNodeToDictionary(propsNode, 'prop');
745
+ }
746
+ logger.debug('fetched props');
747
+ return props;
748
+ };
749
+ /**
750
+ * modify a chat -- mark unread, read etc.
751
+ * lastMessages must be sorted in reverse chronologically
752
+ * requires the last messages till the last message received; required for archive & unread
753
+ */
754
+ const chatModify = (mod, jid) => {
755
+ const patch = chatModificationToAppPatch(mod, jid);
756
+ return appPatch(patch);
757
+ };
758
+ /**
759
+ * Enable/Disable link preview privacy, not related to baileys link preview generation
760
+ */
761
+ const updateDisableLinkPreviewsPrivacy = isPreviewsDisabled => {
762
+ return chatModify({
763
+ disableLinkPreviews: {
764
+ isPreviewsDisabled
765
+ }
766
+ }, '');
767
+ };
768
+ /**
769
+ * Star or Unstar a message
770
+ */
771
+ const star = (jid, messages, star) => {
772
+ return chatModify({
773
+ star: {
774
+ messages,
775
+ star
776
+ }
777
+ }, jid);
778
+ };
779
+ /**
780
+ * Add or Edit Contact
781
+ */
782
+ const addOrEditContact = (jid, contact) => {
783
+ return chatModify({
784
+ contact
785
+ }, jid);
786
+ };
787
+ /**
788
+ * Remove Contact
789
+ */
790
+ const removeContact = jid => {
791
+ return chatModify({
792
+ contact: null
793
+ }, jid);
794
+ };
795
+ /**
796
+ * Adds label
797
+ */
798
+ const addLabel = (jid, labels) => {
799
+ return chatModify({
800
+ addLabel: {
801
+ ...labels
802
+ }
803
+ }, jid);
804
+ };
805
+ /**
806
+ * Adds label for the chats
807
+ */
808
+ const addChatLabel = (jid, labelId) => {
809
+ return chatModify({
810
+ addChatLabel: {
811
+ labelId
812
+ }
813
+ }, jid);
814
+ };
815
+ /**
816
+ * Removes label for the chat
817
+ */
818
+ const removeChatLabel = (jid, labelId) => {
819
+ return chatModify({
820
+ removeChatLabel: {
821
+ labelId
822
+ }
823
+ }, jid);
824
+ };
825
+ /**
826
+ * Adds label for the message
827
+ */
828
+ const addMessageLabel = (jid, messageId, labelId) => {
829
+ return chatModify({
830
+ addMessageLabel: {
831
+ messageId,
832
+ labelId
833
+ }
834
+ }, jid);
835
+ };
836
+ /**
837
+ * Removes label for the message
838
+ */
839
+ const removeMessageLabel = (jid, messageId, labelId) => {
840
+ return chatModify({
841
+ removeMessageLabel: {
842
+ messageId,
843
+ labelId
844
+ }
845
+ }, jid);
846
+ };
847
+ /**
848
+ * Add or Edit Quick Reply
849
+ */
850
+ const addOrEditQuickReply = quickReply => {
851
+ return chatModify({
852
+ quickReply
853
+ }, '');
854
+ };
855
+ /**
856
+ * Remove Quick Reply
857
+ */
858
+ const removeQuickReply = timestamp => {
859
+ return chatModify({
860
+ quickReply: {
861
+ timestamp,
862
+ deleted: true
863
+ }
864
+ }, '');
865
+ };
866
+ /**
867
+ * queries need to be fired on connection open
868
+ * help ensure parity with WA Web
869
+ * */
870
+ const executeInitQueries = async () => {
871
+ await Promise.all([fetchProps(), fetchBlocklist(), fetchPrivacySettings()]);
872
+ };
873
+ const upsertMessage = ev.createBufferedFunction(async (msg, type) => {
874
+ ev.emit('messages.upsert', {
875
+ messages: [msg],
876
+ type
877
+ });
878
+ if (!!msg.pushName) {
879
+ let jid = msg.key.fromMe ? authState.creds.me.id : msg.key.participant || msg.key.remoteJid;
880
+ jid = jidNormalizedUser(jid);
881
+ if (!msg.key.fromMe) {
882
+ ev.emit('contacts.update', [{
883
+ id: jid,
884
+ notify: msg.pushName,
885
+ verifiedName: msg.verifiedBizName
886
+ }]);
887
+ }
888
+ // update our pushname too
889
+ if (msg.key.fromMe && msg.pushName && authState.creds.me?.name !== msg.pushName) {
890
+ ev.emit('creds.update', {
891
+ me: {
892
+ ...authState.creds.me,
893
+ name: msg.pushName
894
+ }
895
+ });
896
+ }
897
+ }
898
+ const historyMsg = getHistoryMsg(msg.message);
899
+ const shouldProcessHistoryMsg = historyMsg ? shouldSyncHistoryMessage(historyMsg) && PROCESSABLE_HISTORY_TYPES.includes(historyMsg.syncType) : false;
900
+ // State machine: decide on sync and flush
901
+ if (historyMsg && syncState === SyncState.AwaitingInitialSync) {
902
+ if (awaitingSyncTimeout) {
903
+ clearTimeout(awaitingSyncTimeout);
904
+ awaitingSyncTimeout = undefined;
905
+ }
906
+ if (shouldProcessHistoryMsg) {
907
+ syncState = SyncState.Syncing;
908
+ logger.info('Transitioned to Syncing state');
909
+ // Let doAppStateSync handle the final flush after it's done
910
+ } else {
911
+ syncState = SyncState.Online;
912
+ logger.info('History sync skipped, transitioning to Online state and flushing buffer');
913
+ ev.flush();
914
+ }
915
+ }
916
+ const doAppStateSync = async () => {
917
+ if (syncState === SyncState.Syncing) {
918
+ logger.info('Doing app state sync');
919
+ await resyncAppState(ALL_WA_PATCH_NAMES, true);
920
+ // Sync is complete, go online and flush everything
921
+ syncState = SyncState.Online;
922
+ logger.info('App state sync complete, transitioning to Online state and flushing buffer');
923
+ ev.flush();
924
+ const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1;
925
+ ev.emit('creds.update', {
926
+ accountSyncCounter
927
+ });
928
+ }
957
929
  };
930
+ await Promise.all([(async () => {
931
+ if (shouldProcessHistoryMsg) {
932
+ await doAppStateSync();
933
+ }
934
+ })(), processMessage(msg, {
935
+ signalRepository,
936
+ shouldProcessHistoryMsg,
937
+ placeholderResendCache,
938
+ ev,
939
+ creds: authState.creds,
940
+ keyStore: authState.keys,
941
+ logger,
942
+ options: config.options
943
+ })]);
944
+ // If the app state key arrives and we are waiting to sync, trigger the sync now.
945
+ if (msg.message?.protocolMessage?.appStateSyncKeyShare && syncState === SyncState.Syncing) {
946
+ logger.info('App state sync key arrived, triggering app state sync');
947
+ await doAppStateSync();
948
+ }
949
+ });
950
+ ws.on('CB:presence', handlePresenceUpdate);
951
+ ws.on('CB:chatstate', handlePresenceUpdate);
952
+ ws.on('CB:ib,,dirty', async node => {
953
+ const {
954
+ attrs
955
+ } = getBinaryNodeChild(node, 'dirty');
956
+ const type = attrs.type;
957
+ switch (type) {
958
+ case 'account_sync':
959
+ if (attrs.timestamp) {
960
+ let {
961
+ lastAccountSyncTimestamp
962
+ } = authState.creds;
963
+ if (lastAccountSyncTimestamp) {
964
+ await cleanDirtyBits('account_sync', lastAccountSyncTimestamp);
965
+ }
966
+ lastAccountSyncTimestamp = +attrs.timestamp;
967
+ ev.emit('creds.update', {
968
+ lastAccountSyncTimestamp
969
+ });
970
+ }
971
+ break;
972
+ case 'groups':
973
+ // handled in groups.ts
974
+ break;
975
+ default:
976
+ logger.info({
977
+ node
978
+ }, 'received unknown sync');
979
+ break;
980
+ }
981
+ });
982
+ ev.on('connection.update', ({
983
+ connection,
984
+ receivedPendingNotifications
985
+ }) => {
986
+ if (connection === 'open') {
987
+ if (fireInitQueries) {
988
+ executeInitQueries().catch(error => onUnexpectedError(error, 'init queries'));
989
+ }
990
+ sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable').catch(error => onUnexpectedError(error, 'presence update requests'));
991
+ }
992
+ if (!receivedPendingNotifications || syncState !== SyncState.Connecting) {
993
+ return;
994
+ }
995
+ syncState = SyncState.AwaitingInitialSync;
996
+ logger.info('Connection is now AwaitingInitialSync, buffering events');
997
+ ev.buffer();
998
+ const willSyncHistory = shouldSyncHistoryMessage(proto.Message.HistorySyncNotification.create({
999
+ syncType: proto.HistorySync.HistorySyncType.RECENT
1000
+ }));
1001
+ if (!willSyncHistory) {
1002
+ logger.info('History sync is disabled by config, not waiting for notification. Transitioning to Online.');
1003
+ syncState = SyncState.Online;
1004
+ setTimeout(() => ev.flush(), 0);
1005
+ return;
1006
+ }
1007
+ logger.info('History sync is enabled, awaiting notification with a 20s timeout.');
1008
+ if (awaitingSyncTimeout) {
1009
+ clearTimeout(awaitingSyncTimeout);
1010
+ }
1011
+ awaitingSyncTimeout = setTimeout(() => {
1012
+ if (syncState === SyncState.AwaitingInitialSync) {
1013
+ logger.warn('Timeout in AwaitingInitialSync, forcing state to Online and flushing buffer');
1014
+ syncState = SyncState.Online;
1015
+ ev.flush();
1016
+ }
1017
+ }, 20000);
1018
+ });
1019
+ return {
1020
+ ...sock,
1021
+ createCallLink,
1022
+ getBotListV2,
1023
+ processingMutex,
1024
+ fetchPrivacySettings,
1025
+ upsertMessage,
1026
+ appPatch,
1027
+ sendPresenceUpdate,
1028
+ presenceSubscribe,
1029
+ profilePictureUrl,
1030
+ fetchBlocklist,
1031
+ fetchStatus,
1032
+ fetchDisappearingDuration,
1033
+ updateProfilePicture,
1034
+ removeProfilePicture,
1035
+ updateProfileStatus,
1036
+ updateProfileName,
1037
+ updateBlockStatus,
1038
+ updateDisableLinkPreviewsPrivacy,
1039
+ updateCallPrivacy,
1040
+ updateMessagesPrivacy,
1041
+ updateLastSeenPrivacy,
1042
+ updateOnlinePrivacy,
1043
+ updateProfilePicturePrivacy,
1044
+ updateStatusPrivacy,
1045
+ updateReadReceiptsPrivacy,
1046
+ updateGroupsAddPrivacy,
1047
+ updateDefaultDisappearingMode,
1048
+ getBusinessProfile,
1049
+ resyncAppState,
1050
+ chatModify,
1051
+ cleanDirtyBits,
1052
+ addOrEditContact,
1053
+ removeContact,
1054
+ addLabel,
1055
+ addChatLabel,
1056
+ removeChatLabel,
1057
+ addMessageLabel,
1058
+ removeMessageLabel,
1059
+ star,
1060
+ addOrEditQuickReply,
1061
+ removeQuickReply
1062
+ };
958
1063
  };
959
1064
  //# sourceMappingURL=chats.js.map