@d0v3riz/baileys 6.7.7 → 6.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +0 -10
  2. package/lib/Defaults/index.d.ts +1 -231
  3. package/lib/Defaults/index.js +1 -17
  4. package/lib/Socket/Client/index.d.ts +2 -3
  5. package/lib/Socket/Client/index.js +2 -3
  6. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  7. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  8. package/lib/Socket/business.d.ts +3 -1
  9. package/lib/Socket/chats.d.ts +4 -1
  10. package/lib/Socket/chats.js +39 -11
  11. package/lib/Socket/groups.d.ts +3 -1
  12. package/lib/Socket/index.d.ts +12 -12
  13. package/lib/Socket/index.js +2 -2
  14. package/lib/Socket/messages-recv.d.ts +4 -2
  15. package/lib/Socket/messages-recv.js +126 -117
  16. package/lib/Socket/messages-send.d.ts +3 -1
  17. package/lib/Socket/messages-send.js +23 -8
  18. package/lib/Socket/socket.d.ts +3 -1
  19. package/lib/Socket/socket.js +9 -14
  20. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  21. package/lib/Store/make-in-memory-store.js +8 -10
  22. package/lib/Store/make-ordered-dictionary.js +2 -2
  23. package/lib/Types/Auth.d.ts +1 -6
  24. package/lib/Types/Call.d.ts +1 -1
  25. package/lib/Types/Chat.d.ts +10 -7
  26. package/lib/Types/Contact.d.ts +1 -1
  27. package/lib/Types/Events.d.ts +4 -0
  28. package/lib/Types/Label.d.ts +11 -0
  29. package/lib/Types/Message.d.ts +5 -2
  30. package/lib/Types/Socket.d.ts +3 -3
  31. package/lib/Utils/auth-utils.js +1 -7
  32. package/lib/Utils/chat-utils.d.ts +5 -4
  33. package/lib/Utils/chat-utils.js +41 -20
  34. package/lib/Utils/crypto.d.ts +1 -0
  35. package/lib/Utils/decode-wa-message.js +1 -0
  36. package/lib/Utils/event-buffer.js +14 -8
  37. package/lib/Utils/generics.d.ts +10 -5
  38. package/lib/Utils/generics.js +35 -7
  39. package/lib/Utils/history.d.ts +2 -2
  40. package/lib/Utils/history.js +1 -1
  41. package/lib/Utils/link-preview.js +24 -1
  42. package/lib/Utils/make-mutex.js +1 -0
  43. package/lib/Utils/messages-media.d.ts +2 -1
  44. package/lib/Utils/messages-media.js +8 -15
  45. package/lib/Utils/messages.d.ts +1 -0
  46. package/lib/Utils/messages.js +7 -11
  47. package/lib/Utils/noise-handler.d.ts +2 -2
  48. package/lib/Utils/noise-handler.js +5 -10
  49. package/lib/Utils/process-message.js +3 -1
  50. package/lib/Utils/signal.js +2 -0
  51. package/lib/Utils/use-multi-file-auth-state.js +1 -0
  52. package/lib/Utils/validate-connection.d.ts +0 -1
  53. package/lib/Utils/validate-connection.js +10 -44
  54. package/lib/WABinary/constants.js +5 -5
  55. package/lib/WABinary/decode.d.ts +1 -0
  56. package/lib/WABinary/encode.d.ts +1 -0
  57. package/lib/WABinary/encode.js +7 -5
  58. package/lib/WABinary/generic-utils.d.ts +1 -0
  59. package/lib/WABinary/jid-utils.d.ts +2 -2
  60. package/lib/WABinary/jid-utils.js +1 -1
  61. package/lib/WAM/BinaryInfo.d.ts +3 -2
  62. package/lib/WAM/constants.d.ts +3 -2
  63. package/lib/WAM/encode.d.ts +1 -0
  64. package/lib/WAM/encode.js +2 -2
  65. package/package.json +5 -6
  66. package/lib/Defaults/phonenumber-mcc.json +0 -223
  67. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  68. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  69. package/lib/Socket/registration.d.ts +0 -241
  70. package/lib/Socket/registration.js +0 -166
  71. /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
  72. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Boom } from '@hapi/boom';
