@queenanya/baileys 6.6.6 → 6.7.0

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 (44) hide show
  1. package/CHANGELOG.md +1 -5
  2. package/README.md +31 -93
  3. package/WAProto/WAProto.proto +473 -8
  4. package/WAProto/index.d.ts +4793 -22
  5. package/WAProto/index.js +32548 -19335
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.d.ts +2 -2
  8. package/lib/Defaults/index.js +6 -2
  9. package/lib/Socket/business.d.ts +9 -0
  10. package/lib/Socket/chats.d.ts +4 -0
  11. package/lib/Socket/chats.js +13 -1
  12. package/lib/Socket/groups.d.ts +6 -0
  13. package/lib/Socket/groups.js +9 -2
  14. package/lib/Socket/index.d.ts +9 -0
  15. package/lib/Socket/messages-recv.d.ts +9 -0
  16. package/lib/Socket/messages-recv.js +29 -7
  17. package/lib/Socket/messages-send.d.ts +7 -0
  18. package/lib/Socket/messages-send.js +7 -4
  19. package/lib/Socket/registration.d.ts +9 -0
  20. package/lib/Socket/socket.js +3 -2
  21. package/lib/Store/make-cache-manager-store.d.ts +0 -1
  22. package/lib/Types/Call.d.ts +1 -0
  23. package/lib/Types/Contact.d.ts +1 -0
  24. package/lib/Types/Events.d.ts +5 -0
  25. package/lib/Types/GroupMetadata.d.ts +2 -0
  26. package/lib/Types/Message.d.ts +7 -1
  27. package/lib/Types/Socket.d.ts +2 -0
  28. package/lib/Types/index.d.ts +3 -1
  29. package/lib/Types/index.js +2 -0
  30. package/lib/Utils/chat-utils.js +14 -0
  31. package/lib/Utils/decode-wa-message.d.ts +2 -2
  32. package/lib/Utils/decode-wa-message.js +18 -4
  33. package/lib/Utils/generics.d.ts +1 -0
  34. package/lib/Utils/generics.js +1 -0
  35. package/lib/Utils/messages-media.js +1 -1
  36. package/lib/Utils/messages.d.ts +1 -1
  37. package/lib/Utils/messages.js +11 -5
  38. package/lib/Utils/process-message.js +27 -4
  39. package/lib/Utils/validate-connection.js +33 -2
  40. package/lib/WABinary/decode.js +1 -1
  41. package/lib/WABinary/encode.js +3 -3
  42. package/lib/WABinary/jid-utils.d.ts +4 -2
  43. package/lib/WABinary/jid-utils.js +6 -3
  44. package/package.json +5 -5
@@ -10,7 +10,7 @@ const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node';
10
10
  * Decode the received node as a message.
11
11
  * @note this will only parse the message, not decrypt it
12
12
  */
