@d0v3riz/baileys 6.7.5 → 6.7.7

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.
@@ -93,7 +93,6 @@ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logg
93
93
  export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
94
94
  export declare const decodeMediaRetryNode: (node: BinaryNode) => {
95
95
  key: proto.IMessageKey;
96
- /** generates all the keys required to encrypt/decrypt & sign a media message */
97
96
  media?: {
98
97
  ciphertext: Uint8Array;
99
98
  iv: Uint8Array;
@@ -30,7 +30,6 @@ const MessageTypeProto = {
30
30
  'sticker': Types_1.WAProto.Message.StickerMessage,
31
31
  'document': Types_1.WAProto.Message.DocumentMessage,
32
32
  };
33
- const ButtonType = WAProto_1.proto.Message.ButtonsMessage.HeaderType;
34
33
  /**
35
34
  * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
36
35
  * @param text eg. hello https://google.com
@@ -238,7 +237,7 @@ const generateForwardMessageContent = (message, forceForward) => {
238
237
  exports.generateForwardMessageContent = generateForwardMessageContent;
239
238
  const generateWAMessageContent = async (message, options) => {
240
239
  var _a;
241
- var _b;
240
+ var _b, _c;
242
241
  let m = {};
243
242
  if ('text' in message) {
244
243
  const extContent = { text: message.text };
@@ -308,6 +307,33 @@ const generateWAMessageContent = async (message, options) => {
308
307
  message.disappearingMessagesInChat;
309
308
  m = (0, exports.prepareDisappearingMessageSettingContent)(exp);
310
309
  }
310
+ else if ('groupInvite' in message) {
311
+ m.groupInviteMessage = {};
312
+ m.groupInviteMessage.inviteCode = message.groupInvite.inviteCode;
313
+ m.groupInviteMessage.inviteExpiration = message.groupInvite.inviteExpiration;
314
+ m.groupInviteMessage.caption = message.groupInvite.text;
315
+ m.groupInviteMessage.groupJid = message.groupInvite.jid;
316
+ m.groupInviteMessage.groupName = message.groupInvite.subject;
317
+ //TODO: use built-in interface and get disappearing mode info etc.
318
+ //TODO: cache / use store!?
319
+ if (options.getProfilePicUrl) {
320
+ const pfpUrl = await options.getProfilePicUrl(message.groupInvite.jid, 'preview');
321
+ if (pfpUrl) {
322
+ const resp = await axios_1.default.get(pfpUrl, { responseType: 'arraybuffer' });
323
+ if (resp.status === 200) {
324
+ m.groupInviteMessage.jpegThumbnail = resp.data;
325
+ }
326
+ }
327
+ }
328
+ }
329
+ else if ('pin' in message) {
330
+ m.pinInChatMessage = {};
331
+ m.messageContextInfo = {};
332
+ m.pinInChatMessage.key = message.pin;
333
+ m.pinInChatMessage.type = message.type;
334
+ m.pinInChatMessage.senderTimestampMs = Date.now();
335
+ m.messageContextInfo.messageAddOnDurationInSecs = message.type === 1 ? message.time || 86400 : 0;
336
+ }
311
337
  else if ('buttonReply' in message) {
312
338
  switch (message.type) {
313
339
  case 'template':
@@ -345,6 +371,7 @@ const generateWAMessageContent = async (message, options) => {
345
371
  }
346
372
  else if ('poll' in message) {
347
373
  (_b = message.poll).selectableCount || (_b.selectableCount = 0);
374
+ (_c = message.poll).toAnnouncementGroup || (_c.toAnnouncementGroup = false);
348
375
  if (!Array.isArray(message.poll.values)) {
349
376
  throw new boom_1.Boom('Invalid poll values', { statusCode: 400 });
350
377
  }
@@ -356,11 +383,25 @@ const generateWAMessageContent = async (message, options) => {
356
383
  // encKey
357
384
  messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
358
385
  };
359
- m.pollCreationMessage = {
386
+ const pollCreationMessage = {
360
387
  name: message.poll.name,
361
388
  selectableOptionsCount: message.poll.selectableCount,
362
389
  options: message.poll.values.map(optionName => ({ optionName })),
363
390
  };
391
+ if (message.poll.toAnnouncementGroup) {
392
+ // poll v2 is for community announcement groups (single select and multiple)
393
+ m.pollCreationMessageV2 = pollCreationMessage;
394
+ }
395
+ else {
396
+ if (message.poll.selectableCount > 0) {
397
+ //poll v3 is for single select polls
398
+ m.pollCreationMessageV3 = pollCreationMessage;
399
+ }
400
+ else {
401
+ // poll v3 for multiple choice polls
402
+ m.pollCreationMessage = pollCreationMessage;
403
+ }
404
+ }
364
405
  }
365
406
  else if ('sharePhoneNumber' in message) {
366
407
  m.protocolMessage = {
@@ -373,61 +414,6 @@ const generateWAMessageContent = async (message, options) => {
373
414
  else {
374
415
  m = await (0, exports.prepareWAMessageMedia)(message, options);
375
416
  }
376
- if ('buttons' in message && !!message.buttons) {
377
- const buttonsMessage = {
378
- buttons: message.buttons.map(b => ({ ...b, type: WAProto_1.proto.Message.ButtonsMessage.Button.Type.RESPONSE }))
379
- };
380
- if ('text' in message) {
381
- buttonsMessage.contentText = message.text;
382
- buttonsMessage.headerType = ButtonType.EMPTY;
383
- }
384
- else {
385
- if ('caption' in message) {
386
- buttonsMessage.contentText = message.caption;
387
- }
388
- const type = Object.keys(m)[0].replace('Message', '').toUpperCase();
389
- buttonsMessage.headerType = ButtonType[type];
390
- Object.assign(buttonsMessage, m);
391
- }
392
- if ('footer' in message && !!message.footer) {
393
- buttonsMessage.footerText = message.footer;
394
- }
395
- m = { buttonsMessage };
396
- }
397
- else if ('templateButtons' in message && !!message.templateButtons) {
398
- const msg = {
399
- hydratedButtons: message.templateButtons
400
- };
401
- if ('text' in message) {
402
- msg.hydratedContentText = message.text;
403
- }
404
- else {
405
- if ('caption' in message) {
406
- msg.hydratedContentText = message.caption;
407
- }
408
- Object.assign(msg, m);
409
- }
410
- if ('footer' in message && !!message.footer) {
411
- msg.hydratedFooterText = message.footer;
412
- }
413
- m = {
414
- templateMessage: {
415
- fourRowTemplate: msg,
416
- hydratedTemplate: msg
417
- }
418
- };
419
- }
420
- if ('sections' in message && !!message.sections) {
421
- const listMessage = {
422
- sections: message.sections,
423
- buttonText: message.buttonText,
424
- title: message.title,
425
- footerText: message.footer,
426
- description: message.text,
427
- listType: WAProto_1.proto.Message.ListMessage.ListType.SINGLE_SELECT
428
- };
429
- m = { listMessage };
430
- }
431
417
  if ('viewOnce' in message && !!message.viewOnce) {
432
418
  m = { viewOnceMessage: { message: m } };
433
419
  }
@@ -1,9 +1,10 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import type { Logger } from 'pino';
3
3
  import { proto } from '../../WAProto';
4
- import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
4
+ import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
5
5
  type ProcessMessageContext = {
6
6
  shouldProcessHistoryMsg: boolean;
7
+ placeholderResendCache?: CacheStore;
7
8
  creds: AuthenticationCreds;
8
9
  keyStore: SignalKeyStoreWithTransaction;
9
10
  ev: BaileysEventEmitter;
@@ -37,5 +38,5 @@ type PollContext = {
37
38
  * @returns list of SHA256 options
38
39
  */
39
40
  export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
40
- declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
+ declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
42
  export default processMessage;
@@ -102,8 +102,8 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
102
102
  }
103
103
  }