3
4
  import { proto } from '../../WAProto';
4
5
  import { MessageReceiptType, MessageRelayOptions, SocketConfig, WAMessageKey } from '../Types';
@@ -8,7 +9,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
8
9
  sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
9
10
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
10
11
  fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
11
- requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<'RESOLVED' | string | undefined>;
12
+ requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
12
13
  getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
13
14
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
14
15
  relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
@@ -94,6 +95,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
94
95
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
95
96
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
96
97
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
98
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
97
99
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
98
100
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
99
101
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -103,7 +105,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
103
105
  fromMe?: boolean | undefined;
104
106
  }[], star: boolean) => Promise<void>;
105
107
  type: "md";
106
- ws: any;
108
+ ws: import("./Client").WebSocketClient;
107
109
  ev: import("../Types").BaileysEventEmitter & {
108
110
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
109
111
  buffer(): void;
@@ -460,8 +460,7 @@ const makeMessagesRecvSocket = (config) => {
460
460
  await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
461
461
  }
462
462
  logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
463
- for (let i = 0; i < msgs.length; i++) {
464
- const msg = msgs[i];
463
+ for (const [i, msg] of msgs.entries()) {
465
464
  if (msg) {
466
465
  updateSendMessageAgainCount(ids[i], participant);
467
466
  const msgRelayOpts = { messageId: ids[i] };
@@ -504,59 +503,63 @@ const makeMessagesRecvSocket = (config) => {
504
503
  const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
505
504
  ids.push(...items.map(i => i.attrs.id));
506
505
  }
507
- await Promise.all([
508
- processingMutex.mutex(async () => {
509
- const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
510
- if (typeof status !== 'undefined' &&
511
- (
512
- // basically, we only want to know when a message from us has been delivered to/read by the other person
513
- // or another device of ours has read some messages
514
- status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
515
- !isNodeFromMe)) {
516
- if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
517
- if (attrs.participant) {
518
- const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
519
- ev.emit('message-receipt.update', ids.map(id => ({
506
+ try {
507
+ await Promise.all([
508
+ processingMutex.mutex(async () => {
509
+ const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
510
+ if (typeof status !== 'undefined' &&
511
+ (
512
+ // basically, we only want to know when a message from us has been delivered to/read by the other person
513
+ // or another device of ours has read some messages
514
+ status > WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ||
515
+ !isNodeFromMe)) {
516
+ if ((0, WABinary_1.isJidGroup)(remoteJid) || (0, WABinary_1.isJidStatusBroadcast)(remoteJid)) {
517
+ if (attrs.participant) {
518
+ const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
519
+ ev.emit('message-receipt.update', ids.map(id => ({
520
+ key: { ...key, id },
521
+ receipt: {
522
+ userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
523
+ [updateKey]: +attrs.t
524
+ }
525
+ })));
526
+ }
527
+ }
528
+ else {
529
+ ev.emit('messages.update', ids.map(id => ({
520
530
  key: { ...key, id },
521
- receipt: {
522
- userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
523
- [updateKey]: +attrs.t
524
- }
531
+ update: { status }
525
532
  })));
526
533
  }
527
534
  }
528
- else {
529
- ev.emit('messages.update', ids.map(id => ({
530
- key: { ...key, id },
531
- update: { status }
532
- })));
533
- }
534
- }
535
- if (attrs.type === 'retry') {
536
- // correctly set who is asking for the retry
537
- key.participant = key.participant || attrs.from;
538
- const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
539
- if (willSendMessageAgain(ids[0], key.participant)) {
540
- if (key.fromMe) {
541
- try {
542
- logger.debug({ attrs, key }, 'recv retry request');
543
- await sendMessagesAgain(key, ids, retryNode);
535
+ if (attrs.type === 'retry') {
536
+ // correctly set who is asking for the retry
537
+ key.participant = key.participant || attrs.from;
538
+ const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
539
+ if (willSendMessageAgain(ids[0], key.participant)) {
540
+ if (key.fromMe) {
541
+ try {
542
+ logger.debug({ attrs, key }, 'recv retry request');
543
+ await sendMessagesAgain(key, ids, retryNode);
544
+ }
545
+ catch (error) {
546
+ logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
547
+ }
544
548
  }
545
- catch (error) {
546
- logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
549
+ else {
550
+ logger.info({ attrs, key }, 'recv retry for not fromMe message');
547
551
  }
548
552
  }
549
553
  else {
550
- logger.info({ attrs, key }, 'recv retry for not fromMe message');
554
+ logger.info({ attrs, key }, 'will not send message again, as sent too many times');
551
555
  }
552
556
  }
553
- else {
554
- logger.info({ attrs, key }, 'will not send message again, as sent too many times');
555
- }
556
- }
557
- }),
558
- sendMessageAck(node)
559
- ]);
557
+ })
558
+ ]);
559
+ }
560
+ finally {
561
+ await sendMessageAck(node);
562
+ }
560
563
  };
561
564
  const handleNotification = async (node) => {
562
565
  const remoteJid = node.attrs.from;
@@ -565,27 +568,31 @@ const makeMessagesRecvSocket = (config) => {
565
568
  await sendMessageAck(node);
566
569
  return;
567
570
  }
568
- await Promise.all([
569
- processingMutex.mutex(async () => {
570
- var _a;
571
- const msg = await processNotification(node);
572
- if (msg) {
573
- const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
574
- msg.key = {
575
- remoteJid,
576
- fromMe,
577
- participant: node.attrs.participant,
578
- id: node.attrs.id,
579
- ...(msg.key || {})
580
- };
581
- (_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
582
- msg.messageTimestamp = +node.attrs.t;
583
- const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
584
- await upsertMessage(fullMsg, 'append');
585
- }
586
- }),
587
- sendMessageAck(node)
588
- ]);
571
+ try {
572
+ await Promise.all([
573
+ processingMutex.mutex(async () => {
574
+ var _a;
575
+ const msg = await processNotification(node);
576
+ if (msg) {
577
+ const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
578
+ msg.key = {
579
+ remoteJid,
580
+ fromMe,
581
+ participant: node.attrs.participant,
582
+ id: node.attrs.id,
583
+ ...(msg.key || {})
584
+ };
585
+ (_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
586
+ msg.messageTimestamp = +node.attrs.t;
587
+ const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
588
+ await upsertMessage(fullMsg, 'append');
589
+ }
590
+ })
591
+ ]);
592
+ }
593
+ finally {
594
+ await sendMessageAck(node);
595
+ }
589
596
  };
590
597
  const handleMessage = async (node) => {
591
598
  var _a, _b, _c;
@@ -613,62 +620,64 @@ const makeMessagesRecvSocket = (config) => {
613
620
  if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
614
621
  msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
615
622
  }
616
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
617
- if (node.attrs.sender_pn) {
618
- ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
619
- }
620
- }
621
- await Promise.all([
622
- processingMutex.mutex(async () => {
623
- await decrypt();
624
- // message failed to decrypt
625
- if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
626
- retryMutex.mutex(async () => {
627
- if (ws.isOpen) {
628
- if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
629
- return;
623
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
624
+ ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
625
+ }
626
+ try {
627
+ await Promise.all([
628
+ processingMutex.mutex(async () => {
629
+ await decrypt();
630
+ // message failed to decrypt
631
+ if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
632
+ retryMutex.mutex(async () => {
633
+ if (ws.isOpen) {
634
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable')) {
635
+ return;
636
+ }
637
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
638
+ await sendRetryRequest(node, !encNode);
639
+ if (retryRequestDelayMs) {
640
+ await (0, Utils_1.delay)(retryRequestDelayMs);
641
+ }
630
642
  }
631
- const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
632
- await sendRetryRequest(node, !encNode);
633
- if (retryRequestDelayMs) {
634
- await (0, Utils_1.delay)(retryRequestDelayMs);
643
+ else {
644
+ logger.debug({ node }, 'connection closed, ignoring retry req');
635
645
  }
646
+ });
647
+ }
648
+ else {
649
+ // no type in the receipt => message delivered
650
+ let type = undefined;
651
+ let participant = msg.key.participant;
652
+ if (category === 'peer') { // special peer message
653
+ type = 'peer_msg';
636
654
  }
637
- else {
638
- logger.debug({ node }, 'connection closed, ignoring retry req');
655
+ else if (msg.key.fromMe) { // message was sent by us from a different device
656
+ type = 'sender';
657
+ // need to specially handle this case
658
+ if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
659
+ participant = author;
660
+ }
639
661
  }
640
- });
641
- }
642
- else {
643
- // no type in the receipt => message delivered
644
- let type = undefined;
645
- let participant = msg.key.participant;
646
- if (category === 'peer') { // special peer message
647
- type = 'peer_msg';
648
- }
649
- else if (msg.key.fromMe) { // message was sent by us from a different device
650
- type = 'sender';
651
- // need to specially handle this case
652
- if ((0, WABinary_1.isJidUser)(msg.key.remoteJid)) {
653
- participant = author;
662
+ else if (!sendActiveReceipts) {
663
+ type = 'inactive';
664
+ }
665
+ await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
666
+ // send ack for history message
667
+ const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
668
+ if (isAnyHistoryMsg) {
669
+ const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
670
+ await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
654
671
  }
655
672
  }
656
- else if (!sendActiveReceipts) {
657
- type = 'inactive';
658
- }
659
- await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
660
- // send ack for history message
661
- const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
662
- if (isAnyHistoryMsg) {
663
- const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
664
- await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
665
- }
666
- }
667
- (0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
668
- await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
669
- }),
670
- sendMessageAck(node)
671
- ]);
673
+ (0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
674
+ await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
675
+ })
676
+ ]);
677
+ }
678
+ finally {
679
+ await sendMessageAck(node);
680
+ }
672
681
  };
673
682
  const fetchMessageHistory = async (count, oldestMsgKey, oldestMsgTimestamp) => {
674
683
  var _a;
@@ -745,7 +754,7 @@ const makeMessagesRecvSocket = (config) => {
745
754
  call.isGroup = existingCall.isGroup;
746
755
  }
747
756
  // delete data once call has ended
748
- if (status === 'reject' || status === 'accept' || status === 'timeout') {
757
+ if (status === 'reject' || status === 'accept' || status === 'timeout' || status === 'terminate') {
749
758
  callOfferCache.del(call.id);
750
759
  }
751
760
  ev.emit('call', [call]);
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Boom } from '@hapi/boom';
3
4
  import { proto } from '../../WAProto';
4
5
  import { AnyMessageContent, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, SocketConfig, WAMessageKey } from '../Types';
@@ -87,6 +88,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
87
88
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
88
89
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
89
90
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
91
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
90
92
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
91
93
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
92
94
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -96,7 +98,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
96
98
  fromMe?: boolean | undefined;
97
99
  }[], star: boolean) => Promise<void>;
98
100
  type: "md";
99
- ws: any;
101
+ ws: import("./Client").WebSocketClient;
100
102
  ev: import("../Types").BaileysEventEmitter & {
101
103
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
102
104
  buffer(): void;
@@ -380,14 +380,13 @@ const makeMessagesSocket = (config) => {
380
380
  await authState.keys.set({ 'sender-key-memory': { [jid]: senderKeyMap } });
381
381
  }
382
382
  else {
383
- const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
383
+ const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
384
384
  if (!participant) {
385
385
  devices.push({ user });
386
- // do not send message to self if the device is 0 (mobile)
387
- if (!((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer' && user === meUser)) {
388
- if (meDevice !== undefined && meDevice !== 0) {
389
- devices.push({ user: meUser });
390
- }
386
+ if (user !== meUser) {
387
+ devices.push({ user: meUser });
388
+ }
389
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
391
390
  const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
392
391
  devices.push(...additionalDevices);
393
392
  }
@@ -434,7 +433,7 @@ const makeMessagesSocket = (config) => {
434
433
  tag: 'message',
435
434
  attrs: {
436
435
  id: msgId,
437
- type: 'text',
436
+ type: getMessageType(message),
438
437
  ...(additionalAttributes || {})
439
438
  },
440
439
  content: binaryNodeContent
@@ -474,6 +473,12 @@ const makeMessagesSocket = (config) => {
474
473
  });
475
474
  return msgId;
476
475
  };
476
+ const getMessageType = (message) => {
477
+ if (message.pollCreationMessage || message.pollCreationMessageV2 || message.pollCreationMessageV3) {
478
+ return 'poll';
479
+ }
480
+ return 'text';
481
+ };
477
482
  const getMediaType = (message) => {
478
483
  if (message.imageMessage) {
479
484
  return 'image';
@@ -643,7 +648,9 @@ const makeMessagesSocket = (config) => {
643
648
  const isDeleteMsg = 'delete' in content && !!content.delete;
644
649
  const isEditMsg = 'edit' in content && !!content.edit;
645
650
  const isPinMsg = 'pin' in content && !!content.pin;
651
+ const isPollMessage = 'poll' in content && !!content.poll;
646
652
  const additionalAttributes = {};
653
+ const additionalNodes = [];
647
654
  // required for delete
648
655
  if (isDeleteMsg) {
649
656
  // if the chat is a group, and I am not the author, then delete the message as an admin
@@ -660,10 +667,18 @@ const makeMessagesSocket = (config) => {
660
667
  else if (isPinMsg) {
661
668
  additionalAttributes.edit = '2';
662
669
  }
670
+ else if (isPollMessage) {
671
+ additionalNodes.push({
672
+ tag: 'meta',
673
+ attrs: {
674
+ polltype: 'creation'
675
+ },
676
+ });
677
+ }
663
678
  if ('cachedGroupMetadata' in options) {
664
679
  console.warn('cachedGroupMetadata in sendMessage are deprecated, now cachedGroupMetadata is part of the socket config.');
665
680
  }
666
- await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList });
681
+ await relayMessage(jid, fullMsg.message, { messageId: fullMsg.key.id, useCachedGroupMetadata: options.useCachedGroupMetadata, additionalAttributes, statusJidList: options.statusJidList, additionalNodes });
667
682
  if (config.emitOwnEvents) {
668
683
  process.nextTick(() => {
669
684
  processingMutex.mutex(() => (upsertMessage(fullMsg, 'append')));
@@ -1,7 +1,9 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { Boom } from '@hapi/boom';
3
4
  import { SocketConfig } from '../Types';
4
5
  import { BinaryNode } from '../WABinary';
6
+ import { WebSocketClient } from './Client';
5
7
  /**
6
8
  * Connects to WA servers and performs:
7
9
  * - simple queries (no retry mechanism, wait for connection establishment)
@@ -10,7 +12,7 @@ import { BinaryNode } from '../WABinary';
10
12
  */
11
13
  export declare const makeSocket: (config: SocketConfig) => {
12
14
  type: "md";
13
- ws: any;
15
+ ws: WebSocketClient;
14
16
  ev: import("../Types").BaileysEventEmitter & {
15
17
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
16
18
  buffer(): void;
@@ -20,15 +20,14 @@ const Client_1 = require("./Client");
20
20
  const makeSocket = (config) => {
21
21
  var _a, _b;
22
22
  const { waWebSocketUrl, connectTimeoutMs, logger, keepAliveIntervalMs, browser, auth: authState, printQRInTerminal, defaultQueryTimeoutMs, transactionOpts, qrTimeout, makeSignalRepository, } = config;
23
- let url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
- config.mobile = config.mobile || url.protocol === 'tcp:';
25
- if (config.mobile && url.protocol !== 'tcp:') {
26
- url = new url_1.URL(`tcp://${Defaults_1.MOBILE_ENDPOINT}:${Defaults_1.MOBILE_PORT}`);
23
+ const url = typeof waWebSocketUrl === 'string' ? new url_1.URL(waWebSocketUrl) : waWebSocketUrl;
24
+ if (config.mobile || url.protocol === 'tcp:') {
25
+ throw new boom_1.Boom('Mobile API is not supported anymore', { statusCode: Types_1.DisconnectReason.loggedOut });
27
26
  }
28
- if (!config.mobile && url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
27
+ if (url.protocol === 'wss' && ((_a = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _a === void 0 ? void 0 : _a.routingInfo)) {
29
28
  url.searchParams.append('ED', authState.creds.routingInfo.toString('base64url'));
30
29
  }
31
- const ws = config.socket ? config.socket : config.mobile ? new Client_1.MobileSocketClient(url, config) : new Client_1.WebSocketClient(url, config);
30
+ const ws = new Client_1.WebSocketClient(url, config);
32
31
  ws.connect();
33
32
  const ev = (0, Utils_1.makeEventBuffer)(logger);
34
33
  /** ephemeral key pair used to encrypt/decrypt communication. Unique for each connection */
@@ -36,8 +35,7 @@ const makeSocket = (config) => {
36
35
  /** WA noise protocol wrapper */
37
36
  const noise = (0, Utils_1.makeNoiseHandler)({
38
37
  keyPair: ephemeralKeyPair,
39
- NOISE_HEADER: config.mobile ? Defaults_1.MOBILE_NOISE_HEADER : Defaults_1.NOISE_WA_HEADER,
40
- mobile: config.mobile,
38
+ NOISE_HEADER: Defaults_1.NOISE_WA_HEADER,
41
39
  logger,
42
40
  routingInfo: (_b = authState === null || authState === void 0 ? void 0 : authState.creds) === null || _b === void 0 ? void 0 : _b.routingInfo
43
41
  });
@@ -159,10 +157,7 @@ const makeSocket = (config) => {
159
157
  logger.trace({ handshake }, 'handshake recv from WA');
160
158
  const keyEnc = noise.processHandshake(handshake, creds.noiseKey);
161
159
  let node;
162
- if (config.mobile) {
163
- node = (0, Utils_1.generateMobileNode)(config);
164
- }
165
- else if (!creds.me) {
160
+ if (!creds.me) {
166
161
  node = (0, Utils_1.generateRegistrationNode)(creds, config);
167
162
  logger.info({ node }, 'not logged in, attempting registration...');
168
163
  }
@@ -232,11 +227,11 @@ const makeSocket = (config) => {
232
227
  const l0 = frame.tag;
233
228
  const l1 = frame.attrs || {};
234
229
  const l2 = Array.isArray(frame.content) ? (_a = frame.content[0]) === null || _a === void 0 ? void 0 : _a.tag : '';
235
- Object.keys(l1).forEach(key => {
230
+ for (const key of Object.keys(l1)) {
236
231
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]},${l2}`, frame) || anyTriggered;
237
232
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}:${l1[key]}`, frame) || anyTriggered;
238
233
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},${key}`, frame) || anyTriggered;
239
- });
234
+ }
240
235
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0},,${l2}`, frame) || anyTriggered;
241
236
  anyTriggered = ws.emit(`${Defaults_1.DEF_CALLBACK_PREFIX}${l0}`, frame) || anyTriggered;
242
237
  if (!anyTriggered && logger.level === 'debug') {
@@ -1,5 +1,6 @@
1
+ import { Store } from 'cache-manager';
1
2
  import { AuthenticationCreds } from '../Types';
2
- declare const makeCacheManagerAuthState: (store: Storage, sessionKey: string) => Promise<{
3
+ declare const makeCacheManagerAuthState: (store: Store, sessionKey: string) => Promise<{
3
4
  clearState: () => Promise<void>;
4
5
  saveCreds: () => Promise<void>;
5
6
  state: {
@@ -182,16 +182,14 @@ exports.default = (config) => {
182
182
  const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
183
183
  const list = assertMessageList(jid);
184
184
  list.upsert(msg, 'append');
185
- if (type === 'notify') {
186
- if (!chats.get(jid)) {
187
- ev.emit('chats.upsert', [
188
- {
189
- id: jid,
190
- conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
191
- unreadCount: 1
192
- }
193
- ]);
194
- }
185
+ if (type === 'notify' && !chats.get(jid)) {
186
+ ev.emit('chats.upsert', [
187
+ {
188
+ id: jid,
189
+ conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
190
+ unreadCount: 1
191
+ }
192
+ ]);
195
193
  }
196
194
  }
197
195
  break;
@@ -56,9 +56,9 @@ function makeOrderedDictionary(idGetter) {
56
56
  },
57
57
  clear: () => {
58
58
  array.splice(0, array.length);
59
- Object.keys(dict).forEach(key => {
59
+ for (const key of Object.keys(dict)) {
60
60
  delete dict[key];
61
- });
61
+ }
62
62
  },
63
63
  filter: (contain) => {
64
64
  let i = 0;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { proto } from '../../WAProto';
3
- import { RegistrationOptions } from '../Socket/registration';
4
4
  import type { Contact } from './Contact';
5
5
  import type { MinimalMessage } from './Message';
6
6
  export type KeyPair = {
@@ -57,12 +57,7 @@ export type AuthenticationCreds = SignalCreds & {
57
57
  /** number of times history & app state has been synced */
58
58
  accountSyncCounter: number;
59
59
  accountSettings: AccountSettings;
60
- deviceId: string;
61
- phoneId: string;
62
- identityId: Buffer;
63
60
  registered: boolean;
64
- backupToken: Buffer;
65
- registration: RegistrationOptions;
66
61
  pairingCode: string | undefined;
67
62
  lastPropHash: string | undefined;
68
63
  routingInfo: Buffer | undefined;
@@ -1,4 +1,4 @@
1
- export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept';
1
+ export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept' | 'terminate';
2
2
  export type WACallEvent = {
3
3
  chatId: string;
4
4
  from: string;
@@ -1,9 +1,10 @@
1
1
  import type { proto } from '../../WAProto';
2
2
  import type { AccountSettings } from './Auth';
3
3
  import type { BufferedEventData } from './Events';
4
+ import type { LabelActionBody } from './Label';
4
5
  import type { ChatLabelAssociationActionBody } from './LabelAssociation';
5
6
  import type { MessageLabelAssociationActionBody } from './LabelAssociation';
6
- import type { MinimalMessage } from './Message';
7
+ import type { MinimalMessage, WAMessageKey } from './Message';
7
8
  /** privacy settings in WhatsApp Web */
8
9
  export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
9
10
  export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
@@ -61,12 +62,12 @@ export type ChatModification = {
61
62
  /** mute for duration, or provide timestamp of mute to remove*/
62
63
  mute: number | null;
63
64
  } | {
64
- clear: 'all' | {
65
- messages: {
66
- id: string;
67
- fromMe?: boolean;
68
- timestamp: number;
69
- }[];
65
+ clear: boolean;
66
+ } | {
67
+ deleteForMe: {
68
+ deleteMedia: boolean;
69
+ key: WAMessageKey;
70
+ timestamp: number;
70
71
  };
71
72
  } | {
72
73
  star: {
@@ -82,6 +83,8 @@ export type ChatModification = {
82
83
  } | {
83
84
  delete: true;
84
85
  lastMessages: LastMessageList;
86
+ } | {
87
+ addLabel: LabelActionBody;
85
88
  } | {
86
89
  addChatLabel: ChatLabelAssociationActionBody;
87
90
  } | {
@@ -14,6 +14,6 @@ export interface Contact {
14
14
  * null => if the profile picture has not been set (default profile picture)
15
15
  * any other string => url of the profile picture
16
16
  */
17
- imgUrl?: string | null | 'changed';
17
+ imgUrl?: string | null;
18
18
  status?: string;
19
19
  }