dcodeindra-baileyspro 2.3.9

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 (286) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2534 -0
  3. package/WAProto/Adv/Adv.d.ts +518 -0
  4. package/WAProto/Adv/Adv.js +1734 -0
  5. package/WAProto/Adv/Adv.proto +36 -0
  6. package/WAProto/BotMetadata/BotMetadata.d.ts +5745 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +16291 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +463 -0
  9. package/WAProto/Cert/Cert.d.ts +497 -0
  10. package/WAProto/Cert/Cert.js +1503 -0
  11. package/WAProto/Cert/Cert.proto +28 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
  13. package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
  14. package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
  15. package/WAProto/CompanionReg/CompanionReg.d.ts +1055 -0
  16. package/WAProto/CompanionReg/CompanionReg.js +3532 -0
  17. package/WAProto/CompanionReg/CompanionReg.proto +89 -0
  18. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
  19. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
  20. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
  21. package/WAProto/E2E/E2E.d.ts +28417 -0
  22. package/WAProto/E2E/E2E.js +98438 -0
  23. package/WAProto/E2E/E2E.proto +2289 -0
  24. package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
  25. package/WAProto/Ephemeral/Ephemeral.js +269 -0
  26. package/WAProto/Ephemeral/Ephemeral.proto +6 -0
  27. package/WAProto/HistorySync/HistorySync.d.ts +40728 -0
  28. package/WAProto/HistorySync/HistorySync.js +142980 -0
  29. package/WAProto/HistorySync/HistorySync.proto +207 -0
  30. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
  31. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
  32. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
  33. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
  34. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
  35. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
  36. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +29294 -0
  37. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +101732 -0
  38. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
  39. package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
  40. package/WAProto/MmsRetry/MmsRetry.js +586 -0
  41. package/WAProto/MmsRetry/MmsRetry.proto +17 -0
  42. package/WAProto/Protocol/Protocol.d.ts +218 -0
  43. package/WAProto/Protocol/Protocol.js +701 -0
  44. package/WAProto/Protocol/Protocol.proto +20 -0
  45. package/WAProto/Reporting/Reporting.d.ts +301 -0
  46. package/WAProto/Reporting/Reporting.js +989 -0
  47. package/WAProto/Reporting/Reporting.proto +19 -0
  48. package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
  49. package/WAProto/ServerSync/ServerSync.js +3176 -0
  50. package/WAProto/ServerSync/ServerSync.proto +59 -0
  51. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
  52. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
  53. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
  54. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
  55. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
  56. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
  57. package/WAProto/StatusAttributions/StatusAttributions.d.ts +636 -0
  58. package/WAProto/StatusAttributions/StatusAttributions.js +2037 -0
  59. package/WAProto/StatusAttributions/StatusAttributions.proto +61 -0
  60. package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
  61. package/WAProto/SyncAction/SyncAction.js +22271 -0
  62. package/WAProto/SyncAction/SyncAction.proto +423 -0
  63. package/WAProto/UserPassword/UserPassword.d.ts +298 -0
  64. package/WAProto/UserPassword/UserPassword.js +898 -0
  65. package/WAProto/UserPassword/UserPassword.proto +27 -0
  66. package/WAProto/VnameCert/VnameCert.d.ts +658 -0
  67. package/WAProto/VnameCert/VnameCert.js +2225 -0
  68. package/WAProto/VnameCert/VnameCert.proto +60 -0
  69. package/WAProto/Wa6/Wa6.d.ts +1613 -0
  70. package/WAProto/Wa6/Wa6.js +6299 -0
  71. package/WAProto/Wa6/Wa6.proto +229 -0
  72. package/WAProto/Web/Web.d.ts +31718 -0
  73. package/WAProto/Web/Web.js +113402 -0
  74. package/WAProto/Web/Web.proto +545 -0
  75. package/WAProto/index.d.ts +49 -0
  76. package/WAProto/index.js +28 -0
  77. package/WASignalGroup/GroupProtocol.js +1771 -0
  78. package/WASignalGroup/ciphertext_message.js +10 -0
  79. package/WASignalGroup/group_cipher.js +103 -0
  80. package/WASignalGroup/group_session_builder.js +39 -0
  81. package/WASignalGroup/index.js +5 -0
  82. package/WASignalGroup/keyhelper.js +17 -0
  83. package/WASignalGroup/protobufs.js +2 -0
  84. package/WASignalGroup/queue_job.js +64 -0
  85. package/WASignalGroup/sender_chain_key.js +38 -0
  86. package/WASignalGroup/sender_key_distribution_message.js +68 -0
  87. package/WASignalGroup/sender_key_message.js +79 -0
  88. package/WASignalGroup/sender_key_name.js +59 -0
  89. package/WASignalGroup/sender_key_record.js +47 -0
  90. package/WASignalGroup/sender_key_state.js +110 -0
  91. package/WASignalGroup/sender_message_key.js +30 -0
  92. package/check-node-version.js +10 -0
  93. package/lib/Defaults/baileys-version.json +3 -0
  94. package/lib/Defaults/index.d.ts +51 -0
  95. package/lib/Defaults/index.js +108 -0
  96. package/lib/Defaults/phonenumber-mcc.json +223 -0
  97. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  98. package/lib/Signal/Group/ciphertext-message.js +19 -0
  99. package/lib/Signal/Group/group-session-builder.d.ts +17 -0
  100. package/lib/Signal/Group/group-session-builder.js +72 -0
  101. package/lib/Signal/Group/group_cipher.d.ts +19 -0
  102. package/lib/Signal/Group/group_cipher.js +99 -0
  103. package/lib/Signal/Group/index.d.ts +11 -0
  104. package/lib/Signal/Group/index.js +61 -0
  105. package/lib/Signal/Group/keyhelper.d.ts +16 -0
  106. package/lib/Signal/Group/keyhelper.js +66 -0
  107. package/lib/Signal/Group/queue-job.d.ts +1 -0
  108. package/lib/Signal/Group/queue-job.js +64 -0
  109. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  110. package/lib/Signal/Group/sender-chain-key.js +39 -0
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  112. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  113. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  114. package/lib/Signal/Group/sender-key-message.js +73 -0
  115. package/lib/Signal/Group/sender-key-name.d.ts +19 -0
  116. package/lib/Signal/Group/sender-key-name.js +59 -0
  117. package/lib/Signal/Group/sender-key-record.d.ts +32 -0
  118. package/lib/Signal/Group/sender-key-record.js +53 -0
  119. package/lib/Signal/Group/sender-key-record.ts +77 -0
  120. package/lib/Signal/Group/sender-key-state.d.ts +44 -0
  121. package/lib/Signal/Group/sender-key-state.js +104 -0
  122. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  123. package/lib/Signal/Group/sender-message-key.js +33 -0
  124. package/lib/Signal/libsignal.d.ts +3 -0
  125. package/lib/Signal/libsignal.js +153 -0
  126. package/lib/Socket/Client/index.d.ts +2 -0
  127. package/lib/Socket/Client/index.js +18 -0
  128. package/lib/Socket/Client/types.d.ts +15 -0
  129. package/lib/Socket/Client/types.js +14 -0
  130. package/lib/Socket/Client/websocket.d.ts +12 -0
  131. package/lib/Socket/Client/websocket.js +57 -0
  132. package/lib/Socket/business.d.ts +181 -0
  133. package/lib/Socket/business.js +259 -0
  134. package/lib/Socket/chats.d.ts +95 -0
  135. package/lib/Socket/chats.js +906 -0
  136. package/lib/Socket/community.d.ts +131 -0
  137. package/lib/Socket/community.js +369 -0
  138. package/lib/Socket/groups.d.ts +122 -0
  139. package/lib/Socket/groups.js +360 -0
  140. package/lib/Socket/index.d.ts +183 -0
  141. package/lib/Socket/index.js +10 -0
  142. package/lib/Socket/messages-recv.d.ts +170 -0
  143. package/lib/Socket/messages-recv.js +1074 -0
  144. package/lib/Socket/messages-send.d.ts +161 -0
  145. package/lib/Socket/messages-send.js +982 -0
  146. package/lib/Socket/newsletter.d.ts +140 -0
  147. package/lib/Socket/newsletter.js +242 -0
  148. package/lib/Socket/socket.d.ts +43 -0
  149. package/lib/Socket/socket.js +749 -0
  150. package/lib/Socket/usync.d.ts +36 -0
  151. package/lib/Socket/usync.js +71 -0
  152. package/lib/Store/index.d.ts +4 -0
  153. package/lib/Store/index.js +20 -0
  154. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  155. package/lib/Store/make-cache-manager-store.js +77 -0
  156. package/lib/Store/make-in-memory-store.d.ts +117 -0
  157. package/lib/Store/make-in-memory-store.js +420 -0
  158. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  159. package/lib/Store/make-ordered-dictionary.js +83 -0
  160. package/lib/Store/object-repository.d.ts +10 -0
  161. package/lib/Store/object-repository.js +28 -0
  162. package/lib/Types/Auth.d.ts +103 -0
  163. package/lib/Types/Auth.js +2 -0
  164. package/lib/Types/Call.d.ts +13 -0
  165. package/lib/Types/Call.js +2 -0
  166. package/lib/Types/Chat.d.ts +115 -0
  167. package/lib/Types/Chat.js +6 -0
  168. package/lib/Types/Contact.d.ts +35 -0
  169. package/lib/Types/Contact.js +2 -0
  170. package/lib/Types/Events.d.ts +208 -0
  171. package/lib/Types/Events.js +2 -0
  172. package/lib/Types/GroupMetadata.d.ts +81 -0
  173. package/lib/Types/GroupMetadata.js +2 -0
  174. package/lib/Types/Label.d.ts +46 -0
  175. package/lib/Types/Label.js +28 -0
  176. package/lib/Types/LabelAssociation.d.ts +29 -0
  177. package/lib/Types/LabelAssociation.js +10 -0
  178. package/lib/Types/Message.d.ts +480 -0
  179. package/lib/Types/Message.js +9 -0
  180. package/lib/Types/MexUpdates.d.ts +9 -0
  181. package/lib/Types/MexUpdates.js +18 -0
  182. package/lib/Types/Newsletter.d.ts +92 -0
  183. package/lib/Types/Newsletter.js +33 -0
  184. package/lib/Types/Product.d.ts +78 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Signal.d.ts +57 -0
  187. package/lib/Types/Signal.js +2 -0
  188. package/lib/Types/Socket.d.ts +116 -0
  189. package/lib/Types/Socket.js +2 -0
  190. package/lib/Types/State.d.ts +27 -0
  191. package/lib/Types/State.js +2 -0
  192. package/lib/Types/USync.d.ts +25 -0
  193. package/lib/Types/USync.js +2 -0
  194. package/lib/Types/index.d.ts +70 -0
  195. package/lib/Types/index.js +42 -0
  196. package/lib/Utils/auth-utils.d.ts +18 -0
  197. package/lib/Utils/auth-utils.js +198 -0
  198. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  199. package/lib/Utils/baileys-event-stream.js +64 -0
  200. package/lib/Utils/business.d.ts +22 -0
  201. package/lib/Utils/business.js +243 -0
  202. package/lib/Utils/chat-utils.d.ts +72 -0
  203. package/lib/Utils/chat-utils.js +762 -0
  204. package/lib/Utils/crypto.d.ts +40 -0
  205. package/lib/Utils/crypto.js +150 -0
  206. package/lib/Utils/decode-wa-message.d.ts +252 -0
  207. package/lib/Utils/decode-wa-message.js +232 -0
  208. package/lib/Utils/event-buffer.d.ts +35 -0
  209. package/lib/Utils/event-buffer.js +539 -0
  210. package/lib/Utils/generics.d.ts +96 -0
  211. package/lib/Utils/generics.js +553 -0
  212. package/lib/Utils/history.d.ts +29 -0
  213. package/lib/Utils/history.js +109 -0
  214. package/lib/Utils/index.d.ts +19 -0
  215. package/lib/Utils/index.js +35 -0
  216. package/lib/Utils/link-preview.d.ts +21 -0
  217. package/lib/Utils/link-preview.js +112 -0
  218. package/lib/Utils/logger.d.ts +11 -0
  219. package/lib/Utils/logger.js +7 -0
  220. package/lib/Utils/lt-hash.d.ts +12 -0
  221. package/lib/Utils/lt-hash.js +53 -0
  222. package/lib/Utils/make-mutex.d.ts +7 -0
  223. package/lib/Utils/make-mutex.js +45 -0
  224. package/lib/Utils/messages-media.d.ts +104 -0
  225. package/lib/Utils/messages-media.js +751 -0
  226. package/lib/Utils/messages.d.ts +80 -0
  227. package/lib/Utils/messages.js +1741 -0
  228. package/lib/Utils/noise-handler.d.ts +19 -0
  229. package/lib/Utils/noise-handler.js +150 -0
  230. package/lib/Utils/process-message.d.ts +41 -0
  231. package/lib/Utils/process-message.js +391 -0
  232. package/lib/Utils/signal.d.ts +33 -0
  233. package/lib/Utils/signal.js +154 -0
  234. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
  235. package/lib/Utils/use-mongo-file-auth-state.js +75 -0
  236. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  237. package/lib/Utils/use-multi-file-auth-state.js +123 -0
  238. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  239. package/lib/Utils/use-single-file-auth-state.js +75 -0
  240. package/lib/Utils/validate-connection.d.ts +10 -0
  241. package/lib/Utils/validate-connection.js +174 -0
  242. package/lib/WABinary/constants.d.ts +27 -0
  243. package/lib/WABinary/constants.js +45 -0
  244. package/lib/WABinary/decode.d.ts +6 -0
  245. package/lib/WABinary/decode.js +255 -0
  246. package/lib/WABinary/encode.d.ts +2 -0
  247. package/lib/WABinary/encode.js +243 -0
  248. package/lib/WABinary/generic-utils.d.ts +16 -0
  249. package/lib/WABinary/generic-utils.js +125 -0
  250. package/lib/WABinary/index.d.ts +5 -0
  251. package/lib/WABinary/index.js +21 -0
  252. package/lib/WABinary/jid-utils.d.ts +34 -0
  253. package/lib/WABinary/jid-utils.js +73 -0
  254. package/lib/WABinary/types.d.ts +18 -0
  255. package/lib/WABinary/types.js +2 -0
  256. package/lib/WAM/BinaryInfo.d.ts +16 -0
  257. package/lib/WAM/BinaryInfo.js +14 -0
  258. package/lib/WAM/constants.d.ts +39 -0
  259. package/lib/WAM/constants.js +15362 -0
  260. package/lib/WAM/encode.d.ts +2 -0
  261. package/lib/WAM/encode.js +156 -0
  262. package/lib/WAM/index.d.ts +3 -0
  263. package/lib/WAM/index.js +19 -0
  264. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
  265. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -0
  266. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  267. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  268. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  269. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  270. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  271. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  272. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
  273. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
  274. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  275. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  276. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  277. package/lib/WAUSync/Protocols/index.js +22 -0
  278. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  279. package/lib/WAUSync/USyncQuery.js +88 -0
  280. package/lib/WAUSync/USyncUser.d.ts +12 -0
  281. package/lib/WAUSync/USyncUser.js +27 -0
  282. package/lib/WAUSync/index.d.ts +3 -0
  283. package/lib/WAUSync/index.js +19 -0
  284. package/lib/index.d.ts +13 -0
  285. package/lib/index.js +45 -0
  286. package/package.json +63 -0
