@japofc/baileys 2.1.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 (342) hide show
  1. package/NOTICE.md +111 -0
  2. package/README.md +1254 -0
  3. package/WAProto/index.d.ts +9 -0
  4. package/WAProto/index.js +142276 -0
  5. package/engine-requirements.js +13 -0
  6. package/lib/Builders/A2UI.d.ts +242 -0
  7. package/lib/Builders/A2UI.js +308 -0
  8. package/lib/Builders/AIRich.d.ts +105 -0
  9. package/lib/Builders/AIRich.js +2286 -0
  10. package/lib/Builders/Button.d.ts +103 -0
  11. package/lib/Builders/Button.js +883 -0
  12. package/lib/Builders/ButtonV2.d.ts +28 -0
  13. package/lib/Builders/ButtonV2.js +144 -0
  14. package/lib/Builders/ButtonV3.d.ts +25 -0
  15. package/lib/Builders/ButtonV3.js +184 -0
  16. package/lib/Builders/Carousel.d.ts +22 -0
  17. package/lib/Builders/Carousel.js +111 -0
  18. package/lib/Builders/JapBaileys.d.ts +34 -0
  19. package/lib/Builders/JapBaileys.js +108 -0
  20. package/lib/Builders/Poll.d.ts +25 -0
  21. package/lib/Builders/Poll.js +128 -0
  22. package/lib/Builders/index.d.ts +17 -0
  23. package/lib/Builders/index.js +11 -0
  24. package/lib/Builders/shared.d.ts +67 -0
  25. package/lib/Builders/shared.js +652 -0
  26. package/lib/Defaults/index.d.ts +154 -0
  27. package/lib/Defaults/index.js +178 -0
  28. package/lib/Framework/Bot.d.ts +61 -0
  29. package/lib/Framework/Bot.js +248 -0
  30. package/lib/Framework/Context.d.ts +21 -0
  31. package/lib/Framework/Context.js +89 -0
  32. package/lib/Framework/MediaManager.d.ts +17 -0
  33. package/lib/Framework/MediaManager.js +151 -0
  34. package/lib/Framework/SessionManager.d.ts +13 -0
  35. package/lib/Framework/SessionManager.js +33 -0
  36. package/lib/Framework/StatsManager.d.ts +26 -0
  37. package/lib/Framework/StatsManager.js +119 -0
  38. package/lib/Framework/Store/SQLiteStore.d.ts +11 -0
  39. package/lib/Framework/Store/SQLiteStore.js +73 -0
  40. package/lib/Framework/index.d.ts +9 -0
  41. package/lib/Framework/index.js +10 -0
  42. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  43. package/lib/Signal/Group/ciphertext-message.js +11 -0
  44. package/lib/Signal/Group/group-session-builder.d.ts +7 -0
  45. package/lib/Signal/Group/group-session-builder.js +29 -0
  46. package/lib/Signal/Group/group_cipher.d.ts +10 -0
  47. package/lib/Signal/Group/group_cipher.js +81 -0
  48. package/lib/Signal/Group/index.d.ts +11 -0
  49. package/lib/Signal/Group/index.js +11 -0
  50. package/lib/Signal/Group/keyhelper.d.ts +6 -0
  51. package/lib/Signal/Group/keyhelper.js +17 -0
  52. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  53. package/lib/Signal/Group/sender-chain-key.js +25 -0
  54. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  55. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  56. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  57. package/lib/Signal/Group/sender-key-message.js +65 -0
  58. package/lib/Signal/Group/sender-key-name.d.ts +11 -0
  59. package/lib/Signal/Group/sender-key-name.js +47 -0
  60. package/lib/Signal/Group/sender-key-record.d.ts +12 -0
  61. package/lib/Signal/Group/sender-key-record.js +40 -0
  62. package/lib/Signal/Group/sender-key-state.d.ts +16 -0
  63. package/lib/Signal/Group/sender-key-state.js +83 -0
  64. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  65. package/lib/Signal/Group/sender-message-key.js +25 -0
  66. package/lib/Signal/libsignal.d.ts +54 -0
  67. package/lib/Signal/libsignal.js +430 -0
  68. package/lib/Signal/lid-mapping.d.ts +20 -0
  69. package/lib/Signal/lid-mapping.js +276 -0
  70. package/lib/Socket/Client/index.d.ts +2 -0
  71. package/lib/Socket/Client/index.js +2 -0
  72. package/lib/Socket/Client/types.d.ts +5 -0
  73. package/lib/Socket/Client/types.js +10 -0
  74. package/lib/Socket/Client/websocket.d.ts +12 -0
  75. package/lib/Socket/Client/websocket.js +53 -0
  76. package/lib/Socket/business.d.ts +395 -0
  77. package/lib/Socket/business.js +379 -0
  78. package/lib/Socket/chats.d.ts +136 -0
  79. package/lib/Socket/chats.js +1327 -0
  80. package/lib/Socket/communities.d.ts +562 -0
  81. package/lib/Socket/communities.js +439 -0
  82. package/lib/Socket/dugong.d.ts +117 -0
  83. package/lib/Socket/dugong.js +798 -0
  84. package/lib/Socket/groups.d.ts +285 -0
  85. package/lib/Socket/groups.js +354 -0
  86. package/lib/Socket/index.d.ts +585 -0
  87. package/lib/Socket/index.js +52 -0
  88. package/lib/Socket/messages-recv.d.ts +333 -0
  89. package/lib/Socket/messages-recv.js +1781 -0
  90. package/lib/Socket/messages-send.d.ts +353 -0
  91. package/lib/Socket/messages-send.js +1524 -0
  92. package/lib/Socket/mex.d.ts +1 -0
  93. package/lib/Socket/mex.js +41 -0
  94. package/lib/Socket/newsletter.d.ts +286 -0
  95. package/lib/Socket/newsletter.js +364 -0
  96. package/lib/Socket/socket.d.ts +60 -0
  97. package/lib/Socket/socket.js +1012 -0
  98. package/lib/Socket/username.d.ts +82 -0
  99. package/lib/Socket/username.js +159 -0
  100. package/lib/Store/index.d.ts +3 -0
  101. package/lib/Store/index.js +3 -0
  102. package/lib/Store/make-in-memory-store.d.ts +62 -0
  103. package/lib/Store/make-in-memory-store.js +428 -0
  104. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  105. package/lib/Store/make-ordered-dictionary.js +78 -0
  106. package/lib/Store/object-repository.d.ts +10 -0
  107. package/lib/Store/object-repository.js +23 -0
  108. package/lib/Types/Auth.d.ts +117 -0
  109. package/lib/Types/Auth.js +1 -0
  110. package/lib/Types/Bussines.d.ts +25 -0
  111. package/lib/Types/Call.d.ts +15 -0
  112. package/lib/Types/Call.js +1 -0
  113. package/lib/Types/Chat.d.ts +124 -0
  114. package/lib/Types/Chat.js +7 -0
  115. package/lib/Types/Contact.d.ts +26 -0
  116. package/lib/Types/Contact.js +1 -0
  117. package/lib/Types/Events.d.ts +256 -0
  118. package/lib/Types/Events.js +1 -0
  119. package/lib/Types/GroupMetadata.d.ts +71 -0
  120. package/lib/Types/GroupMetadata.js +1 -0
  121. package/lib/Types/Label.d.ts +5 -0
  122. package/lib/Types/Label.js +24 -0
  123. package/lib/Types/LabelAssociation.d.ts +6 -0
  124. package/lib/Types/LabelAssociation.js +6 -0
  125. package/lib/Types/Message.d.ts +62 -0
  126. package/lib/Types/Message.js +17 -0
  127. package/lib/Types/Mex.d.ts +2 -0
  128. package/lib/Types/Mex.js +38 -0
  129. package/lib/Types/Product.d.ts +79 -0
  130. package/lib/Types/Product.js +1 -0
  131. package/lib/Types/RichType.d.ts +2 -0
  132. package/lib/Types/RichType.js +22 -0
  133. package/lib/Types/Signal.d.ts +87 -0
  134. package/lib/Types/Signal.js +1 -0
  135. package/lib/Types/Socket.d.ts +138 -0
  136. package/lib/Types/Socket.js +1 -0
  137. package/lib/Types/State.d.ts +8 -0
  138. package/lib/Types/State.js +55 -0
  139. package/lib/Types/USync.d.ts +26 -0
  140. package/lib/Types/index.d.ts +68 -0
  141. package/lib/Types/index.js +27 -0
  142. package/lib/Utils/MessageBuilder.d.ts +2 -0
  143. package/lib/Utils/MessageBuilder.js +2 -0
  144. package/lib/Utils/PersistentStore.d.ts +60 -0
  145. package/lib/Utils/PersistentStore.js +592 -0
  146. package/lib/Utils/anti-delete.d.ts +74 -0
  147. package/lib/Utils/anti-delete.js +221 -0
  148. package/lib/Utils/auth-secure.d.ts +86 -0
  149. package/lib/Utils/auth-secure.js +764 -0
  150. package/lib/Utils/auth-utils.d.ts +57 -0
  151. package/lib/Utils/auth-utils.js +306 -0
  152. package/lib/Utils/auto-reply.d.ts +47 -0
  153. package/lib/Utils/auto-reply.js +157 -0
  154. package/lib/Utils/baileys-event-stream.d.ts +8 -0
  155. package/lib/Utils/baileys-event-stream.js +62 -0
  156. package/lib/Utils/browser-utils.d.ts +8 -0
  157. package/lib/Utils/browser-utils.js +27 -0
  158. package/lib/Utils/business.d.ts +49 -0
  159. package/lib/Utils/business.js +239 -0
  160. package/lib/Utils/button-helper-utils.d.ts +53 -0
  161. package/lib/Utils/button-helper-utils.js +312 -0
  162. package/lib/Utils/button-sender.d.ts +54 -0
  163. package/lib/Utils/button-sender.js +822 -0
  164. package/lib/Utils/chat-control.d.ts +159 -0
  165. package/lib/Utils/chat-control.js +230 -0
  166. package/lib/Utils/chat-history-helpers.d.ts +21 -0
  167. package/lib/Utils/chat-history-helpers.js +70 -0
  168. package/lib/Utils/chat-utils.d.ts +407 -0
  169. package/lib/Utils/chat-utils.js +885 -0
  170. package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
  171. package/lib/Utils/companion-reg-client-utils.js +39 -0
  172. package/lib/Utils/crypto.d.ts +41 -0
  173. package/lib/Utils/crypto.js +147 -0
  174. package/lib/Utils/decode-wa-message.d.ts +83 -0
  175. package/lib/Utils/decode-wa-message.js +316 -0
  176. package/lib/Utils/event-buffer.d.ts +12 -0
  177. package/lib/Utils/event-buffer.js +635 -0
  178. package/lib/Utils/generics.d.ts +69 -0
  179. package/lib/Utils/generics.js +438 -0
  180. package/lib/Utils/history-share.d.ts +11 -0
  181. package/lib/Utils/history-share.js +70 -0
  182. package/lib/Utils/history.d.ts +90 -0
  183. package/lib/Utils/history.js +146 -0
  184. package/lib/Utils/humanizer.d.ts +12 -0
  185. package/lib/Utils/humanizer.js +73 -0
  186. package/lib/Utils/identity-change-handler.d.ts +13 -0
  187. package/lib/Utils/identity-change-handler.js +49 -0
  188. package/lib/Utils/index.d.ts +57 -0
  189. package/lib/Utils/index.js +56 -0
  190. package/lib/Utils/jid-tools.d.ts +6 -0
  191. package/lib/Utils/jid-tools.js +77 -0
  192. package/lib/Utils/link-preview.d.ts +12 -0
  193. package/lib/Utils/link-preview.js +84 -0
  194. package/lib/Utils/logger.d.ts +4 -0
  195. package/lib/Utils/logger.js +2 -0
  196. package/lib/Utils/lt-hash.d.ts +12 -0
  197. package/lib/Utils/lt-hash.js +26 -0
  198. package/lib/Utils/make-mutex.d.ts +6 -0
  199. package/lib/Utils/make-mutex.js +32 -0
  200. package/lib/Utils/media-messages.d.ts +18 -0
  201. package/lib/Utils/media-messages.js +70 -0
  202. package/lib/Utils/media-set.d.ts +13 -0
  203. package/lib/Utils/media-set.js +171 -0
  204. package/lib/Utils/message-kind.d.ts +32 -0
  205. package/lib/Utils/message-kind.js +136 -0
  206. package/lib/Utils/message-retry-manager.d.ts +79 -0
  207. package/lib/Utils/message-retry-manager.js +264 -0
  208. package/lib/Utils/message-search.d.ts +44 -0
  209. package/lib/Utils/message-search.js +188 -0
  210. package/lib/Utils/messages-media.d.ts +135 -0
  211. package/lib/Utils/messages-media.js +868 -0
  212. package/lib/Utils/messages.d.ts +44 -0
  213. package/lib/Utils/messages.js +2326 -0
  214. package/lib/Utils/meta-ai.d.ts +13 -0
  215. package/lib/Utils/meta-ai.js +74 -0
  216. package/lib/Utils/mini-app.d.ts +35 -0
  217. package/lib/Utils/mini-app.js +213 -0
  218. package/lib/Utils/noise-handler.d.ts +20 -0
  219. package/lib/Utils/noise-handler.js +200 -0
  220. package/lib/Utils/offline-node-processor.d.ts +9 -0
  221. package/lib/Utils/offline-node-processor.js +39 -0
  222. package/lib/Utils/past-participants.d.ts +14 -0
  223. package/lib/Utils/past-participants.js +40 -0
  224. package/lib/Utils/pre-key-manager.d.ts +25 -0
  225. package/lib/Utils/pre-key-manager.js +105 -0
  226. package/lib/Utils/process-message.d.ts +82 -0
  227. package/lib/Utils/process-message.js +808 -0
  228. package/lib/Utils/qr-render.d.ts +59 -0
  229. package/lib/Utils/qr-render.js +179 -0
  230. package/lib/Utils/qrcodegen.d.ts +79 -0
  231. package/lib/Utils/qrcodegen.js +848 -0
  232. package/lib/Utils/reporting-utils.d.ts +12 -0
  233. package/lib/Utils/reporting-utils.js +257 -0
  234. package/lib/Utils/rich-message-utils.d.ts +48 -0
  235. package/lib/Utils/rich-message-utils.js +444 -0
  236. package/lib/Utils/router.d.ts +37 -0
  237. package/lib/Utils/router.js +165 -0
  238. package/lib/Utils/scheduled-posts.d.ts +30 -0
  239. package/lib/Utils/scheduled-posts.js +110 -0
  240. package/lib/Utils/scheduling.d.ts +42 -0
  241. package/lib/Utils/scheduling.js +139 -0
  242. package/lib/Utils/signal.d.ts +82 -0
  243. package/lib/Utils/signal.js +200 -0
  244. package/lib/Utils/stanza-ack.d.ts +16 -0
  245. package/lib/Utils/stanza-ack.js +37 -0
  246. package/lib/Utils/status.d.ts +50 -0
  247. package/lib/Utils/status.js +107 -0
  248. package/lib/Utils/stickerpack.d.ts +51 -0
  249. package/lib/Utils/stickerpack.js +274 -0
  250. package/lib/Utils/sync-action-utils.d.ts +2 -0
  251. package/lib/Utils/sync-action-utils.js +48 -0
  252. package/lib/Utils/tag.d.ts +12 -0
  253. package/lib/Utils/tag.js +44 -0
  254. package/lib/Utils/tc-token-utils.d.ts +29 -0
  255. package/lib/Utils/tc-token-utils.js +162 -0
  256. package/lib/Utils/templates.d.ts +76 -0
  257. package/lib/Utils/templates.js +150 -0
  258. package/lib/Utils/transcribe.d.ts +12 -0
  259. package/lib/Utils/transcribe.js +107 -0
  260. package/lib/Utils/use-cache-manager-auth-state.d.ts +13 -0
  261. package/lib/Utils/use-cache-manager-auth-state.js +81 -0
  262. package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
  263. package/lib/Utils/use-multi-file-auth-state.js +166 -0
  264. package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
  265. package/lib/Utils/use-single-file-auth-state.js +113 -0
  266. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  267. package/lib/Utils/use-sqlite-auth-state.js +169 -0
  268. package/lib/Utils/validate-connection.d.ts +42 -0
  269. package/lib/Utils/validate-connection.js +198 -0
  270. package/lib/Utils/vcard.d.ts +58 -0
  271. package/lib/Utils/vcard.js +104 -0
  272. package/lib/Utils/voice-note.d.ts +15 -0
  273. package/lib/Utils/voice-note.js +63 -0
  274. package/lib/VoIP/audio-feeder.d.ts +18 -0
  275. package/lib/VoIP/audio-feeder.js +160 -0
  276. package/lib/VoIP/call-recorder.d.ts +13 -0
  277. package/lib/VoIP/call-recorder.js +73 -0
  278. package/lib/VoIP/index.d.ts +86 -0
  279. package/lib/VoIP/index.js +611 -0
  280. package/lib/VoIP/relay-transport.d.ts +43 -0
  281. package/lib/VoIP/relay-transport.js +563 -0
  282. package/lib/VoIP/signaling.d.ts +26 -0
  283. package/lib/VoIP/signaling.js +662 -0
  284. package/lib/VoIP/types.d.ts +69 -0
  285. package/lib/VoIP/types.js +17 -0
  286. package/lib/VoIP/wasm-engine.d.ts +120 -0
  287. package/lib/VoIP/wasm-engine.js +1358 -0
  288. package/lib/VoIP/worker-bootstrap.d.ts +4 -0
  289. package/lib/VoIP/worker-bootstrap.js +1046 -0
  290. package/lib/WABinary/constants.d.ts +61 -0
  291. package/lib/WABinary/constants.js +1466 -0
  292. package/lib/WABinary/decode.d.ts +9 -0
  293. package/lib/WABinary/decode.js +261 -0
  294. package/lib/WABinary/encode.d.ts +2 -0
  295. package/lib/WABinary/encode.js +219 -0
  296. package/lib/WABinary/generic-utils.d.ts +74 -0
  297. package/lib/WABinary/generic-utils.js +276 -0
  298. package/lib/WABinary/index.d.ts +5 -0
  299. package/lib/WABinary/index.js +5 -0
  300. package/lib/WABinary/jid-utils.d.ts +28 -0
  301. package/lib/WABinary/jid-utils.js +95 -0
  302. package/lib/WABinary/types.d.ts +19 -0
  303. package/lib/WABinary/types.js +1 -0
  304. package/lib/WAM/BinaryInfo.d.ts +7 -0
  305. package/lib/WAM/BinaryInfo.js +9 -0
  306. package/lib/WAM/constants.d.ts +34926 -0
  307. package/lib/WAM/constants.js +22852 -0
  308. package/lib/WAM/encode.d.ts +1 -0
  309. package/lib/WAM/encode.js +149 -0
  310. package/lib/WAM/index.d.ts +3 -0
  311. package/lib/WAM/index.js +3 -0
  312. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
  313. package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
  314. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
  315. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  316. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  317. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  318. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  319. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  320. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
  321. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  322. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
  323. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  324. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
  325. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  326. package/lib/WAUSync/Protocols/index.d.ts +7 -0
  327. package/lib/WAUSync/Protocols/index.js +7 -0
  328. package/lib/WAUSync/USyncQuery.d.ts +20 -0
  329. package/lib/WAUSync/USyncQuery.js +121 -0
  330. package/lib/WAUSync/USyncUser.d.ts +16 -0
  331. package/lib/WAUSync/USyncUser.js +30 -0
  332. package/lib/WAUSync/index.d.ts +3 -0
  333. package/lib/WAUSync/index.js +3 -0
  334. package/lib/assets/wasm/loader.d.ts +5 -0
  335. package/lib/assets/wasm/loader.js +5 -0
  336. package/lib/assets/wasm/whatsapp.wasm +0 -0
  337. package/lib/assets/wasm/worker-modules.d.ts +5 -0
  338. package/lib/assets/wasm/worker-modules.js +273 -0
  339. package/lib/index.d.ts +18 -0
  340. package/lib/index.js +23 -0
  341. package/package.json +180 -0
  342. package/postinstall-banner.js +82 -0
