@badzz88/baileys 8.5.6 → 8.5.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 (225) hide show
  1. package/README.md +337 -1055
  2. package/WAProto/WAProto.proto +28 -1189
  3. package/WAProto/fix-imports.js +79 -69
  4. package/WAProto/index.d.ts +71491 -15254
  5. package/WAProto/index.js +126436 -19814
  6. package/engine-requirements.js +8 -15
  7. package/lib/Defaults/index.js +130 -0
  8. package/{src → lib}/Signal/Group/ciphertext-message.js +2 -5
  9. package/lib/Signal/Group/group-session-builder.js +30 -0
  10. package/{src → lib}/Signal/Group/group_cipher.js +11 -11
  11. package/lib/Signal/Group/index.js +12 -0
  12. package/lib/Signal/Group/keyhelper.js +18 -0
  13. package/{src → lib}/Signal/Group/sender-chain-key.js +6 -9
  14. package/{src → lib}/Signal/Group/sender-key-distribution-message.js +6 -9
  15. package/{src → lib}/Signal/Group/sender-key-message.js +9 -12
  16. package/{src → lib}/Signal/Group/sender-key-name.js +2 -5
  17. package/{src → lib}/Signal/Group/sender-key-record.js +8 -11
  18. package/{src → lib}/Signal/Group/sender-key-state.js +6 -9
  19. package/lib/Signal/Group/sender-message-key.js +26 -0
  20. package/{src → lib}/Signal/libsignal.js +131 -155
  21. package/{src → lib}/Signal/lid-mapping.js +27 -23
  22. package/lib/Socket/Client/index.js +3 -0
  23. package/lib/Socket/Client/types.js +11 -0
  24. package/{src → lib}/Socket/Client/websocket.js +11 -18
  25. package/{src → lib}/Socket/business.js +35 -67
  26. package/{src → lib}/Socket/chats.js +294 -550
  27. package/{src → lib}/Socket/communities.js +82 -114
  28. package/lib/Socket/graphql.js +716 -0
  29. package/lib/Socket/groups.js +374 -0
  30. package/lib/Socket/index.js +18 -0
  31. package/lib/Socket/interop.js +463 -0
  32. package/{src → lib}/Socket/luxu.js +120 -82
  33. package/lib/Socket/messages-recv.js +1916 -0
  34. package/lib/Socket/messages-send.js +1436 -0
  35. package/lib/Socket/mex.js +54 -0
  36. package/lib/Socket/newsletter.js +757 -0
  37. package/lib/Socket/privacy.js +318 -0
  38. package/{src → lib}/Socket/socket.js +356 -244
  39. package/lib/Socket/username.js +236 -0
  40. package/lib/Store/index.js +10 -0
  41. package/{src → lib}/Store/keyed-db.js +11 -21
  42. package/lib/Store/make-cache-manager-store.js +85 -0
  43. package/lib/Store/make-in-memory-store.js +244 -0
  44. package/{src → lib}/Store/make-ordered-dictionary.js +19 -25
  45. package/{src → lib}/Store/object-repository.js +11 -5
  46. package/lib/Types/Auth.js +2 -0
  47. package/lib/Types/Bussines.js +2 -0
  48. package/lib/Types/Call.js +2 -0
  49. package/lib/Types/Chat.js +8 -0
  50. package/lib/Types/Contact.js +2 -0
  51. package/lib/Types/Events.js +2 -0
  52. package/lib/Types/GroupMetadata.js +2 -0
  53. package/lib/Types/Label.js +25 -0
  54. package/lib/Types/LabelAssociation.js +7 -0
  55. package/lib/Types/Message.js +11 -0
  56. package/lib/Types/Mex.js +111 -0
  57. package/lib/Types/Product.js +2 -0
  58. package/lib/Types/Signal.js +2 -0
  59. package/lib/Types/Socket.js +3 -0
  60. package/lib/Types/State.js +56 -0
  61. package/lib/Types/USync.js +2 -0
  62. package/lib/Types/index.js +26 -0
  63. package/{src → lib}/Utils/auth-utils.js +91 -43
  64. package/lib/Utils/browser-utils.js +48 -0
  65. package/lib/Utils/business.js +231 -0
  66. package/lib/Utils/chat-utils.js +872 -0
  67. package/lib/Utils/companion-reg-client-utils.js +35 -0
  68. package/lib/Utils/crypto.js +118 -0
  69. package/lib/Utils/decode-wa-message.js +350 -0
  70. package/{src → lib}/Utils/event-buffer.js +81 -39
  71. package/lib/Utils/generics.js +403 -0
  72. package/lib/Utils/history.js +134 -0
  73. package/{src → lib}/Utils/identity-change-handler.js +9 -11
  74. package/lib/Utils/index.js +23 -0
  75. package/lib/Utils/link-preview.js +85 -0
  76. package/lib/Utils/logger.js +3 -0
  77. package/lib/Utils/lt-hash.js +8 -0
  78. package/{src → lib}/Utils/make-mutex.js +7 -10
  79. package/lib/Utils/message-composer.js +273 -0
  80. package/{src → lib}/Utils/message-retry-manager.js +76 -28
  81. package/lib/Utils/messages-media.js +870 -0
  82. package/lib/Utils/messages.js +1337 -0
  83. package/lib/Utils/noise-handler.js +201 -0
  84. package/{src → lib}/Utils/offline-node-processor.js +10 -4
  85. package/{src → lib}/Utils/pre-key-manager.js +27 -11
  86. package/lib/Utils/process-message.js +630 -0
  87. package/{src → lib}/Utils/reporting-utils.js +12 -15
  88. package/lib/Utils/signal.js +201 -0
  89. package/{src → lib}/Utils/stanza-ack.js +12 -4
  90. package/lib/Utils/sticker.js +110 -0
  91. package/{src → lib}/Utils/sync-action-utils.js +14 -10
  92. package/{src → lib}/Utils/tc-token-utils.js +48 -43
  93. package/{src → lib}/Utils/use-multi-file-auth-state.js +35 -25
  94. package/lib/Utils/validate-connection.js +203 -0
  95. package/{src → lib}/WABinary/constants.js +9 -12
  96. package/{src → lib}/WABinary/decode.js +38 -118
  97. package/{src → lib}/WABinary/encode.js +6 -11
  98. package/lib/WABinary/generic-utils.js +204 -0
  99. package/lib/WABinary/index.js +6 -0
  100. package/lib/WABinary/jid-utils.js +98 -0
  101. package/lib/WABinary/types.js +2 -0
  102. package/{src → lib}/WAM/BinaryInfo.js +2 -5
  103. package/{src → lib}/WAM/constants.js +4 -16635
  104. package/{src → lib}/WAM/encode.js +18 -17
  105. package/lib/WAM/index.js +4 -0
  106. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
  107. package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
  108. package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
  109. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  110. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  111. package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +58 -0
  112. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  113. package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
  114. package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +28 -0
  115. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  116. package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
  117. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
  118. package/lib/WAUSync/Protocols/index.js +12 -0
  119. package/lib/WAUSync/USyncQuery.js +151 -0
  120. package/lib/WAUSync/USyncUser.js +56 -0
  121. package/lib/WAUSync/index.js +3 -0
  122. package/{src → lib}/index.js +16 -51
  123. package/package.json +129 -99
  124. package/LICENSE +0 -21
  125. package/src/Defaults/index.js +0 -186
  126. package/src/Defaults/phonenumber-mcc.json +0 -223
  127. package/src/Signal/Group/group-session-builder.js +0 -86
  128. package/src/Signal/Group/index.js +0 -140
  129. package/src/Signal/Group/keyhelper.js +0 -77
  130. package/src/Signal/Group/sender-message-key.js +0 -29
  131. package/src/Socket/Client/index.js +0 -31
  132. package/src/Socket/Client/types.js +0 -13
  133. package/src/Socket/aigroups.js +0 -221
  134. package/src/Socket/graphql.js +0 -523
  135. package/src/Socket/groups.js +0 -516
  136. package/src/Socket/index.js +0 -31
  137. package/src/Socket/interactive-handler.js +0 -527
  138. package/src/Socket/interop.js +0 -339
  139. package/src/Socket/managed-account.js +0 -98
  140. package/src/Socket/messages-recv.js +0 -2685
  141. package/src/Socket/messages-send.js +0 -2047
  142. package/src/Socket/mex.js +0 -57
  143. package/src/Socket/newsletter.js +0 -455
  144. package/src/Socket/privacy.js +0 -125
  145. package/src/Socket/registration.js +0 -236
  146. package/src/Socket/text-router.js +0 -65
  147. package/src/Socket/username.js +0 -130
  148. package/src/Store/index.js +0 -33
  149. package/src/Store/make-cache-manager-store.js +0 -84
  150. package/src/Store/make-in-memory-store.js +0 -551
  151. package/src/Types/Auth.js +0 -31
  152. package/src/Types/Bussines.js +0 -2
  153. package/src/Types/Call.js +0 -2
  154. package/src/Types/Chat.js +0 -4
  155. package/src/Types/Contact.js +0 -2
  156. package/src/Types/Events.js +0 -2
  157. package/src/Types/GroupMetadata.js +0 -2
  158. package/src/Types/Label.js +0 -26
  159. package/src/Types/LabelAssociation.js +0 -8
  160. package/src/Types/Message.js +0 -93
  161. package/src/Types/Mex.js +0 -112
  162. package/src/Types/Newsletter.js +0 -109
  163. package/src/Types/Product.js +0 -2
  164. package/src/Types/Signal.js +0 -2
  165. package/src/Types/Socket.js +0 -2
  166. package/src/Types/State.js +0 -62
  167. package/src/Types/USync.js +0 -2
  168. package/src/Types/index.js +0 -56
  169. package/src/Utils/browser-utils.js +0 -112
  170. package/src/Utils/business.js +0 -240
  171. package/src/Utils/chat-utils.js +0 -1230
  172. package/src/Utils/command-loader.d.ts +0 -27
  173. package/src/Utils/command-loader.js +0 -89
  174. package/src/Utils/companion-reg-client-utils.js +0 -40
  175. package/src/Utils/consumer-application.js +0 -105
  176. package/src/Utils/crypto.js +0 -118
  177. package/src/Utils/curve25519-js.js +0 -242
  178. package/src/Utils/decode-wa-message.js +0 -529
  179. package/src/Utils/generics.js +0 -483
  180. package/src/Utils/group-history.js +0 -44
  181. package/src/Utils/history.js +0 -232
  182. package/src/Utils/index.js +0 -58
  183. package/src/Utils/jid-display-normalization.js +0 -195
  184. package/src/Utils/link-preview.js +0 -135
  185. package/src/Utils/logger.js +0 -8
  186. package/src/Utils/lt-hash.js +0 -25
  187. package/src/Utils/message-composer.js +0 -471
  188. package/src/Utils/messages-media.js +0 -843
  189. package/src/Utils/messages.js +0 -2817
  190. package/src/Utils/meta-ai-msmsg.js +0 -222
  191. package/src/Utils/native-bridge.js +0 -68
  192. package/src/Utils/noise-handler.js +0 -169
  193. package/src/Utils/process-message.js +0 -950
  194. package/src/Utils/session-pool.d.ts +0 -14
  195. package/src/Utils/session-pool.js +0 -70
  196. package/src/Utils/signal.js +0 -217
  197. package/src/Utils/sticker.d.ts +0 -13
  198. package/src/Utils/sticker.js +0 -123
  199. package/src/Utils/validate-connection.js +0 -209
  200. package/src/Utils/view-once-cache.d.ts +0 -12
  201. package/src/Utils/view-once-cache.js +0 -63
  202. package/src/Utils/voip-rekey.js +0 -22
  203. package/src/WABinary/generic-utils.js +0 -238
  204. package/src/WABinary/index.js +0 -34
  205. package/src/WABinary/jid-utils.js +0 -351
  206. package/src/WABinary/types.js +0 -2
  207. package/src/WAM/index.js +0 -32
  208. package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -53
  209. package/src/WAUSync/Protocols/USyncBusinessProtocol.js +0 -44
  210. package/src/WAUSync/Protocols/USyncContactProtocol.js +0 -55
  211. package/src/WAUSync/Protocols/USyncDeviceProtocol.js +0 -55
  212. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -31
  213. package/src/WAUSync/Protocols/USyncFeatureProtocol.js +0 -54
  214. package/src/WAUSync/Protocols/USyncLIDProtocol.js +0 -32
  215. package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -473
  216. package/src/WAUSync/Protocols/USyncPictureProtocol.js +0 -34
  217. package/src/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
  218. package/src/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  219. package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
  220. package/src/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
  221. package/src/WAUSync/Protocols/index.js +0 -40
  222. package/src/WAUSync/USyncQuery.js +0 -126
  223. package/src/WAUSync/USyncUser.js +0 -50
  224. package/src/WAUSync/index.js +0 -32
  225. package/src/antiban.js +0 -4152
