@vanzxy/baileys 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (281) hide show
  1. package/NOTICE.md +111 -0
  2. package/README.md +830 -0
  3. package/WAProto/index.d.ts +9 -0
  4. package/WAProto/index.js +142036 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Defaults/index.d.ts +152 -0
  7. package/lib/Defaults/index.js +179 -0
  8. package/lib/Framework/Bot.js +209 -0
  9. package/lib/Framework/Context.js +90 -0
  10. package/lib/Framework/MediaManager.js +152 -0
  11. package/lib/Framework/SessionManager.js +34 -0
  12. package/lib/Framework/StatsManager.js +120 -0
  13. package/lib/Framework/Store/SQLiteStore.js +74 -0
  14. package/lib/Framework/index.js +11 -0
  15. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  16. package/lib/Signal/Group/ciphertext-message.js +12 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  18. package/lib/Signal/Group/group-session-builder.js +30 -0
  19. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  20. package/lib/Signal/Group/group_cipher.js +82 -0
  21. package/lib/Signal/Group/index.d.ts +11 -0
  22. package/lib/Signal/Group/index.js +12 -0
  23. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  24. package/lib/Signal/Group/keyhelper.js +18 -0
  25. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  26. package/lib/Signal/Group/sender-chain-key.js +26 -0
  27. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  28. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  29. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  30. package/lib/Signal/Group/sender-key-message.js +66 -0
  31. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  32. package/lib/Signal/Group/sender-key-name.js +48 -0
  33. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  34. package/lib/Signal/Group/sender-key-record.js +41 -0
  35. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  36. package/lib/Signal/Group/sender-key-state.js +84 -0
  37. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  38. package/lib/Signal/Group/sender-message-key.js +26 -0
  39. package/lib/Signal/libsignal.d.ts +54 -0
  40. package/lib/Signal/libsignal.js +431 -0
  41. package/lib/Signal/lid-mapping.d.ts +20 -0
  42. package/lib/Signal/lid-mapping.js +277 -0
  43. package/lib/Socket/Client/index.d.ts +2 -0
  44. package/lib/Socket/Client/index.js +3 -0
  45. package/lib/Socket/Client/types.d.ts +5 -0
  46. package/lib/Socket/Client/types.js +11 -0
  47. package/lib/Socket/Client/websocket.d.ts +12 -0
  48. package/lib/Socket/Client/websocket.js +54 -0
  49. package/lib/Socket/business.d.ts +395 -0
  50. package/lib/Socket/business.js +380 -0
  51. package/lib/Socket/chats.d.ts +136 -0
  52. package/lib/Socket/chats.js +1328 -0
  53. package/lib/Socket/communities.d.ts +561 -0
  54. package/lib/Socket/communities.js +434 -0
  55. package/lib/Socket/dugong.d.ts +117 -0
  56. package/lib/Socket/dugong.js +799 -0
  57. package/lib/Socket/groups.d.ts +285 -0
  58. package/lib/Socket/groups.js +355 -0
  59. package/lib/Socket/index.d.ts +531 -0
  60. package/lib/Socket/index.js +34 -0
  61. package/lib/Socket/messages-recv.d.ts +333 -0
  62. package/lib/Socket/messages-recv.js +1782 -0
  63. package/lib/Socket/messages-send.d.ts +329 -0
  64. package/lib/Socket/messages-send.js +1383 -0
  65. package/lib/Socket/mex.d.ts +1 -0
  66. package/lib/Socket/mex.js +42 -0
  67. package/lib/Socket/newsletter.d.ts +281 -0
  68. package/lib/Socket/newsletter.js +321 -0
  69. package/lib/Socket/socket.d.ts +60 -0
  70. package/lib/Socket/socket.js +1001 -0
  71. package/lib/Socket/username.js +153 -0
  72. package/lib/Store/index.d.ts +3 -0
  73. package/lib/Store/index.js +4 -0
  74. package/lib/Store/make-in-memory-store.d.ts +62 -0
  75. package/lib/Store/make-in-memory-store.js +429 -0
  76. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  77. package/lib/Store/make-ordered-dictionary.js +79 -0
  78. package/lib/Store/object-repository.d.ts +10 -0
  79. package/lib/Store/object-repository.js +24 -0
  80. package/lib/Types/Auth.d.ts +117 -0
  81. package/lib/Types/Auth.js +2 -0
  82. package/lib/Types/Bussines.d.ts +25 -0
  83. package/lib/Types/Bussines.js +2 -0
  84. package/lib/Types/Call.d.ts +15 -0
  85. package/lib/Types/Call.js +2 -0
  86. package/lib/Types/Chat.d.ts +124 -0
  87. package/lib/Types/Chat.js +8 -0
  88. package/lib/Types/Contact.d.ts +26 -0
  89. package/lib/Types/Contact.js +2 -0
  90. package/lib/Types/Events.d.ts +256 -0
  91. package/lib/Types/Events.js +2 -0
  92. package/lib/Types/GroupMetadata.d.ts +71 -0
  93. package/lib/Types/GroupMetadata.js +2 -0
  94. package/lib/Types/Label.d.ts +2 -0
  95. package/lib/Types/Label.js +25 -0
  96. package/lib/Types/LabelAssociation.d.ts +2 -0
  97. package/lib/Types/LabelAssociation.js +7 -0
  98. package/lib/Types/Message.d.ts +11 -0
  99. package/lib/Types/Message.js +18 -0
  100. package/lib/Types/Mex.d.ts +2 -0
  101. package/lib/Types/Mex.js +39 -0
  102. package/lib/Types/Product.d.ts +79 -0
  103. package/lib/Types/Product.js +2 -0
  104. package/lib/Types/RichType.d.ts +2 -0
  105. package/lib/Types/RichType.js +23 -0
  106. package/lib/Types/Signal.d.ts +87 -0
  107. package/lib/Types/Signal.js +2 -0
  108. package/lib/Types/Socket.d.ts +136 -0
  109. package/lib/Types/Socket.js +2 -0
  110. package/lib/Types/State.d.ts +5 -0
  111. package/lib/Types/State.js +56 -0
  112. package/lib/Types/USync.d.ts +26 -0
  113. package/lib/Types/USync.js +2 -0
  114. package/lib/Types/index.d.ts +66 -0
  115. package/lib/Types/index.js +26 -0
  116. package/lib/Utils/A2UI.js +277 -0
  117. package/lib/Utils/MessageBuilder.js +4405 -0
  118. package/lib/Utils/MessageBuilder_d.ts +411 -0
  119. package/lib/Utils/PersistentStore.js +592 -0
  120. package/lib/Utils/PersistentStore_d.ts +60 -0
  121. package/lib/Utils/anti-delete.d.ts +74 -0
  122. package/lib/Utils/anti-delete.js +222 -0
  123. package/lib/Utils/auth-utils.d.ts +57 -0
  124. package/lib/Utils/auth-utils.js +307 -0
  125. package/lib/Utils/auto-reply.d.ts +47 -0
  126. package/lib/Utils/auto-reply.js +158 -0
  127. package/lib/Utils/baileys-event-stream.d.ts +8 -0
  128. package/lib/Utils/baileys-event-stream.js +62 -0
  129. package/lib/Utils/browser-utils.d.ts +8 -0
  130. package/lib/Utils/browser-utils.js +28 -0
  131. package/lib/Utils/business.d.ts +49 -0
  132. package/lib/Utils/business.js +240 -0
  133. package/lib/Utils/button-helper-utils.js +314 -0
  134. package/lib/Utils/button-sender.js +824 -0
  135. package/lib/Utils/chat-control.d.ts +159 -0
  136. package/lib/Utils/chat-control.js +232 -0
  137. package/lib/Utils/chat-history-helpers.d.ts +21 -0
  138. package/lib/Utils/chat-history-helpers.js +71 -0
  139. package/lib/Utils/chat-utils.d.ts +407 -0
  140. package/lib/Utils/chat-utils.js +886 -0
  141. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  142. package/lib/Utils/companion-reg-client-utils.js +40 -0
  143. package/lib/Utils/crypto.d.ts +41 -0
  144. package/lib/Utils/crypto.js +148 -0
  145. package/lib/Utils/decode-wa-message.d.ts +83 -0
  146. package/lib/Utils/decode-wa-message.js +317 -0
  147. package/lib/Utils/event-buffer.d.ts +12 -0
  148. package/lib/Utils/event-buffer.js +636 -0
  149. package/lib/Utils/generics.d.ts +69 -0
  150. package/lib/Utils/generics.js +439 -0
  151. package/lib/Utils/history.d.ts +90 -0
  152. package/lib/Utils/history.js +147 -0
  153. package/lib/Utils/identity-change-handler.d.ts +13 -0
  154. package/lib/Utils/identity-change-handler.js +50 -0
  155. package/lib/Utils/index.d.ts +39 -0
  156. package/lib/Utils/index.js +46 -0
  157. package/lib/Utils/link-preview.d.ts +12 -0
  158. package/lib/Utils/link-preview.js +85 -0
  159. package/lib/Utils/logger.d.ts +2 -0
  160. package/lib/Utils/logger.js +3 -0
  161. package/lib/Utils/lt-hash.d.ts +12 -0
  162. package/lib/Utils/lt-hash.js +27 -0
  163. package/lib/Utils/make-mutex.d.ts +6 -0
  164. package/lib/Utils/make-mutex.js +33 -0
  165. package/lib/Utils/media-messages.d.ts +18 -0
  166. package/lib/Utils/media-messages.js +71 -0
  167. package/lib/Utils/media-set.d.ts +13 -0
  168. package/lib/Utils/media-set.js +172 -0
  169. package/lib/Utils/message-kind.js +139 -0
  170. package/lib/Utils/message-retry-manager.d.ts +79 -0
  171. package/lib/Utils/message-retry-manager.js +265 -0
  172. package/lib/Utils/message-search.d.ts +44 -0
  173. package/lib/Utils/message-search.js +189 -0
  174. package/lib/Utils/messages-media.d.ts +135 -0
  175. package/lib/Utils/messages-media.js +869 -0
  176. package/lib/Utils/messages.d.ts +44 -0
  177. package/lib/Utils/messages.js +2155 -0
  178. package/lib/Utils/noise-handler.d.ts +20 -0
  179. package/lib/Utils/noise-handler.js +201 -0
  180. package/lib/Utils/offline-node-processor.d.ts +9 -0
  181. package/lib/Utils/offline-node-processor.js +40 -0
  182. package/lib/Utils/past-participants.d.ts +14 -0
  183. package/lib/Utils/past-participants.js +40 -0
  184. package/lib/Utils/pre-key-manager.d.ts +25 -0
  185. package/lib/Utils/pre-key-manager.js +106 -0
  186. package/lib/Utils/process-message.d.ts +82 -0
  187. package/lib/Utils/process-message.js +809 -0
  188. package/lib/Utils/reporting-utils.d.ts +12 -0
  189. package/lib/Utils/reporting-utils.js +258 -0
  190. package/lib/Utils/rich-message-utils.d.ts +48 -0
  191. package/lib/Utils/rich-message-utils.js +445 -0
  192. package/lib/Utils/scheduling.d.ts +42 -0
  193. package/lib/Utils/scheduling.js +140 -0
  194. package/lib/Utils/signal.d.ts +82 -0
  195. package/lib/Utils/signal.js +201 -0
  196. package/lib/Utils/stanza-ack.d.ts +16 -0
  197. package/lib/Utils/stanza-ack.js +38 -0
  198. package/lib/Utils/status.d.ts +50 -0
  199. package/lib/Utils/status.js +108 -0
  200. package/lib/Utils/stickerpack.d.ts +51 -0
  201. package/lib/Utils/stickerpack.js +275 -0
  202. package/lib/Utils/sync-action-utils.d.ts +2 -0
  203. package/lib/Utils/sync-action-utils.js +49 -0
  204. package/lib/Utils/tc-token-utils.d.ts +29 -0
  205. package/lib/Utils/tc-token-utils.js +163 -0
  206. package/lib/Utils/templates.d.ts +76 -0
  207. package/lib/Utils/templates.js +151 -0
  208. package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
  209. package/lib/Utils/use-cache-manager-auth-state.js +82 -0
  210. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  211. package/lib/Utils/use-multi-file-auth-state.js +167 -0
  212. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  213. package/lib/Utils/use-single-file-auth-state.js +114 -0
  214. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  215. package/lib/Utils/use-sqlite-auth-state.js +170 -0
  216. package/lib/Utils/validate-connection.d.ts +42 -0
  217. package/lib/Utils/validate-connection.js +199 -0
  218. package/lib/Utils/vcard.d.ts +58 -0
  219. package/lib/Utils/vcard.js +105 -0
  220. package/lib/VoIP/audio-feeder.d.ts +15 -0
  221. package/lib/VoIP/audio-feeder.js +132 -0
  222. package/lib/VoIP/index.js +277 -0
  223. package/lib/VoIP/relay-transport.d.ts +43 -0
  224. package/lib/VoIP/relay-transport.js +559 -0
  225. package/lib/VoIP/signaling.js +624 -0
  226. package/lib/VoIP/types.d.ts +69 -0
  227. package/lib/VoIP/types.js +17 -0
  228. package/lib/VoIP/wasm-engine.d.ts +103 -0
  229. package/lib/VoIP/wasm-engine.js +1214 -0
  230. package/lib/VoIP/worker-bootstrap.js +1042 -0
  231. package/lib/WABinary/constants.d.ts +61 -0
  232. package/lib/WABinary/constants.js +1467 -0
  233. package/lib/WABinary/decode.d.ts +9 -0
  234. package/lib/WABinary/decode.js +262 -0
  235. package/lib/WABinary/encode.d.ts +2 -0
  236. package/lib/WABinary/encode.js +220 -0
  237. package/lib/WABinary/generic-utils.d.ts +74 -0
  238. package/lib/WABinary/generic-utils.js +277 -0
  239. package/lib/WABinary/index.d.ts +5 -0
  240. package/lib/WABinary/index.js +6 -0
  241. package/lib/WABinary/jid-utils.d.ts +28 -0
  242. package/lib/WABinary/jid-utils.js +96 -0
  243. package/lib/WABinary/types.d.ts +19 -0
  244. package/lib/WABinary/types.js +2 -0
  245. package/lib/WAM/BinaryInfo.d.ts +7 -0
  246. package/lib/WAM/BinaryInfo.js +10 -0
  247. package/lib/WAM/constants.d.ts +34926 -0
  248. package/lib/WAM/constants.js +22853 -0
  249. package/lib/WAM/encode.d.ts +1 -0
  250. package/lib/WAM/encode.js +150 -0
  251. package/lib/WAM/index.d.ts +3 -0
  252. package/lib/WAM/index.js +4 -0
  253. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  254. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  255. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  256. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +63 -0
  257. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  258. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  259. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  260. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  261. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  262. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  263. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  264. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  265. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  266. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  267. package/lib/WAUSync/Protocols/index.d.ts +7 -0
  268. package/lib/WAUSync/Protocols/index.js +8 -0
  269. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  270. package/lib/WAUSync/USyncQuery.js +122 -0
  271. package/lib/WAUSync/USyncUser.d.ts +16 -0
  272. package/lib/WAUSync/USyncUser.js +31 -0
  273. package/lib/WAUSync/index.d.ts +3 -0
  274. package/lib/WAUSync/index.js +4 -0
  275. package/lib/assets/wasm/loader.js +5 -0
  276. package/lib/assets/wasm/whatsapp.wasm +0 -0
  277. package/lib/assets/wasm/worker-modules.js +273 -0
  278. package/lib/index.d.ts +12 -0
  279. package/lib/index.js +20 -0
  280. package/package.json +175 -0
  281. package/postinstall-banner.js +56 -0