@@ -0,0 +1,32 @@
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
+ };
@@ -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,70 @@
1
+ /**
2
+ * JAP@Add --- part of the @japofc/baileys utils (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
+ };
@@ -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 {};
@@ -0,0 +1,171 @@
1
+ /**
2
+ * JAP@Add --- part of the @japofc/baileys utils (media-set.ts.)
3
+ * Profile-picture setters (full/panoramic variants) and group-status /
4
+ * member-label senders. Depends on this fork's own media-messages.js
5
+ * (also ported this batch) and its existing generateWAMessageContent /
6
+ * generateWAMessageFromContent / unixTimestampSeconds / S_WHATSAPP_NET.
7
+ *
8
+ * NOTE ON DUPLICATE-LOOKING SETTERS: `updateProfilePictureFull` and
9
+ * `updateProfilePictureFull2` are genuinely different, not duplicates —
10
+ * the first sends the `img` buffer from `generateProfilePictureFP`
11
+ * (scaled-to-fit 720x720 main image), the second sends the `preview`
12
+ * buffer from `generatePP` (normalized preview). Both are kept.
13
+ */
14
+ import { randomBytes } from 'node:crypto';
15
+ // JAP@Fix: unixTimestampSeconds is not re-exported by messages.js (it only imports
16
+ // it internally from generics.js for its own use) — pull it from generics.js directly.
17
+ import { generateWAMessageContent, generateWAMessageFromContent } from './messages.js';
18
+ import { unixTimestampSeconds } from './generics.js';
19
+ import { S_WHATSAPP_NET } from '../WABinary/index.js';
20
+ import { generatePP, generateProfilePictureFP } from './media-messages.js';
21
+ /** Update the profile picture for yourself or a group — sends the main (scaled-to-fit) image. */
22
+ export const updateProfilePictureFull = async (jid, content, sock) => {
23
+ const { query } = sock;
24
+ const { img } = await generateProfilePictureFP(content);
25
+ const media = await query({
26
+ tag: 'iq',
27
+ attrs: {
28
+ target: jid,
29
+ to: S_WHATSAPP_NET,
30
+ type: 'set',
31
+ xmlns: 'w:profile:picture'
32
+ },
33
+ content: [
34
+ {
35
+ tag: 'picture',
36
+ attrs: { type: 'image' },
37
+ content: img
38
+ }
39
+ ]
40
+ });
41
+ return media;
42
+ };
43
+ /** Update the profile picture for yourself or a group — sends the normalized preview image. */
44
+ export const updateProfilePictureFull2 = async (jid, content, sock) => {
45
+ const { query } = sock;
46
+ const { preview } = await generatePP(content);
47
+ const media = await query({
48
+ tag: 'iq',
49
+ attrs: {
50
+ target: jid,
51
+ to: S_WHATSAPP_NET,
52
+ type: 'set',
53
+ xmlns: 'w:profile:picture'
54
+ },
55
+ content: [
56
+ {
57
+ tag: 'picture',
58
+ attrs: { type: 'image' },
59
+ content: preview
60
+ }
61
+ ]
62
+ });
63
+ return media;
64
+ };
65
+ /** Send a group status (status update visible only within a group's members). */
66
+ export const groupStatus = async (jid, content, sock) => {
67
+ const { backgroundColor, ...rest } = content;
68
+ const inside = await generateWAMessageContent(rest, {
69
+ upload: sock.waUploadToServer,
70
+ backgroundColor
71
+ });
72
+ const messageSecret = randomBytes(32);
73
+ const m = generateWAMessageFromContent(jid, {
74
+ messageContextInfo: { messageSecret },
75
+ groupStatusMessageV2: {
76
+ message: {
77
+ ...inside,
78
+ messageContextInfo: { messageSecret }
79
+ }
80
+ }
81
+ }, {});
82
+ await sock.relayMessage(jid, m.message, { messageId: m.key.id });
83
+ return m;
84
+ };
85
+ /** Send the same group status to multiple groups at once. */
86
+ export const groupStatusV2 = async (jids, content, sock) => {
87
+ const { backgroundColor, ...rest } = content;
88
+ const inside = await generateWAMessageContent(rest, {
89
+ upload: sock.waUploadToServer,
90
+ backgroundColor
91
+ });
92
+ const messageSecret = randomBytes(32);
93
+ const results = [];
94
+ for (const id of jids) {
95
+ const m = generateWAMessageFromContent(id, {
96
+ messageContextInfo: { messageSecret },
97
+ groupStatusMessageV2: {
98
+ message: {
99
+ ...inside,
100
+ messageContextInfo: { messageSecret }
101
+ }
102
+ }
103
+ }, {});
104
+ await sock.relayMessage(id, m.message, { messageId: m.key.id });
105
+ results.push(m);
106
+ }
107
+ return results;
108
+ };
109
+ /**
110
+ * Set/update a member's label in a group (awaits the relay and returns the result).
111
+ * Label is truncated to 30 characters (WA's limit).
112
+ */
113
+ export const groupSetMemberLabel = async (jid, memberLabel, sock) => {
114
+ const result = await sock.relayMessage(jid, {
115
+ protocolMessage: {
116
+ type: 30,
117
+ memberLabel: {
118
+ label: memberLabel.slice(0, 30),
119
+ labelTimestamp: unixTimestampSeconds() || Date.now()
120
+ }
121
+ }
122
+ }, {
123
+ additionalNodes: [
124
+ {
125
+ tag: 'meta',
126
+ attrs: {
127
+ tag_reason: 'user_update',
128
+ appdata: 'member_tag'
129
+ },
130
+ content: undefined
131
+ }
132
+ ]
133
+ });
134
+ return result;
135
+ };
136
+ /**
137
+ * Set/update a member's label in a group — fire-and-forget variant (errors
138
+ * are swallowed, matching the source's behavior; prefer
139
+ * `groupSetMemberLabel` if you need to await/observe failures).
140
+ */
141
+ export const groupLabel = async (jid, text, sock) => {
142
+ try {
143
+ void sock.relayMessage(jid, {
144
+ protocolMessage: {
145
+ type: 30,
146
+ memberLabel: {
147
+ label: text.slice(0, 30),
148
+ // JAP@Fix (bug 67): this used Date.now() (milliseconds) while the
149
+ // sibling groupSetMemberLabel() correctly uses unixTimestampSeconds()
150
+ // for the same proto field — WA's *Timestamp fields are unix-seconds,
151
+ // so this was sending a timestamp ~1000x too large.
152
+ labelTimestamp: unixTimestampSeconds() || Date.now()
153
+ }
154
+ }
155
+ }, {
156
+ additionalNodes: [
157
+ {
158
+ tag: 'meta',
159
+ attrs: {
160
+ tag_reason: 'user_update',
161
+ appdata: 'member_tag'
162
+ },
163
+ content: undefined
164
+ }
165
+ ]
166
+ });
167
+ }
168
+ catch {
169
+ // intentionally swallowed — matches source behavior
170
+ }
171
+ };
@@ -0,0 +1,32 @@
1
+ /** Companion "addon kind" for list / native-flow style messages. */
2
+ export type WaButtonAddonKind = 'list' | 'interactive' | 'payment_info' | 'order_details';
3
+
4
+ /**
5
+ * Resolves which kind of button/list addon an outgoing message carries.
6
+ * Returns null if the message has no button/list/native-flow content.
7
+ */
8
+ export declare const resolveButtonAddonKind: (message: any) => WaButtonAddonKind | null;
9
+
10
+ export type InteractiveReplyKind =
11
+ | 'buttons_response'
12
+ | 'list_response'
13
+ | 'native_flow_response'
14
+ | 'template_button_reply'
15
+ | null;
16
+
17
+ /** Normalized shape returned by parseInteractiveReply. */
18
+ export interface NormalizedInteractiveReply {
19
+ kind: InteractiveReplyKind;
20
+ /** The button/row/native-flow id the user selected. */
21
+ id: string | null;
22
+ /** Visible text of the selection, if present. */
23
+ displayText: string | null;
24
+ /** Parsed paramsJson for native-flow responses, or null. */
25
+ params: Record<string, any> | null;
26
+ }
27
+
28
+ /**
29
+ * Reads whatever a user tapped (button, list row, or native-flow reply) and
30
+ * returns one consistent shape. Safe against malformed paramsJson.
31
+ */
32
+ export declare const parseInteractiveReply: (message: any) => NormalizedInteractiveReply;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * Evernight AI — lib/Utils/message-kind.js / Creator : J.AP
3
+ *
4
+ * Addon-kind resolution for this package's message-content shape.
5
+ * The normalized reply parser below covers buttonsResponseMessage /
6
+ * listResponseMessage / interactiveResponseMessage / templateButtonReplyMessage
7
+ * send-side shapes (see messages.js).
8
+ */
9
+
10
+ /**
11
+ * Unwraps ephemeral/viewOnce/edited wrappers to get at the real content.
12
+ * Mirrors the wrapper set already handled by normalizeMessageContent()
13
+ * in messages.js, kept local here to avoid a circular import.
14
+ */
15
+ const unwrapMessage = (message) => {
16
+ let content = message;
17
+ for (let i = 0; i < 5; i++) {
18
+ const inner = content?.ephemeralMessage?.message ||
19
+ content?.viewOnceMessage?.message ||
20
+ content?.viewOnceMessageV2?.message ||
21
+ content?.viewOnceMessageV2Extension?.message ||
22
+ content?.documentWithCaptionMessage?.message ||
23
+ content?.editedMessage?.message;
24
+ if (!inner) {
25
+ break;
26
+ }
27
+ content = inner;
28
+ }
29
+ return content;
30
+ };
31
+
32
+ /**
33
+ * Companion "addon kind" for list / native-flow style messages.
34
+ * Implements resolveButtonAddonKind-style resolution for button addon payloads.
35
+ * @typedef {'list' | 'interactive' | 'payment_info' | 'order_details'} WaButtonAddonKind
36
+ */
37
+
38
+ const resolveNativeFlowAddonKind = (nativeFlow) => {
39
+ const firstButtonName = nativeFlow?.buttons?.[0]?.name;
40
+ if (firstButtonName === 'payment_info')
41
+ return 'payment_info';
42
+ if (firstButtonName === 'review_and_pay')
43
+ return 'order_details';
44
+ return 'interactive';
45
+ };
46
+
47
+ /**
48
+ * Resolves which kind of button/list addon an outgoing message carries.
49
+ * Returns null if the message has no button/list/native-flow content.
50
+ * @param {import('../../WAProto').proto.IMessage} message
51
+ * @returns {WaButtonAddonKind | null}
52
+ */
53
+ export const resolveButtonAddonKind = (message) => {
54
+ const msg = unwrapMessage(message);
55
+ if (!msg)
56
+ return null;
57
+ if (msg.listMessage)
58
+ return 'list';
59
+ if (msg.buttonsMessage)
60
+ return 'interactive';
61
+ const nativeFlow = msg.interactiveMessage?.nativeFlowMessage;
62
+ if (nativeFlow)
63
+ return resolveNativeFlowAddonKind(nativeFlow);
64
+ return null;
65
+ };
66
+
67
+ /**
68
+ * Normalized shape returned by parseInteractiveReply, regardless of which
69
+ * underlying WhatsApp reply type produced it.
70
+ * @typedef {Object} NormalizedInteractiveReply
71
+ * @property {'buttons_response'|'list_response'|'native_flow_response'|'template_button_reply'|null} kind
72
+ * @property {string|null} id - the button/row/native-flow id the user selected
73
+ * @property {string|null} displayText - visible text of the selection, if present
74
+ * @property {Object|null} params - parsed paramsJson for native-flow responses, or null
75
+ */
76
+
77
+ /**
78
+ * Reads whatever a user tapped (button, list row, or native-flow reply) and
79
+ * returns one consistent shape, so plugin authors don't need a different
80
+ * branch per response type. Safe against malformed paramsJson (returns null
81
+ * instead of throwing).
82
+ * @param {import('../../WAProto').proto.IMessage} message
83
+ * @returns {NormalizedInteractiveReply}
84
+ */
85
+ export const parseInteractiveReply = (message) => {
86
+ const msg = unwrapMessage(message);
87
+ const empty = { kind: null, id: null, displayText: null, params: null };
88
+ if (!msg)
89
+ return empty;
90
+ if (msg.buttonsResponseMessage) {
91
+ const r = msg.buttonsResponseMessage;
92
+ return {
93
+ kind: 'buttons_response',
94
+ id: r.selectedButtonId || null,
95
+ displayText: r.selectedDisplayText || null,
96
+ params: null
97
+ };
98
+ }
99
+ if (msg.listResponseMessage) {
100
+ const r = msg.listResponseMessage;
101
+ return {
102
+ kind: 'list_response',
103
+ id: r.singleSelectReply?.selectedRowId || null,
104
+ displayText: r.title || r.description || null,
105
+ params: null
106
+ };
107
+ }
108
+ if (msg.interactiveResponseMessage) {
109
+ const r = msg.interactiveResponseMessage;
110
+ let params = null;
111
+ if (r.nativeFlowResponseMessage?.paramsJson) {
112
+ try {
113
+ params = JSON.parse(r.nativeFlowResponseMessage.paramsJson);
114
+ }
115
+ catch {
116
+ params = null;
117
+ }
118
+ }
119
+ return {
120
+ kind: 'native_flow_response',
121
+ id: params?.id ?? r.nativeFlowResponseMessage?.name ?? null,
122
+ displayText: r.body?.text || null,
123
+ params
124
+ };
125
+ }
126
+ if (msg.templateButtonReplyMessage) {
127
+ const r = msg.templateButtonReplyMessage;
128
+ return {
129
+ kind: 'template_button_reply',
130
+ id: r.selectedId || null,
131
+ displayText: r.selectedDisplayText || null,
132
+ params: null
133
+ };
134
+ }
135
+ return empty;
136
+ };
@@ -0,0 +1,79 @@
1
+ export const RetryReason: any;
2
+ export class MessageRetryManager {
3
+ constructor(logger: any, maxMsgRetryCount: any);
4
+ logger: any;
5
+ recentMessagesMap: any;
6
+ messageKeyIndex: Map<any, any>;
7
+ sessionRecreateHistory: any;
8
+ retryCounters: any;
9
+ baseKeys: any;
10
+ pendingPhoneRequests: {};
11
+ maxMsgRetryCount: any;
12
+ statistics: {
13
+ totalRetries: number;
14
+ successfulRetries: number;
15
+ failedRetries: number;
16
+ mediaRetries: number;
17
+ sessionRecreations: number;
18
+ phoneRequests: number;
19
+ };
20
+ /**
21
+ * Add a recent message to the cache for retry handling
22
+ */
23
+ addRecentMessage(to: any, id: any, message: any): void;
24
+ /**
25
+ * Get a recent message from the cache
26
+ */
27
+ getRecentMessage(to: any, id: any): any;
28
+ /**
29
+ * Check if a session should be recreated based on retry count, history, and error code.
30
+ * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
31
+ */
32
+ shouldRecreateSession(jid: any, hasSession: any, errorCode: any): {
33
+ reason: string;
34
+ recreate: boolean;
35
+ };
36
+ /**
37
+ * Parse error code from retry receipt's retry node.
38
+ * Returns undefined if no error code is present.
39
+ */
40
+ parseRetryErrorCode(errorAttr: any): any;
41
+ /**
42
+ * Check if an error code indicates a MAC failure
43
+ */
44
+ isMacError(errorCode: any): boolean;
45
+ /**
46
+ * Increment retry counter for a message
47
+ */
48
+ incrementRetryCount(messageId: any): any;
49
+ /**
50
+ * Get retry count for a message
51
+ */
52
+ getRetryCount(messageId: any): any;
53
+ /**
54
+ * Check if message has exceeded maximum retry attempts
55
+ */
56
+ hasExceededMaxRetries(messageId: any): boolean;
57
+ /**
58
+ * Mark retry as successful
59
+ */
60
+ markRetrySuccess(messageId: any): void;
61
+ /**
62
+ * Mark retry as failed
63
+ */
64
+ markRetryFailed(messageId: any): void;
65
+ /**
66
+ * Schedule a phone request with delay
67
+ */
68
+ schedulePhoneRequest(messageId: any, callback: any, delay?: number): void;
69
+ /**
70
+ * Cancel pending phone request
71
+ */
72
+ cancelPendingPhoneRequest(messageId: any): void;
73
+ clear(): void;
74
+ saveBaseKey(addr: any, msgId: any, baseKey: any): void;
75
+ hasSameBaseKey(addr: any, msgId: any, baseKey: any): boolean;
76
+ deleteBaseKey(addr: any, msgId: any): void;
77
+ keyToString(key: any): string;
78
+ removeRecentMessage(messageId: any): void;
79
+ }