13
- function decodeMessageNode(stanza, meId) {
13
+ function decodeMessageNode(stanza, meId, meLid) {
14
14
  let msgType;
15
15
  let chatId;
16
16
  let author;
@@ -19,6 +19,7 @@ function decodeMessageNode(stanza, meId) {
19
19
  const participant = stanza.attrs.participant;
20
20
  const recipient = stanza.attrs.recipient;
21
21
  const isMe = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meId);
22
+ const isMeLid = (jid) => (0, WABinary_1.areJidsSameUser)(jid, meLid);
22
23
  if ((0, WABinary_1.isJidUser)(from)) {
23
24
  if (recipient) {
24
25
  if (!isMe(from)) {
@@ -32,6 +33,19 @@ function decodeMessageNode(stanza, meId) {
32
33
  msgType = 'chat';
33
34
  author = from;
34
35
  }
36
+ else if ((0, WABinary_1.isLidUser)(from)) {
37
+ if (recipient) {
38
+ if (!isMeLid(from)) {
39
+ throw new boom_1.Boom('receipient present, but msg not from me', { data: stanza });
40
+ }
41
+ chatId = recipient;
42
+ }
43
+ else {
44
+ chatId = from;
45
+ }
46
+ msgType = 'chat';
47
+ author = from;
48
+ }
35
49
  else if ((0, WABinary_1.isJidGroup)(from)) {
36
50
  if (!participant) {
37
51
  throw new boom_1.Boom('No participant in group message');
@@ -57,7 +71,7 @@ function decodeMessageNode(stanza, meId) {
57
71
  else {
58
72
  throw new boom_1.Boom('Unknown message type', { data: stanza });
59
73
  }
60
- const fromMe = isMe(stanza.attrs.participant || stanza.attrs.from);
74
+ const fromMe = ((0, WABinary_1.isLidUser)(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from);
61
75
  const pushname = stanza.attrs.notify;
62
76
  const key = {
63
77
  remoteJid: chatId,
@@ -81,8 +95,8 @@ function decodeMessageNode(stanza, meId) {
81
95
  };
82
96
  }
83
97
  exports.decodeMessageNode = decodeMessageNode;
84
- const decryptMessageNode = (stanza, meId, repository, logger) => {
85
- const { fullMessage, author, sender } = decodeMessageNode(stanza, meId);
98
+ const decryptMessageNode = (stanza, meId, meLid, repository, logger) => {
99
+ const { fullMessage, author, sender } = decodeMessageNode(stanza, meId, meLid);
86
100
  return {
87
101
  fullMessage,
88
102
  category: stanza.attrs.category,
@@ -8,6 +8,7 @@ export declare const Browsers: {
8
8
  ubuntu: (browser: any) => [string, string, string];
9
9
  macOS: (browser: any) => [string, string, string];
10
10
  baileys: (browser: any) => [string, string, string];
11
+ windows: (browser: any) => [string, string, string];
11
12
  /** The appropriate browser based on your OS & release */
12
13
  appropriate: (browser: any) => [string, string, string];
13
14
  };
@@ -22,6 +22,7 @@ exports.Browsers = {
22
22
  ubuntu: browser => ['Firefox (linux)', browser, '119.0'],
23
23
  macOS: browser => ['Firefox (linux)', browser, '119.0'],
24
24
  baileys: browser => ['Firefox (linux)', browser, '119.0'],
25
+ windows: browser => ['Windows', browser, '10.0.22621'],
25
26
  /** The appropriate browser based on your OS & release */
26
27
  appropriate: browser => [PLATFORM_MAP[(0, os_1.platform)()] || 'Firefox (linux)', browser, (0, os_1.release)()]
27
28
  };
@@ -213,7 +213,7 @@ exports.getAudioDuration = getAudioDuration;
213
213
  */
214
214
  async function getAudioWaveform(buffer, logger) {
215
215
  try {
216
- const audioDecode = (...args) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(...args));
216
+ const audioDecode = (buffer) => import('audio-decode').then(({ default: audioDecode }) => audioDecode(buffer));
217
217
  let audioData;
218
218
  if (Buffer.isBuffer(buffer)) {
219
219
  audioData = buffer;
@@ -39,7 +39,7 @@ export declare const extractMessageContent: (content: WAMessageContent | undefin
39
39
  /**
40
40
  * Returns the device predicted by message ID
41
41
  */
42
- export declare const getDevice: (id: string) => "android" | "web" | "ios";
42
+ export declare const getDevice: (id: string) => "android" | "unknown" | "web" | "ios" | "desktop";
43
43
  /** Upserts a receipt in the message */
44
44
  export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => void;
45
45
  /** Update the message with a new reaction */
@@ -357,6 +357,14 @@ const generateWAMessageContent = async (message, options) => {
357
357
  options: message.poll.values.map(optionName => ({ optionName })),
358
358
  };
359
359
  }
360
+ else if ('sharePhoneNumber' in message) {
361
+ m.protocolMessage = {
362
+ type: WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
363
+ };
364
+ }
365
+ else if ('requestPhoneNumber' in message) {
366
+ m.requestPhoneNumberMessage = {};
367
+ }
360
368
  else {
361
369
  m = await (0, exports.prepareWAMessageMedia)(message, options);
362
370
  }
@@ -511,7 +519,7 @@ exports.generateWAMessage = generateWAMessage;
511
519
  const getContentType = (content) => {
512
520
  if (content) {
513
521
  const keys = Object.keys(content);
514
- const key = keys.find(k => (k === 'conversation' || k.endsWith('Message')) && k !== 'senderKeyDistributionMessage');
522
+ const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage');
515
523
  return key;
516
524
  }
517
525
  };
@@ -540,6 +548,7 @@ const normalizeMessageContent = (content) => {
540
548
  || (message === null || message === void 0 ? void 0 : message.viewOnceMessage)
541
549
  || (message === null || message === void 0 ? void 0 : message.documentWithCaptionMessage)
542
550
  || (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2)
551
+ || (message === null || message === void 0 ? void 0 : message.viewOnceMessageV2Extension)
543
552
  || (message === null || message === void 0 ? void 0 : message.editedMessage));
544
553
  }
545
554
  };
@@ -590,10 +599,7 @@ exports.extractMessageContent = extractMessageContent;
590
599
  /**
591
600
  * Returns the device predicted by message ID
592
601
  */
593
- const getDevice = (id) => {
594
- const deviceType = id.length > 21 ? 'android' : id.substring(0, 2) === '3A' ? 'ios' : 'web';
595
- return deviceType;
596
- };
602
+ const getDevice = (id) => /^3A.{18}$/.test(id) ? 'ios' : /^3E.{20}$/.test(id) ? 'web' : /^(.{21}|.{32})$/.test(id) ? 'android' : /^.{18}$/.test(id) ? 'desktop' : 'unknown';
597
603
  exports.getDevice = getDevice;
598
604
  /** Upserts a receipt in the message */
599
605
  const updateMessageWithReceipt = (msg, receipt) => {
@@ -103,7 +103,7 @@ function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pol
103
103
  }
104
104
  exports.decryptPollVote = decryptPollVote;
105
105
  const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }) => {
106
- var _a, _b, _c, _d, _e, _f, _g, _h;
106
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
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)) };
@@ -184,6 +184,21 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
184
184
  ephemeralExpiration: protocolMsg.ephemeralExpiration || null
185
185
  });
186
186
  break;
187
+ case WAProto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
188
+ const response = protocolMsg.peerDataOperationRequestResponseMessage;
189
+ if (response) {
190
+ const { peerDataOperationResult } = response;
191
+ for (const result of peerDataOperationResult) {
192
+ const { placeholderMessageResendResponse: retryResponse } = result;
193
+ if (retryResponse) {
194
+ const webMessageInfo = WAProto_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
195
+ ev.emit('messages.update', [
196
+ { key: webMessageInfo.key, update: { message: webMessageInfo.message } }
197
+ ]);
198
+ }
199
+ }
200
+ }
201
+ break;
187
202
  }
188
203
  }
189
204
  else if (content === null || content === void 0 ? void 0 : content.reactionMessage) {
@@ -200,7 +215,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
200
215
  const jid = message.key.remoteJid;
201
216
  //let actor = whatsappID (message.participant)
202
217
  let participants;
203
- const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, participants, action }));
218
+ const emitParticipantsUpdate = (action) => (ev.emit('group-participants.update', { id: jid, author: message.participant, participants, action }));
204
219
  const emitGroupUpdate = (update) => {
205
220
  ev.emit('groups.update', [{ id: jid, ...update }]);
206
221
  };
@@ -249,6 +264,14 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
249
264
  const code = (_g = message.messageStubParameters) === null || _g === void 0 ? void 0 : _g[0];
250
265
  emitGroupUpdate({ inviteCode: code });
251
266
  break;
267
+ case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
268
+ const memberAddValue = (_h = message.messageStubParameters) === null || _h === void 0 ? void 0 : _h[0];
269
+ emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
270
+ break;
271
+ case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
272
+ const approvalMode = (_j = message.messageStubParameters) === null || _j === void 0 ? void 0 : _j[0];
273
+ emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
274
+ break;
252
275
  }
253
276
  }