104
104
  exports.decryptPollVote = decryptPollVote;
105
- const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
106
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
105
+ const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }) => {
106
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
107
107
  const meId = creds.me.id;
108
108
  const { accountSettings } = creds;
109
109
  const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
@@ -137,14 +137,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
137
137
  isLatest,
138
138
  }, 'got history notification');
139
139
  if (process) {
140
- ev.emit('creds.update', {
141
- processedHistoryMessages: [
142
- ...(creds.processedHistoryMessages || []),
143
- { key: message.key, messageTimestamp: message.messageTimestamp }
144
- ]
145
- });
140
+ if (histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
141
+ ev.emit('creds.update', {
142
+ processedHistoryMessages: [
143
+ ...(creds.processedHistoryMessages || []),
144
+ { key: message.key, messageTimestamp: message.messageTimestamp }
145
+ ]
146
+ });
147
+ }
146
148
  const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options);
147
- ev.emit('messaging-history.set', { ...data, isLatest });
149
+ ev.emit('messaging-history.set', {
150
+ ...data,
151
+ isLatest: histNotification.syncType !== WAProto_1.proto.HistorySync.HistorySyncType.ON_DEMAND
152
+ ? isLatest
153
+ : undefined
154
+ });
148
155
  }
149
156
  break;
150
157
  case WAProto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