@@ -1,950 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.getChatId = exports.shouldIncrementChatUnread = exports.isRealMessage = exports.cleanMessage = void 0;
4
- exports.decryptPollVote = decryptPollVote;
5
- exports.decryptEventResponse = decryptEventResponse;
6
- const index_js_1 = require('../../WAProto/index.js');
7
- const Types_1 = require('../Types');
8
- const messages_1 = require('../Utils/messages');
9
- const WABinary_1 = require('../WABinary');
10
- const crypto_1 = require('./crypto');
11
- const generics_1 = require('./generics');
12
- const history_1 = require('./history');
13
- const tc_token_utils_1 = require('./tc-token-utils');
14
- async function storeTcTokensFromHistorySync(chats, signalRepository, keyStore, logger) {
15
- const getLIDForPN = signalRepository.lidMapping.getLIDForPN.bind(signalRepository.lidMapping);
16
- const candidates = [];
17
- for (const chat of chats) {
18
- const ts = chat.tcTokenTimestamp ? (0, generics_1.toNumber)(chat.tcTokenTimestamp) : 0;
19
- if (chat.tcToken?.length && ts > 0) {
20
- const jid = (0, WABinary_1.jidNormalizedUser)(chat.id);
21
- const storageJid = await (0, tc_token_utils_1.resolveTcTokenJid)(jid, getLIDForPN);
22
- candidates.push({
23
- storageJid,
24
- token: Buffer.from(chat.tcToken),
25
- ts,
26
- senderTs: chat.tcTokenSenderTimestamp ? (0, generics_1.toNumber)(chat.tcTokenSenderTimestamp) : undefined
27
- });
28
- }
29
- }
30
- if (!candidates.length)
31
- return;
32
- const jids = candidates.map(c => c.storageJid);
33
- const existing = await keyStore.get('tctoken', jids);
34
- const entries = {};
35
- for (const c of candidates) {
36
- const existingEntry = existing[c.storageJid];
37
- const existingTs = existingEntry?.timestamp ? Number(existingEntry.timestamp) : 0;
38
- if (existingTs > 0 && existingTs >= c.ts)
39
- continue;
40
- entries[c.storageJid] = {
41
- ...existingEntry,
42
- token: c.token,
43
- timestamp: String(c.ts),
44
- ...(c.senderTs !== undefined ? { senderTimestamp: c.senderTs } : {})
45
- };
46
- }
47
- if (Object.keys(entries).length) {
48
- logger?.debug({ count: Object.keys(entries).length }, 'storing tctokens from history sync');
49
- try {
50
- const indexWrite = await (0, tc_token_utils_1.buildMergedTcTokenIndexWrite)(keyStore, Object.keys(entries));
51
- await keyStore.set({ tctoken: { ...entries, ...indexWrite } });
52
- }
53
- catch (err) {
54
- logger?.warn({ err }, 'failed to store tctokens from history sync');
55
- }
56
- }
57
- }
58
- const REAL_MSG_STUB_TYPES = new Set([
59
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VIDEO,
60
- Types_1.WAMessageStubType.CALL_MISSED_GROUP_VOICE,
61
- Types_1.WAMessageStubType.CALL_MISSED_VIDEO,
62
- Types_1.WAMessageStubType.CALL_MISSED_VOICE
63
- ]);
64
- const REAL_MSG_REQ_ME_STUB_TYPES = new Set([Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD]);
65
- const cleanMessage = (message, meId, meLid) => {
66
- if ((0, WABinary_1.isHostedPnUser)(message.key.remoteJid) || (0, WABinary_1.isHostedLidUser)(message.key.remoteJid)) {
67
- message.key.remoteJid = (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(message.key?.remoteJid)?.user, (0, WABinary_1.isHostedPnUser)(message.key.remoteJid) ? 's.whatsapp.net' : 'lid');
68
- }
69
- else {
70
- message.key.remoteJid = (0, WABinary_1.jidNormalizedUser)(message.key.remoteJid);
71
- }
72
- if ((0, WABinary_1.isHostedPnUser)(message.key.participant) ||
73
- (0, WABinary_1.isHostedLidUser)(message.key.participant)) {
74
- message.key.participant = (0, WABinary_1.jidEncode)((0, WABinary_1.jidDecode)(message.key.participant)?.user, (0, WABinary_1.isHostedPnUser)(message.key.participant) ? 's.whatsapp.net' : 'lid');
75
- }
76
- else {
77
- message.key.participant = (0, WABinary_1.jidNormalizedUser)(message.key.participant);
78
- }
79
- const content = (0, messages_1.normalizeMessageContent)(message.message);
80
- if (content?.reactionMessage) {
81
- normaliseKey(content.reactionMessage.key);
82
- }
83
- if (content?.pollUpdateMessage) {
84
- normaliseKey(content.pollUpdateMessage.pollCreationMessageKey);
85
- }
86
- function normaliseKey(msgKey) {
87
- if (!message.key.fromMe) {
88
- msgKey.fromMe = !msgKey.fromMe
89
- ? (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meId) ||
90
- (0, WABinary_1.areJidsSameUser)(msgKey.participant || msgKey.remoteJid, meLid)
91
- :
92
- false;
93
- msgKey.remoteJid = message.key.remoteJid;
94
- msgKey.participant = msgKey.participant || message.key.participant;
95
- }
96
- }
97
- };
98
- exports.cleanMessage = cleanMessage;
99
- const isRealMessage = message => {
100
- const normalizedContent = (0, messages_1.normalizeMessageContent)(message.message);
101
- const hasSomeContent = !!(0, messages_1.getContentType)(normalizedContent);
102
- return ((!!normalizedContent ||
103
- REAL_MSG_STUB_TYPES.has(message.messageStubType) ||
104
- REAL_MSG_REQ_ME_STUB_TYPES.has(message.messageStubType)) &&
105
- hasSomeContent &&
106
- !normalizedContent?.protocolMessage &&
107
- !normalizedContent?.reactionMessage &&
108
- !normalizedContent?.pollUpdateMessage);
109
- };
110
- exports.isRealMessage = isRealMessage;
111
- const shouldIncrementChatUnread = message => !message.key.fromMe && !message.messageStubType;
112
- exports.shouldIncrementChatUnread = shouldIncrementChatUnread;
113
- const getChatId = ({ remoteJid, participant, fromMe }) => {
114
- if ((0, WABinary_1.isJidBroadcast)(remoteJid) && !(0, WABinary_1.isJidStatusBroadcast)(remoteJid) && !fromMe) {
115
- return participant;
116
- }
117
- return remoteJid;
118
- };
119
- exports.getChatId = getChatId;
120
- function decryptPollVote({ encPayload, encIv }, { pollCreatorJid, pollMsgId, pollEncKey, voterJid }) {
121
- const sign = Buffer.concat([
122
- toBinary(pollMsgId),
123
- toBinary(pollCreatorJid),
124
- toBinary(voterJid),
125
- toBinary('Poll Vote'),
126
- new Uint8Array([1])
127
- ]);
128
- const key0 = (0, crypto_1.hmacSign)(pollEncKey, new Uint8Array(32), 'sha256');
129
- const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
130
- const aad = toBinary(`${pollMsgId}\u0000${voterJid}`);
131
- const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
132
- return index_js_1.proto.Message.PollVoteMessage.decode(decrypted);
133
- function toBinary(txt) {
134
- return Buffer.from(txt);
135
- }
136
- }
137
- function decryptEventResponse({ encPayload, encIv }, { eventCreatorJid, eventMsgId, eventEncKey, responderJid }) {
138
- const sign = Buffer.concat([
139
- toBinary(eventMsgId),
140
- toBinary(eventCreatorJid),
141
- toBinary(responderJid),
142
- toBinary('Event Response'),
143
- new Uint8Array([1])
144
- ]);
145
- const key0 = (0, crypto_1.hmacSign)(eventEncKey, new Uint8Array(32), 'sha256');
146
- const decKey = (0, crypto_1.hmacSign)(sign, key0, 'sha256');
147
- const aad = toBinary(`${eventMsgId}\u0000${responderJid}`);
148
- const decrypted = (0, crypto_1.aesDecryptGCM)(encPayload, decKey, encIv, aad);
149
- return index_js_1.proto.Message.EventResponseMessage.decode(decrypted);
150
- function toBinary(txt) {
151
- return Buffer.from(txt);
152
- }
153
- }
154
- const processMessage = async (message, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, signalRepository, keyStore, logger, options, getMessage }) => {
155
- const meId = creds.me.id;
156
- const { accountSettings } = creds;
157
- const chat = { id: (0, WABinary_1.jidNormalizedUser)((0, exports.getChatId)(message.key)) };
158
- const isRealMsg = (0, exports.isRealMessage)(message);
159
- if (isRealMsg) {
160
- chat.messages = [{ message }];
161
- chat.conversationTimestamp = (0, generics_1.toNumber)(message.messageTimestamp);
162
- if ((0, exports.shouldIncrementChatUnread)(message)) {
163
- chat.unreadCount = (chat.unreadCount || 0) + 1;
164
- }
165
- }
166
- if (message.statusPsa) {
167
- ev.emit('status.psa', {
168
- key: message.key,
169
- psa: message.statusPsa,
170
- chatId: chat.id
171
- });
172
- }
173
- if (message.quarantinedMessage) {
174
- ev.emit('message.quarantined', {
175
- key: message.key,
176
- quarantineInfo: message.quarantinedMessage,
177
- chatId: chat.id
178
- });
179
- }
180
- if (message.interactiveMessageAdditionalMetadata?.isGalaxyFlowCompleted) {
181
- ev.emit('galaxy.flow.completed', {
182
- key: message.key,
183
- chatId: chat.id
184
- });
185
- }
186
- if (message.ephemeralExpirationTimestamp) {
187
- Object.assign(chat, {
188
- ephemeralExpirationTimestamp: (0, generics_1.toNumber)(message.ephemeralExpirationTimestamp)
189
- });
190
- }
191
- const content = (0, messages_1.normalizeMessageContent)(message.message);
192
- if ((isRealMsg || content?.reactionMessage?.key?.fromMe) && accountSettings?.unarchiveChats) {
193
- chat.archived = false;
194
- chat.readOnly = false;
195
- }
196
- const protocolMsg = content?.protocolMessage;
197
- if (protocolMsg) {
198
- switch (protocolMsg.type) {
199
- case index_js_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION:
200
- const histNotification = protocolMsg.historySyncNotification;
201
- const process = shouldProcessHistoryMsg;
202
- const isLatest = !creds.processedHistoryMessages?.length;
203
- logger?.info({
204
- histNotification,
205
- process,
206
- id: message.key.id,
207
- isLatest
208
- }, 'got history notification');
209
- if (process) {
210
- if (histNotification.syncType !== index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND) {
211
- ev.emit('creds.update', {
212
- processedHistoryMessages: [
213
- ...(creds.processedHistoryMessages || []),
214
- { key: message.key, messageTimestamp: message.messageTimestamp }
215
- ]
216
- });
217
- }
218
- const data = await (0, history_1.downloadAndProcessHistorySyncNotification)(histNotification, options, logger);
219
- if (data.lidPnMappings?.length) {
220
- logger?.debug({ count: data.lidPnMappings.length }, 'processing LID-PN mappings from history sync');
221
- await signalRepository.lidMapping
222
- .storeLIDPNMappings(data.lidPnMappings)
223
- .catch(err => logger?.warn({ err }, 'failed to store LID-PN mappings from history sync'));
224
- }
225
- await storeTcTokensFromHistorySync(data.chats, signalRepository, keyStore, logger);
226
- ev.emit('messaging-history.set', {
227
- ...data,
228
- isLatest: histNotification.syncType !== index_js_1.proto.HistorySync.HistorySyncType.ON_DEMAND
229
- ? isLatest
230
- : undefined,
231
- peerDataRequestSessionId: histNotification.peerDataRequestSessionId
232
- });
233
- }
234
- break;
235
- case index_js_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE:
236
- const keys = protocolMsg.appStateSyncKeyShare.keys;
237
- if (keys?.length) {
238
- let newAppStateSyncKeyId = '';
239
- await keyStore.transaction(async () => {
240
- const newKeys = [];
241
- for (const { keyData, keyId } of keys) {
242
- const strKeyId = Buffer.from(keyId.keyId).toString('base64');
243
- newKeys.push(strKeyId);
244
- await keyStore.set({ 'app-state-sync-key': { [strKeyId]: keyData } });
245
- newAppStateSyncKeyId = strKeyId;
246
- }
247
- logger?.info({ newAppStateSyncKeyId, newKeys }, 'injecting new app state sync keys');
248
- }, meId);
249
- ev.emit('creds.update', { myAppStateKeyId: newAppStateSyncKeyId });
250
- }
251
- else {
252
- logger?.info({ protocolMsg }, 'recv app state sync with 0 keys');
253
- }
254
- break;
255
- case index_js_1.proto.Message.ProtocolMessage.Type.REVOKE:
256
- ev.emit('messages.update', [
257
- {
258
- key: {
259
- ...message.key,
260
- id: protocolMsg.key.id
261
- },
262
- update: { message: null, messageStubType: Types_1.WAMessageStubType.REVOKE, key: message.key }
263
- }
264
- ]);
265
- break;
266
- case index_js_1.proto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING:
267
- Object.assign(chat, {
268
- ephemeralSettingTimestamp: (0, generics_1.toNumber)(message.messageTimestamp),
269
- ephemeralExpiration: protocolMsg.ephemeralExpiration || null
270
- });
271
- break;
272
- case index_js_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE:
273
- const response = protocolMsg.peerDataOperationRequestResponseMessage;
274
- if (response) {
275
- const peerDataOperationResult = response.peerDataOperationResult || [];
276
- for (const result of peerDataOperationResult) {
277
- const retryResponse = result?.placeholderMessageResendResponse;
278
- if (!retryResponse?.webMessageInfoBytes) {
279
- continue;
280
- }
281
- try {
282
- const webMessageInfo = index_js_1.proto.WebMessageInfo.decode(retryResponse.webMessageInfoBytes);
283
- const msgId = webMessageInfo.key?.id;
284
- const cachedData = msgId ? await placeholderResendCache?.get(msgId) : undefined;
285
- if (msgId) {
286
- await placeholderResendCache?.del(msgId);
287
- }
288
- let finalMsg;
289
- if (cachedData && typeof cachedData === 'object') {
290
- cachedData.message = webMessageInfo.message;
291
- if (webMessageInfo.messageTimestamp) {
292
- cachedData.messageTimestamp = webMessageInfo.messageTimestamp;
293
- }
294
- finalMsg = cachedData;
295
- }
296
- else {
297
- finalMsg = webMessageInfo;
298
- }
299
- logger?.debug({ msgId, requestId: response.stanzaId }, 'received placeholder resend');
300
- ev.emit('messages.upsert', {
301
- messages: [finalMsg],
302
- type: 'notify',
303
- requestId: response.stanzaId
304
- });
305
- }
306
- catch (err) {
307
- logger?.warn({ err, stanzaId: response.stanzaId }, 'failed to decode placeholder resend response');
308
- }
309
- }
310
- }
311
- break;
312
- case index_js_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT:
313
- ev.emit('messages.update', [
314
- {
315
- key: { ...message.key, id: protocolMsg.key?.id },
316
- update: {
317
- message: {
318
- editedMessage: {
319
- message: protocolMsg.editedMessage
320
- }
321
- },
322
- messageTimestamp: protocolMsg.timestampMs
323
- ? Math.floor((0, generics_1.toNumber)(protocolMsg.timestampMs) / 1000)
324
- : message.messageTimestamp
325
- }
326
- }
327
- ]);
328
- break;
329
- case index_js_1.proto.Message.ProtocolMessage.Type.GROUP_MEMBER_LABEL_CHANGE:
330
- const labelAssociationMsg = protocolMsg.memberLabel;
331
- if (labelAssociationMsg?.label) {
332
- ev.emit('group.member-tag.update', {
333
- groupId: chat.id,
334
- label: labelAssociationMsg.label,
335
- participant: message.key.participant,
336
- participantAlt: message.key.participantAlt,
337
- messageTimestamp: Number(message.messageTimestamp)
338
- });
339
- }
340
- break;
341
- case index_js_1.proto.Message.ProtocolMessage.Type.BOT_FEEDBACK_MESSAGE:
342
- if (protocolMsg.botFeedbackMessage) {
343
- ev.emit('bot.feedback', {
344
- key: message.key,
345
- botFeedback: protocolMsg.botFeedbackMessage,
346
- targetKey: protocolMsg.key
347
- });
348
- }
349
- break;
350
- case index_js_1.proto.Message.ProtocolMessage.Type.CLOUD_API_THREAD_CONTROL_NOTIFICATION:
351
- if (protocolMsg.cloudAPIThreadControlNotification) {
352
- ev.emit('cloud.thread.control', {
353
- key: message.key,
354
- notification: protocolMsg.cloudAPIThreadControlNotification,
355
- chatId: chat.id
356
- });
357
- }
358
- break;
359
- case index_js_1.proto.Message.ProtocolMessage.Type.CHAT_THEME_SETTING:
360
- if (protocolMsg.chatThemeSetting) {
361
- ev.emit('chats.update', [
362
- {
363
- id: chat.id,
364
- chatThemeSetting: protocolMsg.chatThemeSetting
365
- }
366
- ]);
367
- }
368
- break;
369
- case index_js_1.proto.Message.ProtocolMessage.Type.STOP_GENERATION_MESSAGE:
370
- ev.emit('bot.stop-generation', {
371
- key: message.key,
372
- targetKey: protocolMsg.key,
373
- chatId: chat.id
374
- });
375
- break;
376
- case index_js_1.proto.Message.ProtocolMessage.Type.MEDIA_NOTIFY_MESSAGE:
377
- if (protocolMsg.mediaNotifyMessage) {
378
- ev.emit('media.notify', {
379
- key: message.key,
380
- mediaNotify: protocolMsg.mediaNotifyMessage
381
- });
382
- }
383
- break;
384
- case index_js_1.proto.Message.ProtocolMessage.Type.REQUEST_WELCOME_MESSAGE:
385
- ev.emit('bot.welcome-request', {
386
- key: message.key,
387
- chatId: chat.id,
388
- timestamp: message.messageTimestamp
389
- });
390
- break;
391
- case index_js_1.proto.Message.ProtocolMessage.Type.BOT_MEMU_ONBOARDING_MESSAGE:
392
- ev.emit('bot.memu-onboarding', {
393
- key: message.key,
394
- chatId: chat.id
395
- });
396
- break;
397
- case index_js_1.proto.Message.ProtocolMessage.Type.STATUS_MENTION_MESSAGE:
398
- if (protocolMsg.statusMentionMessage) {
399
- ev.emit('status.mention', {
400
- key: message.key,
401
- statusMention: protocolMsg.statusMentionMessage,
402
- chatId: chat.id
403
- });
404
- }
405
- break;
406
- case index_js_1.proto.Message.ProtocolMessage.Type.AI_PSI_METADATA:
407
- if (protocolMsg.aiPsiMetadata) {
408
- ev.emit('bot.psi-metadata', {
409
- key: message.key,
410
- psiMetadata: protocolMsg.aiPsiMetadata,
411
- chatId: chat.id
412
- });
413
- }
414
- break;
415
- case index_js_1.proto.Message.ProtocolMessage.Type.AI_QUERY_FANOUT:
416
- if (protocolMsg.aiQueryFanout) {
417
- ev.emit('bot.query-fanout', {
418
- key: message.key,
419
- queryFanout: protocolMsg.aiQueryFanout,
420
- chatId: chat.id
421
- });
422
- }
423
- break;
424
- case index_js_1.proto.Message.ProtocolMessage.Type.AI_MEDIA_COLLECTION_MESSAGE:
425
- if (protocolMsg.aiMediaCollectionMessage) {
426
- ev.emit('bot.media-collection', {
427
- key: message.key,
428
- collection: protocolMsg.aiMediaCollectionMessage,
429
- chatId: chat.id
430
- });
431
- }
432
- break;
433
- case index_js_1.proto.Message.ProtocolMessage.Type.REMINDER_MESSAGE:
434
- ev.emit('reminder.update', {
435
- key: message.key,
436
- chatId: chat.id,
437
- timestamp: message.messageTimestamp
438
- });
439
- break;
440
- case index_js_1.proto.Message.ProtocolMessage.Type.MESSAGE_UNSCHEDULE:
441
- if (protocolMsg.key) {
442
- ev.emit('messages.update', [
443
- {
444
- key: { ...message.key, id: protocolMsg.key.id },
445
- update: { scheduledMessageMetadata: null }
446
- }
447
- ]);
448
- }
449
- break;
450
- case index_js_1.proto.Message.ProtocolMessage.Type.LID_MIGRATION_MAPPING_SYNC:
451
- const encodedPayload = protocolMsg.lidMigrationMappingSyncMessage?.encodedMappingPayload;
452
- const { pnToLidMappings, chatDbMigrationTimestamp } = index_js_1.proto.LIDMigrationMappingSyncPayload.decode(encodedPayload);
453
- logger?.debug({ pnToLidMappings, chatDbMigrationTimestamp }, 'got lid mappings and chat db migration timestamp');
454
- const pairs = [];
455
- for (const { pn, latestLid, assignedLid } of pnToLidMappings) {
456
- const lid = latestLid || assignedLid;
457
- pairs.push({ lid: `${lid}@lid`, pn: `${pn}@s.whatsapp.net` });
458
- }
459
- await signalRepository.lidMapping.storeLIDPNMappings(pairs);
460
- if (pairs.length) {
461
- for (const { pn, lid } of pairs) {
462
- await signalRepository.migrateSession(pn, lid);
463
- }
464
- }
465
- }
466
- }
467
- else if (content?.reactionMessage) {
468
- const reaction = {
469
- ...content.reactionMessage,
470
- key: message.key
471
- };
472
- ev.emit('messages.reaction', [
473
- {
474
- reaction,
475
- key: content.reactionMessage?.key
476
- }
477
- ]);
478
- }
479
- else if (content?.keepInChatMessage) {
480
- const kic = content.keepInChatMessage;
481
- if (kic.key) {
482
- ev.emit('messages.update', [
483
- {
484
- key: kic.key,
485
- update: { keepInChat: { keepType: kic.keepType, serverTimestamp: message.messageTimestamp, key: kic.key } }
486
- }
487
- ]);
488
- }
489
- }
490
- else if (content?.encReactionMessage) {
491
- ev.emit('messages.update', [
492
- {
493
- key: content.encReactionMessage.targetMessageKey,
494
- update: { encReactionMessage: content.encReactionMessage }
495
- }
496
- ]);
497
- }
498
- else if (content?.commentMessage) {
499
- if (content.commentMessage.targetMessageKey) {
500
- ev.emit('message.comment', {
501
- comment: content.commentMessage,
502
- commentKey: message.key,
503
- targetKey: content.commentMessage.targetMessageKey
504
- });
505
- }
506
- }
507
- else if (content?.encCommentMessage) {
508
- ev.emit('message.comment', {
509
- comment: content.encCommentMessage,
510
- commentKey: message.key,
511
- targetKey: content.encCommentMessage.targetMessageKey,
512
- encrypted: true
513
- });
514
- }
515
- else if (content?.bcallMessage) {
516
- ev.emit('call', [
517
- {
518
- id: content.bcallMessage.sessionId || message.key.id,
519
- from: message.key.participant || message.key.remoteJid,
520
- chatId: chat.id,
521
- isVideo: content.bcallMessage.mediaType === index_js_1.proto.Message.BCallMessage.MediaType.VIDEO,
522
- isBroadcast: true,
523
- caption: content.bcallMessage.caption
524
- }
525
- ]);
526
- }
527
- else if (content?.pollAddOptionMessage) {
528
- const pao = content.pollAddOptionMessage;
529
- if (pao.pollCreationMessageKey) {
530
- ev.emit('poll.add-option', {
531
- pollKey: pao.pollCreationMessageKey,
532
- addedOption: pao.addOption,
533
- addedBy: message.key.participant || message.key.remoteJid,
534
- messageKey: message.key
535
- });
536
- }
537
- }
538
- else if (content?.scheduledCallCreationMessage) {
539
- ev.emit('call.scheduled', {
540
- messageKey: message.key,
541
- scheduledCall: content.scheduledCallCreationMessage,
542
- chatId: chat.id
543
- });
544
- }
545
- else if (content?.scheduledCallEditMessage) {
546
- ev.emit('call.schedule-cancelled', {
547
- messageKey: message.key,
548
- editedCallKey: content.scheduledCallEditMessage.key,
549
- chatId: chat.id
550
- });
551
- }
552
- else if (content?.splitPaymentMessage) {
553
- ev.emit('payment.split', {
554
- messageKey: message.key,
555
- splitPayment: content.splitPaymentMessage,
556
- chatId: chat.id
557
- });
558
- }
559
- else if (content?.p2PPaymentReminderNotification) {
560
- ev.emit('payment.reminder', {
561
- messageKey: message.key,
562
- reminder: content.p2PPaymentReminderNotification,
563
- chatId: chat.id
564
- });
565
- }
566
- else if (content?.encEventResponseMessage) {
567
- const encEventResponse = content.encEventResponseMessage;
568
- const creationMsgKey = encEventResponse.eventCreationMessageKey;
569
- const eventMsg = await getMessage(creationMsgKey);
570
- if (eventMsg) {
571
- try {
572
- const meIdNormalised = (0, WABinary_1.jidNormalizedUser)(meId);
573
- const eventCreatorKey = creationMsgKey.participant || creationMsgKey.remoteJid;
574
- const eventCreatorPn = (0, WABinary_1.isLidUser)(eventCreatorKey)
575
- ? await signalRepository.lidMapping.getPNForLID(eventCreatorKey)
576
- : eventCreatorKey;
577
- const eventCreatorJid = (0, generics_1.getKeyAuthor)({ remoteJid: (0, WABinary_1.jidNormalizedUser)(eventCreatorPn), fromMe: meIdNormalised === eventCreatorPn }, meIdNormalised);
578
- const responderJid = (0, generics_1.getKeyAuthor)(message.key, meIdNormalised);
579
- const eventEncKey = eventMsg?.messageContextInfo?.messageSecret;
580
- if (!eventEncKey) {
581
- logger?.warn({ creationMsgKey }, 'event response: missing messageSecret for decryption');
582
- }
583
- else {
584
- const responseMsg = decryptEventResponse(encEventResponse, {
585
- eventEncKey,
586
- eventCreatorJid,
587
- eventMsgId: creationMsgKey.id,
588
- responderJid
589
- });
590
- const eventResponse = {
591
- eventResponseMessageKey: message.key,
592
- senderTimestampMs: responseMsg.timestampMs,
593
- response: responseMsg
594
- };
595
- ev.emit('messages.update', [
596
- {
597
- key: creationMsgKey,
598
- update: {
599
- eventResponses: [eventResponse]
600
- }
601
- }
602
- ]);
603
- }
604
- }
605
- catch (err) {
606
- logger?.warn({ err, creationMsgKey }, 'failed to decrypt event response');
607
- }
608
- }
609
- else {
610
- logger?.warn({ creationMsgKey }, 'event creation message not found, cannot decrypt response');
611
- }
612
- }
613
- else if (message.messageStubType) {
614
- const jid = message.key?.remoteJid;
615
- let participants;
616
- const emitParticipantsUpdate = action => ev.emit('group-participants.update', {
617
- id: jid,
618
- author: message.key.participant,
619
- authorPn: message.key.participantAlt,
620
- authorUsername: message.key.participantUsername,
621
- participants,
622
- action
623
- });
624
- const emitGroupUpdate = update => {
625
- ev.emit('groups.update', [
626
- {
627
- id: jid,
628
- ...update,
629
- author: message.key.participant ?? undefined,
630
- authorPn: message.key.participantAlt,
631
- authorUsername: message.key.participantUsername
632
- }
633
- ]);
634
- };
635
- const emitGroupRequestJoin = (participant, action, method) => {
636
- ev.emit('group.join-request', {
637
- id: jid,
638
- author: message.key.participant,
639
- authorPn: message.key.participantAlt,
640
- authorUsername: message.key.participantUsername,
641
- participant: participant.lid,
642
- participantPn: participant.pn,
643
- action,
644
- method: method
645
- });
646
- };
647
- const participantsIncludesMe = () => participants.find(jid => (0, WABinary_1.areJidsSameUser)(meId, jid.phoneNumber));
648
- switch (message.messageStubType) {
649
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_CHANGE_NUMBER:
650
- participants = message.messageStubParameters.map(a => JSON.parse(a)) || [];
651
- emitParticipantsUpdate('modify');
652
- break;
653
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LEAVE:
654
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_REMOVE:
655
- participants = message.messageStubParameters.map(a => JSON.parse(a)) || [];
656
- emitParticipantsUpdate('remove');
657
- if (participantsIncludesMe()) {
658
- chat.readOnly = true;
659
- }
660
- break;
661
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD:
662
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_INVITE:
663
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD_REQUEST_JOIN:
664
- participants = message.messageStubParameters.map(a => JSON.parse(a)) || [];
665
- if (participantsIncludesMe()) {
666
- chat.readOnly = false;
667
- }
668
- emitParticipantsUpdate('add');
669
- break;
670
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_DEMOTE:
671
- participants = message.messageStubParameters.map(a => JSON.parse(a)) || [];
672
- emitParticipantsUpdate('demote');
673
- break;
674
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_PROMOTE:
675
- participants = message.messageStubParameters.map(a => JSON.parse(a)) || [];
676
- emitParticipantsUpdate('promote');
677
- break;
678
- case Types_1.WAMessageStubType.GROUP_CHANGE_ANNOUNCE:
679
- const announceValue = message.messageStubParameters?.[0];
680
- emitGroupUpdate({ announce: announceValue === 'true' || announceValue === 'on' });
681
- break;
682
- case Types_1.WAMessageStubType.GROUP_CHANGE_RESTRICT:
683
- const restrictValue = message.messageStubParameters?.[0];
684
- emitGroupUpdate({ restrict: restrictValue === 'true' || restrictValue === 'on' });
685
- break;
686
- case Types_1.WAMessageStubType.GROUP_CHANGE_SUBJECT:
687
- const name = message.messageStubParameters?.[0];
688
- chat.name = name;
689
- emitGroupUpdate({ subject: name });
690
- break;
691
- case Types_1.WAMessageStubType.GROUP_CHANGE_DESCRIPTION:
692
- const description = message.messageStubParameters?.[0];
693
- chat.description = description;
694
- emitGroupUpdate({ desc: description });
695
- break;
696
- case Types_1.WAMessageStubType.GROUP_CHANGE_INVITE_LINK:
697
- const code = message.messageStubParameters?.[0];
698
- emitGroupUpdate({ inviteCode: code });
699
- break;
700
- case Types_1.WAMessageStubType.GROUP_MEMBER_ADD_MODE:
701
- const memberAddValue = message.messageStubParameters?.[0];
702
- emitGroupUpdate({ memberAddMode: memberAddValue === 'all_member_add' });
703
- break;
704
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_MODE:
705
- const approvalMode = message.messageStubParameters?.[0];
706
- emitGroupUpdate({ joinApprovalMode: approvalMode === 'on' });
707
- break;
708
- case Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD:
709
- const participant = JSON.parse(message.messageStubParameters?.[0]);
710
- const action = message.messageStubParameters?.[1];
711
- const method = message.messageStubParameters?.[2];
712
- emitGroupRequestJoin(participant, action, method);
713
- break;
714
- case Types_1.WAMessageStubType.GROUP_CREATE:
715
- emitGroupUpdate({ subject: message.messageStubParameters?.[0] });
716
- break;
717
- case Types_1.WAMessageStubType.GROUP_CHANGE_ICON:
718
- emitGroupUpdate({ pictureId: message.messageStubParameters?.[0] });
719
- break;
720
- case Types_1.WAMessageStubType.GROUP_DELETE:
721
- emitGroupUpdate({ readOnly: true, deleted: true });
722
- break;
723
- case Types_1.WAMessageStubType.GROUP_CREATING:
724
- emitGroupUpdate({ subject: message.messageStubParameters?.[0], creating: true });
725
- break;
726
- case Types_1.WAMessageStubType.GROUP_CREATE_FAILED:
727
- emitGroupUpdate({ createFailed: true });
728
- break;
729
- case Types_1.WAMessageStubType.GROUP_BOUNCED:
730
- emitGroupUpdate({ bounced: true });
731
- break;
732
- case Types_1.WAMessageStubType.CHANGE_EPHEMERAL_SETTING:
733
- const ephValue = message.messageStubParameters?.[0];
734
- emitGroupUpdate({ ephemeralDuration: ephValue ? +ephValue : 0 });
735
- break;
736
- case Types_1.WAMessageStubType.DISAPPEARING_MODE:
737
- const disappearingValue = message.messageStubParameters?.[0];
738
- emitGroupUpdate({ ephemeralDuration: disappearingValue ? +disappearingValue : 0 });
739
- break;
740
- case Types_1.WAMessageStubType.ADMIN_REVOKE:
741
- emitGroupUpdate({ adminRevoked: true, revokedBy: message.messageStubParameters?.[0] });
742
- break;
743
- case Types_1.WAMessageStubType.BLOCK_CONTACT:
744
- ev.emit('contacts.update', [{ id: jid, isBlocked: true }]);
745
- break;
746
- case Types_1.WAMessageStubType.CHANGE_USERNAME:
747
- ev.emit('contacts.update', [
748
- { id: message.key.participant || jid, username: message.messageStubParameters?.[0] }
749
- ]);
750
- break;
751
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_ACCEPT:
752
- participants =
753
- message.messageStubParameters?.map(a => {
754
- try {
755
- return JSON.parse(a);
756
- }
757
- catch {
758
- return a;
759
- }
760
- }) || [];
761
- emitParticipantsUpdate('accept');
762
- break;
763
- case Types_1.WAMessageStubType.GROUP_PARTICIPANT_LINKED_GROUP_JOIN:
764
- participants =
765
- message.messageStubParameters?.map(a => {
766
- try {
767
- return JSON.parse(a);
768
- }
769
- catch {
770
- return a;
771
- }
772
- }) || [];
773
- emitParticipantsUpdate('linked-group-join');
774
- break;
775
- case Types_1.WAMessageStubType.EPHEMERAL_KEEP_IN_CHAT:
776
- ev.emit('messages.update', [{ key: message.key, update: { keepInChat: true } }]);
777
- break;
778
- case Types_1.WAMessageStubType.PINNED_MESSAGE_IN_CHAT:
779
- ev.emit('messages.update', [
780
- {
781
- key: message.key,
782
- update: {
783
- pinInChat: {
784
- pinned: true,
785
- pinnedMessageKey: message.messageStubParameters?.[0]
786
- ? { id: message.messageStubParameters[0] }
787
- : undefined,
788
- senderTimestampMs: message.messageTimestamp
789
- ? (0, generics_1.toNumber)(message.messageTimestamp) * 1000
790
- : undefined
791
- }
792
- }
793
- }
794
- ]);
795
- break;
796
- case Types_1.WAMessageStubType.CHAT_PSA:
797
- ev.emit('chats.update', [{ id: jid, psa: { urlParams: message.messageStubParameters } }]);
798
- break;
799
- case Types_1.WAMessageStubType.CHAT_POLL_CREATION_MESSAGE:
800
- break;
801
- case Types_1.WAMessageStubType.BIZ_CHAT_ASSIGNMENT:
802
- ev.emit('chats.update', [
803
- {
804
- id: jid,
805
- bizAssignment: {
806
- assigned: true,
807
- assignee: message.messageStubParameters?.[0],
808
- agent: message.messageStubParameters?.[1]
809
- }
810
- }
811
- ]);
812
- break;
813
- case Types_1.WAMessageStubType.BIZ_CHAT_ASSIGNMENT_UNASSIGN:
814
- ev.emit('chats.update', [{ id: jid, bizAssignment: { assigned: false } }]);
815
- break;
816
- case Types_1.WAMessageStubType.SILENCED_UNKNOWN_CALLER_AUDIO:
817
- case Types_1.WAMessageStubType.SILENCED_UNKNOWN_CALLER_VIDEO:
818
- ev.emit('call', [
819
- {
820
- id: message.messageStubParameters?.[0] || message.key.id,
821
- from: jid,
822
- isVideo: message.messageStubType === Types_1.WAMessageStubType.SILENCED_UNKNOWN_CALLER_VIDEO,
823
- status: 'silenced',
824
- isUnknown: true,
825
- timestamp: (0, generics_1.toNumber)(message.messageTimestamp)
826
- }
827
- ]);
828
- break;
829
- case Types_1.WAMessageStubType.SCHEDULED_CALL_START_MESSAGE:
830
- ev.emit('call', [
831
- {
832
- id: message.messageStubParameters?.[0] || message.key.id,
833
- from: message.key.participant || jid,
834
- status: 'scheduled-start',
835
- timestamp: (0, generics_1.toNumber)(message.messageTimestamp)
836
- }
837
- ]);
838
- break;
839
- case Types_1.WAMessageStubType.SCHEDULED_CALL_CANCEL:
840
- ev.emit('call', [
841
- {
842
- id: message.messageStubParameters?.[0] || message.key.id,
843
- from: message.key.participant || jid,
844
- status: 'schedule-cancelled',
845
- timestamp: (0, generics_1.toNumber)(message.messageTimestamp)
846
- }
847
- ]);
848
- break;
849
- case Types_1.WAMessageStubType.COMMUNITY_CREATE:
850
- emitGroupUpdate({ isCommunity: true, subject: message.messageStubParameters?.[0] });
851
- break;
852
- case Types_1.WAMessageStubType.COMMUNITY_LINK_PARENT_GROUP:
853
- case Types_1.WAMessageStubType.COMMUNITY_LINK_PARENT_GROUP_RICH:
854
- emitGroupUpdate({ linkedParent: message.messageStubParameters?.[0] });
855
- break;
856
- case Types_1.WAMessageStubType.COMMUNITY_LINK_SUB_GROUP:
857
- case Types_1.WAMessageStubType.COMMUNITY_LINK_SIBLING_GROUP:
858
- emitGroupUpdate({ linkedSubGroup: message.messageStubParameters?.[0] });
859
- break;
860
- case Types_1.WAMessageStubType.COMMUNITY_UNLINK_PARENT_GROUP:
861
- emitGroupUpdate({ linkedParent: undefined });
862
- break;
863
- case Types_1.WAMessageStubType.COMMUNITY_UNLINK_SUB_GROUP:
864
- case Types_1.WAMessageStubType.COMMUNITY_UNLINK_SIBLING_GROUP:
865
- emitGroupUpdate({ unlinkedSubGroup: message.messageStubParameters?.[0] });
866
- break;
867
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_PROMOTE:
868
- participants =
869
- message.messageStubParameters?.map(a => {
870
- try {
871
- return JSON.parse(a);
872
- }
873
- catch {
874
- return a;
875
- }
876
- }) || [];
877
- emitParticipantsUpdate('promote');
878
- break;
879
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_DEMOTE:
880
- participants =
881
- message.messageStubParameters?.map(a => {
882
- try {
883
- return JSON.parse(a);
884
- }
885
- catch {
886
- return a;
887
- }
888
- }) || [];
889
- emitParticipantsUpdate('demote');
890
- break;
891
- case Types_1.WAMessageStubType.COMMUNITY_PARENT_GROUP_DELETED:
892
- emitGroupUpdate({ parentDeleted: true, readOnly: true });
893
- break;
894
- case Types_1.WAMessageStubType.COMMUNITY_PARENT_GROUP_SUBJECT_CHANGED:
895
- emitGroupUpdate({ parentSubject: message.messageStubParameters?.[0] });
896
- break;
897
- case Types_1.WAMessageStubType.COMMUNITY_LINK_PARENT_GROUP_MEMBERSHIP_APPROVAL:
898
- emitGroupUpdate({ linkedParentMembershipApproval: message.messageStubParameters?.[0] === 'true' });
899
- break;
900
- case Types_1.WAMessageStubType.COMMUNITY_INVITE_RICH:
901
- case Types_1.WAMessageStubType.COMMUNITY_INVITE_AUTO_ADD_RICH:
902
- participants =
903
- message.messageStubParameters?.map(a => {
904
- try {
905
- return JSON.parse(a);
906
- }
907
- catch {
908
- return a;
909
- }
910
- }) || [];
911
- emitParticipantsUpdate('add');
912
- break;
913
- case Types_1.WAMessageStubType.COMMUNITY_PARTICIPANT_ADD_RICH:
914
- participants =
915
- message.messageStubParameters?.map(a => {
916
- try {
917
- return JSON.parse(a);
918
- }
919
- catch {
920
- return a;
921
- }
922
- }) || [];
923
- emitParticipantsUpdate('add');
924
- break;
925
- case Types_1.WAMessageStubType.COMMUNITY_CHANGE_DESCRIPTION:
926
- const communityDesc = message.messageStubParameters?.[0];
927
- emitGroupUpdate({ desc: communityDesc });
928
- break;
929
- case Types_1.WAMessageStubType.COMMUNITY_ALLOW_MEMBER_ADDED_GROUPS:
930
- emitGroupUpdate({ communityMemberAddGroupMode: message.messageStubParameters?.[0] });
931
- break;
932
- case Types_1.WAMessageStubType.EMPTY_SUBGROUP_CREATE:
933
- emitGroupUpdate({ subject: message.messageStubParameters?.[0], isEmpty: true });
934
- break;
935
- case Types_1.WAMessageStubType.COMMUNITY_DEACTIVATE_SIBLING_GROUP:
936
- emitGroupUpdate({ deactivated: true, linkedSibling: message.messageStubParameters?.[0] });
937
- break;
938
- case Types_1.WAMessageStubType.COMMUNITY_OWNER_UPDATED:
939
- emitGroupUpdate({ owner: message.messageStubParameters?.[0] });
940
- break;
941
- case Types_1.WAMessageStubType.COMMUNITY_SUB_GROUP_VISIBILITY_HIDDEN:
942
- emitGroupUpdate({ hidden: true });
943
- break;
944
- }
945
- }
946
- if (Object.keys(chat).length > 1) {
947
- ev.emit('chats.update', [chat]);
948
- }
949
- };
950
- exports.default = processMessage;