package/README.md ADDED
@@ -0,0 +1,2534 @@
1
+ # <div align='center'>Baileys - Typescript/Javascript WhatsApp Web API</div>
2
+
3
+ <div align="center">
4
+
5
+ <img src="https://files.catbox.moe/ibob7z.png" alt="Header Image" width="100%"/>
6
+
7
+ <br/>
8
+
9
+ <!-- WhatsApp Links -->
10
+ <p>
11
+ <a href="https://whatsapp.com/channel/0029Vb054T9C1FuLUKkFy236">
12
+ <img src="https://img.shields.io/badge/WhatsApp-Channel-brightgreen" alt="WA Channel"/>
13
+ </a>
14
+ <a href="https://wa.me/6282375165100">
15
+ <img src="https://img.shields.io/badge/Owner-WA-green" alt="WA Owner"/>
16
+ </a>
17
+ </p>
18
+
19
+ </div>
20
+
21
+ ### Important Note
22
+
23
+ This library was originally a project for **CS-2362 at Ashoka University** and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.
24
+
25
+ #### Liability and License Notice
26
+ Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/WhiskeySockets/Baileys/blob/master/LICENSE).
27
+ The maintainers of Baileys do not in any way condone the use of this application in practices that violate the Terms of Service of WhatsApp. The maintainers of this application call upon the personal responsibility of its users to use this application in a fair way, as it is intended to be used.
28
+ ##
29
+
30
+ - Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using a **WebSocket**.
31
+ - Not running Selenium or Chromimum saves you like **half a gig** of ram :/
32
+ - Baileys supports interacting with the multi-device & web versions of WhatsApp.
33
+ - Thank you to [@pokearaujo](https://github.com/pokearaujo/multidevice) for writing his observations on the workings of WhatsApp Multi-Device. Also, thank you to [@Sigalor](https://github.com/sigalor/whatsapp-web-reveng) for writing his observations on the workings of WhatsApp Web and thanks to [@Rhymen](https://github.com/Rhymen/go-whatsapp/) for the __go__ implementation.
34
+
35
+ > [!IMPORTANT]
36
+ > The original repository had to be removed by the original author - we now continue development in this repository here.
37
+ This is the only official repository and is maintained by the community.
38
+ > **Join the Discord [here](https://discord.gg/WeJM5FP9GG)**
39
+
40
+ ## Example
41
+
42
+ Do check out & run [example.ts](Example/example.ts) to see an example usage of the library.
43
+ The script covers most common use cases.
44
+ To run the example script, download or clone the repo and then type the following in a terminal:
45
+ 1. ``` cd path/to/Baileys ```
46
+ 2. ``` yarn ```
47
+ 3. ``` yarn example ```
48
+
49
+ ## Install
50
+
51
+ Use the stable version:
52
+ ```
53
+ yarn add Sanka-Baileyss
54
+ ```
55
+ ```
56
+ npm install sanka-baileyss
57
+ ```
58
+
59
+ Use package.json
60
+ ```
61
+ "@whiskeysockets/baileys": "npm:sanka-baileyss@latest"
62
+ ```
63
+ ```
64
+ "@adiwajshing/baileys": "npm:sanka-baileyss@latest"
65
+ ```
66
+
67
+ Use the edge version (no guarantee of stability, but latest fixes + features)
68
+ ```
69
+ yarn add github:SankaVollereii/Sanka-Baileys
70
+ ```
71
+ ```
72
+ yarn add npm:sanka-baileyss@latest
73
+ ```
74
+
75
+ Then import your code using:
76
+ ```ts
77
+ import makeWASocket from 'Sanka-Baileyss'
78
+ ```
79
+
80
+ # Links
81
+
82
+ - [Discord](https://discord.gg/WeJM5FP9GG)
83
+ - [Docs](https://guide.whiskeysockets.io/)
84
+
85
+ # Index
86
+
87
+ - [Connecting Account](#connecting-account)
88
+ - [Connect with QR-CODE](#starting-socket-with-qr-code)
89
+ - [Connect with Pairing Code](#starting-socket-with-pairing-code)
90
+ - [Receive Full History](#receive-full-history)
91
+ - [Important Notes About Socket Config](#important-notes-about-socket-config)
92
+ - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
93
+ - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
94
+ - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
95
+
96
+ - [Save Auth Info](#saving--restoring-sessions)
97
+ - [Handling Events](#handling-events)
98
+ - [Example to Start](#example-to-start)
99
+ - [Decrypt Poll Votes](#decrypt-poll-votes)
100
+ - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
101
+ - [Implementing a Data Store](#implementing-a-data-store)
102
+ - [Whatsapp IDs Explain](#whatsapp-ids-explain)
103
+ - [Utility Functions](#utility-functions)
104
+ - [Sending Messages](#sending-messages)
105
+ - [Non-Media Messages](#non-media-messages)
106
+ - [Text Message](#text-message)
107
+ - [Quote Message](#quote-message-works-with-all-types)
108
+ - [Mention User](#mention-user-works-with-most-types)
109
+ - [Forward Messages](#forward-messages)
110
+ - [Location Message](#location-message)
111
+ - [Live Location Message](#live-location-message)
112
+ - [Contact Message](#contact-message)
113
+ - [Reaction Message](#reaction-message)
114
+ - [Pin Message](#pin-message)
115
+ - [Keep Message](#keep-message)
116
+ - [Poll Message](#poll-message)
117
+ - [Poll Result Message](#poll-result-message)
118
+ - [Call Message](#call-message)
119
+ - [Event Message](#event-message)
120
+ - [Order Message](#order-message)
121
+ - [Product Message](#product-message)
122
+ - [Payment Message](#payment-message)
123
+ - [Payment Invite Message](#payment-invite-message)
124
+ - [Admin Invite Message](#invite-admin-message)
125
+ - [Group Invite Message](#group-invite-message)
126
+ - [Share Phone Number Message](#share-phone-number-message)
127
+ - [Request Phone Number Message](#request-phone-number-message)
128
+ - [Buttons Reply Message](#buttons-reply-message)
129
+ - [Buttons Message](#buttons-message)
130
+ - [Buttons List Message](#buttons-list-message)
131
+ - [Buttons Product List Message](#buttons-product-list-message)
132
+ - [Buttons Cards Message](#buttons-cards-message)
133
+ - [Buttons Template Message](#buttons-template-message)
134
+ - [Buttons Interactive Message](#buttons-interactive-message)
135
+ - [Buttons Interactive Message PIX](#buttons-interactive-message-pix)
136
+ - [Buttons Interactive Message PAY](#buttons-interactive-message-PAY)
137
+ - [Status Mentions Message](#status-mentions-message)
138
+ - [Send Album Message](#send-album-message)
139
+ - [Shop Message](#shop-message)
140
+ - [Collection Message](#collection-message)
141
+ - [Sending with Link Preview](#sending-messages-with-link-previews)
142
+ - [Media Messages](#media-messages)
143
+ - [Gif Message](#gif-message)
144
+ - [Video Message](#video-message)
145
+ - [Audio Message](#audio-message)
146
+ - [Image Message](#image-message)
147
+ - [Ptv Video Message](#ptv-video-message)
148
+ - [ViewOnce Message](#view-once-message)
149
+ - [Modify Messages](#modify-messages)
150
+ - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
151
+ - [Edit Messages](#editing-messages)
152
+ - [Manipulating Media Messages](#manipulating-media-messages)
153
+ - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
154
+ - [Downloading Media Messages](#downloading-media-messages)
155
+ - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
156
+ - [Reject Call](#reject-call)
157
+ - [Send States in Chat](#send-states-in-chat)
158
+ - [Reading Messages](#reading-messages)
159
+ - [Update Presence](#update-presence)
160
+ - [Modifying Chats](#modifying-chats)
161
+ - [Archive a Chat](#archive-a-chat)
162
+ - [Mute/Unmute a Chat](#muteunmute-a-chat)
163
+ - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
164
+ - [Delete a Message for Me](#delete-a-message-for-me)
165
+ - [Delete a Chat](#delete-a-chat)
166
+ - [Star/Unstar a Message](#starunstar-a-message)
167
+ - [Disappearing Messages](#disappearing-messages)
168
+ - [Clear Messages](#clear-messages)
169
+ - [User Querys](#user-querys)
170
+ - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
171
+ - [Query Chat History (groups too)](#query-chat-history-groups-too)
172
+ - [Fetch Status](#fetch-status)
173
+ - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
174
+ - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
175
+ - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
176
+ - [Change Profile](#change-profile)
177
+ - [Change Profile Status](#change-profile-status)
178
+ - [Change Profile Name](#change-profile-name)
179
+ - [Change Display Picture (groups too)](#change-display-picture-groups-too)
180
+ - [Remove display picture (groups too)](#remove-display-picture-groups-too)
181
+ - [Groups](#groups)
182
+ - [Create a Group](#create-a-group)
183
+ - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
184
+ - [Change Subject (name)](#change-subject-name)
185
+ - [Change Description](#change-description)
186
+ - [Change Settings](#change-settings)
187
+ - [Leave a Group](#leave-a-group)
188
+ - [Get Invite Code](#get-invite-code)
189
+ - [Revoke Invite Code](#revoke-invite-code)
190
+ - [Join Using Invitation Code](#join-using-invitation-code)
191
+ - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
192
+ - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
193
+ - [Join using groupInviteMessage](#join-using-groupinvitemessage)
194
+ - [Get Request Join List](#get-request-join-list)
195
+ - [Approve/Reject Request Join](#approvereject-request-join)
196
+ - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
197
+ - [Toggle Ephemeral](#toggle-ephemeral)
198
+ - [Change Add Mode](#change-add-mode)
199
+ - [Privacy](#privacy)
200
+ - [Block/Unblock User](#blockunblock-user)
201
+ - [Get Privacy Settings](#get-privacy-settings)
202
+ - [Get BlockList](#get-blocklist)
203
+ - [Update LastSeen Privacy](#update-lastseen-privacy)
204
+ - [Update Online Privacy](#update-online-privacy)
205
+ - [Update Profile Picture Privacy](#update-profile-picture-privacy)
206
+ - [Update Status Privacy](#update-status-privacy)
207
+ - [Update Read Receipts Privacy](#update-read-receipts-privacy)
208
+ - [Update Groups Add Privacy](#update-groups-add-privacy)
209
+ - [Update Default Disappearing Mode](#update-default-disappearing-mode)
210
+ - [Broadcast Lists & Stories](#broadcast-lists--stories)
211
+ - [Send Broadcast & Stories](#send-broadcast--stories)
212
+ - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
213
+ - [Writing Custom Functionality](#writing-custom-functionality)
214
+ - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
215
+ - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
216
+ - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
217
+
218
+ ## Connecting Account
219
+
220
+ 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.
221
+
222
+ > [!NOTE]
223
+ > **[Here](#example-to-start) is a simple example of event handling**
224
+
225
+ > [!TIP]
226
+ > **You can see all supported socket configs [here](https://baileys.whiskeysockets.io/types/SocketConfig.html) (Recommended)**
227
+
228
+ ### Starting socket with **QR-CODE**
229
+
230
+ > [!TIP]
231
+ > You can customize browser name if you connect with **QR-CODE**, with `Browser` constant, we have some browsers config, **see [here](https://baileys.whiskeysockets.io/types/BrowsersMap.html)**
232
+
233
+ ```ts
234
+ import makeWASocket from 'Sanka-Baileyss'
235
+
236
+ const sanka = makeWASocket({
237
+ // can provide additional config here
238
+ browser: Browsers.ubuntu('My App'),
239
+ printQRInTerminal: true
240
+ })
241
+ ```
242
+
243
+ 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!
244
+
245
+ ### Starting socket with **Pairing Code**
246
+
247
+
248
+ > [!IMPORTANT]
249
+ > 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)
250
+
251
+ The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
252
+
253
+ ```ts
254
+ import makeWASocket from 'Sanka-Baileyss'
255
+
256
+ const sanka = makeWASocket({
257
+ // can provide additional config here
258
+ printQRInTerminal: false //need to be false
259
+ })
260
+
261
+ if (!sanka.authState.creds.registered) {
262
+ const number = 'XXXXXXXXXXX'
263
+ const code = await sanka.requestPairingCode(number) // or await sanka.requestPairingCode(number, 'CODEOTPS') custom your pairing code
264
+ console.log(code)
265
+ }
266
+ ```
267
+
268
+ ### Receive Full History
269
+
270
+ 1. Set `syncFullHistory` as `true`
271
+ 2. Baileys, by default, use chrome browser config
272
+ - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
273
+
274
+ ```ts
275
+ const sanka = makeWASocket({
276
+ ...otherOpts,
277
+ // can use Windows, Ubuntu here too
278
+ browser: Browsers.macOS('Desktop'),
279
+ syncFullHistory: true
280
+ })
281
+ ```
282
+
283
+ ## Important Notes About Socket Config
284
+
285
+ ### Caching Group Metadata (Recommended)
286
+ - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
287
+
288
+ ```ts
289
+ const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
290
+
291
+ const sanka = makeWASocket({
292
+ cachedGroupMetadata: async (jid) => groupCache.get(jid)
293
+ })
294
+
295
+ sanka.ev.on('groups.update', async ([event]) => {
296
+ const metadata = await sanka.groupMetadata(event.id)
297
+ groupCache.set(event.id, metadata)
298
+ })
299
+
300
+ sanka.ev.on('group-participants.update', async (event) => {
301
+ const metadata = await sanka.groupMetadata(event.id)
302
+ groupCache.set(event.id, metadata)
303
+ })
304
+ ```
305
+
306
+ ### Improve Retry System & Decrypt Poll Votes
307
+ - 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:
308
+ ```ts
309
+ const sanka = makeWASocket({
310
+ getMessage: async (key) => await getMessageFromStore(key)
311
+ })
312
+ ```
313
+
314
+ ### Receive Notifications in Whatsapp App
315
+ - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
316
+ ```ts
317
+ const sanka = makeWASocket({
318
+ markOnlineOnConnect: false
319
+ })
320
+ ```
321
+ ## Saving & Restoring Sessions
322
+
323
+ You obviously don't want to keep scanning the QR code every time you want to connect.
324
+
325
+ So, you can load the credentials to log back in:
326
+ ```ts
327
+ import makeWASocket, { useMultiFileAuthState } from 'Sanka-Baileyss'
328
+
329
+ const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
330
+
331
+ // will use the given state to connect
332
+ // so if valid credentials are available -- it'll connect without QR
333
+ const sanka = makeWASocket({ auth: state })
334
+
335
+ // this will be called as soon as the credentials are updated
336
+ sanka.ev.on('creds.update', saveCreds)
337
+ ```
338
+
339
+ > [!IMPORTANT]
340
+ > `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.
341
+
342
+ > [!NOTE]
343
+ > 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.
344
+
345
+ ## Handling Events
346
+
347
+ - Baileys uses the EventEmitter syntax for events.
348
+ They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
349
+
350
+ > [!IMPORTANT]
351
+ > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
352
+
353
+ You can listen to these events like this:
354
+ ```ts
355
+ const sanka = makeWASocket()
356
+ sanka.ev.on('messages.upsert', ({ messages }) => {
357
+ console.log('got messages', messages)
358
+ })
359
+ ```
360
+
361
+ ### Example to Start
362
+
363
+ > [!NOTE]
364
+ > This example includes basic auth storage too
365
+
366
+ ```ts
367
+ import makeWASocket, { DisconnectReason, useMultiFileAuthState } from 'Sanka-Baileyss'
368
+ import { Boom } from '@hapi/boom'
369
+
370
+ async function connectToWhatsApp () {
371
+ const { state, saveCreds } = await useMultiFileAuthState('./auth_info_baileys')
372
+ const sanka = makeWASocket({
373
+ // can provide additional config here
374
+ auth: state,
375
+ printQRInTerminal: true
376
+ })
377
+ sanka.ev.on('connection.update', (update) => {
378
+ const { connection, lastDisconnect } = update
379
+ if(connection === 'close') {
380
+ const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
381
+ console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
382
+ // reconnect if not logged out
383
+ if(shouldReconnect) {
384
+ connectToWhatsApp()
385
+ }
386
+ } else if(connection === 'open') {
387
+ console.log('opened connection')
388
+ }
389
+ })
390
+ sanka.ev.on('messages.upsert', event => {
391
+ for (const m of event.messages) {
392
+ console.log(JSON.stringify(m, undefined, 2))
393
+
394
+ console.log('replying to', m.key.remoteJid)
395
+ await sanka.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
396
+ }
397
+ })
398
+
399
+ // to storage creds (session info) when it updates
400
+ sanka.ev.on('creds.update', saveCreds)
401
+ }
402
+ // run in main file
403
+ connectToWhatsApp()
404
+ ```
405
+
406
+ ### For example if you use useSingleFileAuthState and useMongoFileAuthState
407
+ ```ts
408
+ import makeWASocket, { useSingleFileAuthState, useMongoFileAuthState } from 'Sanka-Baileyss'
409
+
410
+ // Single Auth
411
+ const { state, saveState } = await useSingleFileAuthState('./auth_info_baileys.json')
412
+ const sanka = makeWASocket({
413
+ auth: state,
414
+ printQRInTerminal: true
415
+ })
416
+
417
+ sanka.ev.on('creds.update', saveState)
418
+
419
+ // Mongo Auth
420
+ import { MongoClient } from "mongodb"
421
+
422
+ const connectAuth = async() => {
423
+ global.client = new MongoClient('mongoURL')
424
+ global.client.connect(err => {
425
+ if (err) {
426
+ console.warn("Warning: MongoDB link is invalid or cannot be connected.")
427
+ } else {
428
+ console.log('Successfully Connected To MongoDB Server')
429
+ }
430
+ })
431
+ }
432
+ await client.connect()
433
+ const collection = client.db("@SankaVollereii").collection("sessions")
434
+ return collection
435
+ }
436
+
437
+ const Authentication = await connectAuth()
438
+ const { state, saveCreds } = await useMongoFileAuthState(Authentication)
439
+ const sanka = makeWASocket({
440
+ auth: state,
441
+ printQRInTerminal: true
442
+ })
443
+
444
+ sanka.ev.on('creds.update', saveCreds)
445
+ ```
446
+
447
+ > [!IMPORTANT]
448
+ > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
449
+
450
+ ### Decrypt Poll Votes
451
+
452
+ - By default poll votes are encrypted and handled in `messages.update`
453
+ ```ts
454
+ import pino from "pino"
455
+ import { makeInMemoryStore, getAggregateVotesInPollMessage } from 'Sanka-Baileyss'
456
+
457
+ const logger = pino({ timestamp: () => `,"time":"${new Date().toJSON()}"` }).child({ class: "Sanka-Baileyss" })
458
+ logger.level = "fatal"
459
+ const store = makeInMemoryStore({ logger })
460
+
461
+ async function getMessage(key){
462
+ if (store) {
463
+ const msg = await store.loadMessage(key.remoteJid, key.id)
464
+ return msg?.message
465
+ }
466
+ return {
467
+ conversation: "Plana AI"
468
+ }
469
+ }
470
+
471
+ sanka.ev.on("messages.update", async (chatUpdate) => {
472
+ for(const { key, update } of chatUpdate) {
473
+ if(update.pollUpdates && key.fromMe) {
474
+ const pollCreation = await getMessage(key)
475
+ if(pollCreation) {
476
+ const pollUpdate = await getAggregateVotesInPollMessage({
477
+ message: pollCreation,
478
+ pollUpdates: update.pollUpdates,
479
+ })
480
+ const toCmd = pollUpdate.filter(v => v.voters.length !== 0)[0]?.name
481
+ if (toCmd == undefined) return
482
+ console.log(toCmd)
483
+ }
484
+ }
485
+ }
486
+ })
487
+ ```
488
+
489
+ ### Summary of Events on First Connection
490
+
491
+ 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
492
+ 2. Then, history messages will be received in `messaging.history-set`
493
+
494
+ ## Implementing a Data Store
495
+
496
+ - 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.
497
+
498
+ > [!IMPORTANT]
499
+ > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
500
+
501
+ It can be used as follows:
502
+
503
+ ```ts
504
+ import makeWASocket, { makeInMemoryStore } from 'Sanka-Baileyss'
505
+ // the store maintains the data of the WA connection in memory
506
+ // can be written out to a file & read from it
507
+ const store = makeInMemoryStore({ })
508
+ // can be read from a file
509
+ store.readFromFile('./baileys_store.json')
510
+ // saves the state to a file every 10s
511
+ setInterval(() => {
512
+ store.writeToFile('./baileys_store.json')
513
+ }, 10_000)
514
+
515
+ const sanka = makeWASocket({ })
516
+ // will listen from this socket
517
+ // the store can listen from a new socket once the current socket outlives its lifetime
518
+ store.bind(sanka.ev)
519
+
520
+ sanka.ev.on('chats.upsert', () => {
521
+ // can use 'store.chats' however you want, even after the socket dies out
522
+ // 'chats' => a KeyedDB instance
523
+ console.log('got chats', store.chats.all())
524
+ })
525
+
526
+ sanka.ev.on('contacts.upsert', () => {
527
+ console.log('got contacts', Object.values(store.contacts))
528
+ })
529
+
530
+ ```
531
+
532
+ The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
533
+
534
+ ## Whatsapp IDs Explain
535
+
536
+ - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
537
+ - It must be in the format ```[country code][phone number]@s.whatsapp.net```
538
+ - Example for people: ```+19999999999@s.whatsapp.net```.
539
+ - For groups, it must be in the format ``` 123456789-123345@g.us ```.
540
+ - For broadcast lists, it's `[timestamp of creation]@broadcast`.
541
+ - For stories, the ID is `status@broadcast`.
542
+
543
+ ## Utility Functions
544
+
545
+ - `getContentType`, returns the content type for any message
546
+ - `getDevice`, returns the device from message
547
+ - `makeCacheableSignalKeyStore`, make auth store more fast
548
+ - `downloadContentFromMessage`, download content from any message
549
+
550
+ ## Sending Messages
551
+
552
+ - Send all types of messages with a single function
553
+ - **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
554
+ - **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
555
+
556
+ ```ts
557
+ const jid: string
558
+ const content: AnyMessageContent
559
+ const options: MiscMessageGenerationOptions
560
+
561
+ sanka.sendMessage(jid, content, options)
562
+ ```
563
+
564
+ ### Non-Media Messages
565
+
566
+ #### Text Message
567
+ ```ts
568
+ await sanka.sendMessage(jid, { text: 'hello word' })
569
+ ```
570
+
571
+ #### Quote Message (works with all types)
572
+ ```ts
573
+ await sanka.sendMessage(jid, { text: 'hello word' }, { quoted: message })
574
+ ```
575
+
576
+ #### Mention User (works with most types)
577
+ - @number is to mention in text, it's optional
578
+ ```ts
579
+ await sanka.sendMessage(
580
+ jid,
581
+ {
582
+ text: '@12345678901',
583
+ mentions: ['12345678901@s.whatsapp.net']
584
+ }
585
+ )
586
+ ```
587
+
588
+ #### Forward Messages
589
+ - You need to have message object, can be retrieved from [store](#implementing-a-data-store) or use a [message](https://baileys.whiskeysockets.io/types/WAMessage.html) object
590
+ ```ts
591
+ const msg = getMessageFromStore() // implement this on your end
592
+ await sanka.sendMessage(jid, { forward: msg, force: true or number }) // WA forward the message!
593
+ ```
594
+
595
+ #### Location Message
596
+ ```ts
597
+ await sanka.sendMessage(
598
+ jid,
599
+ {
600
+ location: {
601
+ degreesLatitude: 24.121231,
602
+ degreesLongitude: 55.1121221
603
+ }
604
+ }
605
+ )
606
+ ```
607
+
608
+ #### Live Location Message
609
+ ```ts
610
+ await sanka.sendMessage(
611
+ jid,
612
+ {
613
+ location: {
614
+ degreesLatitude: 24.121231,
615
+ degreesLongitude: 55.1121221
616
+ },
617
+ live: true
618
+ }
619
+ )
620
+ ```
621
+ #### Contact Message
622
+ ```ts
623
+ const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
624
+ + 'VERSION:3.0\n'
625
+ + 'FN:Jeff Singh\n' // full name
626
+ + 'ORG:Ashoka Uni\n' // the organization of the contact
627
+ + 'TELtype=CELLtype=VOICEwaid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
628
+ + 'END:VCARD'
629
+
630
+ await sanka.sendMessage(
631
+ id,
632
+ {
633
+ contacts: {
634
+ displayName: 'Plana AI',
635
+ contacts: [{ vcard }]
636
+ }
637
+ }
638
+ )
639
+ ```
640
+
641
+ #### Reaction Message
642
+ - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.whiskeysockets.io/types/WAMessageKey.html) object
643
+ ```ts
644
+ await sanka.sendMessage(
645
+ jid,
646
+ {
647
+ react: {
648
+ text: '💖', // use an empty string to remove the reaction
649
+ key: message.key
650
+ }
651
+ }
652
+ )
653
+ ```
654
+
655
+ #### Pin Message
656
+ - You need to pass the key of message, you can retrieve from [store](#implementing-a-data-store) or use a [key](https://baileys.whiskeysockets.io/types/WAMessageKey.html) object
657
+
658
+ - Time can be:
659
+
660
+ | Time | Seconds |
661
+ |-------|----------------|
662
+ | 24h | 86.400 |
663
+ | 7d | 604.800 |
664
+ | 30d | 2.592.000 |
665
+
666
+ ```ts
667
+ await sanka.sendMessage(
668
+ jid,
669
+ {
670
+ pin: {
671
+ type: 1, // 2 to remove
672
+ time: 86400,
673
+ key: Key
674
+ }
675
+ }
676
+ )
677
+ ```
678
+
679
+ ### Keep Message
680
+ ```ts
681
+ await sanka.sendMessage(
682
+ jid,
683
+ {
684
+ keep: {
685
+ key: Key,
686
+ type: 1 // or 2
687
+ }
688
+ }
689
+ )
690
+ ```
691
+
692
+ #### Poll Message
693
+ ```ts
694
+ await sanka.sendMessage(
695
+ jid,
696
+ {
697
+ poll: {
698
+ name: 'My Poll',
699
+ values: ['Option 1', 'Option 2', ...],
700
+ selectableCount: 1,
701
+ toAnnouncementGroup: false // or true
702
+ }
703
+ }
704
+ )
705
+ ```
706
+
707
+ #### Poll Result Message
708
+ ```ts
709
+ await sanka.sendMessage(
710
+ jid,
711
+ {
712
+ pollResult: {
713
+ name: 'Hi',
714
+ values: [
715
+ [
716
+ 'Option 1',
717
+ 1000
718
+ ],
719
+ [
720
+ 'Option 2',
721
+ 2000
722
+ ]
723
+ ]
724
+ }
725
+ }
726
+ )
727
+ ```
728
+
729
+ ### Call Message
730
+ ```ts
731
+ await sanka.sendMessage(
732
+ jid,
733
+ {
734
+ call: {
735
+ name: 'Hay',
736
+ type: 1 // 2 for video
737
+ }
738
+ }
739
+ )
740
+ ```
741
+
742
+ ### Event Message
743
+ ```ts
744
+ await sanka.sendMessage(
745
+ jid,
746
+ {
747
+ event: {
748
+ isCanceled: false, // or true
749
+ name: 'holiday together!',
750
+ description: 'who wants to come along?',
751
+ location: {
752
+ degreesLatitude: 24.121231,
753
+ degreesLongitude: 55.1121221,
754
+ name: 'name'
755
+ },
756
+ startTime: number,
757
+ endTime: number,
758
+ extraGuestsAllowed: true // or false
759
+ }
760
+ }
761
+ )
762
+ ```
763
+
764
+ ### Order Message
765
+ ```ts
766
+ await sanka.sendMessage(
767
+ jid,
768
+ {
769
+ order: {
770
+ orderId: '574xxx',
771
+ thumbnail: 'your_thumbnail',
772
+ itemCount: 'your_count',
773
+ status: 'your_status', // INQUIRY || ACCEPTED || DECLINED
774
+ surface: 'CATALOG',
775
+ message: 'your_caption',
776
+ orderTitle: "your_title",
777
+ sellerJid: 'your_jid'',
778
+ token: 'your_token',
779
+ totalAmount1000: 'your_amount',
780
+ totalCurrencyCode: 'IDR'
781
+ }
782
+ }
783
+ )
784
+ ```
785
+
786
+ ### Product Message
787
+ ```ts
788
+ await sanka.sendMessage(
789
+ jid,
790
+ {
791
+ product: {
792
+ productImage: { // for using buffer >> productImage: your_buffer
793
+ url: your_url
794
+ },
795
+ productId: 'your_id',
796
+ title: 'your_title',
797
+ description: 'your_description',
798
+ currencyCode: 'IDR',
799
+ priceAmount1000: 'your_amount',
800
+ retailerId: 'your_reid', // optional use if needed
801
+ url: 'your_url', // optional use if needed
802
+ productImageCount: 'your_imageCount',
803
+ firstImageId: 'your_image', // optional use if needed
804
+ salePriceAmount1000: 'your_priceSale',
805
+ signedUrl: 'your_url' // optional use if needed
806
+ },
807
+ businessOwnerJid: 'your_jid'
808
+ }
809
+ )
810
+ ```
811
+
812
+ ### Payment Message
813
+ ```ts
814
+ await sanka.sendMessage(
815
+ jid,
816
+ {
817
+ payment: {
818
+ note: 'Hi!',
819
+ currency: 'IDR', // optional
820
+ offset: 0, // optional
821
+ amount: '10000', // optional
822
+ expiry: 0, // optional
823
+ from: '628xxxx@s.whatsapp.net', // optional
824
+ image: { // optional
825
+ placeholderArgb: "your_background", // optional
826
+ textArgb: "your_text", // optional
827
+ subtextArgb: "your_subtext" // optional
828
+ }
829
+ }
830
+ }
831
+ )
832
+ ```
833
+
834
+ #### Payment Invite Message
835
+ ```ts
836
+ await sanka.sendMessage(
837
+ id,
838
+ {
839
+ paymentInvite: {
840
+ type: number, // 1 || 2 || 3
841
+ expiry: 0
842
+ }
843
+ }
844
+ )
845
+ ```
846
+
847
+ ### Admin Invite Message
848
+ ```ts
849
+ await sanka.sendMessage(
850
+ jid,
851
+ {
852
+ adminInvite: {
853
+ jid: '123xxx@newsletter',
854
+ name: 'newsletter_name',
855
+ caption: 'Please be my channel admin',
856
+ expiration: 86400,
857
+ jpegThumbnail: Buffer // optional
858
+ }
859
+ }
860
+ )
861
+ ```
862
+
863
+ ### Group Invite Message
864
+ ```ts
865
+ await sanka.sendMessage(
866
+ jid,
867
+ {
868
+ groupInvite: {
869
+ jid: '123xxx@g.us',
870
+ name: 'group_name',
871
+ caption: 'Please Join My Whatsapp Group',
872
+ code: 'code_invite',
873
+ expiration: 86400,
874
+ jpegThumbnail: Buffer, // optional
875
+ }
876
+ }
877
+ )
878
+ ```
879
+
880
+ ### Share Phone Number Message
881
+ ```ts
882
+ await sanka.sendMessage(
883
+ jid,
884
+ {
885
+ sharePhoneNumber: {
886
+ }
887
+ }
888
+ )
889
+ ```
890
+
891
+ ### Request Phone Number Message
892
+ ```ts
893
+ await sanka.sendMessage(
894
+ jid,
895
+ {
896
+ requestPhoneNumber: {
897
+ }
898
+ }
899
+ )
900
+ ```
901
+
902
+ ### Buttons Reply Message
903
+ ```ts
904
+ // List
905
+ await sanka.sendMessage(
906
+ jid,
907
+ {
908
+ buttonReply: {
909
+ name: 'Hii',
910
+ description: 'description',
911
+ rowId: 'ID'
912
+ },
913
+ type: 'list'
914
+ }
915
+ )
916
+ // Plain
917
+ await sanka.sendMessage(
918
+ jid,
919
+ {
920
+ buttonReply: {
921
+ displayText: 'Hii',
922
+ id: 'ID'
923
+ },
924
+ type: 'plain'
925
+ }
926
+ )
927
+
928
+ // Template
929
+ await sanka.sendMessage(
930
+ jid,
931
+ {
932
+ buttonReply: {
933
+ displayText: 'Hii',
934
+ id: 'ID',
935
+ index: 'number'
936
+ },
937
+ type: 'template'
938
+ }
939
+ )
940
+
941
+ // Interactive
942
+ await sanka.sendMessage(
943
+ jid,
944
+ {
945
+ buttonReply: {
946
+ body: 'Hii',
947
+ nativeFlows: {
948
+ name: 'menu_options',
949
+ paramsJson: JSON.stringify({ id: 'ID', description: 'description' })
950
+ version: 1 // 2 | 3
951
+ }
952
+ },
953
+ type: 'interactive'
954
+ }
955
+ )
956
+ ```
957
+
958
+ ### Buttons Message
959
+ ```ts
960
+ await sanka.sendMessage(
961
+ jid,
962
+ {
963
+ text: 'This is a button message!', // image: buffer or // image: { url: url } If you want to use images
964
+ caption: 'caption', // Use this if you are using an image or video
965
+ footer: 'Hello World!',
966
+ buttons: [{
967
+ buttonId: 'Id1',
968
+ buttonText: {
969
+ displayText: 'Button 1'
970
+ }
971
+ },
972
+ {
973
+ buttonId: 'Id2',
974
+ buttonText: {
975
+ displayText: 'Button 2'
976
+ }
977
+ },
978
+ {
979
+ buttonId: 'Id3',
980
+ buttonText: {
981
+ displayText: 'Button 3'
982
+ }
983
+ }]
984
+ }
985
+ )
986
+ ```
987
+
988
+ ### Buttons List Message
989
+ ```ts
990
+ // Just working in a private chat
991
+ await sanka.sendMessage(
992
+ jid,
993
+ {
994
+ text: 'This is a list!',
995
+ footer: 'Hello World!',
996
+ title: 'Amazing boldfaced list title',
997
+ buttonText: 'Required, text on the button to view the list',
998
+ sections: [
999
+ {
1000
+ title: 'Section 1',
1001
+ rows: [{
1002
+ title: 'Option 1',
1003
+ rowId: 'option1'
1004
+ },
1005
+ {
1006
+ title: 'Option 2',
1007
+ rowId: 'option2',
1008
+ description: 'This is a description'
1009
+ }]
1010
+ },
1011
+ {
1012
+ title: 'Section 2',
1013
+ rows: [{
1014
+ title: 'Option 3',
1015
+ rowId: 'option3'
1016
+ },
1017
+ {
1018
+ title: 'Option 4',
1019
+ rowId: 'option4',
1020
+ description: 'This is a description V2'
1021
+ }]
1022
+ }]
1023
+ }
1024
+ )
1025
+ ```
1026
+
1027
+ ### Buttons Product List Message
1028
+ ```ts
1029
+ // Just working in a private chat
1030
+ await sanka.sendMessage(
1031
+ jid,
1032
+ {
1033
+ text: 'This is a list!',
1034
+ footer: 'Hello World!',
1035
+ title: 'Amazing boldfaced list title',
1036
+ buttonText: 'Required, text on the button to view the list',
1037
+ productList: [{
1038
+ title: 'This is a title',
1039
+ products: [
1040
+ {
1041
+ productId: '1234'
1042
+ },
1043
+ {
1044
+ productId: '5678'
1045
+ }
1046
+ ]
1047
+ }],
1048
+ businessOwnerJid: '628xxx@s.whatsapp.net',
1049
+ thumbnail: 'https://example.jpg' // or buffer
1050
+ }
1051
+ )
1052
+ ```
1053
+
1054
+ ### Buttons Cards Message
1055
+ ```ts
1056
+ await sanka.sendMessage(
1057
+ jid,
1058
+ {
1059
+ text: 'Body Message',
1060
+ title: 'Title Message',
1061
+ subtile: 'Subtitle Message',
1062
+ footer: 'Footer Message',
1063
+ cards: [
1064
+ {
1065
+ image: { url: 'https://example.jpg' }, // or buffer
1066
+ title: 'Title Cards',
1067
+ body: 'Body Cards',
1068
+ footer: 'Footer Cards',
1069
+ buttons: [
1070
+ {
1071
+ name: 'quick_reply',
1072
+ buttonParamsJson: JSON.stringify({
1073
+ display_text: 'Display Button',
1074
+ id: 'ID'
1075
+ })
1076
+ },
1077
+ {
1078
+ name: 'cta_url',
1079
+ buttonParamsJson: JSON.stringify({
1080
+ display_text: 'Display Button',
1081
+ url: 'https://www.example.com'
1082
+ })
1083
+ }
1084
+ ]
1085
+ },
1086
+ {
1087
+ video: { url: 'https://example.mp4' }, // or buffer
1088
+ title: 'Title Cards',
1089
+ body: 'Body Cards',
1090
+ footer: 'Footer Cards',
1091
+ buttons: [
1092
+ {
1093
+ name: 'quick_reply',
1094
+ buttonParamsJson: JSON.stringify({
1095
+ display_text: 'Display Button',
1096
+ id: 'ID'
1097
+ })
1098
+ },
1099
+ {
1100
+ name: 'cta_url',
1101
+ buttonParamsJson: JSON.stringify({
1102
+ display_text: 'Display Button',
1103
+ url: 'https://www.example.com'
1104
+ })
1105
+ }
1106
+ ]
1107
+ }
1108
+ ]
1109
+ }
1110
+ )
1111
+ ```
1112
+
1113
+ ### Buttons Template Message
1114
+ ```ts
1115
+ await sanka.sendMessage(
1116
+ jid,
1117
+ {
1118
+ text: 'This is a template message!',
1119
+ footer: 'Hello World!',
1120
+ templateButtons: [{
1121
+ index: 1,
1122
+ urlButton: {
1123
+ displayText: 'Follow Me',
1124
+ url: 'https://whatsapp.com/channel/0029Vag9VSI2ZjCocqa2lB1y'
1125
+ },
1126
+ },
1127
+ {
1128
+ index: 2,
1129
+ callButton: {
1130
+ displayText: 'Call Me!',
1131
+ phoneNumber: '628xxx'
1132
+ },
1133
+ },
1134
+ {
1135
+ index: 3,
1136
+ quickReplyButton: {
1137
+ displayText: 'This is a reply, just like normal buttons!',
1138
+ id: 'id-like-buttons-message'
1139
+ },
1140
+ }]
1141
+ }
1142
+ )
1143
+ ```
1144
+
1145
+ ### Buttons Interactive Message
1146
+ ```ts
1147
+ await sanka.sendMessage(
1148
+ jid,
1149
+ {
1150
+ text: 'This is an Interactive message!',
1151
+ title: 'Hiii',
1152
+ subtitle: 'There is a subtitle',
1153
+ footer: 'Hello World!',
1154
+ interactiveButtons: [
1155
+ {
1156
+ name: 'quick_reply',
1157
+ buttonParamsJson: JSON.stringify({
1158
+ display_text: 'Click Me!',
1159
+ id: 'your_id'
1160
+ })
1161
+ },
1162
+ {
1163
+ name: 'cta_url',
1164
+ buttonParamsJson: JSON.stringify({
1165
+ display_text: 'Follow Me',
1166
+ url: 'https://whatsapp.com/channel/0029Vag9VSI2ZjCocqa2lB1y',
1167
+ merchant_url: 'https://whatsapp.com/channel/0029Vag9VSI2ZjCocqa2lB1y'
1168
+ })
1169
+ },
1170
+ {
1171
+ name: 'cta_copy',
1172
+ buttonParamsJson: JSON.stringify({
1173
+ display_text: 'Click Me!',
1174
+ copy_code: 'https://whatsapp.com/channel/0029Vag9VSI2ZjCocqa2lB1y'
1175
+ })
1176
+ },
1177
+ {
1178
+ name: 'cta_call',
1179
+ buttonParamsJson: JSON.stringify({
1180
+ display_text: 'Call Me!',
1181
+ phone_number: '628xxx'
1182
+ })
1183
+ },
1184
+ {
1185
+ name: 'cta_catalog',
1186
+ buttonParamsJson: JSON.stringify({
1187
+ business_phone_number: '628xxx'
1188
+ })
1189
+ },
1190
+ {
1191
+ name: 'cta_reminder',
1192
+ buttonParamsJson: JSON.stringify({
1193
+ display_text: '...'
1194
+ })
1195
+ },
1196
+ {
1197
+ name: 'cta_cancel_reminder',
1198
+ buttonParamsJson: JSON.stringify({
1199
+ display_text: '...'
1200
+ })
1201
+ },
1202
+ {
1203
+ name: 'address_message',
1204
+ buttonParamsJson: JSON.stringify({
1205
+ display_text: '...'
1206
+ })
1207
+ },
1208
+ {
1209
+ name: 'send_location',
1210
+ buttonParamsJson: JSON.stringify({
1211
+ display_text: '...'
1212
+ })
1213
+ },
1214
+ {
1215
+ name: 'open_webview',
1216
+ buttonParamsJson: JSON.stringify({
1217
+ title: 'Follow Me!',
1218
+ link: {
1219
+ in_app_webview: true, // or false
1220
+ url: 'https://whatsapp.com/channel/0029Vag9VSI2ZjCocqa2lB1y'
1221
+ }
1222
+ })
1223
+ },
1224
+ {
1225
+ name: 'mpm',
1226
+ buttonParamsJson: JSON.stringify({
1227
+ product_id: '8816262248471474'
1228
+ })
1229
+ },
1230
+ {
1231
+ name: 'wa_payment_transaction_details',
1232
+ buttonParamsJson: JSON.stringify({
1233
+ transaction_id: '12345848'
1234
+ })
1235
+ },
1236
+ {
1237
+ name: 'automated_greeting_message_view_catalog',
1238
+ buttonParamsJson: JSON.stringify({
1239
+ business_phone_number: '628xxx',
1240
+ catalog_product_id: '12345'
1241
+ })
1242
+ },
1243
+ {
1244
+ name: 'galaxy_message',
1245
+ buttonParamsJson: JSON.stringify({
1246
+ mode: 'published',
1247
+ flow_message_version: '3',
1248
+ flow_token: '1:1307913409923914:293680f87029f5a13d1ec5e35e718af3',
1249
+ flow_id: '1307913409923914',
1250
+ flow_cta: 'I Love Plana >\\<',
1251
+ flow_action: 'navigate',
1252
+ flow_action_payload: {
1253
+ screen: 'QUESTION_ONE',
1254
+ params: {
1255
+ user_id: '123456789',
1256
+ referral: 'campaign_xyz'
1257
+ }
1258
+ },
1259
+ flow_metadata: {
1260
+ flow_json_version: '201',
1261
+ data_api_protocol: 'v2',
1262
+ flow_name: 'Lead Qualification [en]',
1263
+ data_api_version: 'v2',
1264
+ categories: ['Lead Generation', 'Sales']
1265
+ }
1266
+ })
1267
+ },
1268
+ {
1269
+ name: 'single_select',
1270
+ buttonParamsJson: JSON.stringify({
1271
+ title: 'Click Me!',
1272
+ sections: [
1273
+ {
1274
+ title: 'Title 1',
1275
+ highlight_label: 'Highlight label 1',
1276
+ rows: [
1277
+ {
1278
+ header: 'Header 1',
1279
+ title: 'Title 1',
1280
+ description: 'Description 1',
1281
+ id: 'Id 1'
1282
+ },
1283
+ {
1284
+ header: 'Header 2',
1285
+ title: 'Title 2',
1286
+ description: 'Description 2',
1287
+ id: 'Id 2'
1288
+ }
1289
+ ]
1290
+ }
1291
+ ]
1292
+ })
1293
+ }
1294
+ ]
1295
+ }
1296
+ )
1297
+
1298
+ // If you want to use an image
1299
+ await sanka.sendMessage(
1300
+ jid,
1301
+ {
1302
+ image: {
1303
+ url: 'https://example.jpg'
1304
+ },
1305
+ caption: 'Body',
1306
+ title: 'Title',
1307
+ subtitle: 'Subtitle',
1308
+ footer: 'Footer',
1309
+ interactiveButtons: [
1310
+ {
1311
+ name: 'quick_reply',
1312
+ buttonParamsJson: JSON.stringify({
1313
+ display_text: 'DisplayText',
1314
+ id: 'ID1'
1315
+ })
1316
+ }
1317
+ ],
1318
+ hasMediaAttachment: false // or true
1319
+ }
1320
+ )
1321
+
1322
+ // If you want to use an video
1323
+ await sanka.sendMessage(
1324
+ jid,
1325
+ {
1326
+ video: {
1327
+ url: 'https://example.mp4'
1328
+ },
1329
+ caption: 'Body',
1330
+ title: 'Title',
1331
+ subtitle: 'Subtitle',
1332
+ footer: 'Footer',
1333
+ interactiveButtons: [
1334
+ {
1335
+ name: 'quick_reply',
1336
+ buttonParamsJson: JSON.stringify({
1337
+ display_text: 'DisplayText',
1338
+ id: 'ID1'
1339
+ })
1340
+ }
1341
+ ],
1342
+ hasMediaAttachment: false // or true
1343
+ }
1344
+ )
1345
+
1346
+ // If you want to use an document
1347
+ await sanka.sendMessage(
1348
+ jid,
1349
+ {
1350
+ document: {
1351
+ url: 'https://example.jpg'
1352
+ },
1353
+ mimetype: 'image/jpeg',
1354
+ jpegThumbnail: await sanka.resize('https://example.jpg', 320, 320),
1355
+ caption: 'Body',
1356
+ title: 'Title',
1357
+ subtitle: 'Subtitle',
1358
+ footer: 'Footer',
1359
+ interactiveButtons: [
1360
+ {
1361
+ name: 'quick_reply',
1362
+ buttonParamsJson: JSON.stringify({
1363
+ display_text: 'DisplayText',
1364
+ id: 'ID1'
1365
+ })
1366
+ }
1367
+ ],
1368
+ hasMediaAttachment: false // or true
1369
+ }
1370
+ )
1371
+
1372
+ // If you want to use an location
1373
+ await sanka.sendMessage(
1374
+ jid,
1375
+ {
1376
+ location: {
1377
+ degressLatitude: -0,
1378
+ degressLongitude: 0,
1379
+ name: 'Hi'
1380
+ },
1381
+ caption: 'Body',
1382
+ title: 'Title',
1383
+ subtitle: 'Subtitle',
1384
+ footer: 'Footer',
1385
+ interactiveButtons: [
1386
+ {
1387
+ name: 'quick_reply',
1388
+ buttonParamsJson: JSON.stringify({
1389
+ display_text: 'DisplayText',
1390
+ id: 'ID1'
1391
+ })
1392
+ }
1393
+ ],
1394
+ hasMediaAttachment: false // or true
1395
+ }
1396
+ )
1397
+
1398
+ // if you want to use an product
1399
+ await sanka.sendMessage(
1400
+ jid,
1401
+ {
1402
+ product: {
1403
+ productImage: {
1404
+ url: 'https://example.jpg'
1405
+ },
1406
+ productId: '836xxx',
1407
+ title: 'Title',
1408
+ description: 'Description',
1409
+ currencyCode: 'IDR',
1410
+ priceAmount1000: '283xxx',
1411
+ retailerId: 'Plana AI',
1412
+ url: 'https://example.com',
1413
+ productImageCount: 1
1414
+ },
1415
+ businessOwnerJid: '628xxx@s.whatsapp.net',
1416
+ caption: 'Body',
1417
+ title: 'Title',
1418
+ subtitle: 'Subtitle',
1419
+ footer: 'Footer',
1420
+ interactiveButtons: [
1421
+ {
1422
+ name: 'quick_reply',
1423
+ buttonParamsJson: JSON.stringify({
1424
+ display_text: 'DisplayText',
1425
+ id: 'ID1'
1426
+ })
1427
+ }
1428
+ ],
1429
+ hasMediaAttachment: false // or true
1430
+ }
1431
+ )
1432
+ ```
1433
+
1434
+ ### Buttons Interactive Message PIX
1435
+ ```ts
1436
+ await sanka.sendMessage(
1437
+ jid,
1438
+ {
1439
+ text: '', // This string is required. Even it's empty.
1440
+ interactiveButtons: [
1441
+ {
1442
+ name: 'payment_info',
1443
+ buttonParamsJson: JSON.stringify({
1444
+ payment_settings: [{
1445
+ type: "pix_static_code",
1446
+ pix_static_code: {
1447
+ merchant_name: 'Plana kawaii >\\\\\\<',
1448
+ key: 'example@Plana.ai',
1449
+ key_type: 'EMAIL' // PHONE || EMAIL || CPF || EVP
1450
+ }
1451
+ }]
1452
+ })
1453
+ }
1454
+ ],
1455
+ }
1456
+ )
1457
+ ```
1458
+
1459
+ ### Buttons Interactive Message PAY
1460
+ ```ts
1461
+ await sanka.sendMessage(
1462
+ jid,
1463
+ {
1464
+ text: '', // This string is required. Even it's empty.
1465
+ interactiveButtons: [
1466
+ {
1467
+ name: 'review_and_pay',
1468
+ buttonParamsJson: JSON.stringify({
1469
+ currency: 'IDR',
1470
+ payment_configuration: '',
1471
+ payment_type: '',
1472
+ total_amount: {
1473
+ value: '999999999',
1474
+ offset: '100'
1475
+ },
1476
+ reference_id: '45XXXXX',
1477
+ type: 'physical-goods',
1478
+ payment_method: 'confirm',
1479
+ payment_status: 'captured',
1480
+ payment_timestamp: Math.floor(Date.now() / 1000),
1481
+ order: {
1482
+ status: 'completed',
1483
+ description: '',
1484
+ subtotal: {
1485
+ value: '0',
1486
+ offset: '100'
1487
+ },
1488
+ order_type: 'PAYMENT_REQUEST',
1489
+ items: [{
1490
+ retailer_id: 'your_retailer_id',
1491
+ name: 'I Love Plana >\\\<',
1492
+ amount: {
1493
+ value: '999999999',
1494
+ offset: '100'
1495
+ },
1496
+ quantity: '1',
1497
+ }]
1498
+ },
1499
+ additional_note: 'I Love Plana >\\\<',
1500
+ native_payment_methods: [],
1501
+ share_payment_status: false
1502
+ })
1503
+ }
1504
+ ],
1505
+ }
1506
+ )
1507
+ ```
1508
+
1509
+ ### Status Mentions Message
1510
+ ```ts
1511
+ await sanka.sendStatusMentions(
1512
+ jid,
1513
+ {
1514
+ image: {
1515
+ url: 'https://example.com.jpg'
1516
+ },
1517
+ caption: 'Hi'
1518
+ }
1519
+ )
1520
+ ```
1521
+
1522
+ ### Send Album Message
1523
+ ```ts
1524
+ await sanka.sendAlbumMessage(
1525
+ jid,
1526
+ [
1527
+ {
1528
+ image: { url: 'https://example.jpg' },
1529
+ caption: 'Hello World'
1530
+ },
1531
+ {
1532
+ image: Buffer,
1533
+ caption: 'Hello World'
1534
+ },
1535
+ {
1536
+ video: { url: 'https://example.mp4' },
1537
+ caption: 'Hello World'
1538
+ },
1539
+ {
1540
+ video: Buffer,
1541
+ caption: 'Hello World'
1542
+ }
1543
+ ],
1544
+ {
1545
+ quoted: message,
1546
+ delay: 2000
1547
+ }
1548
+ )
1549
+ ```
1550
+ ### Shop Message
1551
+ ```ts
1552
+ await sanka.sendMessage(
1553
+ jid,
1554
+ {
1555
+ text: 'Body',
1556
+ title: 'Title',
1557
+ subtitle: 'Subtitle',
1558
+ footer: 'Footer',
1559
+ shop: {
1560
+ surface: 1, // 2 | 3 | 4
1561
+ id: 'https://example.com'
1562
+ },
1563
+ viewOnce: true
1564
+ }
1565
+ )
1566
+
1567
+ // Image
1568
+ await sanka.sendMessage(
1569
+ jid,
1570
+ {
1571
+ image: {
1572
+ url: 'https://example.jpg'
1573
+ },
1574
+ caption: 'Body',
1575
+ title: 'Title',
1576
+ subtitle: 'Subtitle',
1577
+ footer: 'Footer',
1578
+ shop: {
1579
+ surface: 1, // 2 | 3 | 4
1580
+ id: 'https://example.com'
1581
+ },
1582
+ hasMediaAttachment: false, // or true
1583
+ viewOnce: true
1584
+ }
1585
+ )
1586
+
1587
+ // Video
1588
+ await sanka.sendMessage(
1589
+ jid,
1590
+ {
1591
+ video: {
1592
+ url: 'https://example.jpg'
1593
+ },
1594
+ caption: 'Body',
1595
+ title: 'Title',
1596
+ subtitle: 'Subtitle',
1597
+ footer: 'Footer',
1598
+ shop: {
1599
+ surface: 1, // 2 | 3 | 4
1600
+ id: 'https://example.com'
1601
+ },
1602
+ hasMediaAttachment: false, // or true
1603
+ viewOnce: true
1604
+ }
1605
+ )
1606
+
1607
+ // Document
1608
+ await sanka.sendMessage(
1609
+ jid,
1610
+ {
1611
+ document: {
1612
+ url: 'https://example.jpg'
1613
+ },
1614
+ mimetype: 'image/jpeg',
1615
+ jpegThumbnail: await sanka.resize('https://example.jpg', 320, 320),
1616
+ caption: 'Body',
1617
+ title: 'Title',
1618
+ subtitle: 'Subtitle',
1619
+ footer: 'Footer',
1620
+ shop: {
1621
+ surface: 1, // 2 | 3 | 4
1622
+ id: 'https://example.com'
1623
+ },
1624
+ hasMediaAttachment: false, // or true,
1625
+ viewOnce: true
1626
+ }
1627
+ )
1628
+
1629
+ // Location
1630
+ await sanka.sendMessage(
1631
+ jid,
1632
+ {
1633
+ location: {
1634
+ degressLatitude: -0,
1635
+ degressLongitude: 0,
1636
+ name: 'Hi'
1637
+ },
1638
+ caption: 'Body',
1639
+ title: 'Title',
1640
+ subtitle: 'Subtitle',
1641
+ footer: 'Footer',
1642
+ shop: {
1643
+ surface: 1, // 2 | 3 | 4
1644
+ id: 'https://example.com'
1645
+ },
1646
+ hasMediaAttachment: false, // or true
1647
+ viewOnce: true
1648
+ }
1649
+ )
1650
+
1651
+ // Product
1652
+ await sanka.sendMessage(
1653
+ jid,
1654
+ {
1655
+ product: {
1656
+ productImage: {
1657
+ url: 'https://example.jpg'
1658
+ },
1659
+ productId: '836xxx',
1660
+ title: 'Title',
1661
+ description: 'Description',
1662
+ currencyCode: 'IDR',
1663
+ priceAmount1000: '283xxx',
1664
+ retailerId: 'Plana AI',
1665
+ url: 'https://example.com',
1666
+ productImageCount: 1
1667
+ },
1668
+ businessOwnerJid: '628xxx@s.whatsapp.net',
1669
+ caption: 'Body',
1670
+ title: 'Title',
1671
+ subtitle: 'Subtitle',
1672
+ footer: 'Footer',
1673
+ shop: {
1674
+ surface: 1, // 2 | 3 | 4
1675
+ id: 'https://example.com'
1676
+ },
1677
+ hasMediaAttachment: false, // or true
1678
+ viewOnce: true
1679
+ }
1680
+ )
1681
+ ```
1682
+ ### Collection Message
1683
+ ```ts
1684
+ await sanka.sendMessage(
1685
+ jid,
1686
+ {
1687
+ text: 'Body',
1688
+ title: 'Title',
1689
+ subtitle: 'Subtitle',
1690
+ footer: 'Footer',
1691
+ collection: {
1692
+ bizJid: 'jid',
1693
+ id: 'https://example.com',
1694
+ version: 1
1695
+ },
1696
+ viewOnce: true
1697
+ }
1698
+ )
1699
+
1700
+ // Image
1701
+ await sanka.sendMessage(
1702
+ jid,
1703
+ {
1704
+ image: {
1705
+ url: 'https://example.jpg'
1706
+ },
1707
+ caption: 'Body',
1708
+ title: 'Title',
1709
+ subtitle: 'Subtitle',
1710
+ footer: 'Footer',
1711
+ collection: {
1712
+ bizJid: 'jid',
1713
+ id: 'https://example.com',
1714
+ version: 1
1715
+ },
1716
+ hasMediaAttachment: false, // or true
1717
+ viewOnce: true
1718
+ }
1719
+ )
1720
+
1721
+ // Video
1722
+ await sanka.sendMessage(
1723
+ jid,
1724
+ {
1725
+ video: {
1726
+ url: 'https://example.jpg'
1727
+ },
1728
+ caption: 'Body',
1729
+ title: 'Title',
1730
+ subtitle: 'Subtitle',
1731
+ footer: 'Footer',
1732
+ collection: {
1733
+ bizJid: 'jid',
1734
+ id: 'https://example.com',
1735
+ version: 1
1736
+ },
1737
+ hasMediaAttachment: false, // or true
1738
+ viewOnce: true
1739
+ }
1740
+ )
1741
+
1742
+ // Document
1743
+ await sanka.sendMessage(
1744
+ jid,
1745
+ {
1746
+ document: {
1747
+ url: 'https://example.jpg'
1748
+ },
1749
+ mimetype: 'image/jpeg',
1750
+ jpegThumbnail: await sanka.resize('https://example.jpg', 320, 320),
1751
+ caption: 'Body',
1752
+ title: 'Title',
1753
+ subtitle: 'Subtitle',
1754
+ footer: 'Footer',
1755
+ collection: {
1756
+ bizJid: 'jid',
1757
+ id: 'https://example.com',
1758
+ version: 1
1759
+ },
1760
+ hasMediaAttachment: false, // or true,
1761
+ viewOnce: true
1762
+ }
1763
+ )
1764
+
1765
+ // Location
1766
+ await sanka.sendMessage(
1767
+ jid,
1768
+ {
1769
+ location: {
1770
+ degressLatitude: -0,
1771
+ degressLongitude: 0,
1772
+ name: 'Hi'
1773
+ },
1774
+ caption: 'Body',
1775
+ title: 'Title',
1776
+ subtitle: 'Subtitle',
1777
+ footer: 'Footer',
1778
+ collection: {
1779
+ bizJid: 'jid',
1780
+ id: 'https://example.com',
1781
+ version: 1
1782
+ },
1783
+ hasMediaAttachment: false, // or true
1784
+ viewOnce: true
1785
+ }
1786
+ )
1787
+
1788
+ // Product
1789
+ await sanka.sendMessage(
1790
+ jid,
1791
+ {
1792
+ product: {
1793
+ productImage: {
1794
+ url: 'https://example.jpg'
1795
+ },
1796
+ productId: '836xxx',
1797
+ title: 'Title',
1798
+ description: 'Description',
1799
+ currencyCode: 'IDR',
1800
+ priceAmount1000: '283xxx',
1801
+ retailerId: 'Plana AI',
1802
+ url: 'https://example.com',
1803
+ productImageCount: 1
1804
+ },
1805
+ businessOwnerJid: '628xxx@s.whatsapp.net',
1806
+ caption: 'Body',
1807
+ title: 'Title',
1808
+ subtitle: 'Subtitle',
1809
+ footer: 'Footer',
1810
+ collection: {
1811
+ bizJid: 'jid',
1812
+ id: 'https://example.com',
1813
+ version: 1
1814
+ },
1815
+ hasMediaAttachment: false, // or true
1816
+ viewOnce: true
1817
+ }
1818
+ )
1819
+ ```
1820
+
1821
+ ### Sending Messages with Link Previews
1822
+
1823
+ 1. By default, wa does not have link generation when sent from the web
1824
+ 2. Baileys has a function to generate the content for these link previews
1825
+ 3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
1826
+ 4. Send a link:
1827
+ ```ts
1828
+ await sanka.sendMessage(
1829
+ jid,
1830
+ {
1831
+ text: 'Hi, this was sent using https://github.com/whiskeysockets/baileys'
1832
+ }
1833
+ )
1834
+ ```
1835
+
1836
+ ### Media Messages
1837
+
1838
+ Sending media (video, stickers, images) is easier & more efficient than ever.
1839
+
1840
+ > [!NOTE]
1841
+ > In media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
1842
+
1843
+ - When specifying a media url, Baileys never loads the entire buffer into memory it even encrypts the media as a readable stream.
1844
+
1845
+ > [!TIP]
1846
+ > It's recommended to use Stream or Url to save memory
1847
+
1848
+ #### Gif Message
1849
+ - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
1850
+ ```ts
1851
+ await sanka.sendMessage(
1852
+ jid,
1853
+ {
1854
+ video: fs.readFileSync('Media/ma_gif.mp4'),
1855
+ caption: 'hello word',
1856
+ gifPlayback: true
1857
+ }
1858
+ )
1859
+ ```
1860
+
1861
+ #### Video Message
1862
+ ```ts
1863
+ await sanka.sendMessage(
1864
+ id,
1865
+ {
1866
+ video: {
1867
+ url: './Media/ma_gif.mp4'
1868
+ },
1869
+ caption: 'hello word',
1870
+ }
1871
+ )
1872
+ ```
1873
+
1874
+ #### Video Ptv Message
1875
+ ```ts
1876
+ await sanka.sendMessage(
1877
+ id,
1878
+ {
1879
+ video: {
1880
+ url: './Media/ma_gif.mp4'
1881
+ },
1882
+ ptv: true
1883
+ }
1884
+ )
1885
+ ```
1886
+
1887
+ #### Audio Message
1888
+ - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
1889
+ ```bash
1890
+ codec: libopus //ogg file
1891
+ ac: 1 //one channel
1892
+ avoid_negative_ts
1893
+ make_zero
1894
+ ```
1895
+ - Example:
1896
+ ```bash
1897
+ ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
1898
+ ```
1899
+ ```ts
1900
+ await sanka.sendMessage(
1901
+ jid,
1902
+ {
1903
+ audio: {
1904
+ url: './Media/audio.mp3'
1905
+ },
1906
+ mimetype: 'audio/mp4'
1907
+ }
1908
+ )
1909
+ ```
1910
+
1911
+ #### Image Message
1912
+ ```ts
1913
+ await sanka.sendMessage(
1914
+ id,
1915
+ {
1916
+ image: {
1917
+ url: './Media/ma_img.png'
1918
+ },
1919
+ caption: 'hello word'
1920
+ }
1921
+ )
1922
+ ```
1923
+
1924
+ #### View Once Message
1925
+
1926
+ - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
1927
+
1928
+ ```ts
1929
+ await sanka.sendMessage(
1930
+ id,
1931
+ {
1932
+ image: {
1933
+ url: './Media/ma_img.png'
1934
+ },
1935
+ viewOnce: true, //works with video, audio too
1936
+ caption: 'hello word'
1937
+ }
1938
+ )
1939
+ ```
1940
+
1941
+ ## Modify Messages
1942
+
1943
+ ### Deleting Messages (for everyone)
1944
+
1945
+ ```ts
1946
+ const msg = await sanka.sendMessage(jid, { text: 'hello word' })
1947
+ await sanka.sendMessage(jid, { delete: msg.key })
1948
+ ```
1949
+
1950
+ **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
1951
+
1952
+ ### Editing Messages
1953
+
1954
+ - You can pass all editable contents here
1955
+ ```ts
1956
+ await sanka.sendMessage(jid, {
1957
+ text: 'updated text goes here',
1958
+ edit: response.key,
1959
+ })
1960
+ ```
1961
+
1962
+ ## Manipulating Media Messages
1963
+
1964
+ ### Thumbnail in Media Messages
1965
+ - 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`.
1966
+ - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
1967
+
1968
+ ### Downloading Media Messages
1969
+
1970
+ If you want to save the media you received
1971
+ ```ts
1972
+ import { createWriteStream } from 'fs'
1973
+ import { downloadMediaMessage, getContentType } from 'Sanka-Baileyss'
1974
+
1975
+ sanka.ev.on('messages.upsert', async ({ [m] }) => {
1976
+ if (!m.message) return // if there is no text or media message
1977
+ const messageType = getContentType(m) // get what type of message it is (text, image, video...)
1978
+
1979
+ // if the message is an image
1980
+ if (messageType === 'imageMessage') {
1981
+ // download the message
1982
+ const stream = await downloadMediaMessage(
1983
+ m,
1984
+ 'stream', // can be 'buffer' too
1985
+ { },
1986
+ {
1987
+ logger,
1988
+ // pass this so that baileys can request a reupload of media
1989
+ // that has been deleted
1990
+ reuploadRequest: sanka.updateMediaMessage
1991
+ }
1992
+ )
1993
+ // save to file
1994
+ const writeStream = createWriteStream('./my-download.jpeg')
1995
+ stream.pipe(writeStream)
1996
+ }
1997
+ }
1998
+ ```
1999
+
2000
+ ### Re-upload Media Message to Whatsapp
2001
+
2002
+ - 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:
2003
+ ```ts
2004
+ await sanka.updateMediaMessage(msg)
2005
+ ```
2006
+
2007
+ ## Reject Call
2008
+
2009
+ - You can obtain `callId` and `callFrom` from `call` event
2010
+
2011
+ ```ts
2012
+ await sanka.rejectCall(callId, callFrom)
2013
+ ```
2014
+
2015
+ ## Send States in Chat
2016
+
2017
+ ### Reading Messages
2018
+ - A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
2019
+ - You cannot mark an entire 'chat' read as it were with Baileys Web.
2020
+ This means you have to keep track of unread messages.
2021
+
2022
+ ```ts
2023
+ const key: WAMessageKey
2024
+ // can pass multiple keys to read multiple messages as well
2025
+ await sanka.readMessages([key])
2026
+ ```
2027
+
2028
+ The message ID is the unique identifier of the message that you are marking as read.
2029
+ On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
2030
+
2031
+ ### Update Presence
2032
+
2033
+ - ``` presence ``` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
2034
+ - The presence expires after about 10 seconds.
2035
+ - This lets the person/group with `jid` know whether you're online, offline, typing etc.
2036
+
2037
+ ```ts
2038
+ await sanka.sendPresenceUpdate('available', jid)
2039
+ ```
2040
+
2041
+ > [!NOTE]
2042
+ > 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 `sanka.sendPresenceUpdate('unavailable')`
2043
+
2044
+ ## Modifying Chats
2045
+
2046
+ WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
2047
+
2048
+ > [!IMPORTANT]
2049
+ > 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.
2050
+
2051
+ ### Archive a Chat
2052
+ ```ts
2053
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
2054
+ await sanka.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
2055
+ ```
2056
+ ### Mute/Unmute a Chat
2057
+
2058
+ - Supported times:
2059
+
2060
+ | Time | Miliseconds |
2061
+ |-------|-----------------|
2062
+ | Remove | null |
2063
+ | 8h | 86.400.000 |
2064
+ | 7d | 604.800.000 |
2065
+
2066
+ ```ts
2067
+ // mute for 8 hours
2068
+ await sanka.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
2069
+ // unmute
2070
+ await sanka.chatModify({ mute: null }, jid)
2071
+ ```
2072
+ ### Mark a Chat Read/Unread
2073
+ ```ts
2074
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
2075
+ // mark it unread
2076
+ await sanka.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
2077
+ ```
2078
+
2079
+ ### Delete a Message for Me
2080
+ ```ts
2081
+ await sanka.chatModify(
2082
+ {
2083
+ clear: {
2084
+ messages: [
2085
+ {
2086
+ id: 'ATWYHDNNWU81732J',
2087
+ fromMe: true,
2088
+ timestamp: '1654823909'
2089
+ }
2090
+ ]
2091
+ }
2092
+ },
2093
+ jid
2094
+ )
2095
+
2096
+ ```
2097
+ ### Delete a Chat
2098
+ ```ts
2099
+ const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
2100
+ await sanka.chatModify({
2101
+ delete: true,
2102
+ lastMessages: [
2103
+ {
2104
+ key: lastMsgInChat.key,
2105
+ messageTimestamp: lastMsgInChat.messageTimestamp
2106
+ }
2107
+ ]
2108
+ },
2109
+ jid
2110
+ )
2111
+ ```
2112
+ ### Pin/Unpin a Chat
2113
+ ```ts
2114
+ await sanka.chatModify({
2115
+ pin: true // or `false` to unpin
2116
+ },
2117
+ jid
2118
+ )
2119
+ ```
2120
+ ### Star/Unstar a Message
2121
+ ```ts
2122
+ await sanka.chatModify({
2123
+ star: {
2124
+ messages: [
2125
+ {
2126
+ id: 'messageID',
2127
+ fromMe: true // or `false`
2128
+ }
2129
+ ],
2130
+ star: true // - true: Star Message false: Unstar Message
2131
+ }
2132
+ },
2133
+ jid
2134
+ )
2135
+ ```
2136
+
2137
+ ### Disappearing Messages
2138
+
2139
+ - Ephemeral can be:
2140
+
2141
+ | Time | Seconds |
2142
+ |-------|----------------|
2143
+ | Remove | 0 |
2144
+ | 24h | 86.400 |
2145
+ | 7d | 604.800 |
2146
+ | 90d | 7.776.000 |
2147
+
2148
+ - You need to pass in **Seconds**, default is 7 days
2149
+
2150
+ ```ts
2151
+ // turn on disappearing messages
2152
+ await sanka.sendMessage(
2153
+ jid,
2154
+ // this is 1 week in seconds -- how long you want messages to appear for
2155
+ { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
2156
+ )
2157
+
2158
+ // will send as a disappearing message
2159
+ await sanka.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
2160
+
2161
+ // turn off disappearing messages
2162
+ await sanka.sendMessage(
2163
+ jid,
2164
+ { disappearingMessagesInChat: false }
2165
+ )
2166
+ ```
2167
+
2168
+ ### Clear Messages
2169
+ ```ts
2170
+ await sanka.clearMessage(jid, key, timestamps)
2171
+ ```
2172
+
2173
+ ## User Querys
2174
+
2175
+ ### Check If ID Exists in Whatsapp
2176
+ ```ts
2177
+ const [result] = await sanka.onWhatsApp(jid)
2178
+ if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
2179
+ ```
2180
+
2181
+ ### Query Chat History (groups too)
2182
+
2183
+ - You need to have oldest message in chat
2184
+ ```ts
2185
+ const msg = await getOldestMessageInChat(jid)
2186
+ await sanka.fetchMessageHistory(
2187
+ 50, //quantity (max: 50 per query)
2188
+ msg.key,
2189
+ msg.messageTimestamp
2190
+ )
2191
+ ```
2192
+ - Messages will be received in `messaging.history-set` event
2193
+
2194
+ ### Fetch Status
2195
+ ```ts
2196
+ const status = await sanka.fetchStatus(jid)
2197
+ console.log('status: ' + status)
2198
+ ```
2199
+
2200
+ ### Fetch Profile Picture
2201
+ - To get the display picture of some person, group and channel
2202
+ ```ts
2203
+ // for low res picture
2204
+ const ppUrl = await sanka.profilePictureUrl(jid)
2205
+ console.log(ppUrl)
2206
+ ```
2207
+
2208
+ ### Fetch Bussines Profile (such as description or category)
2209
+ ```ts
2210
+ const profile = await sanka.getBusinessProfile(jid)
2211
+ console.log('business description: ' + profile.description + ', category: ' + profile.category)
2212
+ ```
2213
+
2214
+ ### Fetch Someone's Presence (if they're typing or online)
2215
+ ```ts
2216
+ // the presence update is fetched and called here
2217
+ sanka.ev.on('presence.update', console.log)
2218
+
2219
+ // request updates for a chat
2220
+ await sanka.presenceSubscribe(jid)
2221
+ ```
2222
+
2223
+ ## Change Profile
2224
+
2225
+ ### Change Profile Status
2226
+ ```ts
2227
+ await sanka.updateProfileStatus('Hello World!')
2228
+ ```
2229
+ ### Change Profile Name
2230
+ ```ts
2231
+ await sanka.updateProfileName('My name')
2232
+ ```
2233
+ ### Change Display Picture (groups too)
2234
+ - To change your display picture or a group's
2235
+
2236
+ > [!NOTE]
2237
+ > Like media messages, you can pass `{ stream: Stream }` or `{ url: Url }` or `Buffer` directly, you can see more [here](https://baileys.whiskeysockets.io/types/WAMediaUpload.html)
2238
+
2239
+ ```ts
2240
+ await sanka.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
2241
+ ```
2242
+ ### Remove display picture (groups too)
2243
+ ```ts
2244
+ await sanka.removeProfilePicture(jid)
2245
+ ```
2246
+
2247
+ ## Groups
2248
+
2249
+ - To change group properties you need to be admin
2250
+
2251
+ ### Create a Group
2252
+ ```ts
2253
+ // title & participants
2254
+ const group = await sanka.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
2255
+ console.log('created group with id: ' + group.gid)
2256
+ await sanka.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
2257
+ ```
2258
+ ### Add/Remove or Demote/Promote
2259
+ ```ts
2260
+ // id & people to add to the group (will throw error if it fails)
2261
+ await sanka.groupParticipantsUpdate(
2262
+ jid,
2263
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
2264
+ 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
2265
+ )
2266
+ ```
2267
+ ### Change Subject (name)
2268
+ ```ts
2269
+ await sanka.groupUpdateSubject(jid, 'New Subject!')
2270
+ ```
2271
+ ### Change Description
2272
+ ```ts
2273
+ await sanka.groupUpdateDescription(jid, 'New Description!')
2274
+ ```
2275
+ ### Change Settings
2276
+ ```ts
2277
+ // only allow admins to send messages
2278
+ await sanka.groupSettingUpdate(jid, 'announcement')
2279
+ // allow everyone to send messages
2280
+ await sanka.groupSettingUpdate(jid, 'not_announcement')
2281
+ // allow everyone to modify the group's settings -- like display picture etc.
2282
+ await sanka.groupSettingUpdate(jid, 'unlocked')
2283
+ // only allow admins to modify the group's settings
2284
+ await sanka.groupSettingUpdate(jid, 'locked')
2285
+ ```
2286
+ ### Leave a Group
2287
+ ```ts
2288
+ // will throw error if it fails
2289
+ await sanka.groupLeave(jid)
2290
+ ```
2291
+ ### Get Invite Code
2292
+ - To create link with code use `'https://chat.whatsapp.com/' + code`
2293
+ ```ts
2294
+ const code = await sanka.groupInviteCode(jid)
2295
+ console.log('group code: ' + code)
2296
+ ```
2297
+ ### Revoke Invite Code
2298
+ ```ts
2299
+ const code = await sanka.groupRevokeInvite(jid)
2300
+ console.log('New group code: ' + code)
2301
+ ```
2302
+ ### Join Using Invitation Code
2303
+ - Code can't have `https://chat.whatsapp.com/`, only code
2304
+ ```ts
2305
+ const response = await sanka.groupAcceptInvite(code)
2306
+ console.log('joined to: ' + response)
2307
+ ```
2308
+ ### Get Group Info by Invite Code
2309
+ ```ts
2310
+ const response = await sanka.groupGetInviteInfo(code)
2311
+ console.log('group information: ' + response)
2312
+ ```
2313
+ ### Query Metadata (participants, name, description...)
2314
+ ```ts
2315
+ const metadata = await sanka.groupMetadata(jid)
2316
+ console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
2317
+ ```
2318
+ ### Join using `groupInviteMessage`
2319
+ ```ts
2320
+ const response = await sanka.groupAcceptInviteV4(jid, groupInviteMessage)
2321
+ console.log('joined to: ' + response)
2322
+ ```
2323
+ ### Get Request Join List
2324
+ ```ts
2325
+ const response = await sanka.groupRequestParticipantsList(jid)
2326
+ console.log(response)
2327
+ ```
2328
+ ### Approve/Reject Request Join
2329
+ ```ts
2330
+ const response = await sanka.groupRequestParticipantsUpdate(
2331
+ jid, // group id
2332
+ ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
2333
+ 'approve' // or 'reject'
2334
+ )
2335
+ console.log(response)
2336
+ ```
2337
+ ### Get All Participating Groups Metadata
2338
+ ```ts
2339
+ const response = await sanka.groupFetchAllParticipating()
2340
+ console.log(response)
2341
+ ```
2342
+ ### Toggle Ephemeral
2343
+
2344
+ - Ephemeral can be:
2345
+
2346
+ | Time | Seconds |
2347
+ |-------|----------------|
2348
+ | Remove | 0 |
2349
+ | 24h | 86.400 |
2350
+ | 7d | 604.800 |
2351
+ | 90d | 7.776.000 |
2352
+
2353
+ ```ts
2354
+ await sanka.groupToggleEphemeral(jid, 86400)
2355
+ ```
2356
+
2357
+ ### Change Add Mode
2358
+ ```ts
2359
+ await sanka.groupMemberAddMode(
2360
+ jid,
2361
+ 'all_member_add' // or 'admin_add'
2362
+ )
2363
+ ```
2364
+
2365
+ ## Privacy
2366
+
2367
+ ### Block/Unblock User
2368
+ ```ts
2369
+ await sanka.updateBlockStatus(jid, 'block') // Block user
2370
+ await sanka.updateBlockStatus(jid, 'unblock') // Unblock user
2371
+ ```
2372
+ ### Get Privacy Settings
2373
+ ```ts
2374
+ const privacySettings = await sanka.fetchPrivacySettings(true)
2375
+ console.log('privacy settings: ' + privacySettings)
2376
+ ```
2377
+ ### Get BlockList
2378
+ ```ts
2379
+ const response = await sanka.fetchBlocklist()
2380
+ console.log(response)
2381
+ ```
2382
+ ### Update LastSeen Privacy
2383
+ ```ts
2384
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
2385
+ await sanka.updateLastSeenPrivacy(value)
2386
+ ```
2387
+ ### Update Online Privacy
2388
+ ```ts
2389
+ const value = 'all' // 'match_last_seen'
2390
+ await sanka.updateOnlinePrivacy(value)
2391
+ ```
2392
+ ### Update Profile Picture Privacy
2393
+ ```ts
2394
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
2395
+ await sanka.updateProfilePicturePrivacy(value)
2396
+ ```
2397
+ ### Update Status Privacy
2398
+ ```ts
2399
+ const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
2400
+ await sanka.updateStatusPrivacy(value)
2401
+ ```
2402
+ ### Update Read Receipts Privacy
2403
+ ```ts
2404
+ const value = 'all' // 'none'
2405
+ await sanka.updateReadReceiptsPrivacy(value)
2406
+ ```
2407
+ ### Update Groups Add Privacy
2408
+ ```ts
2409
+ const value = 'all' // 'contacts' | 'contact_blacklist'
2410
+ await sanka.updateGroupsAddPrivacy(value)
2411
+ ```
2412
+ ### Update Default Disappearing Mode
2413
+
2414
+ - Like [this](#disappearing-messages), ephemeral can be:
2415
+
2416
+ | Time | Seconds |
2417
+ |-------|----------------|
2418
+ | Remove | 0 |
2419
+ | 24h | 86.400 |
2420
+ | 7d | 604.800 |
2421
+ | 90d | 7.776.000 |
2422
+
2423
+ ```ts
2424
+ const ephemeral = 86400
2425
+ await sanka.updateDefaultDisappearingMode(ephemeral)
2426
+ ```
2427
+
2428
+ ## Broadcast Lists & Stories
2429
+
2430
+ ### Send Broadcast & Stories
2431
+ - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
2432
+ ```ts
2433
+ await sanka.sendMessage(
2434
+ jid,
2435
+ {
2436
+ image: {
2437
+ url: url
2438
+ },
2439
+ caption: caption
2440
+ },
2441
+ {
2442
+ backgroundColor: backgroundColor,
2443
+ font: font,
2444
+ statusJidList: statusJidList,
2445
+ broadcast: true
2446
+ }
2447
+ )
2448
+ ```
2449
+ - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
2450
+ - You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
2451
+ - `broadcast: true` enables broadcast mode
2452
+ - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
2453
+
2454
+ - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
2455
+ - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
2456
+ - Broadcast IDs are in the format `12345678@broadcast`
2457
+ ### Query a Broadcast List's Recipients & Name
2458
+ ```ts
2459
+ const bList = await sanka.getBroadcastListInfo('1234@broadcast')
2460
+ console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
2461
+ ```
2462
+
2463
+ ## Writing Custom Functionality
2464
+ Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
2465
+
2466
+ ### Enabling Debug Level in Baileys Logs
2467
+ First, enable the logging of unhandled messages from WhatsApp by setting:
2468
+ ```ts
2469
+ const sanka = makeWASocket({
2470
+ logger: P({ level: 'debug' }),
2471
+ })
2472
+ ```
2473
+ This will enable you to see all sorts of messages WhatsApp sends in the console.
2474
+
2475
+ ### How Whatsapp Communicate With Us
2476
+
2477
+ > [!TIP]
2478
+ > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
2479
+
2480
+ - **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:
2481
+ ```
2482
+ {
2483
+ "level": 10,
2484
+ "fromMe": false,
2485
+ "frame": {
2486
+ "tag": "ib",
2487
+ "attrs": {
2488
+ "from": "@s.whatsapp.net"
2489
+ },
2490
+ "content": [
2491
+ {
2492
+ "tag": "edge_routing",
2493
+ "attrs": {},
2494
+ "content": [
2495
+ {
2496
+ "tag": "routing_info",
2497
+ "attrs": {},
2498
+ "content": {
2499
+ "type": "Buffer",
2500
+ "data": [8,2,8,5]
2501
+ }
2502
+ }
2503
+ ]
2504
+ }
2505
+ ]
2506
+ },
2507
+ "msg":"communication"
2508
+ }
2509
+ ```
2510
+
2511
+ The `'frame'` is what the message received is, it has three components:
2512
+ - `tag` -- what this frame is about (eg. message will have 'message')
2513
+ - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
2514
+ - `content` -- the actual data (eg. a message node will have the actual message content in it)
2515
+ - read more about this format [here](/src/WABinary/readme.md)
2516
+
2517
+ ### Register a Callback for Websocket Events
2518
+
2519
+ > [!TIP]
2520
+ > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
2521
+
2522
+ ```ts
2523
+ // for any message with tag 'edge_routing'
2524
+ sanka.ws.on('CB:edge_routing', (node: BinaryNode) => { })
2525
+
2526
+ // for any message with tag 'edge_routing' and id attribute = abcd
2527
+ sanka.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
2528
+
2529
+ // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
2530
+ sanka.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
2531
+ ```
2532
+
2533
+ > [!NOTE]
2534
+ > Also, this repo is now licenced under GPL 3 since it uses [libsignal-node](https://git.questbook.io/backend/service-coderunner/-/merge_requests/1)