@realvare/based 2.7.51 → 2.7.52

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.
@@ -46,7 +46,7 @@ const makeMessagesRecvSocket = (config) => {
46
46
  tag: 'ack',
47
47
  attrs: {
48
48
  id: attrs.id,
49
- to: attrs.from,
49
+ to: resolveJid(attrs.from),
50
50
  class: tag
51
51
  }
52
52
  };
@@ -54,10 +54,10 @@ const makeMessagesRecvSocket = (config) => {
54
54
  stanza.attrs.error = errorCode.toString();
55
55
  }
56
56
  if (!!attrs.participant) {
57
- stanza.attrs.participant = attrs.participant;
57
+ stanza.attrs.participant = resolveJid(attrs.participant);
58
58
  }
59
59
  if (!!attrs.recipient) {
60
- stanza.attrs.recipient = attrs.recipient;
60
+ stanza.attrs.recipient = resolveJid(attrs.recipient);
61
61
  }
62
62
  if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable') || errorCode !== 0)) {
63
63
  stanza.attrs.type = attrs.type;
@@ -68,7 +68,6 @@ const makeMessagesRecvSocket = (config) => {
68
68
  logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
69
69
  await sendNode(stanza);
70
70
  };
71
-
72
71
  // Add withAck wrapper for guaranteed acknowledgments
