nishiki-bail 1.1.1

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 (403) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1231 -0
  3. package/WAProto/GenerateStatics.sh +3 -0
  4. package/WAProto/WAProto.proto +5479 -0
  5. package/WAProto/fix-imports.js +85 -0
  6. package/WAProto/index.d.ts +14017 -0
  7. package/WAProto/index.js +97691 -0
  8. package/engine-requirements.js +10 -0
  9. package/lib/Defaults/index.d.ts +75 -0
  10. package/lib/Defaults/index.d.ts.map +1 -0
  11. package/lib/Defaults/index.js +129 -0
  12. package/lib/Defaults/index.js.map +1 -0
  13. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  14. package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
  15. package/lib/Signal/Group/ciphertext-message.js +12 -0
  16. package/lib/Signal/Group/ciphertext-message.js.map +1 -0
  17. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  18. package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
  19. package/lib/Signal/Group/group-session-builder.js +30 -0
  20. package/lib/Signal/Group/group-session-builder.js.map +1 -0
  21. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  22. package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
  23. package/lib/Signal/Group/group_cipher.js +82 -0
  24. package/lib/Signal/Group/group_cipher.js.map +1 -0
  25. package/lib/Signal/Group/index.d.ts +12 -0
  26. package/lib/Signal/Group/index.d.ts.map +1 -0
  27. package/lib/Signal/Group/index.js +12 -0
  28. package/lib/Signal/Group/index.js.map +1 -0
  29. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  30. package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
  31. package/lib/Signal/Group/keyhelper.js +18 -0
  32. package/lib/Signal/Group/keyhelper.js.map +1 -0
  33. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  34. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
  35. package/lib/Signal/Group/sender-chain-key.js +26 -0
  36. package/lib/Signal/Group/sender-chain-key.js.map +1 -0
  37. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  38. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
  39. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  40. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
  41. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  42. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
  43. package/lib/Signal/Group/sender-key-message.js +66 -0
  44. package/lib/Signal/Group/sender-key-message.js.map +1 -0
  45. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  46. package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
  47. package/lib/Signal/Group/sender-key-name.js +48 -0
  48. package/lib/Signal/Group/sender-key-name.js.map +1 -0
  49. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  50. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
  51. package/lib/Signal/Group/sender-key-record.js +41 -0
  52. package/lib/Signal/Group/sender-key-record.js.map +1 -0
  53. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  54. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
  55. package/lib/Signal/Group/sender-key-state.js +84 -0
  56. package/lib/Signal/Group/sender-key-state.js.map +1 -0
  57. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  58. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
  59. package/lib/Signal/Group/sender-message-key.js +26 -0
  60. package/lib/Signal/Group/sender-message-key.js.map +1 -0
  61. package/lib/Signal/libsignal.d.ts +5 -0
  62. package/lib/Signal/libsignal.d.ts.map +1 -0
  63. package/lib/Signal/libsignal.js +431 -0
  64. package/lib/Signal/libsignal.js.map +1 -0
  65. package/lib/Signal/lid-mapping.d.ts +23 -0
  66. package/lib/Signal/lid-mapping.d.ts.map +1 -0
  67. package/lib/Signal/lid-mapping.js +277 -0
  68. package/lib/Signal/lid-mapping.js.map +1 -0
  69. package/lib/Socket/Client/index.d.ts +3 -0
  70. package/lib/Socket/Client/index.d.ts.map +1 -0
  71. package/lib/Socket/Client/index.js +3 -0
  72. package/lib/Socket/Client/index.js.map +1 -0
  73. package/lib/Socket/Client/types.d.ts +16 -0
  74. package/lib/Socket/Client/types.d.ts.map +1 -0
  75. package/lib/Socket/Client/types.js +11 -0
  76. package/lib/Socket/Client/types.js.map +1 -0
  77. package/lib/Socket/Client/websocket.d.ts +13 -0
  78. package/lib/Socket/Client/websocket.d.ts.map +1 -0
  79. package/lib/Socket/Client/websocket.js +54 -0
  80. package/lib/Socket/Client/websocket.js.map +1 -0
  81. package/lib/Socket/business.d.ts +217 -0
  82. package/lib/Socket/business.d.ts.map +1 -0
  83. package/lib/Socket/business.js +379 -0
  84. package/lib/Socket/business.js.map +1 -0
  85. package/lib/Socket/chats.d.ts +125 -0
  86. package/lib/Socket/chats.d.ts.map +1 -0
  87. package/lib/Socket/chats.js +1198 -0
  88. package/lib/Socket/chats.js.map +1 -0
  89. package/lib/Socket/clutch-handler.d.ts +29 -0
  90. package/lib/Socket/clutch-handler.js +844 -0
  91. package/lib/Socket/communities.d.ts +273 -0
  92. package/lib/Socket/communities.d.ts.map +1 -0
  93. package/lib/Socket/communities.js +431 -0
  94. package/lib/Socket/communities.js.map +1 -0
  95. package/lib/Socket/groups.d.ts +161 -0
  96. package/lib/Socket/groups.d.ts.map +1 -0
  97. package/lib/Socket/groups.js +347 -0
  98. package/lib/Socket/groups.js.map +1 -0
  99. package/lib/Socket/index.d.ts +260 -0
  100. package/lib/Socket/index.d.ts.map +1 -0
  101. package/lib/Socket/index.js +12 -0
  102. package/lib/Socket/index.js.map +1 -0
  103. package/lib/Socket/messages-recv.d.ts +203 -0
  104. package/lib/Socket/messages-recv.d.ts.map +1 -0
  105. package/lib/Socket/messages-recv.js +1772 -0
  106. package/lib/Socket/messages-recv.js.map +1 -0
  107. package/lib/Socket/messages-send.d.ts +247 -0
  108. package/lib/Socket/messages-send.d.ts.map +1 -0
  109. package/lib/Socket/messages-send.js +1404 -0
  110. package/lib/Socket/messages-send.js.map +1 -0
  111. package/lib/Socket/mex.d.ts +3 -0
  112. package/lib/Socket/mex.d.ts.map +1 -0
  113. package/lib/Socket/mex.js +42 -0
  114. package/lib/Socket/mex.js.map +1 -0
  115. package/lib/Socket/newsletter.d.ts +170 -0
  116. package/lib/Socket/newsletter.d.ts.map +1 -0
  117. package/lib/Socket/newsletter.js +192 -0
  118. package/lib/Socket/newsletter.js.map +1 -0
  119. package/lib/Socket/socket.d.ts +59 -0
  120. package/lib/Socket/socket.d.ts.map +1 -0
  121. package/lib/Socket/socket.js +970 -0
  122. package/lib/Socket/socket.js.map +1 -0
  123. package/lib/Types/Auth.d.ts +117 -0
  124. package/lib/Types/Auth.d.ts.map +1 -0
  125. package/lib/Types/Auth.js +2 -0
  126. package/lib/Types/Auth.js.map +1 -0
  127. package/lib/Types/Bussines.d.ts +25 -0
  128. package/lib/Types/Bussines.d.ts.map +1 -0
  129. package/lib/Types/Bussines.js +2 -0
  130. package/lib/Types/Bussines.js.map +1 -0
  131. package/lib/Types/Call.d.ts +15 -0
  132. package/lib/Types/Call.d.ts.map +1 -0
  133. package/lib/Types/Call.js +2 -0
  134. package/lib/Types/Call.js.map +1 -0
  135. package/lib/Types/Chat.d.ts +124 -0
  136. package/lib/Types/Chat.d.ts.map +1 -0
  137. package/lib/Types/Chat.js +8 -0
  138. package/lib/Types/Chat.js.map +1 -0
  139. package/lib/Types/Contact.d.ts +26 -0
  140. package/lib/Types/Contact.d.ts.map +1 -0
  141. package/lib/Types/Contact.js +2 -0
  142. package/lib/Types/Contact.js.map +1 -0
  143. package/lib/Types/Events.d.ts +256 -0
  144. package/lib/Types/Events.d.ts.map +1 -0
  145. package/lib/Types/Events.js +2 -0
  146. package/lib/Types/Events.js.map +1 -0
  147. package/lib/Types/GroupMetadata.d.ts +71 -0
  148. package/lib/Types/GroupMetadata.d.ts.map +1 -0
  149. package/lib/Types/GroupMetadata.js +2 -0
  150. package/lib/Types/GroupMetadata.js.map +1 -0
  151. package/lib/Types/Label.d.ts +47 -0
  152. package/lib/Types/Label.d.ts.map +1 -0
  153. package/lib/Types/Label.js +25 -0
  154. package/lib/Types/Label.js.map +1 -0
  155. package/lib/Types/LabelAssociation.d.ts +30 -0
  156. package/lib/Types/LabelAssociation.d.ts.map +1 -0
  157. package/lib/Types/LabelAssociation.js +7 -0
  158. package/lib/Types/LabelAssociation.js.map +1 -0
  159. package/lib/Types/Message.d.ts +320 -0
  160. package/lib/Types/Message.d.ts.map +1 -0
  161. package/lib/Types/Message.js +11 -0
  162. package/lib/Types/Message.js.map +1 -0
  163. package/lib/Types/Mex.d.ts +141 -0
  164. package/lib/Types/Mex.d.ts.map +1 -0
  165. package/lib/Types/Mex.js +37 -0
  166. package/lib/Types/Mex.js.map +1 -0
  167. package/lib/Types/Product.d.ts +79 -0
  168. package/lib/Types/Product.d.ts.map +1 -0
  169. package/lib/Types/Product.js +2 -0
  170. package/lib/Types/Product.js.map +1 -0
  171. package/lib/Types/Signal.d.ts +87 -0
  172. package/lib/Types/Signal.d.ts.map +1 -0
  173. package/lib/Types/Signal.js +2 -0
  174. package/lib/Types/Signal.js.map +1 -0
  175. package/lib/Types/Socket.d.ts +136 -0
  176. package/lib/Types/Socket.d.ts.map +1 -0
  177. package/lib/Types/Socket.js +3 -0
  178. package/lib/Types/Socket.js.map +1 -0
  179. package/lib/Types/State.d.ts +97 -0
  180. package/lib/Types/State.d.ts.map +1 -0
  181. package/lib/Types/State.js +56 -0
  182. package/lib/Types/State.js.map +1 -0
  183. package/lib/Types/USync.d.ts +26 -0
  184. package/lib/Types/USync.d.ts.map +1 -0
  185. package/lib/Types/USync.js +2 -0
  186. package/lib/Types/USync.js.map +1 -0
  187. package/lib/Types/index.d.ts +66 -0
  188. package/lib/Types/index.d.ts.map +1 -0
  189. package/lib/Types/index.js +26 -0
  190. package/lib/Types/index.js.map +1 -0
  191. package/lib/Utils/auth-utils.d.ts +24 -0
  192. package/lib/Utils/auth-utils.d.ts.map +1 -0
  193. package/lib/Utils/auth-utils.js +302 -0
  194. package/lib/Utils/auth-utils.js.map +1 -0
  195. package/lib/Utils/browser-utils.d.ts +4 -0
  196. package/lib/Utils/browser-utils.d.ts.map +1 -0
  197. package/lib/Utils/browser-utils.js +29 -0
  198. package/lib/Utils/browser-utils.js.map +1 -0
  199. package/lib/Utils/business.d.ts +23 -0
  200. package/lib/Utils/business.d.ts.map +1 -0
  201. package/lib/Utils/business.js +231 -0
  202. package/lib/Utils/business.js.map +1 -0
  203. package/lib/Utils/chat-utils.d.ts +100 -0
  204. package/lib/Utils/chat-utils.d.ts.map +1 -0
  205. package/lib/Utils/chat-utils.js +872 -0
  206. package/lib/Utils/chat-utils.js.map +1 -0
  207. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  208. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  209. package/lib/Utils/companion-reg-client-utils.js +35 -0
  210. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  211. package/lib/Utils/crypto.d.ts +37 -0
  212. package/lib/Utils/crypto.d.ts.map +1 -0
  213. package/lib/Utils/crypto.js +118 -0
  214. package/lib/Utils/crypto.js.map +1 -0
  215. package/lib/Utils/decode-wa-message.d.ts +66 -0
  216. package/lib/Utils/decode-wa-message.d.ts.map +1 -0
  217. package/lib/Utils/decode-wa-message.js +317 -0
  218. package/lib/Utils/decode-wa-message.js.map +1 -0
  219. package/lib/Utils/event-buffer.d.ts +36 -0
  220. package/lib/Utils/event-buffer.d.ts.map +1 -0
  221. package/lib/Utils/event-buffer.js +622 -0
  222. package/lib/Utils/event-buffer.js.map +1 -0
  223. package/lib/Utils/generics.d.ts +92 -0
  224. package/lib/Utils/generics.d.ts.map +1 -0
  225. package/lib/Utils/generics.js +393 -0
  226. package/lib/Utils/generics.js.map +1 -0
  227. package/lib/Utils/history.d.ts +24 -0
  228. package/lib/Utils/history.d.ts.map +1 -0
  229. package/lib/Utils/history.js +134 -0
  230. package/lib/Utils/history.js.map +1 -0
  231. package/lib/Utils/identity-change-handler.d.ts +44 -0
  232. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  233. package/lib/Utils/identity-change-handler.js +50 -0
  234. package/lib/Utils/identity-change-handler.js.map +1 -0
  235. package/lib/Utils/index.d.ts +22 -0
  236. package/lib/Utils/index.d.ts.map +1 -0
  237. package/lib/Utils/index.js +22 -0
  238. package/lib/Utils/index.js.map +1 -0
  239. package/lib/Utils/link-preview.d.ts +21 -0
  240. package/lib/Utils/link-preview.d.ts.map +1 -0
  241. package/lib/Utils/link-preview.js +85 -0
  242. package/lib/Utils/link-preview.js.map +1 -0
  243. package/lib/Utils/logger.d.ts +12 -0
  244. package/lib/Utils/logger.d.ts.map +1 -0
  245. package/lib/Utils/logger.js +3 -0
  246. package/lib/Utils/logger.js.map +1 -0
  247. package/lib/Utils/lt-hash.d.ts +8 -0
  248. package/lib/Utils/lt-hash.d.ts.map +1 -0
  249. package/lib/Utils/lt-hash.js +8 -0
  250. package/lib/Utils/lt-hash.js.map +1 -0
  251. package/lib/Utils/make-mutex.d.ts +9 -0
  252. package/lib/Utils/make-mutex.d.ts.map +1 -0
  253. package/lib/Utils/make-mutex.js +33 -0
  254. package/lib/Utils/make-mutex.js.map +1 -0
  255. package/lib/Utils/message-retry-manager.d.ts +115 -0
  256. package/lib/Utils/message-retry-manager.d.ts.map +1 -0
  257. package/lib/Utils/message-retry-manager.js +265 -0
  258. package/lib/Utils/message-retry-manager.js.map +1 -0
  259. package/lib/Utils/messages-media.d.ts +133 -0
  260. package/lib/Utils/messages-media.d.ts.map +1 -0
  261. package/lib/Utils/messages-media.js +788 -0
  262. package/lib/Utils/messages-media.js.map +1 -0
  263. package/lib/Utils/messages.d.ts +91 -0
  264. package/lib/Utils/messages.d.ts.map +1 -0
  265. package/lib/Utils/messages.js +893 -0
  266. package/lib/Utils/messages.js.map +1 -0
  267. package/lib/Utils/noise-handler.d.ts +20 -0
  268. package/lib/Utils/noise-handler.d.ts.map +1 -0
  269. package/lib/Utils/noise-handler.js +201 -0
  270. package/lib/Utils/noise-handler.js.map +1 -0
  271. package/lib/Utils/offline-node-processor.d.ts +17 -0
  272. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  273. package/lib/Utils/offline-node-processor.js +40 -0
  274. package/lib/Utils/offline-node-processor.js.map +1 -0
  275. package/lib/Utils/pre-key-manager.d.ts +28 -0
  276. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  277. package/lib/Utils/pre-key-manager.js +106 -0
  278. package/lib/Utils/pre-key-manager.js.map +1 -0
  279. package/lib/Utils/process-message.d.ts +60 -0
  280. package/lib/Utils/process-message.d.ts.map +1 -0
  281. package/lib/Utils/process-message.js +630 -0
  282. package/lib/Utils/process-message.js.map +1 -0
  283. package/lib/Utils/reporting-utils.d.ts +11 -0
  284. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  285. package/lib/Utils/reporting-utils.js +258 -0
  286. package/lib/Utils/reporting-utils.js.map +1 -0
  287. package/lib/Utils/signal.d.ts +47 -0
  288. package/lib/Utils/signal.d.ts.map +1 -0
  289. package/lib/Utils/signal.js +201 -0
  290. package/lib/Utils/signal.js.map +1 -0
  291. package/lib/Utils/stanza-ack.d.ts +11 -0
  292. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  293. package/lib/Utils/stanza-ack.js +38 -0
  294. package/lib/Utils/stanza-ack.js.map +1 -0
  295. package/lib/Utils/sync-action-utils.d.ts +19 -0
  296. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  297. package/lib/Utils/sync-action-utils.js +49 -0
  298. package/lib/Utils/sync-action-utils.js.map +1 -0
  299. package/lib/Utils/tc-token-utils.d.ts +37 -0
  300. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  301. package/lib/Utils/tc-token-utils.js +164 -0
  302. package/lib/Utils/tc-token-utils.js.map +1 -0
  303. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  304. package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
  305. package/lib/Utils/use-multi-file-auth-state.js +119 -0
  306. package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
  307. package/lib/Utils/validate-connection.d.ts +11 -0
  308. package/lib/Utils/validate-connection.d.ts.map +1 -0
  309. package/lib/Utils/validate-connection.js +210 -0
  310. package/lib/Utils/validate-connection.js.map +1 -0
  311. package/lib/WABinary/constants.d.ts +28 -0
  312. package/lib/WABinary/constants.d.ts.map +1 -0
  313. package/lib/WABinary/constants.js +1301 -0
  314. package/lib/WABinary/constants.js.map +1 -0
  315. package/lib/WABinary/decode.d.ts +7 -0
  316. package/lib/WABinary/decode.d.ts.map +1 -0
  317. package/lib/WABinary/decode.js +262 -0
  318. package/lib/WABinary/decode.js.map +1 -0
  319. package/lib/WABinary/encode.d.ts +3 -0
  320. package/lib/WABinary/encode.d.ts.map +1 -0
  321. package/lib/WABinary/encode.js +220 -0
  322. package/lib/WABinary/encode.js.map +1 -0
  323. package/lib/WABinary/generic-utils.d.ts +15 -0
  324. package/lib/WABinary/generic-utils.d.ts.map +1 -0
  325. package/lib/WABinary/generic-utils.js +113 -0
  326. package/lib/WABinary/generic-utils.js.map +1 -0
  327. package/lib/WABinary/index.d.ts +6 -0
  328. package/lib/WABinary/index.d.ts.map +1 -0
  329. package/lib/WABinary/index.js +6 -0
  330. package/lib/WABinary/index.js.map +1 -0
  331. package/lib/WABinary/jid-utils.d.ts +48 -0
  332. package/lib/WABinary/jid-utils.d.ts.map +1 -0
  333. package/lib/WABinary/jid-utils.js +96 -0
  334. package/lib/WABinary/jid-utils.js.map +1 -0
  335. package/lib/WABinary/types.d.ts +19 -0
  336. package/lib/WABinary/types.d.ts.map +1 -0
  337. package/lib/WABinary/types.js +2 -0
  338. package/lib/WABinary/types.js.map +1 -0
  339. package/lib/WAM/BinaryInfo.d.ts +9 -0
  340. package/lib/WAM/BinaryInfo.d.ts.map +1 -0
  341. package/lib/WAM/BinaryInfo.js +10 -0
  342. package/lib/WAM/BinaryInfo.js.map +1 -0
  343. package/lib/WAM/constants.d.ts +40 -0
  344. package/lib/WAM/constants.d.ts.map +1 -0
  345. package/lib/WAM/constants.js +22853 -0
  346. package/lib/WAM/constants.js.map +1 -0
  347. package/lib/WAM/encode.d.ts +3 -0
  348. package/lib/WAM/encode.d.ts.map +1 -0
  349. package/lib/WAM/encode.js +150 -0
  350. package/lib/WAM/encode.js.map +1 -0
  351. package/lib/WAM/index.d.ts +4 -0
  352. package/lib/WAM/index.d.ts.map +1 -0
  353. package/lib/WAM/index.js +4 -0
  354. package/lib/WAM/index.js.map +1 -0
  355. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  356. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
  357. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  358. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
  359. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  360. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
  361. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  362. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
  363. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  364. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
  365. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  366. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
  367. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  368. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
  369. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  370. package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
  371. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  372. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  373. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  374. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  375. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  376. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
  377. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  378. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
  379. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  380. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
  381. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  382. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
  383. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  384. package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
  385. package/lib/WAUSync/Protocols/index.js +6 -0
  386. package/lib/WAUSync/Protocols/index.js.map +1 -0
  387. package/lib/WAUSync/USyncQuery.d.ts +30 -0
  388. package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
  389. package/lib/WAUSync/USyncQuery.js +98 -0
  390. package/lib/WAUSync/USyncQuery.js.map +1 -0
  391. package/lib/WAUSync/USyncUser.d.ts +17 -0
  392. package/lib/WAUSync/USyncUser.d.ts.map +1 -0
  393. package/lib/WAUSync/USyncUser.js +31 -0
  394. package/lib/WAUSync/USyncUser.js.map +1 -0
  395. package/lib/WAUSync/index.d.ts +4 -0
  396. package/lib/WAUSync/index.d.ts.map +1 -0
  397. package/lib/WAUSync/index.js +4 -0
  398. package/lib/WAUSync/index.js.map +1 -0
  399. package/lib/index.d.ts +12 -0
  400. package/lib/index.d.ts.map +1 -0
  401. package/lib/index.js +60 -0
  402. package/lib/index.js.map +1 -0
  403. package/package.json +134 -0
