sanka-baileyss 1.4.8

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