73
72
  const withAck = (processFn) => async (node) => {
74
73
  try {
@@ -118,7 +117,7 @@ const makeMessagesRecvSocket = (config) => {
118
117
  const stanza = ({
119
118
  tag: 'call',
120
119
  attrs: {
121
- to: toJid,
120
+ to: resolveJid(toJid),
122
121
  },
123
122
  content: [{
124
123
  tag: 'offer',
@@ -141,13 +140,13 @@ const makeMessagesRecvSocket = (config) => {
141
140
  tag: 'call',
142
141
  attrs: {
143
142
  from: authState.creds.me.id,
144
- to: callFrom,
143
+ to: resolveJid(callFrom),
145
144
  },
146
145
  content: [{
147
146
  tag: 'reject',
148
147
  attrs: {
149
148
  'call-id': callId,
150
- 'call-creator': callFrom,
149
+ 'call-creator': resolveJid(callFrom),
151
150
  count: '0',
152
151
  },
153
152
  content: undefined,
@@ -181,7 +180,7 @@ const makeMessagesRecvSocket = (config) => {
181
180
  attrs: {
182
181
  id: msgId,
183
182
  type: 'retry',
184
- to: node.attrs.from
183
+ to: resolveJid(node.attrs.from)
185
184
  },
186
185
  content: [
187
186
  {
@@ -201,10 +200,10 @@ const makeMessagesRecvSocket = (config) => {
201
200
  ]
202
201
  };
203
202
  if (node.attrs.recipient) {
204
- receipt.attrs.recipient = node.attrs.recipient;
203
+ receipt.attrs.recipient = resolveJid(node.attrs.recipient);
205
204
  }
206
205
  if (node.attrs.participant) {
207
- receipt.attrs.participant = node.attrs.participant;
206
+ receipt.attrs.participant = resolveJid(node.attrs.participant);
208
207
  }
209
208
  if (retryCount > 1 || forceIncludeKeys) {
210
209
  const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
@@ -229,7 +228,7 @@ const makeMessagesRecvSocket = (config) => {
229
228
  });
230
229
  };
231
230
  const handleEncryptNotification = async (node) => {
232
- const from = node.attrs.from;
231
+ const from = resolveJid(node.attrs.from);
233
232
  if (from === WABinary_1.S_WHATSAPP_NET) {
234
233
  const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
235
234
  const count = +countChild.attrs.value;
@@ -294,13 +293,24 @@ const makeMessagesRecvSocket = (config) => {
294
293
  msg.messageStubParameters = oldNumber || [];
295
294
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER;
296
295
  break;
296
+ case 'add':
297
+ case 'remove':
297
298
  case 'promote':
298
299
  case 'demote':
299
- case 'remove':
300
- case 'add':
301
300
  case 'leave':
302
- msg.messageStubType = Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE;
303
- msg.messageStubParameters = [participant];
301
+ const stubTypes = {
302
+ add: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
303
+ remove: Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE,
304
+ promote: Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE,
305
+ demote: Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE,
306
+ leave: Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE,
307
+ };
308
+ msg.messageStubType = stubTypes[child.tag];
309
+ let affected = (0, WABinary_1.getBinaryNodeChildren)(child, 'participant').map(p => p.attrs.jid);
310
+ if (affected.length === 0) {
311
+ affected = [participant];
312
+ }
313
+ msg.messageStubParameters = affected;
304
314
  break;
305
315
  case 'subject':
306
316
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT;
@@ -613,7 +623,7 @@ const makeMessagesRecvSocket = (config) => {
613
623
  // todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
614
624
  const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
615
625
  const remoteJid = key.remoteJid;
616
- const participant = key.participant || remoteJid;
626
+ const participant = resolveJid(key.participant || remoteJid);
617
627
  // if it's the primary jid sending the request
618
628
  // just re-send the message to everyone
619
629
  // prevents the first message decryption failure
@@ -648,7 +658,7 @@ const makeMessagesRecvSocket = (config) => {
648
658
  const { attrs, content } = node;
649
659
  const isLid = attrs.from.includes('lid');
650
660
  const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(resolveJid(attrs.participant) || resolveJid(attrs.from), isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
651
- const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? resolveJid(attrs.from) : attrs.recipient;
661
+ const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? resolveJid(attrs.from) : resolveJid(attrs.recipient);
652
662
  const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender') && isNodeFromMe);
653
663
  const key = {
654
664
  remoteJid,
@@ -709,13 +719,14 @@ const makeMessagesRecvSocket = (config) => {
709
719
  }
710
720
  if (attrs.type === 'retry') {
711
721
  // correctly set who is asking for the retry
712
- key.participant = key.participant || attrs.from;
722
+ key.participant = key.participant || resolveJid(attrs.from);
713
723
  const retryNode = (0, WABinary_1.getBinaryNodeChild)(node, 'retry');
714
724
  if (willSendMessageAgain(ids[0], key.participant)) {
715
725
  if (key.fromMe) {
716
726
  try {
717
727
  logger.debug({ attrs, key }, 'recv retry request');
718
- await sendMessagesAgain(key, ids, retryNode);
728
+ sendMessagesAgain(key, ids, retryNode)
729
+ .catch(error => logger.error({ key, ids, trace: error.stack }, 'error in sending message again'));
719
730
  }
720
731
  catch (error) {
721
732
  logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
@@ -771,7 +782,7 @@ const makeMessagesRecvSocket = (config) => {
771
782
  };
772
783
  const handleMessage = withAck(async (node) => {
773
784
  var _a, _b, _c;
774
- if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
785
+ if (shouldIgnoreJid(resolveJid(node.attrs.from)) && node.attrs.from !== '@s.whatsapp.net') {
775
786
  logger.debug({ key: node.attrs.key }, 'ignored message');
776
787
  return;
777
788
  }
@@ -838,8 +849,8 @@ const makeMessagesRecvSocket = (config) => {
838
849
  if (msg.message.extendedTextMessage.contextInfo) {
839
850
  const metadata = await groupMetadata(msg.key.remoteJid);
840
851
  const sender = msg.message.extendedTextMessage.contextInfo.participant;
841
- const found = metadata.participants.find(p => p.id === sender);
842
- msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || (0, WABinary_1.lidToJid)(sender); }
852
+ const found = metadata.participants.find(p => p.id === sender);
853
+ msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || (0, WABinary_1.lidToJid)(sender); }
843
854
  }
844
855
  if (!(0, WABinary_1.isJidGroup)(msg.key.remoteJid) && (0, WABinary_1.isLidUser)(msg.key.remoteJid)) {
845
856
  msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
@@ -959,7 +970,7 @@ const makeMessagesRecvSocket = (config) => {
959
970
  await sendMessageAck(node);
960
971
  };
961
972
  const handleBadAck = async ({ attrs }) => {
962
- const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
973
+ const key = { remoteJid: resolveJid(attrs.from), fromMe: true, id: attrs.id, 'server_id': attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
963
974
  // current hypothesis is that if pash is sent in the ack
964
975
  // it means -- the message hasn't reached all devices yet
965
976
  // we'll retry sending the message here
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realvare/based",
3
- "version": "2.7.51",
3
+ "version": "2.7.52",
4
4
  "description": "whatsapp api by sam",
5
5
  "keywords": [
6
6
  "baileys",
@@ -10,7 +10,8 @@
10
10
  "whatsapp-bot",
11
11
  "automation",
12
12
  "multi-device",
13
- "based"
13
+ "based",
14
+ "varebot"
14
15
  ],
15
16
  "homepage": "git+https://github.com/realvare/based.git",
16
17
  "repository": {