@@ -187,14 +194,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
187
194
  case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
188
195
  const response = protocolMsg.peerDataOperationRequestResponseMessage;
189
196
  if (response) {
197
+ placeholderResendCache === null || placeholderResendCache === void 0 ? void 0 : placeholderResendCache.del(response.stanzaId);
198
+ // TODO: IMPLEMENT HISTORY SYNC ETC (sticker uploads etc.).
190
199
  const { peerDataOperationResult } = response;
191
200
  for (const result of peerDataOperationResult) {
192
201
  const { placeholderMessageResendResponse: retryResponse } = result;
193
202
  if (retryResponse) {
194
203
  const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
195
- ev.emit('messages.update', [
196
- { key: webMessageInfo.key, update: { message: webMessageInfo.message } }
197
- ]);
204
+ // wait till another upsert event is available, don't want it to be part of the PDO response message
205
+ setTimeout(() => {
206
+ ev.emit('messages.upsert', {
207
+ messages: [webMessageInfo],
208
+ type: 'notify',
209
+ requestId: response.stanzaId
210
+ });
211
+ }, 500);
198
212
  }
199
213
  }
200
214
  }
@@ -208,11 +222,11 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
208
222
  };
209
223
  ev.emit('messages.reaction', [{
210
224
  reaction,
211
- key: content.reactionMessage.key,
225
+ key: (_d = content.reactionMessage) === null || _d === void 0 ? void 0 : _d.key,
212
226
  }]);
213
227
  }
