gifted-baileys 1.5.0 → 1.5.5

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 (222) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1429 -684
  3. package/package.json +11 -26
  4. package/src/Defaults/baileys-version.json +3 -0
  5. package/{lib → src}/Defaults/index.js +16 -8
  6. package/src/Defaults/index.ts +131 -0
  7. package/src/Defaults/phonenumber-mcc.json +223 -0
  8. package/src/Signal/libsignal.js +180 -0
  9. package/src/Signal/libsignal.ts +141 -0
  10. package/src/Socket/Client/abstract-socket-client.ts +19 -0
  11. package/src/Socket/Client/index.ts +3 -0
  12. package/src/Socket/Client/mobile-socket-client.js +78 -0
  13. package/src/Socket/Client/mobile-socket-client.ts +66 -0
  14. package/src/Socket/Client/web-socket-client.js +75 -0
  15. package/src/Socket/Client/web-socket-client.ts +57 -0
  16. package/{lib → src}/Socket/business.js +33 -27
  17. package/src/Socket/business.ts +281 -0
  18. package/{lib → src}/Socket/chats.js +197 -178
  19. package/src/Socket/chats.ts +1030 -0
  20. package/{lib → src}/Socket/groups.js +69 -79
  21. package/src/Socket/groups.ts +356 -0
  22. package/{lib → src}/Socket/index.js +1 -4
  23. package/src/Socket/index.ts +13 -0
  24. package/{lib → src}/Socket/messages-recv.js +160 -108
  25. package/src/Socket/messages-recv.ts +985 -0
  26. package/{lib → src}/Socket/messages-send.js +183 -100
  27. package/src/Socket/messages-send.ts +871 -0
  28. package/src/Socket/newsletter.js +227 -0
  29. package/src/Socket/newsletter.ts +282 -0
  30. package/{lib → src}/Socket/registration.js +55 -63
  31. package/src/Socket/registration.ts +250 -0
  32. package/{lib → src}/Socket/socket.js +107 -66
  33. package/src/Socket/socket.ts +777 -0
  34. package/src/Store/index.ts +3 -0
  35. package/{lib → src}/Store/make-cache-manager-store.js +34 -25
  36. package/src/Store/make-cache-manager-store.ts +100 -0
  37. package/{lib → src}/Store/make-in-memory-store.js +51 -61
  38. package/src/Store/make-in-memory-store.ts +475 -0
  39. package/src/Store/make-ordered-dictionary.ts +86 -0
  40. package/{lib → src}/Store/object-repository.js +1 -1
  41. package/src/Store/object-repository.ts +32 -0
  42. package/src/Tests/test.app-state-sync.js +204 -0
  43. package/src/Tests/test.app-state-sync.ts +207 -0
  44. package/src/Tests/test.event-buffer.js +270 -0
  45. package/src/Tests/test.event-buffer.ts +319 -0
  46. package/src/Tests/test.key-store.js +76 -0
  47. package/src/Tests/test.key-store.ts +92 -0
  48. package/src/Tests/test.libsignal.js +141 -0
  49. package/src/Tests/test.libsignal.ts +186 -0
  50. package/src/Tests/test.media-download.js +93 -0
  51. package/src/Tests/test.media-download.ts +76 -0
  52. package/src/Tests/test.messages.js +33 -0
  53. package/src/Tests/test.messages.ts +37 -0
  54. package/src/Tests/utils.js +34 -0
  55. package/src/Tests/utils.ts +36 -0
  56. package/src/Types/Auth.ts +113 -0
  57. package/src/Types/Call.ts +15 -0
  58. package/src/Types/Chat.ts +106 -0
  59. package/{lib/Types/Contact.d.ts → src/Types/Contact.ts} +9 -8
  60. package/src/Types/Events.ts +93 -0
  61. package/src/Types/GroupMetadata.ts +53 -0
  62. package/{lib → src}/Types/Label.js +1 -1
  63. package/src/Types/Label.ts +36 -0
  64. package/{lib → src}/Types/LabelAssociation.js +1 -1
  65. package/{lib/Types/LabelAssociation.d.ts → src/Types/LabelAssociation.ts} +22 -16
  66. package/src/Types/Message.ts +288 -0
  67. package/src/Types/Newsletter.js +32 -0
  68. package/src/Types/Newsletter.ts +98 -0
  69. package/src/Types/Product.ts +85 -0
  70. package/src/Types/Signal.ts +68 -0
  71. package/{lib/Types/Socket.d.ts → src/Types/Socket.ts} +68 -56
  72. package/src/Types/State.ts +29 -0
  73. package/{lib → src}/Types/index.js +2 -1
  74. package/src/Types/index.ts +59 -0
  75. package/{lib → src}/Utils/auth-utils.js +95 -76
  76. package/src/Utils/auth-utils.ts +222 -0
  77. package/src/Utils/baileys-event-stream.js +92 -0
  78. package/src/Utils/baileys-event-stream.ts +66 -0
  79. package/{lib → src}/Utils/business.js +45 -17
  80. package/src/Utils/business.ts +275 -0
  81. package/{lib → src}/Utils/chat-utils.js +74 -46
  82. package/src/Utils/chat-utils.ts +860 -0
  83. package/{lib → src}/Utils/crypto.js +31 -21
  84. package/src/Utils/crypto.ts +131 -0
  85. package/src/Utils/decode-wa-message.js +211 -0
  86. package/src/Utils/decode-wa-message.ts +228 -0
  87. package/{lib → src}/Utils/event-buffer.js +13 -4
  88. package/src/Utils/event-buffer.ts +613 -0
  89. package/{lib → src}/Utils/generics.js +98 -45
  90. package/src/Utils/generics.ts +434 -0
  91. package/{lib → src}/Utils/history.js +39 -10
  92. package/src/Utils/history.ts +112 -0
  93. package/src/Utils/index.ts +17 -0
  94. package/{lib → src}/Utils/link-preview.js +54 -17
  95. package/src/Utils/link-preview.ts +122 -0
  96. package/src/Utils/logger.ts +3 -0
  97. package/src/Utils/lt-hash.ts +61 -0
  98. package/{lib → src}/Utils/make-mutex.js +13 -4
  99. package/src/Utils/make-mutex.ts +44 -0
  100. package/{lib → src}/Utils/messages-media.js +296 -192
  101. package/src/Utils/messages-media.ts +847 -0
  102. package/{lib → src}/Utils/messages.js +124 -113
  103. package/src/Utils/messages.ts +956 -0
  104. package/{lib → src}/Utils/noise-handler.js +16 -3
  105. package/src/Utils/noise-handler.ts +197 -0
  106. package/{lib → src}/Utils/process-message.js +33 -29
  107. package/src/Utils/process-message.ts +414 -0
  108. package/{lib → src}/Utils/signal.js +23 -14
  109. package/src/Utils/signal.ts +177 -0
  110. package/{lib → src}/Utils/use-multi-file-auth-state.js +28 -19
  111. package/src/Utils/use-multi-file-auth-state.ts +90 -0
  112. package/{lib → src}/Utils/validate-connection.js +25 -42
  113. package/src/Utils/validate-connection.ts +238 -0
  114. package/src/WABinary/constants.ts +42 -0
  115. package/{lib → src}/WABinary/decode.js +17 -7
  116. package/src/WABinary/decode.ts +265 -0
  117. package/{lib → src}/WABinary/encode.js +17 -7
  118. package/src/WABinary/encode.ts +236 -0
  119. package/{lib → src}/WABinary/generic-utils.js +2 -2
  120. package/src/WABinary/generic-utils.ts +121 -0
  121. package/src/WABinary/index.ts +5 -0
  122. package/{lib → src}/WABinary/jid-utils.js +4 -1
  123. package/src/WABinary/jid-utils.ts +68 -0
  124. package/src/WABinary/types.ts +17 -0
  125. package/src/WAM/BinaryInfo.js +13 -0
  126. package/src/WAM/BinaryInfo.ts +12 -0
  127. package/src/WAM/constants.js +15350 -0
  128. package/src/WAM/constants.ts +15382 -0
  129. package/src/WAM/encode.js +155 -0
  130. package/src/WAM/encode.ts +174 -0
  131. package/src/WAM/index.js +19 -0
  132. package/src/WAM/index.ts +3 -0
  133. package/src/gifted +1 -0
  134. package/{lib → src}/index.js +1 -0
  135. package/src/index.ts +13 -0
  136. package/lib/Defaults/baileys-version.json +0 -3
  137. package/lib/Defaults/index.d.ts +0 -284
  138. package/lib/Defaults/phonenumber-mcc.json +0 -223
  139. package/lib/Signal/libsignal.d.ts +0 -3
  140. package/lib/Signal/libsignal.js +0 -152
  141. package/lib/Socket/Client/abstract-socket-client.d.ts +0 -17
  142. package/lib/Socket/Client/index.d.ts +0 -3
  143. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  144. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  145. package/lib/Socket/Client/web-socket-client.d.ts +0 -12
  146. package/lib/Socket/Client/web-socket-client.js +0 -62
  147. package/lib/Socket/business.d.ts +0 -135
  148. package/lib/Socket/chats.d.ts +0 -79
  149. package/lib/Socket/groups.d.ts +0 -113
  150. package/lib/Socket/index.d.ts +0 -137
  151. package/lib/Socket/messages-recv.d.ts +0 -124
  152. package/lib/Socket/messages-send.d.ts +0 -119
  153. package/lib/Socket/registration.d.ts +0 -232
  154. package/lib/Socket/socket.d.ts +0 -42
  155. package/lib/Store/index.d.ts +0 -3
  156. package/lib/Store/make-cache-manager-store.d.ts +0 -13
  157. package/lib/Store/make-in-memory-store.d.ts +0 -117
  158. package/lib/Store/make-ordered-dictionary.d.ts +0 -13
  159. package/lib/Store/object-repository.d.ts +0 -10
  160. package/lib/Types/Auth.d.ts +0 -108
  161. package/lib/Types/Call.d.ts +0 -13
  162. package/lib/Types/Chat.d.ts +0 -102
  163. package/lib/Types/Events.d.ts +0 -157
  164. package/lib/Types/GroupMetadata.d.ts +0 -52
  165. package/lib/Types/Label.d.ts +0 -35
  166. package/lib/Types/Message.d.ts +0 -261
  167. package/lib/Types/Product.d.ts +0 -78
  168. package/lib/Types/Signal.d.ts +0 -57
  169. package/lib/Types/State.d.ts +0 -27
  170. package/lib/Types/index.d.ts +0 -56
  171. package/lib/Utils/auth-utils.d.ts +0 -18
  172. package/lib/Utils/baileys-event-stream.d.ts +0 -16
  173. package/lib/Utils/baileys-event-stream.js +0 -63
  174. package/lib/Utils/business.d.ts +0 -22
  175. package/lib/Utils/chat-utils.d.ts +0 -71
  176. package/lib/Utils/crypto.d.ts +0 -41
  177. package/lib/Utils/decode-wa-message.d.ts +0 -19
  178. package/lib/Utils/decode-wa-message.js +0 -174
  179. package/lib/Utils/event-buffer.d.ts +0 -35
  180. package/lib/Utils/generics.d.ts +0 -94
  181. package/lib/Utils/history.d.ts +0 -15
  182. package/lib/Utils/index.d.ts +0 -17
  183. package/lib/Utils/link-preview.d.ts +0 -21
  184. package/lib/Utils/logger.d.ts +0 -4
  185. package/lib/Utils/lt-hash.d.ts +0 -12
  186. package/lib/Utils/make-mutex.d.ts +0 -7
  187. package/lib/Utils/messages-media.d.ts +0 -107
  188. package/lib/Utils/messages.d.ts +0 -76
  189. package/lib/Utils/noise-handler.d.ts +0 -20
  190. package/lib/Utils/process-message.d.ts +0 -41
  191. package/lib/Utils/signal.d.ts +0 -32
  192. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -12
  193. package/lib/Utils/validate-connection.d.ts +0 -11
  194. package/lib/WABinary/constants.d.ts +0 -27
  195. package/lib/WABinary/decode.d.ts +0 -7
  196. package/lib/WABinary/encode.d.ts +0 -3
  197. package/lib/WABinary/generic-utils.d.ts +0 -15
  198. package/lib/WABinary/index.d.ts +0 -5
  199. package/lib/WABinary/jid-utils.d.ts +0 -29
  200. package/lib/WABinary/types.d.ts +0 -18
  201. package/lib/index.d.ts +0 -10
  202. /package/{lib → src}/Socket/Client/abstract-socket-client.js +0 -0
  203. /package/{lib → src}/Socket/Client/index.js +0 -0
  204. /package/{lib → src}/Store/index.js +0 -0
  205. /package/{lib → src}/Store/make-ordered-dictionary.js +0 -0
  206. /package/{lib → src}/Types/Auth.js +0 -0
  207. /package/{lib → src}/Types/Call.js +0 -0
  208. /package/{lib → src}/Types/Chat.js +0 -0
  209. /package/{lib → src}/Types/Contact.js +0 -0
  210. /package/{lib → src}/Types/Events.js +0 -0
  211. /package/{lib → src}/Types/GroupMetadata.js +0 -0
  212. /package/{lib → src}/Types/Message.js +0 -0
  213. /package/{lib → src}/Types/Product.js +0 -0
  214. /package/{lib → src}/Types/Signal.js +0 -0
  215. /package/{lib → src}/Types/Socket.js +0 -0
  216. /package/{lib → src}/Types/State.js +0 -0
  217. /package/{lib → src}/Utils/index.js +0 -0
  218. /package/{lib → src}/Utils/logger.js +0 -0
  219. /package/{lib → src}/Utils/lt-hash.js +0 -0
  220. /package/{lib → src}/WABinary/constants.js +0 -0
  221. /package/{lib → src}/WABinary/index.js +0 -0
  222. /package/{lib → src}/WABinary/types.js +0 -0
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -19,19 +28,19 @@ const messages_send_1 = require("./messages-send");
19
28
  const makeMessagesRecvSocket = (config) => {
20
29
  const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
21
30
  const sock = (0, messages_send_1.makeMessagesSocket)(config);
22
- const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, } = sock;
31
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, getUSyncDevices, createParticipantNodes } = sock;
23
32
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
24
33
  const retryMutex = (0, make_mutex_1.makeMutex)();