package/README.md ADDED
@@ -0,0 +1,1231 @@
1
+ <p align="center">
2
+ <img src="https://files.catbox.moe/0oigpb.png" alt="Thumbnail" />
3
+ </p>
4
+
5
+
6
+
7
+ ## Install
8
+
9
+ Use the stable version:
10
+ ```
11
+ yarn add saturn-baileys
12
+ ```
13
+
14
+ Then import your code using:
15
+ ```ts
16
+ import makeWASocket from 'saturn-baileys''
17
+ ```
18
+
19
+ # Index
20
+
21
+ - [Connecting Account](#connecting-account)
22
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
23
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
24
+ - [Receive Full History](#receive-full-history)
25
+ - [Important Notes About Socket Config](#important-notes-about-socket-config)
26
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
27
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
28
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
29
+
30
+ - [Save Auth Info](#saving--restoring-sessions)
31
+ - [Handling Events](#handling-events)
32
+ - [Example to Start](#example-to-start)
33
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
34
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
35
+ - [Implementing a Data Store](#implementing-a-data-store)
36
+ - [Whatsapp IDs Explain](#whatsapp-ids-explain)
37
+ - [Utility Functions](#utility-functions)
38
+ - [Sending Messages](#sending-messages)
39
+ - [Non-Media Messages](#non-media-messages)
40
+ - [Text Message](#text-message)
41
+ - [Quote Message](#quote-message-works-with-all-types)
42
+ - [Mention User](#mention-user-works-with-most-types)
43
+ - [Forward Messages](#forward-messages)
44
+ - [Location Message](#location-message)
45
+ - [Contact Message](#contact-message)
46
+ - [Reaction Message](#reaction-message)
47
+ - [Pin Message](#pin-message)
48
+ - [Poll Message](#poll-message)
49
+ - [Sending with Link Preview](#sending-messages-with-link-previews)
50
+ - [Media Messages](#media-messages)
51
+ - [Gif Message](#gif-message)
52
+ - [Video Message](#video-message)
53
+ - [Audio Message](#audio-message)
54
+ - [Image Message](#image-message)
55
+ - [ViewOnce Message](#view-once-message)
56
+ - [Modify Messages](#modify-messages)
57
+ - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
58
+ - [Edit Messages](#editing-messages)
59
+ - [Manipulating Media Messages](#manipulating-media-messages)
60
+ - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
61
+ - [Downloading Media Messages](#downloading-media-messages)
62
+ - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
63
+ - [Reject Call](#reject-call)
64
+ - [Send States in Chat](#send-states-in-chat)
65
+ - [Reading Messages](#reading-messages)
66
+ - [Update Presence](#update-presence)
67
+ - [Modifying Chats](#modifying-chats)
68
+ - [Archive a Chat](#archive-a-chat)
69
+ - [Mute/Unmute a Chat](#muteunmute-a-chat)
70
+ - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
71
+ - [Delete a Message for Me](#delete-a-message-for-me)
72
+ - [Delete a Chat](#delete-a-chat)
73
+ - [Star/Unstar a Message](#starunstar-a-message)
74
+ - [Disappearing Messages](#disappearing-messages)
75
+ - [User Querys](#user-querys)
76
+ - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
77
+ - [Query Chat History (groups too)](#query-chat-history-groups-too)
78
+ - [Fetch Status](#fetch-status)
79
+ - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
80
+ - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
81
+ - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
82
+ - [Change Profile](#change-profile)
83
+ - [Change Profile Status](#change-profile-status)
84
+ - [Change Profile Name](#change-profile-name)
85
+ - [Change Display Picture (groups too)](#change-display-picture-groups-too)
86
+ - [Remove display picture (groups too)](#remove-display-picture-groups-too)
87
+ - [Groups](#groups)
88
+ - [Create a Group](#create-a-group)
89
+ - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
90
+ - [Change Subject (name)](#change-subject-name)
91
+ - [Change Description](#change-description)
92
+ - [Change Settings](#change-settings)
93
+ - [Leave a Group](#leave-a-group)
94
+ - [Get Invite Code](#get-invite-code)
95
+ - [Revoke Invite Code](#revoke-invite-code)
96
+ - [Join Using Invitation Code](#join-using-invitation-code)
97
+ - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
98
+ - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
99
+ - [Join using groupInviteMessage](#join-using-groupinvitemessage)
100
+ - [Get Request Join List](#get-request-join-list)
101
+ - [Approve/Reject Request Join](#approvereject-request-join)
102
+ - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
103
+ - [Toggle Ephemeral](#toggle-ephemeral)
104
+ - [Change Add Mode](#change-add-mode)
105
+ - [Privacy](#privacy)
106
+ - [Block/Unblock User](#blockunblock-user)
107
+ - [Get Privacy Settings](#get-privacy-settings)
108
+ - [Get BlockList](#get-blocklist)
109
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
110
+ - [Update Online Privacy](#update-online-privacy)
111
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
112
+ - [Update Status Privacy](#update-status-privacy)
113
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
114
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
115
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
116
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
117
+ - [Send Broadcast & Stories](#send-broadcast--stories)
118
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
119
+ - [Writing Custom Functionality](#writing-custom-functionality)
120
+ - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
121
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
122
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
123
+
124
+ ## Connecting Account
125
+
126
+ WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a **QR code** or **Pairing Code** with WhatsApp on your phone.
127
+
128
+ > [!NOTE]
129
+ > **[Here](#example-to-start) is a simple example of event handling**
130
+
131
+ > [!TIP]
132
+ > **You can see all supported socket configs in the [SocketConfig type alias](https://baileys.wiki/docs/api/type-aliases/SocketConfig/) (Recommended)**
133
+
134
+ ### Starting socket with **QR-CODE**
135
+
136
+ > [!TIP]
137
+ > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see the [BrowsersMap type alias](https://baileys.wiki/docs/api/type-aliases/BrowsersMap/)**
138
+
139
+ ```ts
140
+ import makeWASocket from 'saturn-baileys'
141
+
142
+ const sock = makeWASocket({
143
+ // can provide additional config here
144
+ browser: Browsers.ubuntu('My App'),
145
+ printQRInTerminal: true
146
+ })
147
+ ```
148
+
149
+ If the connection is successful, you will see a QR code printed on your terminal screen, scan it with WhatsApp on your phone and you'll be logged in!
150
+
151
+ ### Starting socket with **Pairing Code**
152
+
153
+
154
+ > [!IMPORTANT]
155
+ > Pairing Code isn't Mobile API, it's a method to connect Whatsapp Web without QR-CODE, you can connect only with one device, see [here](https://faq.whatsapp.com/1324084875126592/?cms_platform=web)
156
+
157
+ The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
158
+
159
+ ```ts
160
+ import makeWASocket from 'saturn-baileys'
161
+
162
+ const sock = makeWASocket({
163
+ // can provide additional config here
164
+ printQRInTerminal: false //need to be false
165
+ })
166
+
167
+ if (!sock.authState.creds.registered) {
168
+ const number = 'XXXXXXXXXXX'
169
+ const code = await sock.requestPairingCode(number)
170
+ console.log(code)
171
+ }
172
+ ```
173
+
174
+ ### Receive Full History
175
+
176
+ 1. Set `syncFullHistory` as `true`
177
+ 2. Baileys, by default, use chrome browser config
178
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
179
+
180
+ ```ts
181
+ const sock = makeWASocket({
182
+ ...otherOpts,
183
+ // can use Windows, Ubuntu here too
184
+ browser: Browsers.macOS('Desktop'),
185
+ syncFullHistory: true
186
+ })
187
+ ```
188
+
189
+ ## Important Notes About Socket Config
190
+
191
+ ### Caching Group Metadata (Recommended)
192
+ - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
193
+
194
+ ```ts
195
+ const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
196
+
197
+ const sock = makeWASocket({
198
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
199
+ })
200
+
201
+ sock.ev.on('groups.update', async ([event]) => {
202
+ const metadata = await sock.groupMetadata(event.id)
203
+ groupCache.set(event.id, metadata)
204
+ })
205
+
206
+ sock.ev.on('group-participants.update', async (event) => {
207
+ const metadata = await sock.groupMetadata(event.id)
208
+ groupCache.set(event.id, metadata)
209
+ })
210
+ ```
211
+
212
+ ### Improve Retry System & Decrypt Poll Votes
213
+ - If you want to improve sending message, retrying when error occurs and decrypt poll votes, you need to have a store and set `getMessage` config in socket like this:
214
+ ```ts
215
+ const sock = makeWASocket({
216
+ getMessage: async (key) => await getMessageFromStore(key)
217
+ })
218
+ ```
219
+
220
+ ### Receive Notifications in Whatsapp App
221
+ - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
222
+ ```ts
223
+ const sock = makeWASocket({
224
+ markOnlineOnConnect: false
225
+ })
226
+ ```
227
+ ## Saving & Restoring Sessions
228
+
229
+ You obviously don't want to keep scanning the QR code every time you want to connect.
230
+
231
+ So, you can load the credentials to log back in:
232
+ ```ts
233
+ import makeWASocket, { useMultiFileAuthState } from 'saturn-baileys'
234
+
235
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
236
+
237
+ // will use the given state to connect
238
+ // so if valid credentials are available -- it'll connect without QR
239
+ const sock = makeWASocket({ auth: state })
240
+
241
+ // this will be called as soon as the credentials are updated
242
+ sock.ev.on('creds.update', saveCreds)
243
+ ```
244
+
245
+ > [!IMPORTANT]
246
+ > `useMultiFileAuthState` is a utility function to help save the auth state in a single folder, this function serves as a good guide to help write auth & key states for SQL/no-SQL databases, which I would recommend in any production grade system.
247
+
248
+ > [!NOTE]
249
+ > When a message is received/sent, due to signal sessions needing updating, the auth keys (`authState.keys`) will update. Whenever that happens, you must save the updated keys (`authState.keys.set()` is called). Not doing so will prevent your messages from reaching the recipient & cause other unexpected consequences. The `useMultiFileAuthState` function automatically takes care of that, but for any other serious implementation -- you will need to be very careful with the key state management.
250
+
251
+ ## Handling Events
252
+
253
+ - Baileys uses the EventEmitter syntax for events.
254
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
255
+
256
+ > [!IMPORTANT]
257
+ > **The events are in the [BaileysEventMap type alias](https://baileys.wiki/docs/api/type-aliases/BaileysEventMap/)**, it's important you see all events
258
+
259
+ You can listen to these events like this:
260
+ ```ts
261
+ const sock = makeWASocket()
262
+ sock.ev.on('messages.upsert', ({ messages }) => {
263
+ console.log('got messages', messages)
264
+ })
265
+ ```
266
+
267
+ ### Example to Start
268
+
269
+ > [!NOTE]
270
+ > This example includes basic auth storage too
271
+
272
+ > [!NOTE]
273
+ > For reliable serialization of the authentication state, especially when storing as JSON, always use the BufferJSON utility.
274
+
275
+ ```ts
276
+ import makeWASocket, { DisconnectReason, useMultiFileAuthState } from 'saturn-baileys'
277
+ import { Boom } from '@hapi/boom'
278
+
279
+ async function connectToWhatsApp () {
280
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
281
+ const sock = makeWASocket({
282
+ // can provide additional config here
283
+ auth: state,
284
+ printQRInTerminal: true
285
+ })
286
+ sock.ev.on('connection.update', (update) => {
287
+ const { connection, lastDisconnect } = update
288
+ if(connection === 'close') {
289
+ const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
290
+ console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
291
+ // reconnect if not logged out
292
+ if(shouldReconnect) {
293
+ connectToWhatsApp()
294
+ }
295
+ } else if(connection === 'open') {
296
+ console.log('opened connection')
297
+ }
298
+ })
299
+ sock.ev.on('messages.upsert', event => {
300
+ for (const m of event.messages) {
301
+ console.log(JSON.stringify(m, undefined, 2))
302
+
303
+ console.log('replying to', m.key.remoteJid)
304
+ await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
305
+ }
306
+ })
307
+
308
+ // to storage creds (session info) when it updates
309
+ sock.ev.on('creds.update', saveCreds)
310
+ }
311
+ // run in main file
312
+ connectToWhatsApp()
313
+ ```
314
+
315
+ > [!IMPORTANT]
316
+ > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
317
+
318
+ ### Decrypt Poll Votes
319
+
320
+ - By default poll votes are encrypted and handled in `messages.update`
321
+ - That's a simple example
322
+ ```ts
323
+ sock.ev.on('messages.update', event => {
324
+ for(const { key, update } of event) {
325
+ if(update.pollUpdates) {
326
+ const pollCreation = await getMessage(key)
327
+ if(pollCreation) {
328
+ console.log(
329
+ 'got poll update, aggregation: ',
330
+ getAggregateVotesInPollMessage({
331
+ message: pollCreation,
332
+ pollUpdates: update.pollUpdates,
333
+ })
334
+ )
335
+ }
336
+ }
337
+ }
338
+ })
339
+ ```
340
+
341
+ - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
342
+
343
+ ### Summary of Events on First Connection
344
+
345
+ 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
346
+ 2. Then, history messages will be received in `messaging.history-set`
347
+
348
+ ## Implementing a Data Store
349
+
350
+ - Baileys does not come with a defacto storage for chats, contacts, or messages. However, a simple in-memory implementation has been provided. The store listens for chat updates, new messages, message updates, etc., to always have an up-to-date version of the data.
351
+
352
+ > [!IMPORTANT]
353
+ > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
354
+
355
+ It can be used as follows:
356
+
357
+ ```ts
358
+ import makeWASocket, { makeInMemoryStore } from 'saturn-baileys'
359
+ // the store maintains the data of the WA connection in memory
360
+ // can be written out to a file & read from it
361
+ const store = makeInMemoryStore({ })
362
+ // can be read from a file
363
+ store.readFromFile('./baileys_store.json')
364
+ // saves the state to a file every 10s
365
+ setInterval(() => {
366
+ store.writeToFile('./baileys_store.json')
367
+ }, 10_000)
368
+
369
+ const sock = makeWASocket({ })
370
+ // will listen from this socket
371
+ // the store can listen from a new socket once the current socket outlives its lifetime
372
+ store.bind(sock.ev)
373
+
374
+ sock.ev.on('chats.upsert', () => {
375
+ // can use 'store.chats' however you want, even after the socket dies out
376
+ // 'chats' => a KeyedDB instance
377
+ console.log('got chats', store.chats.all())
378
+ })
379
+
380
+ sock.ev.on('contacts.upsert', () => {
381
+ console.log('got contacts', Object.values(store.contacts))
382
+ })
383
+
384
+ ```
385
+
386
+ The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
387
+
388
+ ## Whatsapp IDs Explain
389
+
390
+ - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
391
+ - It must be in the format ```[country code][phone number]@s.whatsapp.net```
392
+ - Example for people: ```+19999999999@s.whatsapp.net```.
393
+ - For groups, it must be in the format ``` 123456789-123345@g.us ```.
394
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
395
+ - For stories, the ID is `status@broadcast`.
396
+
397
+ ## Utility Functions
398
+
399
+ - `getContentType`, returns the content type for any message
400
+ - `getDevice`, returns the device from message
401
+ - `makeCacheableSignalKeyStore`, make auth store more fast
402
+ - `downloadContentFromMessage`, download content from any message
403
+
404
+ ## Sending Messages
405
+
406
+ - Send all types of messages with a single function
407
+ - **In the [AnyMessageContent type alias](https://baileys.wiki/docs/api/type-aliases/AnyMessageContent/) you can see all message contents supported, like text message**
408
+ - **In the [MiscMessageGenerationOptions type alias](https://baileys.wiki/docs/api/type-aliases/MiscMessageGenerationOptions/) you can see all options supported, like quote message**
409
+
410
+ ```ts
411
+ const jid: string
412
+ const content: AnyMessageContent
413
+ const options: MiscMessageGenerationOptions
414
+
415
+ sock.sendMessage(jid, content, options)
416
+ ```
417
+
418
+ ### Non-Media Messages
419
+
420
+ #### Text Message
421
+ ```ts
422
+ await sock.sendMessage(jid, { text: 'hello word' })
423
+ ```
424
+
425
+ #### Quote Message (works with all types)
426
+ ```ts
427
+ await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
428
+ ```
429
+
430
+ #### Mention User (works with most types)
431
+ - @number is to mention in text, it's optional
432
+ ```ts
433
+ await sock.sendMessage(
434
+ jid,
435
+ {
436
+ text: '@12345678901',
437
+ mentions: ['12345678901@s.whatsapp.net']
438
+ }
439
+ )
440
+ ```
441
+
442
+ #### Forward Messages
443
+ - You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://baileys.wiki/docs/api/type-aliases/WAMessage/) object
444
+ ```ts
445
+ const msg = getMessageFromStore() // implement this on your end
446
+ await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
447
+ ```
448
+
449
+ #### Location Message
450
+ ```ts
451
+ await sock.sendMessage(
452
+ jid,
453
+ {
454
+ location: {
455
+ degreesLatitude: 24.121231,
456
+ degreesLongitude: 55.1121221
457
+ }
458
+ }
459
+ )
460
+ ```
461
+ #### Contact Message
462
+ ```ts
463
+ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
464
+ + 'VERSION:3.0\n'
465
+ + 'FN:Jeff Singh\n' // full name
466
+ + 'ORG:Ashoka Uni;\n' // the organization of the contact
467
+ + 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
468
+ + 'END:VCARD'
469
+
470
+ await sock.sendMessage(
471
+ id,
472
+ {
473
+ contacts: {
474
+ displayName: 'Jeff',
475
+ contacts: [{ vcard }]
476
+ }
477
+ }
478
+ )
479
+ ```
480
+
481
+ #### Reaction Message
482
+ - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.wiki/docs/api/type-aliases/WAMessageKey/) object
483
+ ```ts
484
+ await sock.sendMessage(
485
+ jid,
486
+ {
487
+ react: {
488
+ text: '💖', // use an empty string to remove the reaction
489
+ key: message.key
490
+ }
491
+ }
492
+ )
493
+ ```
494
+
495
+ #### Pin Message
496
+ - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.wiki/docs/api/type-aliases/WAMessageKey/) object
497
+
498
+ - Time can be:
499
+
500
+ | Time | Seconds |
501
+ |-------|----------------|
502
+ | 24h | 86.400 |
503
+ | 7d | 604.800 |
504
+ | 30d | 2.592.000 |
505
+
506
+ ```ts
507
+ await sock.sendMessage(
508
+ jid,
509
+ {
510
+ pin: {
511
+ type: 1, // 0 to remove
512
+ time: 86400
513
+ key: message.key
514
+ }
515
+ }
516
+ )
517
+ ```
518
+
519
+ #### Poll Message
520
+ ```ts
521
+ await sock.sendMessage(
522
+ jid,
523
+ {
524
+ poll: {
525
+ name: 'My Poll',
526
+ values: ['Option 1', 'Option 2', ...],
527
+ selectableCount: 1,
528
+ toAnnouncementGroup: false // or true
529
+ }
530
+ }
531
+ )
532
+ ```
533
+
534
+ ### Sending Messages with Link Previews
535
+
536
+ 1. By default, wa does not have link generation when sent from the web
537
+ 2. Baileys has a function to generate the content for these link previews
538
+ 3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
539
+ 4. Send a link:
540
+ ```ts
541
+ await sock.sendMessage(
542
+ jid,
543
+ {
544
+ text: '666'
545
+ }
546
+ )
547
+ ```
548
+
549
+ ### Media Messages
550
+
551
+ Sending media (video, stickers, images) is easier & more efficient than ever.
552
+
553
+ > [!NOTE]
554
+ > In media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more in the [WAMediaUpload type alias](https://baileys.wiki/docs/api/type-aliases/WAMediaUpload/)
555
+
556
+ - When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
557
+
558
+ > [!TIP]
559
+ > It's recommended to use Stream or Url to save memory
560
+
561
+ #### Gif Message
562
+ - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
563
+ ```ts
564
+ await sock.sendMessage(
565
+ jid,
566
+ {
567
+ video: fs.readFileSync('Media/ma_gif.mp4'),
568
+ caption: 'hello word',
569
+ gifPlayback: true
570
+ }
571
+ )
572
+ ```
573
+
574
+ #### Video Message
575
+ ```ts
576
+ await sock.sendMessage(
577
+ id,
578
+ {
579
+ video: {
580
+ url: './Media/ma_gif.mp4'
581
+ },
582
+ caption: 'hello word',
583
+ ptv: false // if set to true, will send as a `video note`
584
+ }
585
+ )
586
+ ```
587
+
588
+ #### Audio Message
589
+ - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
590
+ ```bash
591
+ codec: libopus //ogg file
592
+ ac: 1 //one channel
593
+ avoid_negative_ts
594
+ make_zero
595
+ ```
596
+ - Example:
597
+ ```bash
598
+ ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
599
+ ```
600
+ ```ts
601
+ await sock.sendMessage(
602
+ jid,
603
+ {
604
+ audio: {
605
+ url: './Media/audio.mp3'
606
+ },
607
+ mimetype: 'audio/mp4'
608
+ }
609
+ )
610
+ ```
611
+
612
+ #### Image Message
613
+ ```ts
614
+ await sock.sendMessage(
615
+ id,
616
+ {
617
+ image: {
618
+ url: './Media/ma_img.png'
619
+ },
620
+ caption: 'hello word'
621
+ }
622
+ )
623
+ ```
624
+
625
+ #### View Once Message
626
+
627
+ - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
628
+
629
+ ```ts
630
+ await sock.sendMessage(
631
+ id,
632
+ {
633
+ image: {
634
+ url: './Media/ma_img.png'
635
+ },
636
+ viewOnce: true, //works with video, audio too
637
+ caption: 'hello word'
638
+ }
639
+ )
640
+ ```
641
+
642
+ ## Modify Messages
643
+
644
+ ### Deleting Messages (for everyone)
645
+
646
+ ```ts
647
+ const msg = await sock.sendMessage(jid, { text: 'hello word' })
648
+ await sock.sendMessage(jid, { delete: msg.key })
649
+ ```
650
+
651
+ **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
652
+
653
+ ### Editing Messages
654
+
655
+ - You can pass all editable contents here
656
+ ```ts
657
+ await sock.sendMessage(jid, {
658
+ text: 'updated text goes here',
659
+ edit: response.key,
660
+ });
661
+ ```
662
+
663
+ ## Manipulating Media Messages
664
+
665
+ ### Thumbnail in Media Messages
666
+ - For media messages, the thumbnail can be generated automatically for images & stickers provided you add `jimp` or `sharp` as a dependency in your project using `yarn add jimp` or `yarn add sharp`.
667
+ - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
668
+
669
+ ### Downloading Media Messages
670
+
671
+ If you want to save the media you received
672
+ ```ts
673
+ import { createWriteStream } from 'fs'
674
+ import { downloadMediaMessage, getContentType } from 'saturn-baileys'
675
+
676
+ sock.ev.on('messages.upsert', async ({ [m] }) => {
677
+ if (!m.message) return // if there is no text or media message
678
+ const messageType = getContentType(m) // get what type of message it is (text, image, video...)
679
+
680
+ // if the message is an image
681
+ if (messageType === 'imageMessage') {
682
+ // download the message
683
+ const stream = await downloadMediaMessage(
684
+ m,
685
+ 'stream', // can be 'buffer' too
686
+ { },
687
+ {
688
+ logger,
689
+ // pass this so that baileys can request a reupload of media
690
+ // that has been deleted
691
+ reuploadRequest: sock.updateMediaMessage
692
+ }
693
+ )
694
+ // save to file
695
+ const writeStream = createWriteStream('./my-download.jpeg')
696
+ stream.pipe(writeStream)
697
+ }
698
+ }
699
+ ```
700
+
701
+ ### Re-upload Media Message to Whatsapp
702
+
703
+ - WhatsApp automatically removes old media from their servers. For the device to access said media -- a re-upload is required by another device that has it. This can be accomplished using:
704
+ ```ts
705
+ await sock.updateMediaMessage(msg)
706
+ ```
707
+
708
+ ## Reject Call
709
+
710
+ - You can obtain `callId` and `callFrom` from `call` event
711
+
712
+ ```ts
713
+ await sock.rejectCall(callId, callFrom)
714
+ ```
715
+
716
+ ## Send States in Chat
717
+
718
+ ### Reading Messages
719
+ - A set of message [keys](https://baileys.wiki/docs/api/type-aliases/WAMessageKey/) must be explicitly marked read now.
720
+ - You cannot mark an entire 'chat' read as it were with Baileys Web.
721
+ This means you have to keep track of unread messages.
722
+
723
+ ```ts
724
+ const key: WAMessageKey
725
+ // can pass multiple keys to read multiple messages as well
726
+ await sock.readMessages([key])
727
+ ```
728
+
729
+ The message ID is the unique identifier of the message that you are marking as read.
730
+ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
731
+
732
+ ### Update Presence
733
+
734
+ - ``` presence ``` can be one of the values in the [WAPresence type alias](https://baileys.wiki/docs/api/type-aliases/WAPresence/)
735
+ - The presence expires after about 10 seconds.
736
+ - This lets the person/group with `jid` know whether you're online, offline, typing etc.
737
+
738
+ ```ts
739
+ await sock.sendPresenceUpdate('available', jid)
740
+ ```
741
+
742
+ > [!NOTE]
743
+ > If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `sock.sendPresenceUpdate('unavailable')`
744
+
745
+ ## Modifying Chats
746
+
747
+ WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
748
+
749
+ > [!IMPORTANT]
750
+ > If you mess up one of your updates, WA can log you out of all your devices and you'll have to log in again.
751
+
752
+ ### Archive a Chat
753
+ ```ts
754
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
755
+ await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
756
+ ```
757
+ ### Mute/Unmute a Chat
758
+
759
+ - Supported times:
760
+
761
+ | Time | Miliseconds |
762
+ |-------|-----------------|
763
+ | Remove | null |
764
+ | 8h | 86.400.000 |
765
+ | 7d | 604.800.000 |
766
+
767
+ ```ts
768
+ // mute for 8 hours
769
+ await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
770
+ // unmute
771
+ await sock.chatModify({ mute: null }, jid)
772
+ ```
773
+ ### Mark a Chat Read/Unread
774
+ ```ts
775
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
776
+ // mark it unread
777
+ await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
778
+ ```
779
+
780
+ ### Delete a Message for Me
781
+ ```ts
782
+ await sock.chatModify(
783
+ {
784
+ clear: {
785
+ messages: [
786
+ {
787
+ id: 'ATWYHDNNWU81732J',
788
+ fromMe: true,
789
+ timestamp: '1654823909'
790
+ }
791
+ ]
792
+ }
793
+ },
794
+ jid
795
+ )
796
+
797
+ ```
798
+ ### Delete a Chat
799
+ ```ts
800
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
801
+ await sock.chatModify({
802
+ delete: true,
803
+ lastMessages: [
804
+ {
805
+ key: lastMsgInChat.key,
806
+ messageTimestamp: lastMsgInChat.messageTimestamp
807
+ }
808
+ ]
809
+ },
810
+ jid
811
+ )
812
+ ```
813
+ ### Pin/Unpin a Chat
814
+ ```ts
815
+ await sock.chatModify({
816
+ pin: true // or `false` to unpin
817
+ },
818
+ jid
819
+ )
820
+ ```
821
+ ### Star/Unstar a Message
822
+ ```ts
823
+ await sock.chatModify({
824
+ star: {
825
+ messages: [
826
+ {
827
+ id: 'messageID',
828
+ fromMe: true // or `false`
829
+ }
830
+ ],
831
+ star: true // - true: Star Message; false: Unstar Message
832
+ }
833
+ },
834
+ jid
835
+ )
836
+ ```
837
+
838
+ ### Disappearing Messages
839
+
840
+ - Ephemeral can be:
841
+
842
+ | Time | Seconds |
843
+ |-------|----------------|
844
+ | Remove | 0 |
845
+ | 24h | 86.400 |
846
+ | 7d | 604.800 |
847
+ | 90d | 7.776.000 |
848
+
849
+ - You need to pass in **Seconds**, default is 7 days
850
+
851
+ ```ts
852
+ // turn on disappearing messages
853
+ await sock.sendMessage(
854
+ jid,
855
+ // this is 1 week in seconds -- how long you want messages to appear for
856
+ { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
857
+ )
858
+
859
+ // will send as a disappearing message
860
+ await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
861
+
862
+ // turn off disappearing messages
863
+ await sock.sendMessage(
864
+ jid,
865
+ { disappearingMessagesInChat: false }
866
+ )
867
+ ```
868
+
869
+ ## User Querys
870
+
871
+ ### Check If ID Exists in Whatsapp
872
+ ```ts
873
+ const [result] = await sock.onWhatsApp(jid)
874
+ if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
875
+ ```
876
+
877
+ ### Query Chat History (groups too)
878
+
879
+ - You need to have oldest message in chat
880
+ ```ts
881
+ const msg = await getOldestMessageInChat(jid) // implement this on your end
882
+ await sock.fetchMessageHistory(
883
+ 50, //quantity (max: 50 per query)
884
+ msg.key,
885
+ msg.messageTimestamp
886
+ )
887
+ ```
888
+ - Messages will be received in `messaging.history-set` event
889
+
890
+ ### Fetch Status
891
+ ```ts
892
+ const status = await sock.fetchStatus(jid)
893
+ console.log('status: ' + status)
894
+ ```
895
+
896
+ ### Fetch Profile Picture (groups too)
897
+ - To get the display picture of some person/group
898
+ ```ts
899
+ // for low res picture
900
+ const ppUrl = await sock.profilePictureUrl(jid)
901
+ console.log(ppUrl)
902
+
903
+ // for high res picture
904
+ const ppUrl = await sock.profilePictureUrl(jid, 'image')
905
+ ```
906
+
907
+ ### Fetch Bussines Profile (such as description or category)
908
+ ```ts
909
+ const profile = await sock.getBusinessProfile(jid)
910
+ console.log('business description: ' + profile.description + ', category: ' + profile.category)
911
+ ```
912
+
913
+ ### Fetch Someone's Presence (if they're typing or online)
914
+ ```ts
915
+ // the presence update is fetched and called here
916
+ sock.ev.on('presence.update', console.log)
917
+
918
+ // request updates for a chat
919
+ await sock.presenceSubscribe(jid)
920
+ ```
921
+
922
+ ## Change Profile
923
+
924
+ ### Change Profile Status
925
+ ```ts
926
+ await sock.updateProfileStatus('Hello World!')
927
+ ```
928
+ ### Change Profile Name
929
+ ```ts
930
+ await sock.updateProfileName('My name')
931
+ ```
932
+ ### Change Display Picture (groups too)
933
+ - To change your display picture or a group's
934
+
935
+ > [!NOTE]
936
+ > Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more in the [WAMediaUpload type alias](https://baileys.wiki/docs/api/type-aliases/WAMediaUpload/)
937
+
938
+ ```ts
939
+ await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
940
+ ```
941
+ ### Remove display picture (groups too)
942
+ ```ts
943
+ await sock.removeProfilePicture(jid)
944
+ ```
945
+
946
+ ## Groups
947
+
948
+ - To change group properties you need to be admin
949
+
950
+ ### Create a Group
951
+ ```ts
952
+ // title & participants
953
+ const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
954
+ console.log('created group with id: ' + group.gid)
955
+ await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
956
+ ```
957
+ ### Add/Remove or Demote/Promote
958
+ ```ts
959
+ // id & people to add to the group (will throw error if it fails)
960
+ await sock.groupParticipantsUpdate(
961
+ jid,
962
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
963
+ 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
964
+ )
965
+ ```
966
+ ### Change Subject (name)
967
+ ```ts
968
+ await sock.groupUpdateSubject(jid, 'New Subject!')
969
+ ```
970
+ ### Change Description
971
+ ```ts
972
+ await sock.groupUpdateDescription(jid, 'New Description!')
973
+ ```
974
+ ### Change Settings
975
+ ```ts
976
+ // only allow admins to send messages
977
+ await sock.groupSettingUpdate(jid, 'announcement')
978
+ // allow everyone to send messages
979
+ await sock.groupSettingUpdate(jid, 'not_announcement')
980
+ // allow everyone to modify the group's settings -- like display picture etc.
981
+ await sock.groupSettingUpdate(jid, 'unlocked')
982
+ // only allow admins to modify the group's settings
983
+ await sock.groupSettingUpdate(jid, 'locked')
984
+ ```
985
+ ### Leave a Group
986
+ ```ts
987
+ // will throw error if it fails
988
+ await sock.groupLeave(jid)
989
+ ```
990
+ ### Get Invite Code
991
+ - To create link with code use `'https://chat.whatsapp.com/' + code`
992
+ ```ts
993
+ const code = await sock.groupInviteCode(jid)
994
+ console.log('group code: ' + code)
995
+ ```
996
+ ### Revoke Invite Code
997
+ ```ts
998
+ const code = await sock.groupRevokeInvite(jid)
999
+ console.log('New group code: ' + code)
1000
+ ```
1001
+ ### Join Using Invitation Code
1002
+ - Code can't have `https://chat.whatsapp.com/`, only code
1003
+ ```ts
1004
+ const response = await sock.groupAcceptInvite(code)
1005
+ console.log('joined to: ' + response)
1006
+ ```
1007
+ ### Get Group Info by Invite Code
1008
+ ```ts
1009
+ const response = await sock.groupGetInviteInfo(code)
1010
+ console.log('group information: ' + response)
1011
+ ```
1012
+ ### Query Metadata (participants, name, description...)
1013
+ ```ts
1014
+ const metadata = await sock.groupMetadata(jid)
1015
+ console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
1016
+ ```
1017
+ ### Join using `groupInviteMessage`
1018
+ ```ts
1019
+ const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
1020
+ console.log('joined to: ' + response)
1021
+ ```
1022
+ ### Get Request Join List
1023
+ ```ts
1024
+ const response = await sock.groupRequestParticipantsList(jid)
1025
+ console.log(response)
1026
+ ```
1027
+ ### Approve/Reject Request Join
1028
+ ```ts
1029
+ const response = await sock.groupRequestParticipantsUpdate(
1030
+ jid, // group id
1031
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1032
+ 'approve' // or 'reject'
1033
+ )
1034
+ console.log(response)
1035
+ ```
1036
+ ### Get All Participating Groups Metadata
1037
+ ```ts
1038
+ const response = await sock.groupFetchAllParticipating()
1039
+ console.log(response)
1040
+ ```
1041
+ ### Toggle Ephemeral
1042
+
1043
+ - Ephemeral can be:
1044
+
1045
+ | Time | Seconds |
1046
+ |-------|----------------|
1047
+ | Remove | 0 |
1048
+ | 24h | 86.400 |
1049
+ | 7d | 604.800 |
1050
+ | 90d | 7.776.000 |
1051
+
1052
+ ```ts
1053
+ await sock.groupToggleEphemeral(jid, 86400)
1054
+ ```
1055
+
1056
+ ### Change Add Mode
1057
+ ```ts
1058
+ await sock.groupMemberAddMode(
1059
+ jid,
1060
+ 'all_member_add' // or 'admin_add'
1061
+ )
1062
+ ```
1063
+
1064
+ ## Privacy
1065
+
1066
+ ### Block/Unblock User
1067
+ ```ts
1068
+ await sock.updateBlockStatus(jid, 'block') // Block user
1069
+ await sock.updateBlockStatus(jid, 'unblock') // Unblock user
1070
+ ```
1071
+ ### Get Privacy Settings
1072
+ ```ts
1073
+ const privacySettings = await sock.fetchPrivacySettings(true)
1074
+ console.log('privacy settings: ' + privacySettings)
1075
+ ```
1076
+ ### Get BlockList
1077
+ ```ts
1078
+ const response = await sock.fetchBlocklist()
1079
+ console.log(response)
1080
+ ```
1081
+ ### Update LastSeen Privacy
1082
+ ```ts
1083
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1084
+ await sock.updateLastSeenPrivacy(value)
1085
+ ```
1086
+ ### Update Online Privacy
1087
+ ```ts
1088
+ const value = 'all' // 'match_last_seen'
1089
+ await sock.updateOnlinePrivacy(value)
1090
+ ```
1091
+ ### Update Profile Picture Privacy
1092
+ ```ts
1093
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1094
+ await sock.updateProfilePicturePrivacy(value)
1095
+ ```
1096
+ ### Update Status Privacy
1097
+ ```ts
1098
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1099
+ await sock.updateStatusPrivacy(value)
1100
+ ```
1101
+ ### Update Read Receipts Privacy
1102
+ ```ts
1103
+ const value = 'all' // 'none'
1104
+ await sock.updateReadReceiptsPrivacy(value)
1105
+ ```
1106
+ ### Update Groups Add Privacy
1107
+ ```ts
1108
+ const value = 'all' // 'contacts' | 'contact_blacklist'
1109
+ await sock.updateGroupsAddPrivacy(value)
1110
+ ```
1111
+ ### Update Default Disappearing Mode
1112
+
1113
+ - Like [this](#disappearing-messages), ephemeral can be:
1114
+
1115
+ | Time | Seconds |
1116
+ |-------|----------------|
1117
+ | Remove | 0 |
1118
+ | 24h | 86.400 |
1119
+ | 7d | 604.800 |
1120
+ | 90d | 7.776.000 |
1121
+
1122
+ ```ts
1123
+ const ephemeral = 86400
1124
+ await sock.updateDefaultDisappearingMode(ephemeral)
1125
+ ```
1126
+
1127
+ ## Broadcast Lists & Stories
1128
+
1129
+ ### Send Broadcast & Stories
1130
+ - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
1131
+ ```ts
1132
+ await sock.sendMessage(
1133
+ jid,
1134
+ {
1135
+ image: {
1136
+ url: url
1137
+ },
1138
+ caption: caption
1139
+ },
1140
+ {
1141
+ backgroundColor: backgroundColor,
1142
+ font: font,
1143
+ statusJidList: statusJidList,
1144
+ broadcast: true
1145
+ }
1146
+ )
1147
+ ```
1148
+ - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see the [AnyRegularMessageContent type alias](https://baileys.wiki/docs/api/type-aliases/AnyRegularMessageContent/)
1149
+ - You can add `backgroundColor` and other options in the message options, see the [MiscMessageGenerationOptions type alias](https://baileys.wiki/docs/api/type-aliases/MiscMessageGenerationOptions/)
1150
+ - `broadcast: true` enables broadcast mode
1151
+ - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
1152
+
1153
+ - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
1154
+ - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
1155
+ - Broadcast IDs are in the format `12345678@broadcast`
1156
+ ### Query a Broadcast List's Recipients & Name
1157
+ ```ts
1158
+ const bList = await sock.getBroadcastListInfo('1234@broadcast')
1159
+ console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
1160
+ ```
1161
+
1162
+ ## Writing Custom Functionality
1163
+ Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
1164
+
1165
+ ### Enabling Debug Level in Baileys Logs
1166
+ First, enable the logging of unhandled messages from WhatsApp by setting:
1167
+ ```ts
1168
+ const sock = makeWASocket({
1169
+ logger: P({ level: 'debug' }),
1170
+ })
1171
+ ```
1172
+ This will enable you to see all sorts of messages WhatsApp sends in the console.
1173
+
1174
+ ### How Whatsapp Communicate With Us
1175
+
1176
+ > [!TIP]
1177
+ > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
1178
+
1179
+ - **Example:** Functionality to track the battery percentage of your phone. You enable logging and you'll see a message about your battery pop up in the console:
1180
+ ```
1181
+ {
1182
+ "level": 10,
1183
+ "fromMe": false,
1184
+ "frame": {
1185
+ "tag": "ib",
1186
+ "attrs": {
1187
+ "from": "@s.whatsapp.net"
1188
+ },
1189
+ "content": [
1190
+ {
1191
+ "tag": "edge_routing",
1192
+ "attrs": {},
1193
+ "content": [
1194
+ {
1195
+ "tag": "routing_info",
1196
+ "attrs": {},
1197
+ "content": {
1198
+ "type": "Buffer",
1199
+ "data": [8,2,8,5]
1200
+ }
1201
+ }
1202
+ ]
1203
+ }
1204
+ ]
1205
+ },
1206
+ "msg":"communication"
1207
+ }
1208
+ ```
1209
+
1210
+ The `'frame'` is what the message received is, it has three components:
1211
+ - `tag` -- what this frame is about (eg. message will have 'message')
1212
+ - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
1213
+ - `content` -- the actual data (eg. a message node will have the actual message content in it)
1214
+ - read more about this format [here](/src/WABinary/readme.md)
1215
+
1216
+ ### Register a Callback for Websocket Events
1217
+
1218
+ > [!TIP]
1219
+ > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
1220
+
1221
+ ```ts
1222
+ // for any message with tag 'edge_routing'
1223
+ sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
1224
+
1225
+ // for any message with tag 'edge_routing' and id attribute = abcd
1226
+ sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
1227
+
1228
+ // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
1229
+ sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1230
+ ```
1231
+