214
228
  else if (message.messageStubType) {
215
- const jid = message.key.remoteJid;
229
+ const jid = (_e = message.key) === null || _e === void 0 ? void 0 : _e.remoteJid;
216
230
  //let actor = whatsappID (message.participant)
217
231
  let participants;
218
232
  const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
@@ -256,34 +270,39 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
256
270
  emitParticipantsUpdate('promote');
257
271
  break;
258
272
  case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
259
- const announceValue = (_d = message.messageStubParameters) === null || _d === void 0 ? void 0 : _d[0];
273
+ const announceValue = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
260
274
  emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
261
275
  break;
262
276
  case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
263
- const restrictValue = (_e = message.messageStubParameters) === null || _e === void 0 ? void 0 : _e[0];
277
+ const restrictValue = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
264
278
  emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
265
279
  break;
266
280
  case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
267
- const name = (_f = message.messageStubParameters) === null || _f === void 0 ? void 0 : _f[0];
281
+ const name = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
268
282
  chat.name = name;
269
283
  emitGroupUpdate({ subject: name });
270
284
  break;
285
+ case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
286
+ const description = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
287
+ chat.description = description;
288
+ emitGroupUpdate({ desc: description });
289
+ break;
271
290
  case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
272
- const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
291
+ const code = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
273
292
  emitGroupUpdate({ inviteCode: code });
274
293
  break;
275
294
  case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
276
- const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
295
+ const memberAddValue = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[0];
277
296
  emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
278
297
  break;
279
298
  case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
280
- const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
299
+ const approvalMode = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[0];
281
300
  emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
282
301
  break;
283
302
  case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
284
- const participant = (_k = message.messageStubParameters) === null || _k === void 0 ? void 0 : _k[0];
285
- const action = (_l = message.messageStubParameters) === null || _l === void 0 ? void 0 : _l[1];
286
- const method = (_m = message.messageStubParameters) === null || _m === void 0 ? void 0 : _m[2];
303
+ const participant = (_o = message.messageStubParameters) === null || _o === void 0 ? void 0 : _o[0];
304
+ const action = (_p = message.messageStubParameters) === null || _p === void 0 ? void 0 : _p[1];
305
+ const method = (_q = message.messageStubParameters) === null || _q === void 0 ? void 0 : _q[2];
287
306
  emitGroupRequestJoin(participant, action, method);
288
307
  break;
289
308
  }
@@ -296,7 +315,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
296
315
  const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
297
316
  const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
298
317
  const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
299
- const pollEncKey = (_o = pollMsg.messageContextInfo) === null || _o === void 0 ? void 0 : _o.messageSecret;
318
+ const pollEncKey = (_r = pollMsg.messageContextInfo) === null || _r === void 0 ? void 0 : _r.messageSecret;
300
319
  try {
301
320
  const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
302
321
  pollEncKey,
@@ -26,4 +26,6 @@ export declare const isJidBroadcast: (jid: string | undefined) => boolean | unde
26
26
  export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
27
  /** is the jid the status broadcast */
28
28
  export declare const isJidStatusBroadcast: (jid: string) => boolean;
29
+ /** is the jid a newsletter */
30
+ export declare const isJidNewsletter: (jid: string | undefined) => boolean | undefined;
29
31
  export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jidNormalizedUser = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
3
+ exports.jidNormalizedUser = exports.isJidNewsletter = exports.isJidStatusBroadcast = exports.isJidGroup = exports.isJidBroadcast = exports.isLidUser = exports.isJidUser = exports.areJidsSameUser = exports.jidDecode = exports.jidEncode = exports.STORIES_JID = exports.PSA_WID = exports.SERVER_JID = exports.OFFICIAL_BIZ_JID = exports.S_WHATSAPP_NET = void 0;
4
4
  exports.S_WHATSAPP_NET = '@s.whatsapp.net';
5
5
  exports.OFFICIAL_BIZ_JID = '16505361212@c.us';
6
6
  exports.SERVER_JID = 'server@c.us';
@@ -48,6 +48,9 @@ exports.isJidGroup = isJidGroup;
48
48
  /** is the jid the status broadcast */
49
49
  const isJidStatusBroadcast = (jid) => jid === 'status@broadcast';
50
50
  exports.isJidStatusBroadcast = isJidStatusBroadcast;
51
+ /** is the jid a newsletter */
52
+ const isJidNewsletter = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@newsletter'));
53
+ exports.isJidNewsletter = isJidNewsletter;
51
54
  const jidNormalizedUser = (jid) => {
52
55
  const result = (0, exports.jidDecode)(jid);
53
56
  if (!result) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d0v3riz/baileys",
3
- "version": "6.7.5",
3
+ "version": "6.7.7",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",