25
34
  const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
26
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY,
35
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.MSG_RETRY, // 1 hour
27
36
  useClones: false
28
37
  });
29
38
  const callOfferCache = config.callOfferCache || new node_cache_1.default({
30
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER,
39
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.CALL_OFFER, // 5 mins
31
40
  useClones: false
32
41
  });
33
42
  let sendActiveReceipts = false;
34
- const sendMessageAck = async ({ tag, attrs }) => {
43
+ const sendMessageAck = (_a) => __awaiter(void 0, [_a], void 0, function* ({ tag, attrs, content }) {
35
44
  const stanza = {
36
45
  tag: 'ack',
37
46
  attrs: {
@@ -46,13 +55,68 @@ const makeMessagesRecvSocket = (config) => {
46
55
  if (!!attrs.recipient) {
47
56
  stanza.attrs.recipient = attrs.recipient;
48
57
  }
49
- if (tag !== 'message' && attrs.type) {
58
+ if (!!attrs.type && (tag !== 'message' || (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable'))) {
50
59
  stanza.attrs.type = attrs.type;
51
60
  }
61
+ if (tag === 'message' && (0, WABinary_1.getBinaryNodeChild)({ tag, attrs, content }, 'unavailable')) {
62
+ stanza.attrs.from = authState.creds.me.id;
63
+ }
52
64
  logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
53
- await sendNode(stanza);
54
- };
55
- const rejectCall = async (callId, callFrom) => {
65
+ yield sendNode(stanza);
66
+ });
67
+ const offerCall = (toJid_1, ...args_1) => __awaiter(void 0, [toJid_1, ...args_1], void 0, function* (toJid, isVideo = false) {
68
+ const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
69
+ const offerContent = [];
70
+ offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '16000' }, content: undefined });
71
+ offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '8000' }, content: undefined });
72
+ if (isVideo) {
73
+ offerContent.push({
74
+ tag: 'video',
75
+ attrs: { enc: 'vp8', dec: 'vp8', orientation: '0', 'screen_width': '1920', 'screen_height': '1080', 'device_orientation': '0' },
76
+ content: undefined
77
+ });
78
+ }
79
+ offerContent.push({ tag: 'net', attrs: { medium: '3' }, content: undefined });
80
+ offerContent.push({ tag: 'capability', attrs: { ver: '1' }, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
81
+ offerContent.push({ tag: 'encopt', attrs: { keygen: '2' }, content: undefined });
82
+ const encKey = (0, crypto_1.randomBytes)(32);
83
+ const devices = (yield getUSyncDevices([toJid], true, false)).map(({ user, device }) => (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device));
84
+ yield assertSessions(devices, true);
85
+ const { nodes: destinations, shouldIncludeDeviceIdentity } = yield createParticipantNodes(devices, {
86
+ call: {
87
+ callKey: new Uint8Array(encKey)
88
+ }
89
+ }, { count: '0' });
90
+ offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
91
+ if (shouldIncludeDeviceIdentity) {
92
+ offerContent.push({
93
+ tag: 'device-identity',
94
+ attrs: {},
95
+ content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
96
+ });
97
+ }
98
+ const stanza = ({
99
+ tag: 'call',
100
+ attrs: {
101
+ id: (0, Utils_1.generateMessageIDV2)(),
102
+ to: toJid,
103
+ },
104
+ content: [{
105
+ tag: 'offer',
106
+ attrs: {
107
+ 'call-id': callId,
108
+ 'call-creator': authState.creds.me.id,
109
+ },
110
+ content: offerContent,
111
+ }],
112
+ });
113
+ yield query(stanza);
114
+ return {
115
+ id: callId,
116
+ to: toJid
117
+ };
118
+ });
119
+ const rejectCall = (callId, callFrom) => __awaiter(void 0, void 0, void 0, function* () {
56
120
  const stanza = ({
57
121
  tag: 'call',
58
122
  attrs: {
@@ -69,9 +133,9 @@ const makeMessagesRecvSocket = (config) => {
69
133
  content: undefined,
70
134
  }],
71
135
  });
72
- await query(stanza);
73
- };
74
- const sendRetryRequest = async (node, forceIncludeKeys = false) => {
136
+ yield query(stanza);
137
+ });
138
+ const sendRetryRequest = (node_1, ...args_1) => __awaiter(void 0, [node_1, ...args_1], void 0, function* (node, forceIncludeKeys = false) {
75
139
  const msgId = node.attrs.id;
76
140
  let retryCount = msgRetryCache.get(msgId) || 0;
77
141
  if (retryCount >= maxMsgRetryCount) {
@@ -83,7 +147,7 @@ const makeMessagesRecvSocket = (config) => {
83
147
  msgRetryCache.set(msgId, retryCount);
84
148
  const { account, signedPreKey, signedIdentityKey: identityKey } = authState.creds;
85
149
  const deviceIdentity = (0, Utils_1.encodeSignedDeviceIdentity)(account, true);
86
- await authState.keys.transaction(async () => {
150
+ yield authState.keys.transaction(() => __awaiter(void 0, void 0, void 0, function* () {
87
151
  const receipt = {
88
152
  tag: 'receipt',
89
153
  attrs: {
@@ -115,7 +179,7 @@ const makeMessagesRecvSocket = (config) => {
115
179
  receipt.attrs.participant = node.attrs.participant;
116
180
  }
117
181
  if (retryCount > 1 || forceIncludeKeys) {
118
- const { update, preKeys } = await (0, Utils_1.getNextPreKeys)(authState, 1);
182
+ const { update, preKeys } = yield (0, Utils_1.getNextPreKeys)(authState, 1);
119
183
  const [keyId] = Object.keys(preKeys);
120
184
  const key = preKeys[+keyId];
121
185
  const content = receipt.content;
@@ -132,11 +196,11 @@ const makeMessagesRecvSocket = (config) => {
132
196
  });
133
197
  ev.emit('creds.update', update);
134
198
  }
135
- await sendNode(receipt);
199
+ yield sendNode(receipt);
136
200
  logger.info({ msgAttrs: node.attrs, retryCount }, 'sent retry receipt');
137
- });
138
- };
139
- const handleEncryptNotification = async (node) => {
201
+ }));
202
+ });
203
+ const handleEncryptNotification = (node) => __awaiter(void 0, void 0, void 0, function* () {
140
204
  const from = node.attrs.from;
141
205
  if (from === WABinary_1.S_WHATSAPP_NET) {
142
206
  const countChild = (0, WABinary_1.getBinaryNodeChild)(node, 'count');
@@ -144,7 +208,7 @@ const makeMessagesRecvSocket = (config) => {
144
208
  const shouldUploadMorePreKeys = count < Defaults_1.MIN_PREKEY_COUNT;
145
209
  logger.debug({ count, shouldUploadMorePreKeys }, 'recv pre-key count');
146
210
  if (shouldUploadMorePreKeys) {
147
- await uploadPreKeys();
211
+ yield uploadPreKeys();
148
212
  }
149
213
  }
150
214
  else {
@@ -158,7 +222,7 @@ const makeMessagesRecvSocket = (config) => {
158
222
  logger.info({ node }, 'unknown encrypt notification');
159
223
  }
160
224
  }
161
- };
225
+ });
162
226
  const handleGroupNotification = (participant, child, msg) => {
163
227
  switch (child === null || child === void 0 ? void 0 : child.tag) {
164
228
  case 'create':
@@ -171,10 +235,7 @@ const makeMessagesRecvSocket = (config) => {
171
235
  name: metadata.subject,
172
236
  conversationTimestamp: metadata.creation,
173
237
  }]);
174
- ev.emit('groups.upsert', [{
175
- ...metadata,
176
- author: participant
177
- }]);
238
+ ev.emit('groups.upsert', [Object.assign(Object.assign({}, metadata), { author: participant })]);
178
239
  break;
179
240
  case 'ephemeral':
180
241
  case 'not_ephemeral':
@@ -236,7 +297,8 @@ const makeMessagesRecvSocket = (config) => {
236
297
  break;
237
298
  }
238
299
  };
239
- const processNotification = async (node) => {
300
+ const processNotification = (node) => __awaiter(void 0, void 0, void 0, function* () {
301
+ var _a, _b, _c;
240
302
  const result = {};
241
303
  const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
242
304
  const nodeType = node.attrs.type;
@@ -263,7 +325,10 @@ const makeMessagesRecvSocket = (config) => {
263
325
  ev.emit('messages.media-update', [event]);
264
326
  break;
265
327
  case 'encrypt':
266
- await handleEncryptNotification(node);
328
+ yield handleEncryptNotification(node);
329
+ break;
330
+ case 'newsletter':
331
+ // TO DO
267
332
  break;
268
333
  case 'devices':
269
334
  const devices = (0, WABinary_1.getBinaryNodeChildren)(child, 'device');
@@ -276,15 +341,15 @@ const makeMessagesRecvSocket = (config) => {
276
341
  const update = (0, WABinary_1.getBinaryNodeChild)(node, 'collection');
277
342
  if (update) {
278
343
  const name = update.attrs.name;
279
- await resyncAppState([name], false);
344
+ yield resyncAppState([name], false);
280
345
  }
281
346
  break;
282
347
  case 'picture':
283
348
  const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
284
349
  const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
285
350
  ev.emit('contacts.update', [{
286
- id: from,
287
- imgUrl: setPicture ? 'changed' : null
351
+ id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.jid) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
352
+ imgUrl: setPicture ? 'changed' : 'removed'
288
353
  }]);
289
354
  if ((0, WABinary_1.isJidGroup)(from)) {
290
355
  const node = setPicture || delPicture;
@@ -293,10 +358,7 @@ const makeMessagesRecvSocket = (config) => {
293
358
  result.messageStubParameters = [setPicture.attrs.id];
294
359
  }
295
360
  result.participant = node === null || node === void 0 ? void 0 : node.attrs.author;
296
- result.key = {
297
- ...result.key || {},
298
- participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author
299
- };
361
+ result.key = Object.assign(Object.assign({}, result.key || {}), { participant: setPicture === null || setPicture === void 0 ? void 0 : setPicture.attrs.author });
300
362
  }
301
363
  break;
302
364
  case 'account_sync':
@@ -305,13 +367,10 @@ const makeMessagesRecvSocket = (config) => {
305
367
  const timestamp = +child.attrs.t;
306
368
  logger.info({ newDuration }, 'updated account disappearing mode');
307
369
  ev.emit('creds.update', {
308
- accountSettings: {
309
- ...authState.creds.accountSettings,
310
- defaultDisappearingMode: {
370
+ accountSettings: Object.assign(Object.assign({}, authState.creds.accountSettings), { defaultDisappearingMode: {
311
371
  ephemeralExpiration: newDuration,
312
372
  ephemeralSettingTimestamp: timestamp,
313
- },
314
- }
373
+ } })
315
374
  });
316
375
  }
317
376
  else if (child.tag === 'blocklist') {
@@ -343,7 +402,7 @@ const makeMessagesRecvSocket = (config) => {
343
402
  const identitySharedKey = Utils_1.Curve.sharedKey(authState.creds.signedIdentityKey.private, primaryIdentityPublicKey);
344
403
  const identityPayload = Buffer.concat([companionSharedKey, identitySharedKey, random]);
345
404
  authState.creds.advSecretKey = (0, Utils_1.hkdf)(identityPayload, 32, { info: 'adv_secret' }).toString('base64');
346
- await query({
405
+ yield query({
347
406
  tag: 'iq',
348
407
  attrs: {
349
408
  to: WABinary_1.S_WHATSAPP_NET,
@@ -384,7 +443,7 @@ const makeMessagesRecvSocket = (config) => {
384
443
  if (Object.keys(result).length) {
385
444
  return result;
386
445
  }
387
- };
446
+ });
388
447
  function decipherLinkPublicKey(data) {
389
448
  const buffer = toRequiredBuffer(data);
390
449
  const salt = buffer.slice(0, 32);
@@ -409,18 +468,18 @@ const makeMessagesRecvSocket = (config) => {
409
468
  const newValue = (msgRetryCache.get(key) || 0) + 1;
410
469
  msgRetryCache.set(key, newValue);
411
470
  };
412
- const sendMessagesAgain = async (key, ids, retryNode) => {
471
+ const sendMessagesAgain = (key, ids, retryNode) => __awaiter(void 0, void 0, void 0, function* () {
413
472
  var _a;
414
- const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
473
+ const msgs = yield Promise.all(ids.map(id => getMessage(Object.assign(Object.assign({}, key), { id }))));
415
474
  const remoteJid = key.remoteJid;
416
475
  const participant = key.participant || remoteJid;
417
476
  // if it's the primary jid sending the request
418
477
  // just re-send the message to everyone
419
478
  // prevents the first message decryption failure
420
479
  const sendToAll = !((_a = (0, WABinary_1.jidDecode)(participant)) === null || _a === void 0 ? void 0 : _a.device);
421
- await assertSessions([participant], true);
480
+ yield assertSessions([participant], true);
422
481
  if ((0, WABinary_1.isJidGroup)(remoteJid)) {
423
- await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
482
+ yield authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
424
483
  }
425
484
  logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
426
485
  for (let i = 0; i < msgs.length; i++) {
@@ -437,14 +496,14 @@ const makeMessagesRecvSocket = (config) => {
437
496
  count: +retryNode.attrs.count
438
497
  };
439
498
  }
440
- await relayMessage(key.remoteJid, msg, msgRelayOpts);
499
+ yield relayMessage(key.remoteJid, msg, msgRelayOpts);
441
500
  }
442
501
  else {
443
502
  logger.debug({ jid: key.remoteJid, id: ids[i] }, 'recv retry request, but message not available');
444
503
  }
445
504
  }
446
- };
447
- const handleReceipt = async (node) => {
505
+ });
506
+ const handleReceipt = (node) => __awaiter(void 0, void 0, void 0, function* () {
448
507
  var _a, _b;
449
508
  const { attrs, content } = node;
450
509
  const isLid = attrs.from.includes('lid');
@@ -457,9 +516,9 @@ const makeMessagesRecvSocket = (config) => {
457
516
  fromMe,
458
517
  participant: attrs.participant
459
518
  };
460
- if (shouldIgnoreJid(remoteJid)) {
519
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
461
520
  logger.debug({ remoteJid }, 'ignoring receipt from jid');
462
- await sendMessageAck(node);
521
+ yield sendMessageAck(node);
463
522
  return;
464
523
  }
465
524
  const ids = [attrs.id];
@@ -467,8 +526,8 @@ const makeMessagesRecvSocket = (config) => {
467
526
  const items = (0, WABinary_1.getBinaryNodeChildren)(content[0], 'item');
468
527
  ids.push(...items.map(i => i.attrs.id));
469
528
  }
470
- await Promise.all([
471
- processingMutex.mutex(async () => {
529
+ yield Promise.all([
530
+ processingMutex.mutex(() => __awaiter(void 0, void 0, void 0, function* () {
472
531
  const status = (0, Utils_1.getStatusFromReceiptType)(attrs.type);
473
532
  if (typeof status !== 'undefined' &&
474
533
  (
@@ -480,7 +539,7 @@ const makeMessagesRecvSocket = (config) => {
480
539
  if (attrs.participant) {
481
540
  const updateKey = status === WAProto_1.proto.WebMessageInfo.Status.DELIVERY_ACK ? 'receiptTimestamp' : 'readTimestamp';
482
541
  ev.emit('message-receipt.update', ids.map(id => ({
483
- key: { ...key, id },
542
+ key: Object.assign(Object.assign({}, key), { id }),
484
543
  receipt: {
485
544
  userJid: (0, WABinary_1.jidNormalizedUser)(attrs.participant),
486
545
  [updateKey]: +attrs.t
@@ -490,7 +549,7 @@ const makeMessagesRecvSocket = (config) => {
490
549
  }
491
550
  else {
492
551
  ev.emit('messages.update', ids.map(id => ({
493
- key: { ...key, id },
552
+ key: Object.assign(Object.assign({}, key), { id }),
494
553
  update: { status }
495
554
  })));
496
555
  }
@@ -503,7 +562,7 @@ const makeMessagesRecvSocket = (config) => {
503
562
  if (key.fromMe) {
504
563
  try {
505
564
  logger.debug({ attrs, key }, 'recv retry request');
506
- await sendMessagesAgain(key, ids, retryNode);
565
+ yield sendMessagesAgain(key, ids, retryNode);
507
566
  }
508
567
  catch (error) {
509
568
  logger.error({ key, ids, trace: error.stack }, 'error in sending message again');
@@ -517,69 +576,64 @@ const makeMessagesRecvSocket = (config) => {
517
576
  logger.info({ attrs, key }, 'will not send message again, as sent too many times');
518
577
  }
519
578
  }
520
- }),
579
+ })),
521
580
  sendMessageAck(node)
522
581
  ]);
523
- };
524
- const handleNotification = async (node) => {
582
+ });
583
+ const handleNotification = (node) => __awaiter(void 0, void 0, void 0, function* () {
525
584
  const remoteJid = node.attrs.from;
526
- if (shouldIgnoreJid(remoteJid)) {
585
+ if (shouldIgnoreJid(remoteJid) && remoteJid !== '@s.whatsapp.net') {
527
586
  logger.debug({ remoteJid, id: node.attrs.id }, 'ignored notification');
528
- await sendMessageAck(node);
587
+ yield sendMessageAck(node);
529
588
  return;
530
589
  }
531
- await Promise.all([
532
- processingMutex.mutex(async () => {
590
+ yield Promise.all([
591
+ processingMutex.mutex(() => __awaiter(void 0, void 0, void 0, function* () {
533
592
  var _a;
534
- const msg = await processNotification(node);
593
+ const msg = yield processNotification(node);
535
594
  if (msg) {
536
595
  const fromMe = (0, WABinary_1.areJidsSameUser)(node.attrs.participant || remoteJid, authState.creds.me.id);
537
- msg.key = {
538
- remoteJid,
539
- fromMe,
540
- participant: node.attrs.participant,
541
- id: node.attrs.id,
542
- ...(msg.key || {})
543
- };
596
+ msg.key = Object.assign({ remoteJid,
597
+ fromMe, participant: node.attrs.participant, id: node.attrs.id }, (msg.key || {}));
544
598
  (_a = msg.participant) !== null && _a !== void 0 ? _a : (msg.participant = node.attrs.participant);
545
599
  msg.messageTimestamp = +node.attrs.t;
546
600
  const fullMsg = WAProto_1.proto.WebMessageInfo.fromObject(msg);
547
- await upsertMessage(fullMsg, 'append');
601
+ yield upsertMessage(fullMsg, 'append');
548
602
  }
549
- }),
603
+ })),
550
604
  sendMessageAck(node)
551
605
  ]);
552
- };
553
- const handleMessage = async (node) => {
606
+ });
607
+ const handleMessage = (node) => __awaiter(void 0, void 0, void 0, function* () {
554
608
  var _a, _b;
609
+ if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
610
+ logger.debug({ key: node.attrs.key }, 'ignored message');
611
+ yield sendMessageAck(node);
612
+ return;
613
+ }
555
614
  const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
556
615
  if (((_b = (_a = msg.message) === null || _a === void 0 ? void 0 : _a.protocolMessage) === null || _b === void 0 ? void 0 : _b.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
557
616
  if (node.attrs.sender_pn) {
558
617
  ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
559
618
  }
560
619
  }
561
- if (shouldIgnoreJid(msg.key.remoteJid)) {
562
- logger.debug({ key: msg.key }, 'ignored message');
563
- await sendMessageAck(node);
564
- return;
565
- }
566
- await Promise.all([
567
- processingMutex.mutex(async () => {
568
- await decrypt();
620
+ yield Promise.all([
621
+ processingMutex.mutex(() => __awaiter(void 0, void 0, void 0, function* () {
622
+ yield decrypt();
569
623
  // message failed to decrypt
570
624
  if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
571
- retryMutex.mutex(async () => {
625
+ retryMutex.mutex(() => __awaiter(void 0, void 0, void 0, function* () {
572
626
  if (ws.isOpen) {
573
627
  const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
574
- await sendRetryRequest(node, !encNode);
628
+ yield sendRetryRequest(node, !encNode);
575
629
  if (retryRequestDelayMs) {
576
- await (0, Utils_1.delay)(retryRequestDelayMs);
630
+ yield (0, Utils_1.delay)(retryRequestDelayMs);
577
631
  }
578
632
  }
579
633
  else {
580
634
  logger.debug({ node }, 'connection closed, ignoring retry req');
581
635
  }
582
- });
636
+ }));
583
637
  }
584
638
  else {
585
639
  // no type in the receipt => message delivered
@@ -598,21 +652,21 @@ const makeMessagesRecvSocket = (config) => {
598
652
  else if (!sendActiveReceipts) {
599
653
  type = 'inactive';
600
654
  }
601
- await sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
655
+ yield sendReceipt(msg.key.remoteJid, participant, [msg.key.id], type);
602
656
  // send ack for history message
603
657
  const isAnyHistoryMsg = (0, Utils_1.getHistoryMsg)(msg.message);
604
658
  if (isAnyHistoryMsg) {
605
659
  const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
606
- await sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
660
+ yield sendReceipt(jid, undefined, [msg.key.id], 'hist_sync');
607
661
  }
608
662
  }
609
663
  (0, Utils_2.cleanMessage)(msg, authState.creds.me.id);
610
- await upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
611
- }),
664
+ yield upsertMessage(msg, node.attrs.offline ? 'append' : 'notify');
665
+ })),
612
666
  sendMessageAck(node)
613
667
  ]);
614
- };
615
- const handleCall = async (node) => {
668
+ });
669
+ const handleCall = (node) => __awaiter(void 0, void 0, void 0, function* () {
616
670
  const { attrs } = node;
617
671
  const [infoChild] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
618
672
  const callId = infoChild.attrs['call-id'];
@@ -643,18 +697,18 @@ const makeMessagesRecvSocket = (config) => {
643
697
  callOfferCache.del(call.id);
644
698
  }
645
699
  ev.emit('call', [call]);
646
- await sendMessageAck(node);
647
- };
648
- const handleBadAck = async ({ attrs }) => {
700
+ yield sendMessageAck(node);
701
+ });
702
+ const handleBadAck = (_a) => __awaiter(void 0, [_a], void 0, function* ({ attrs }) {
649
703
  const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
650
704
  // current hypothesis is that if pash is sent in the ack
651
705
  // it means -- the message hasn't reached all devices yet
652
706
  // we'll retry sending the message here
653
707
  if (attrs.phash) {
654
708
  logger.info({ attrs }, 'received phash in ack, resending message...');
655
- const msg = await getMessage(key);
709
+ const msg = yield getMessage(key);
656
710
  if (msg) {
657
- await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
711
+ yield relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
658
712
  }
659
713
  else {
660
714
  logger.warn({ attrs }, 'could not send message again, as it was not found');
@@ -676,31 +730,31 @@ const makeMessagesRecvSocket = (config) => {
676
730
  }
677
731
  ]);
678
732
  }
679
- };
733
+ });
680
734
  /// processes a node with the given function
681
735
  /// and adds the task to the existing buffer if we're buffering events
682
- const processNodeWithBuffer = async (node, identifier, exec) => {
736
+ const processNodeWithBuffer = (node, identifier, exec) => __awaiter(void 0, void 0, void 0, function* () {
683
737
  ev.buffer();
684
- await execTask();
738
+ yield execTask();
685
739
  ev.flush();
686
740
  function execTask() {
687
741
  return exec(node)
688
742
  .catch(err => onUnexpectedError(err, identifier));
689
743
  }
690
- };
744
+ });
691
745
  // recv a message
692
746
  ws.on('CB:message', (node) => {
693
747
  processNodeWithBuffer(node, 'processing message', handleMessage);
694
748
  });
695
- ws.on('CB:call', async (node) => {
749
+ ws.on('CB:call', (node) => __awaiter(void 0, void 0, void 0, function* () {
696
750
  processNodeWithBuffer(node, 'handling call', handleCall);
697
- });
751
+ }));
698
752
  ws.on('CB:receipt', node => {
699
753
  processNodeWithBuffer(node, 'handling receipt', handleReceipt);
700
754
  });
701
- ws.on('CB:notification', async (node) => {
755
+ ws.on('CB:notification', (node) => __awaiter(void 0, void 0, void 0, function* () {
702
756
  processNodeWithBuffer(node, 'handling notification', handleNotification);
703
- });
757
+ }));
704
758
  ws.on('CB:ack,class:message', (node) => {
705
759
  handleBadAck(node)
706
760
  .catch(error => onUnexpectedError(error, 'handling bad ack'));
@@ -737,11 +791,9 @@ const makeMessagesRecvSocket = (config) => {
737
791
  logger.trace(`sendActiveReceipts set to "${sendActiveReceipts}"`);
738
792
  }
739
793
  });
740
- return {
741
- ...sock,
742
- sendMessageAck,
794
+ return Object.assign(Object.assign({}, sock), { sendMessageAck,
743
795
  sendRetryRequest,
744
- rejectCall
745
- };
796
+ offerCall,
797
+ rejectCall });
746
798
  };
747
799
  exports.makeMessagesRecvSocket = makeMessagesRecvSocket;