254
277
  else if (content === null || content === void 0 ? void 0 : content.pollUpdateMessage) {
@@ -259,7 +282,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
259
282
  const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
260
283
  const pollCreatorJid = (0, generics_1.getKeyAuthor)(creationMsgKey, meIdNormalised);
261
284
  const voterJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
262
- const pollEncKey = (_h = pollMsg.messageContextInfo) === null || _h === void 0 ? void 0 : _h.messageSecret;
285
+ const pollEncKey = (_k = pollMsg.messageContextInfo) === null || _k === void 0 ? void 0 : _k.messageSecret;
263
286
  try {
264
287
  const voteMsg = decryptPollVote(content.pollUpdateMessage.vote, {
265
288
  pollEncKey,
@@ -275,7 +298,7 @@ const processMessage = async (message, { shouldProcessHistoryMsg, ev, creds, key
275
298
  {
276
299
  pollUpdateMessageKey: message.key,
277
300
  vote: voteMsg,
278
- senderTimestampMs: message.messageTimestamp,
301
+ senderTimestampMs: content.pollUpdateMessage.senderTimestampMs.toNumber(),
279
302
  }
280
303
  ]
281
304
  }
@@ -77,8 +77,39 @@ const generateLoginNode = (userJid, config) => {
77
77
  };
78
78
  exports.generateLoginNode = generateLoginNode;
79
79
  const getPlatformType = (platform) => {
80
- const platformType = platform.toUpperCase();
81
- return WAProto_1.proto.DeviceProps.PlatformType[platformType] || WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
80
+ platform = platform.toLowerCase();
81
+ switch (platform) {
82
+ case 'Chrome':
83
+ return WAProto_1.proto.DeviceProps.PlatformType.CHROME;
84
+ case 'Firefox':
85
+ return WAProto_1.proto.DeviceProps.PlatformType.FIREFOX;
86
+ case 'Internet Explorer':
87
+ return WAProto_1.proto.DeviceProps.PlatformType.IE;
88
+ case 'Edge':
89
+ return WAProto_1.proto.DeviceProps.PlatformType.EDGE;
90
+ case 'Opera':
91
+ return WAProto_1.proto.DeviceProps.PlatformType.OPERA;
92
+ case 'Safari':
93
+ return WAProto_1.proto.DeviceProps.PlatformType.SAFARI;
94
+ case 'Desktop':
95
+ return WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
96
+ case 'chrome':
97
+ return WAProto_1.proto.DeviceProps.PlatformType.CHROME;
98
+ case 'firefox':
99
+ return WAProto_1.proto.DeviceProps.PlatformType.FIREFOX;
100
+ case 'internet explorer':
101
+ return WAProto_1.proto.DeviceProps.PlatformType.IE;
102
+ case 'edge':
103
+ return WAProto_1.proto.DeviceProps.PlatformType.EDGE;
104
+ case 'opera':
105
+ return WAProto_1.proto.DeviceProps.PlatformType.OPERA;
106
+ case 'safari':
107
+ return WAProto_1.proto.DeviceProps.PlatformType.SAFARI;
108
+ case 'desktop':
109
+ return WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
110
+ default:
111
+ return WAProto_1.proto.DeviceProps.PlatformType.DESKTOP;
112
+ }
82
113
  };
83
114
  const generateRegistrationNode = ({ registrationId, signedPreKey, signedIdentityKey }, config) => {
84
115
  // the app version needs to be md5 hashed
@@ -147,7 +147,7 @@ const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) =>
147
147
  const agent = readByte();
148
148
  const device = readByte();
149
149
  const user = readString(readByte());
150
- return (0, jid_utils_1.jidEncode)(user, 's.whatsapp.net', device, agent);
150
+ return (0, jid_utils_1.jidEncode)(user, agent === 0 ? 's.whatsapp.net' : 'lid', device);
151
151
  };
152
152
  const readString = (tag) => {
153
153
  if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
@@ -62,10 +62,10 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
62
62
  writeByteLength(bytes.length);
63
63
  pushBytes(bytes);
64
64
  };
65
- const writeJid = ({ agent, device, user, server }) => {
66
- if (typeof agent !== 'undefined' || typeof device !== 'undefined') {
65
+ const writeJid = ({ domainType, device, user, server }) => {
66
+ if (typeof device !== 'undefined') {
67
67
  pushByte(TAGS.AD_JID);
68
- pushByte(agent || 0);
68
+ pushByte(domainType || 0);
69
69
  pushByte(device || 0);
70
70
  writeString(user);
71
71
  }
@@ -3,14 +3,14 @@ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
3
  export declare const SERVER_JID = "server@c.us";
4
4
  export declare const PSA_WID = "0@c.us";
5
5
  export declare const STORIES_JID = "status@broadcast";
6
- export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call';
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid';
7
7
  export type JidWithDevice = {
8
8
  user: string;
9
9
  device?: number;
10
10
  };
11
11
  export type FullJid = JidWithDevice & {
12
12
  server: JidServer | string;
13
- agent?: number;
13
+ domainType?: number;
14
14
  };
15
15
  export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
16
16
  export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
@@ -18,6 +18,8 @@ export declare const jidDecode: (jid: string | undefined) => FullJid | undefined
18
18
  export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
19
19
  /** is the jid a user */
20
20
  export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
21
+ /** is the jid a group */
22
+ export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
21
23
  /** is the jid a broadcast */
22
24
  export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
23
25
  /** is the jid a group */
@@ -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.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.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';
@@ -18,11 +18,11 @@ const jidDecode = (jid) => {
18
18
  const server = jid.slice(sepIdx + 1);
19
19
  const userCombined = jid.slice(0, sepIdx);
20
20
  const [userAgent, device] = userCombined.split(':');
21
- const [user, agent] = userAgent.split('_');
21
+ const user = userAgent.split('_')[0];
22
22
  return {
23
23
  server,
24
24
  user,
25
- agent: agent ? +agent : undefined,
25
+ domainType: server === 'lid' ? 1 : 0,
26
26
  device: device ? +device : undefined
27
27
  };
28
28
  };
@@ -36,6 +36,9 @@ exports.areJidsSameUser = areJidsSameUser;
36
36
  /** is the jid a user */
37
37
  const isJidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@s.whatsapp.net'));
38
38
  exports.isJidUser = isJidUser;
39
+ /** is the jid a group */
40
+ const isLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@lid'));
41
+ exports.isLidUser = isLidUser;
39
42
  /** is the jid a broadcast */
40
43
  const isJidBroadcast = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@broadcast'));
41
44
  exports.isJidBroadcast = isJidBroadcast;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@queenanya/baileys",
3
- "version": "6.6.6",
3
+ "version": "6.7.0",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -46,14 +46,14 @@
46
46
  "@hapi/boom": "^9.1.3",
47
47
  "audio-decode": "^2.1.3",
48
48
  "axios": "^1.3.3",
49
- "cache-manager": "^5.2.2",
49
+ "cache-manager": "4.0.1",
50
50
  "futoin-hkdf": "^1.5.1",
51
51
  "libphonenumber-js": "^1.10.20",
52
- "libsignal": "npm:@queenanya/libsignal",
52
+ "libsignal": "npm:@queenanya/libsignal@latest",
53
53
  "music-metadata": "^7.12.3",
54
54
  "node-cache": "^5.1.2",
55
55
  "pino": "^7.0.0",
56
- "protobufjs": "^6.11.3",
56
+ "protobufjs": "^7.2.4",
57
57
  "uuid": "^9.0.0",
58
58
  "ws": "^8.13.0"
59
59
  },
@@ -82,7 +82,7 @@
82
82
  "jimp": "^0.16.1",
83
83
  "link-preview-js": "^3.0.0",
84
84
  "qrcode-terminal": "^0.12.0",
85
- "sharp": "^0.30.5"
85
+ "sharp": "^0.32.2"
86
86
  },
87
87
  "peerDependenciesMeta": {
88
88
  "jimp": {