@@ -0,0 +1,147 @@
1
+ import { pipeline } from 'stream/promises';
2
+ import { promisify } from 'util';
3
+ import { createInflate, inflate } from 'zlib';
4
+ import { proto } from '../../WAProto/index.js';
5
+ import { WAMessageStubType } from '../Types/index.js';
6
+ import { isHostedLidUser, isHostedPnUser, isLidUser, isPnUser } from '../WABinary/index.js';
7
+ import { toNumber } from './generics.js';
8
+ import { normalizeMessageContent } from './messages.js';
9
+ import { downloadContentFromMessage } from './messages-media.js';
10
+ const inflatePromise = promisify(inflate);
11
+ const extractPnFromMessages = (messages) => {
12
+ for (const msgItem of messages) {
13
+ const message = msgItem.message;
14
+ // Only extract from outgoing messages (fromMe: true) in 1:1 chats
15
+ // because userReceipt.userJid is the recipient's JID
16
+ if (!message?.key?.fromMe || !message.userReceipt?.length) {
17
+ continue;
18
+ }
19
+ const userJid = message.userReceipt[0]?.userJid;
20
+ if (userJid && (isPnUser(userJid) || isHostedPnUser(userJid))) {
21
+ return userJid;
22
+ }
23
+ }
24
+ return undefined;
25
+ };
26
+ export const downloadHistory = async (msg, options) => {
27
+ const stream = await downloadContentFromMessage(msg, 'md-msg-hist', { options });
28
+ // Pipe decrypted stream directly through zlib inflate
29
+ // This avoids allocating an intermediate buffer for the compressed data
30
+ const inflater = createInflate();
31
+ const chunks = [];
32
+ inflater.on('data', (chunk) => chunks.push(chunk));
33
+ await pipeline(stream, inflater);
34
+ const buffer = Buffer.concat(chunks);
35
+ const syncData = proto.HistorySync.decode(buffer);
36
+ return syncData;
37
+ };
38
+ export const processHistoryMessage = (item, logger) => {
39
+ const messages = [];
40
+ const contacts = [];
41
+ const chats = [];
42
+ const lidPnMappings = [];
43
+
44
+ // Vanz@Fix (bug 56): validate sync message before processing
45
+ // Ensure required fields are present and valid
46
+ if (!item || typeof item !== 'object') {
47
+ logger?.warn('invalid history sync message: null or not object');
48
+ return { messages, contacts, chats, lidPnMappings };
49
+ }
50
+
51
+ if (!item.syncType) {
52
+ logger?.warn('invalid history sync message: missing syncType');
53
+ return { messages, contacts, chats, lidPnMappings };
54
+ }
55
+
56
+ logger?.trace({ progress: item.progress }, 'processing history of type ' + item.syncType?.toString());
57
+ // Extract LID-PN mappings for all sync types
58
+ for (const m of item.phoneNumberToLidMappings || []) {
59
+ if (m.lidJid && m.pnJid) {
60
+ lidPnMappings.push({ lid: m.lidJid, pn: m.pnJid });
61
+ }
62
+ }
63
+ switch (item.syncType) {
64
+ case proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP:
65
+ case proto.HistorySync.HistorySyncType.RECENT:
66
+ case proto.HistorySync.HistorySyncType.FULL:
67
+ case proto.HistorySync.HistorySyncType.ON_DEMAND:
68
+ for (const chat of item.conversations) {
69
+ contacts.push({
70
+ id: chat.id,
71
+ name: chat.displayName || chat.name || chat.username || undefined,
72
+ username: chat.username || undefined,
73
+ lid: chat.lidJid || chat.accountLid || undefined,
74
+ phoneNumber: chat.pnJid || undefined
75
+ });
76
+ const chatId = chat.id;
77
+ const isLid = isLidUser(chatId) || isHostedLidUser(chatId);
78
+ const isPn = isPnUser(chatId) || isHostedPnUser(chatId);
79
+ if (isLid && chat.pnJid) {
80
+ lidPnMappings.push({ lid: chatId, pn: chat.pnJid });
81
+ }
82
+ else if (isPn && chat.lidJid) {
83
+ lidPnMappings.push({ lid: chat.lidJid, pn: chatId });
84
+ }
85
+ else if (isLid && !chat.pnJid) {
86
+ // Fallback: extract PN from userReceipt in messages when pnJid is missing
87
+ const pnFromReceipt = extractPnFromMessages(chat.messages || []);
88
+ if (pnFromReceipt) {
89
+ lidPnMappings.push({ lid: chatId, pn: pnFromReceipt });
90
+ }
91
+ }
92
+ const msgs = chat.messages || [];
93
+ delete chat.messages;
94
+ for (const item of msgs) {
95
+ const message = item.message;
96
+ messages.push(message);
97
+ if (!chat.messages?.length) {
98
+ // keep only the most recent message in the chat array
99
+ chat.messages = [{ message }];
100
+ }
101
+ if (!message.key.fromMe && !chat.lastMessageRecvTimestamp) {
102
+ chat.lastMessageRecvTimestamp = toNumber(message.messageTimestamp);
103
+ }
104
+ if ((message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_BSP ||
105
+ message.messageStubType === WAMessageStubType.BIZ_PRIVACY_MODE_TO_FB) &&
106
+ message.messageStubParameters?.[0]) {
107
+ contacts.push({
108
+ id: message.key.participant || message.key.remoteJid,
109
+ verifiedName: message.messageStubParameters?.[0]
110
+ });
111
+ }
112
+ }
113
+ chats.push(chat);
114
+ }
115
+ break;
116
+ case proto.HistorySync.HistorySyncType.PUSH_NAME:
117
+ for (const c of item.pushnames) {
118
+ contacts.push({ id: c.id, notify: c.pushname });
119
+ }
120
+ break;
121
+ }
122
+ return {
123
+ chats,
124
+ contacts,
125
+ messages,
126
+ lidPnMappings,
127
+ pastParticipants: item.pastParticipants,
128
+ syncType: item.syncType,
129
+ progress: item.progress
130
+ };
131
+ };
132
+ export const downloadAndProcessHistorySyncNotification = async (msg, options, logger) => {
133
+ let historyMsg;
134
+ if (msg.initialHistBootstrapInlinePayload) {
135
+ historyMsg = proto.HistorySync.decode(await inflatePromise(msg.initialHistBootstrapInlinePayload));
136
+ }
137
+ else {
138
+ historyMsg = await downloadHistory(msg, options);
139
+ }
140
+ return processHistoryMessage(historyMsg, logger);
141
+ };
142
+ export const getHistoryMsg = (message) => {
143
+ const normalizedContent = !!message ? normalizeMessageContent(message) : undefined;
144
+ const anyHistoryMsg = normalizedContent?.protocolMessage?.historySyncNotification;
145
+ return anyHistoryMsg;
146
+ };
147
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1,13 @@
1
+ export function handleIdentityChange(node: any, ctx: any): Promise<{
2
+ action: string;
3
+ device?: undefined;
4
+ error?: undefined;
5
+ } | {
6
+ action: string;
7
+ device: number;
8
+ error?: undefined;
9
+ } | {
10
+ action: string;
11
+ error: unknown;
12
+ device?: undefined;
13
+ }>;
@@ -0,0 +1,50 @@
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { areJidsSameUser, getBinaryNodeChild, jidDecode } from '../WABinary/index.js';
3
+ import { isStringNullOrEmpty } from './generics.js';
4
+ export async function handleIdentityChange(node, ctx) {
5
+ const from = node.attrs.from;
6
+ if (!from) {
7
+ return { action: 'invalid_notification' };
8
+ }
9
+ const identityNode = getBinaryNodeChild(node, 'identity');
10
+ if (!identityNode) {
11
+ return { action: 'no_identity_node' };
12
+ }
13
+ ctx.logger.info({ jid: from }, 'identity changed');
14
+ const decoded = jidDecode(from);
15
+ if (decoded?.device && decoded.device !== 0) {
16
+ ctx.logger.debug({ jid: from, device: decoded.device }, 'ignoring identity change from companion device');
17
+ return { action: 'skipped_companion_device', device: decoded.device };
18
+ }
19
+ const isSelfPrimary = ctx.meId && (areJidsSameUser(from, ctx.meId) || (ctx.meLid && areJidsSameUser(from, ctx.meLid)));
20
+ if (isSelfPrimary) {
21
+ ctx.logger.info({ jid: from }, 'self primary identity changed');
22
+ return { action: 'skipped_self_primary' };
23
+ }
24
+ if (ctx.debounceCache.get(from)) {
25
+ ctx.logger.debug({ jid: from }, 'skipping identity assert (debounced)');
26
+ return { action: 'debounced' };
27
+ }
28
+ ctx.debounceCache.set(from, true);
29
+ const isOfflineNotification = !isStringNullOrEmpty(node.attrs.offline);
30
+ const hasExistingSession = await ctx.validateSession(from);
31
+ if (!hasExistingSession.exists) {
32
+ ctx.logger.debug({ jid: from }, 'no old session, skipping session refresh');
33
+ return { action: 'skipped_no_session' };
34
+ }
35
+ ctx.logger.debug({ jid: from }, 'old session exists, will refresh session');
36
+ if (isOfflineNotification) {
37
+ ctx.logger.debug({ jid: from }, 'skipping session refresh during offline processing');
38
+ return { action: 'skipped_offline' };
39
+ }
40
+ ctx.onBeforeSessionRefresh?.(from);
41
+ try {
42
+ await ctx.assertSessions([from], true);
43
+ return { action: 'session_refreshed' };
44
+ }
45
+ catch (error) {
46
+ ctx.logger.warn({ error, jid: from }, 'failed to assert sessions after identity change');
47
+ return { action: 'session_refresh_failed', error };
48
+ }
49
+ }
50
+ //# sourceMappingURL=identity-change-handler.js.map
@@ -0,0 +1,39 @@
1
+ export * from "./generics.js";
2
+ export * from "./decode-wa-message.js";
3
+ export * from "./messages.js";
4
+ export * from "./messages-media.js";
5
+ export * from "./validate-connection.js";
6
+ export * from "./crypto.js";
7
+ export * from "./signal.js";
8
+ export * from "./noise-handler.js";
9
+ export * from "./history.js";
10
+ export * from "./chat-utils.js";
11
+ export * from "./lt-hash.js";
12
+ export * from "./auth-utils.js";
13
+ export * from "./use-multi-file-auth-state.js";
14
+ export * from "./use-single-file-auth-state.js";
15
+ export * from "./use-sqlite-auth-state.js";
16
+ export * from "./link-preview.js";
17
+ export * from "./event-buffer.js";
18
+ export * from "./process-message.js";
19
+ export * from "./rich-message-utils.js";
20
+ export * from "./message-retry-manager.js";
21
+ export * from "./browser-utils.js";
22
+ export * from "./companion-reg-client-utils.js";
23
+ export * from "./identity-change-handler.js";
24
+ export * from "./stanza-ack.js";
25
+ export * from "./anti-delete.js";
26
+ export * from "./message-search.js";
27
+ export * from "./chat-history-helpers.js";
28
+ export * from "./scheduling.js";
29
+ export * from "./auto-reply.js";
30
+ export * from "./templates.js";
31
+ export * from "./vcard.js";
32
+ export * from "./media-messages.js";
33
+ export * from "./stickerpack.js";
34
+ export * from "./media-set.js";
35
+ export * from "./status.js";
36
+ export * from "./use-cache-manager-auth-state.js";
37
+ export * from "./baileys-event-stream.js";
38
+ export * from "./past-participants.js";
39
+ export * from "./chat-control.js";
@@ -0,0 +1,46 @@
1
+ export * from './generics.js';
2
+ export * from './decode-wa-message.js';
3
+ export * from './messages.js';
4
+ export * from './messages-media.js';
5
+ export * from './validate-connection.js';
6
+ export * from './crypto.js';
7
+ export * from './signal.js';
8
+ export * from './noise-handler.js';
9
+ export * from './history.js';
10
+ export * from './chat-utils.js';
11
+ export * from './lt-hash.js';
12
+ export * from './auth-utils.js';
13
+ export * from './use-multi-file-auth-state.js';
14
+ export * from './use-single-file-auth-state.js';
15
+ export * from './use-sqlite-auth-state.js';
16
+ export * from './link-preview.js';
17
+ export * from './event-buffer.js';
18
+ export * from './process-message.js';
19
+ export * from './rich-message-utils.js';
20
+ export * from './MessageBuilder.js';
21
+ export * from './A2UI.js';
22
+ export * from './PersistentStore.js';
23
+ export * from './message-kind.js';
24
+ export * from './message-retry-manager.js';
25
+ export * from './browser-utils.js';
26
+ export * from './companion-reg-client-utils.js';
27
+ export * from './identity-change-handler.js';
28
+ export * from './stanza-ack.js';
29
+ export * from './button-helper-utils.js';
30
+ export * from './button-sender.js';
31
+ export * from './anti-delete.js';
32
+ export * from './message-search.js';
33
+ export * from './chat-history-helpers.js';
34
+ export * from './scheduling.js';
35
+ export * from './auto-reply.js';
36
+ export * from './templates.js';
37
+ export * from './vcard.js';
38
+ export * from './media-messages.js';
39
+ export * from './stickerpack.js';
40
+ export * from './media-set.js';
41
+ export * from './status.js';
42
+ export * from './use-cache-manager-auth-state.js';
43
+ export * from './baileys-event-stream.js';
44
+ export * from './past-participants.js';
45
+ export * from './chat-control.js';
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,12 @@
1
+ export function getUrlInfo(text: any, opts?: {
2
+ thumbnailWidth: number;
3
+ fetchOpts: {
4
+ timeout: number;
5
+ };
6
+ }): Promise<{
7
+ 'canonical-url': any;
8
+ 'matched-text': any;
9
+ title: any;
10
+ description: any;
11
+ originalThumbnailUrl: any;
12
+ } | undefined>;
@@ -0,0 +1,85 @@
1
+ import { prepareWAMessageMedia } from './messages.js';
2
+ import { extractImageThumb, getHttpStream } from './messages-media.js';
3
+ const THUMBNAIL_WIDTH_PX = 192;
4
+ /** Fetches an image and generates a thumbnail for it */
5
+ const getCompressedJpegThumbnail = async (url, { thumbnailWidth, fetchOpts }) => {
6
+ const stream = await getHttpStream(url, fetchOpts);
7
+ const result = await extractImageThumb(stream, thumbnailWidth);
8
+ return result;
9
+ };
10
+ /**
11
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
12
+ * Return undefined if the fetch failed or no URL was found
13
+ * @param text first matched URL in text
14
+ * @returns the URL info required to generate link preview
15
+ */
16
+ export const getUrlInfo = async (text, opts = {
17
+ thumbnailWidth: THUMBNAIL_WIDTH_PX,
18
+ fetchOpts: { timeout: 3000 }
19
+ }) => {
20
+ try {
21
+ // retries
22
+ let retries = 0;
23
+ const maxRetry = 5;
24
+ const { getLinkPreview } = await import('link-preview-js');
25
+ let previewLink = text;
26
+ if (!text.startsWith('https://') && !text.startsWith('http://')) {
27
+ previewLink = 'https://' + previewLink;
28
+ }
29
+ const info = await getLinkPreview(previewLink, {
30
+ ...opts.fetchOpts,
31
+ followRedirects: 'follow',
32
+ handleRedirects: (baseURL, forwardedURL) => {
33
+ const urlObj = new URL(baseURL);
34
+ const forwardedURLObj = new URL(forwardedURL);
35
+ if (retries >= maxRetry) {
36
+ return false;
37
+ }
38
+ if (forwardedURLObj.hostname === urlObj.hostname ||
39
+ forwardedURLObj.hostname === 'www.' + urlObj.hostname ||
40
+ 'www.' + forwardedURLObj.hostname === urlObj.hostname) {
41
+ retries += 1;
42
+ return true;
43
+ }
44
+ else {
45
+ return false;
46
+ }
47
+ },
48
+ headers: opts.fetchOpts?.headers
49
+ });
50
+ if (info && 'title' in info && info.title) {
51
+ const [image] = info.images;
52
+ const urlInfo = {
53
+ 'canonical-url': info.url,
54
+ 'matched-text': text,
55
+ title: info.title,
56
+ description: info.description,
57
+ originalThumbnailUrl: image
58
+ };
59
+ if (opts.uploadImage) {
60
+ const { imageMessage } = await prepareWAMessageMedia({ image: { url: image } }, {
61
+ upload: opts.uploadImage,
62
+ mediaTypeOverride: 'thumbnail-link',
63
+ options: opts.fetchOpts
64
+ });
65
+ urlInfo.jpegThumbnail = imageMessage?.jpegThumbnail ? Buffer.from(imageMessage.jpegThumbnail) : undefined;
66
+ urlInfo.highQualityThumbnail = imageMessage || undefined;
67
+ }
68
+ else {
69
+ try {
70
+ urlInfo.jpegThumbnail = image ? (await getCompressedJpegThumbnail(image, opts)).buffer : undefined;
71
+ }
72
+ catch (error) {
73
+ opts.logger?.debug({ err: error.stack, url: previewLink }, 'error in generating thumbnail');
74
+ }
75
+ }
76
+ return urlInfo;
77
+ }
78
+ }
79
+ catch (error) {
80
+ if (!error.message.includes('receive a valid')) {
81
+ throw error;
82
+ }
83
+ }
84
+ };
85
+ //# sourceMappingURL=link-preview.js.map
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import P from 'pino';
2
+ export default P({ timestamp: () => `,"time":"${new Date().toJSON()}"` });
3
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
3
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
4
+ * if the same series of mutations was made sequentially.
5
+ *
6
+ * Vanz@Fix (bug 36 follow-up): whatsapp-rust-bridge is a native module and was previously
7
+ * statically imported here, which crashed the *entire* library at import time on platforms
8
+ * without a prebuilt binary (ARM musl/Alpine/Termux/some Pterodactyl nodes) — even for bots
9
+ * that never touch app-state sync. Same top-level-await try/catch pattern as crypto.js:
10
+ * only throws (with a clear message) if app-state sync (LT hash) is actually used.
11
+ */
12
+ export let LT_HASH_ANTI_TAMPERING: any;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
3
+ * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
4
+ * if the same series of mutations was made sequentially.
5
+ *
6
+ * Vanz@Fix (bug 36 follow-up): whatsapp-rust-bridge is a native module and was previously
7
+ * statically imported here, which crashed the *entire* library at import time on platforms
8
+ * without a prebuilt binary (ARM musl/Alpine/Termux/some Pterodactyl nodes) — even for bots
9
+ * that never touch app-state sync. Same top-level-await try/catch pattern as crypto.js:
10
+ * only throws (with a clear message) if app-state sync (LT hash) is actually used.
11
+ */
12
+ let LT_HASH_ANTI_TAMPERING;
13
+ try {
14
+ const { LTHashAntiTampering } = await import('whatsapp-rust-bridge');
15
+ LT_HASH_ANTI_TAMPERING = new LTHashAntiTampering();
16
+ }
17
+ catch (err) {
18
+ const message = '`whatsapp-rust-bridge` failed to load (no prebuilt binary for this platform/arch). ' +
19
+ 'App-state sync (LT hash) is unavailable here. Original error: ' + (err?.message || err);
20
+ LT_HASH_ANTI_TAMPERING = new Proxy({}, {
21
+ get() {
22
+ throw new Error(message);
23
+ }
24
+ });
25
+ }
26
+ export { LT_HASH_ANTI_TAMPERING };
27
+ //# sourceMappingURL=lt-hash.js.map
@@ -0,0 +1,6 @@
1
+ export function makeMutex(): {
2
+ mutex(code: any): any;
3
+ };
4
+ export function makeKeyedMutex(): {
5
+ mutex(key: any, task: any): Promise<any>;
6
+ };
@@ -0,0 +1,33 @@
1
+ import { Mutex as AsyncMutex } from 'async-mutex';
2
+ export const makeMutex = () => {
3
+ const mutex = new AsyncMutex();
4
+ return {
5
+ mutex(code) {
6
+ return mutex.runExclusive(code);
7
+ }
8
+ };
9
+ };
10
+ export const makeKeyedMutex = () => {
11
+ const map = new Map();
12
+ return {
13
+ async mutex(key, task) {
14
+ let entry = map.get(key);
15
+ if (!entry) {
16
+ entry = { mutex: new AsyncMutex(), refCount: 0 };
17
+ map.set(key, entry);
18
+ }
19
+ entry.refCount++;
20
+ try {
21
+ return await entry.mutex.runExclusive(task);
22
+ }
23
+ finally {
24
+ entry.refCount--;
25
+ // only delete it if this is still the current entry
26
+ if (entry.refCount === 0 && map.get(key) === entry) {
27
+ map.delete(key);
28
+ }
29
+ }
30
+ }
31
+ };
32
+ };
33
+ //# sourceMappingURL=make-mutex.js.map
@@ -0,0 +1,18 @@
1
+ import type { WAMediaUpload } from '../Types/index.js';
2
+ export declare const generateProfilePictureFull: (img: Buffer | string) => Promise<{
3
+ img: Buffer;
4
+ }>;
5
+ export declare const changeprofileFull: (img: Buffer | string) => Promise<{
6
+ img: Buffer;
7
+ }>;
8
+ export declare const generateProfilePictureFP: (buffer: Buffer | string) => Promise<{
9
+ img: Buffer;
10
+ preview: Buffer;
11
+ }>;
12
+ export declare const generatePP: (buffer: Buffer | string) => Promise<{
13
+ img: Buffer;
14
+ preview: Buffer;
15
+ }>;
16
+ export declare const generateProfilePicturee: (mediaUpload: WAMediaUpload) => Promise<{
17
+ img: Buffer;
18
+ }>;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Vanz@Add --- ported from Bail-master addons/media-messages.ts.
3
+ * Jimp-based profile-picture image generators (square + panoramic/wide).
4
+ * Deduplicated aliases kept intact: generateProfilePictureFull ===
5
+ * changeprofileFull, generateProfilePictureFP === generatePP (source had
6
+ * these as byte-identical pairs under different names).
7
+ */
8
+ import { Jimp, JimpMime } from 'jimp';
9
+ const toBuffer = async (stream) => {
10
+ const chunks = [];
11
+ for await (const chunk of stream) {
12
+ chunks.push(chunk);
13
+ }
14
+ stream.destroy?.();
15
+ return Buffer.concat(chunks);
16
+ };
17
+ /**
18
+ * Generates a panoramic/wide profile picture buffer — landscape images are
19
+ * scaled down to a 720px-wide target, portrait images to a 324px-wide
20
+ * target, preserving aspect ratio throughout.
21
+ */
22
+ const generateWideProfilePicture = async (img) => {
23
+ const jimp = await Jimp.read(img);
24
+ const width = jimp.bitmap.width;
25
+ const height = jimp.bitmap.height;
26
+ const ratio = width > height ? width / 720 : width / 324;
27
+ const targetWidth = Math.round(width / ratio);
28
+ const targetHeight = Math.round(height / ratio);
29
+ const buffer = await jimp.resize({ w: targetWidth, h: targetHeight }).getBuffer(JimpMime.jpeg, { quality: 100 });
30
+ return { img: buffer };
31
+ };
32
+ export const generateProfilePictureFull = generateWideProfilePicture;
33
+ export const changeprofileFull = generateWideProfilePicture;
34
+ /**
35
+ * Generates a square profile picture buffer (main image, scaled to fit
36
+ * within 720x720) plus a normalized preview buffer.
37
+ */
38
+ const generateSquareProfilePicture = async (buffer) => {
39
+ const jimp = await Jimp.read(buffer);
40
+ const img = await jimp.clone().scaleToFit({ w: 720, h: 720 }).getBuffer(JimpMime.jpeg);
41
+ const preview = await jimp.clone().normalize().getBuffer(JimpMime.jpeg);
42
+ return { img, preview };
43
+ };
44
+ export const generateProfilePictureFP = generateSquareProfilePicture;
45
+ export const generatePP = generateSquareProfilePicture;
46
+ /**
47
+ * Generates a profile picture buffer from a flexible input source — a raw
48
+ * Buffer, a `{ url }` media-upload descriptor, or a `{ stream }`
49
+ * media-upload descriptor. Resizes the longer dimension down to 720px,
50
+ * preserving aspect ratio on the other.
51
+ */
52
+ export const generateProfilePicturee = async (mediaUpload) => {
53
+ let bufferOrFilePath;
54
+ if (Buffer.isBuffer(mediaUpload)) {
55
+ bufferOrFilePath = mediaUpload;
56
+ }
57
+ else if ('url' in mediaUpload) {
58
+ bufferOrFilePath = mediaUpload.url.toString();
59
+ }
60
+ else {
61
+ bufferOrFilePath = await toBuffer(mediaUpload.stream);
62
+ }
63
+ const jimp = await Jimp.read(bufferOrFilePath);
64
+ const { width, height } = jimp.bitmap;
65
+ const resized = width > height
66
+ ? jimp.resize({ w: 720, h: Math.round((height / width) * 720) })
67
+ : jimp.resize({ w: Math.round((width / height) * 720), h: 720 });
68
+ const img = await resized.getBuffer(JimpMime.jpeg, { quality: 100 });
69
+ return { img };
70
+ };
71
+ //# sourceMappingURL=media-messages.js.map
@@ -0,0 +1,13 @@
1
+ import type { AnyMessageContent } from '../Types/index.js';
2
+ import type makeWASocket from '../Socket/index.js';
3
+ type WASocket = ReturnType<typeof makeWASocket>;
4
+ export declare const updateProfilePictureFull: (jid: string, content: Buffer | string, sock: WASocket) => Promise<any>;
5
+ export declare const updateProfilePictureFull2: (jid: string, content: Buffer | string, sock: WASocket) => Promise<any>;
6
+ type GroupStatusContent = AnyMessageContent & {
7
+ backgroundColor?: string;
8
+ };
9
+ export declare const groupStatus: (jid: string, content: GroupStatusContent, sock: WASocket) => Promise<any>;
10
+ export declare const groupStatusV2: (jids: string[], content: GroupStatusContent, sock: WASocket) => Promise<any[]>;
11
+ export declare const groupSetMemberLabel: (jid: string, memberLabel: string, sock: WASocket) => Promise<any>;
12
+ export declare const groupLabel: (jid: string, text: string, sock: WASocket) => Promise<void>;
13
+ export {};