gifted-baileys 1.5.5 → 1.5.7

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 (251) hide show
  1. package/README.md +6 -1642
  2. package/WAProto/WAProto.proto +969 -88
  3. package/WAProto/index.d.ts +13199 -1260
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +284 -0
  7. package/{src → lib}/Defaults/index.js +7 -14
  8. package/lib/Signal/libsignal.d.ts +3 -0
  9. package/lib/Signal/libsignal.js +161 -0
  10. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  11. package/lib/Socket/Client/index.d.ts +2 -0
  12. package/{src → lib}/Socket/Client/index.js +2 -3
  13. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/websocket.d.ts +12 -0
  18. package/lib/Socket/Client/websocket.js +62 -0
  19. package/lib/Socket/business.d.ts +170 -0
  20. package/{src → lib}/Socket/business.js +28 -33
  21. package/lib/Socket/chats.d.ts +81 -0
  22. package/{src → lib}/Socket/chats.js +174 -176
  23. package/lib/Socket/groups.d.ts +115 -0
  24. package/{src → lib}/Socket/groups.js +80 -68
  25. package/lib/Socket/index.d.ts +172 -0
  26. package/{src → lib}/Socket/index.js +4 -1
  27. package/lib/Socket/messages-recv.d.ts +158 -0
  28. package/{src → lib}/Socket/messages-recv.js +378 -211
  29. package/lib/Socket/messages-send.d.ts +155 -0
  30. package/{src → lib}/Socket/messages-send.js +452 -177
  31. package/lib/Socket/newsletter.d.ts +132 -0
  32. package/{src → lib}/Socket/newsletter.js +107 -98
  33. package/lib/Socket/registration.d.ts +264 -0
  34. package/{src → lib}/Socket/registration.js +56 -48
  35. package/lib/Socket/socket.d.ts +44 -0
  36. package/{src → lib}/Socket/socket.js +77 -77
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.d.ts +3 -0
  40. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  41. package/{src → lib}/Store/make-cache-manager-store.js +25 -34
  42. package/lib/Store/make-in-memory-store.d.ts +118 -0
  43. package/{src → lib}/Store/make-in-memory-store.js +36 -32
  44. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  45. package/lib/Store/object-repository.d.ts +10 -0
  46. package/{src → lib}/Store/object-repository.js +1 -1
  47. package/lib/Types/Auth.d.ts +109 -0
  48. package/lib/Types/Call.d.ts +13 -0
  49. package/lib/Types/Chat.d.ts +107 -0
  50. package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
  51. package/lib/Types/Events.d.ts +172 -0
  52. package/lib/Types/GroupMetadata.d.ts +56 -0
  53. package/lib/Types/Label.d.ts +46 -0
  54. package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
  55. package/lib/Types/Message.d.ts +433 -0
  56. package/lib/Types/Newsletter.d.ts +92 -0
  57. package/lib/Types/Product.d.ts +78 -0
  58. package/lib/Types/Signal.d.ts +57 -0
  59. package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
  60. package/lib/Types/State.d.ts +27 -0
  61. package/lib/Types/USync.d.ts +25 -0
  62. package/lib/Types/index.d.ts +66 -0
  63. package/lib/Utils/auth-utils.d.ts +18 -0
  64. package/{src → lib}/Utils/auth-utils.js +73 -90
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/baileys-event-stream.js +63 -0
  67. package/lib/Utils/business.d.ts +22 -0
  68. package/{src → lib}/Utils/business.js +15 -43
  69. package/lib/Utils/chat-utils.d.ts +70 -0
  70. package/{src → lib}/Utils/chat-utils.js +87 -94
  71. package/lib/Utils/crypto.d.ts +40 -0
  72. package/{src → lib}/Utils/crypto.js +4 -2
  73. package/lib/Utils/decode-wa-message.d.ts +36 -0
  74. package/lib/Utils/decode-wa-message.js +226 -0
  75. package/lib/Utils/event-buffer.d.ts +35 -0
  76. package/{src → lib}/Utils/event-buffer.js +4 -13
  77. package/lib/Utils/generics.d.ts +88 -0
  78. package/{src → lib}/Utils/generics.js +67 -86
  79. package/lib/Utils/history.d.ts +19 -0
  80. package/{src → lib}/Utils/history.js +13 -39
  81. package/lib/Utils/index.d.ts +17 -0
  82. package/lib/Utils/link-preview.d.ts +21 -0
  83. package/{src → lib}/Utils/link-preview.js +17 -54
  84. package/lib/Utils/logger.d.ts +2 -0
  85. package/lib/Utils/lt-hash.d.ts +12 -0
  86. package/lib/Utils/make-mutex.d.ts +7 -0
  87. package/{src → lib}/Utils/make-mutex.js +4 -13
  88. package/lib/Utils/messages-media.d.ts +113 -0
  89. package/{src → lib}/Utils/messages-media.js +193 -255
  90. package/lib/Utils/messages.d.ts +77 -0
  91. package/{src → lib}/Utils/messages.js +588 -118
  92. package/lib/Utils/noise-handler.d.ts +20 -0
  93. package/lib/Utils/process-message.d.ts +41 -0
  94. package/{src → lib}/Utils/process-message.js +27 -30
  95. package/lib/Utils/signal.d.ts +33 -0
  96. package/{src → lib}/Utils/signal.js +25 -42
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  98. package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
  99. package/lib/Utils/validate-connection.d.ts +11 -0
  100. package/{src → lib}/Utils/validate-connection.js +40 -9
  101. package/lib/WABinary/constants.d.ts +27 -0
  102. package/lib/WABinary/decode.d.ts +6 -0
  103. package/lib/WABinary/encode.d.ts +2 -0
  104. package/{src → lib}/WABinary/encode.js +16 -10
  105. package/lib/WABinary/generic-utils.d.ts +14 -0
  106. package/lib/WABinary/index.d.ts +5 -0
  107. package/lib/WABinary/jid-utils.d.ts +31 -0
  108. package/lib/WABinary/types.d.ts +18 -0
  109. package/lib/WABinary/types.js +2 -0
  110. package/lib/WAM/BinaryInfo.d.ts +8 -0
  111. package/lib/WAM/constants.d.ts +38 -0
  112. package/lib/WAM/encode.d.ts +2 -0
  113. package/lib/WAM/index.d.ts +3 -0
  114. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  117. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  118. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  119. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  120. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  121. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  122. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  123. package/lib/WAUSync/Protocols/index.js +20 -0
  124. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  125. package/lib/WAUSync/USyncQuery.js +79 -0
  126. package/lib/WAUSync/USyncUser.d.ts +10 -0
  127. package/lib/WAUSync/USyncUser.js +22 -0
  128. package/lib/WAUSync/index.d.ts +3 -0
  129. package/lib/WAUSync/index.js +19 -0
  130. package/{src → lib}/index.js +1 -0
  131. package/package.json +26 -8
  132. package/LICENSE +0 -21
  133. package/src/Defaults/baileys-version.json +0 -3
  134. package/src/Defaults/index.ts +0 -131
  135. package/src/Signal/libsignal.js +0 -180
  136. package/src/Signal/libsignal.ts +0 -141
  137. package/src/Socket/Client/abstract-socket-client.ts +0 -19
  138. package/src/Socket/Client/index.ts +0 -3
  139. package/src/Socket/Client/mobile-socket-client.js +0 -78
  140. package/src/Socket/Client/mobile-socket-client.ts +0 -66
  141. package/src/Socket/Client/web-socket-client.js +0 -75
  142. package/src/Socket/Client/web-socket-client.ts +0 -57
  143. package/src/Socket/business.ts +0 -281
  144. package/src/Socket/chats.ts +0 -1030
  145. package/src/Socket/groups.ts +0 -356
  146. package/src/Socket/index.ts +0 -13
  147. package/src/Socket/messages-recv.ts +0 -985
  148. package/src/Socket/messages-send.ts +0 -871
  149. package/src/Socket/newsletter.ts +0 -282
  150. package/src/Socket/registration.ts +0 -250
  151. package/src/Socket/socket.ts +0 -777
  152. package/src/Store/index.ts +0 -3
  153. package/src/Store/make-cache-manager-store.ts +0 -100
  154. package/src/Store/make-in-memory-store.ts +0 -475
  155. package/src/Store/make-ordered-dictionary.ts +0 -86
  156. package/src/Store/object-repository.ts +0 -32
  157. package/src/Tests/test.app-state-sync.js +0 -204
  158. package/src/Tests/test.app-state-sync.ts +0 -207
  159. package/src/Tests/test.event-buffer.js +0 -270
  160. package/src/Tests/test.event-buffer.ts +0 -319
  161. package/src/Tests/test.key-store.js +0 -76
  162. package/src/Tests/test.key-store.ts +0 -92
  163. package/src/Tests/test.libsignal.js +0 -141
  164. package/src/Tests/test.libsignal.ts +0 -186
  165. package/src/Tests/test.media-download.js +0 -93
  166. package/src/Tests/test.media-download.ts +0 -76
  167. package/src/Tests/test.messages.js +0 -33
  168. package/src/Tests/test.messages.ts +0 -37
  169. package/src/Tests/utils.js +0 -34
  170. package/src/Tests/utils.ts +0 -36
  171. package/src/Types/Auth.ts +0 -113
  172. package/src/Types/Call.ts +0 -15
  173. package/src/Types/Chat.ts +0 -106
  174. package/src/Types/Events.ts +0 -93
  175. package/src/Types/GroupMetadata.ts +0 -53
  176. package/src/Types/Label.ts +0 -36
  177. package/src/Types/Message.ts +0 -288
  178. package/src/Types/Newsletter.ts +0 -98
  179. package/src/Types/Product.ts +0 -85
  180. package/src/Types/Signal.ts +0 -68
  181. package/src/Types/State.ts +0 -29
  182. package/src/Types/index.ts +0 -59
  183. package/src/Utils/auth-utils.ts +0 -222
  184. package/src/Utils/baileys-event-stream.js +0 -92
  185. package/src/Utils/baileys-event-stream.ts +0 -66
  186. package/src/Utils/business.ts +0 -275
  187. package/src/Utils/chat-utils.ts +0 -860
  188. package/src/Utils/crypto.ts +0 -131
  189. package/src/Utils/decode-wa-message.js +0 -211
  190. package/src/Utils/decode-wa-message.ts +0 -228
  191. package/src/Utils/event-buffer.ts +0 -613
  192. package/src/Utils/generics.ts +0 -434
  193. package/src/Utils/history.ts +0 -112
  194. package/src/Utils/index.ts +0 -17
  195. package/src/Utils/link-preview.ts +0 -122
  196. package/src/Utils/logger.ts +0 -3
  197. package/src/Utils/lt-hash.ts +0 -61
  198. package/src/Utils/make-mutex.ts +0 -44
  199. package/src/Utils/messages-media.ts +0 -847
  200. package/src/Utils/messages.ts +0 -956
  201. package/src/Utils/noise-handler.ts +0 -197
  202. package/src/Utils/process-message.ts +0 -414
  203. package/src/Utils/signal.ts +0 -177
  204. package/src/Utils/use-multi-file-auth-state.ts +0 -90
  205. package/src/Utils/validate-connection.ts +0 -238
  206. package/src/WABinary/constants.ts +0 -42
  207. package/src/WABinary/decode.ts +0 -265
  208. package/src/WABinary/encode.ts +0 -236
  209. package/src/WABinary/generic-utils.ts +0 -121
  210. package/src/WABinary/index.ts +0 -5
  211. package/src/WABinary/jid-utils.ts +0 -68
  212. package/src/WABinary/types.ts +0 -17
  213. package/src/WAM/BinaryInfo.ts +0 -12
  214. package/src/WAM/constants.ts +0 -15382
  215. package/src/WAM/encode.ts +0 -174
  216. package/src/WAM/index.ts +0 -3
  217. package/src/gifted +0 -1
  218. package/src/index.ts +0 -13
  219. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  220. /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
  221. /package/{src → lib}/Store/index.js +0 -0
  222. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  223. /package/{src → lib}/Types/Auth.js +0 -0
  224. /package/{src → lib}/Types/Call.js +0 -0
  225. /package/{src → lib}/Types/Chat.js +0 -0
  226. /package/{src → lib}/Types/Contact.js +0 -0
  227. /package/{src → lib}/Types/Events.js +0 -0
  228. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  229. /package/{src → lib}/Types/Label.js +0 -0
  230. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  231. /package/{src → lib}/Types/Message.js +0 -0
  232. /package/{src → lib}/Types/Newsletter.js +0 -0
  233. /package/{src → lib}/Types/Product.js +0 -0
  234. /package/{src → lib}/Types/Signal.js +0 -0
  235. /package/{src → lib}/Types/Socket.js +0 -0
  236. /package/{src → lib}/Types/State.js +0 -0
  237. /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
  238. /package/{src → lib}/Types/index.js +0 -0
  239. /package/{src → lib}/Utils/index.js +0 -0
  240. /package/{src → lib}/Utils/logger.js +0 -0
  241. /package/{src → lib}/Utils/lt-hash.js +0 -0
  242. /package/{src → lib}/Utils/noise-handler.js +0 -0
  243. /package/{src → lib}/WABinary/constants.js +0 -0
  244. /package/{src → lib}/WABinary/decode.js +0 -0
  245. /package/{src → lib}/WABinary/generic-utils.js +0 -0
  246. /package/{src → lib}/WABinary/index.js +0 -0
  247. /package/{src → lib}/WABinary/jid-utils.js +0 -0
  248. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  249. /package/{src → lib}/WAM/constants.js +0 -0
  250. /package/{src → lib}/WAM/encode.js +0 -0
  251. /package/{src → lib}/WAM/index.js +0 -0
package/README.md CHANGED
@@ -1,1645 +1,9 @@
1
- # **[Gifted-Baileys](https://www.npmjs.com/package/@giftedtech/baileys)** - Typescript/Javascript WhatsApp Web API
1
+ # <div align='center'>Gifted-Baileys WhatsApp Web API</div>
2
2
 
3
- ## Install
3
+ Baileys is a WebSockets-based TypeScript library for interacting with the WhatsApp Web API.
4
4
 
5
- ```
6
- npm i @giftedtech/baileys
7
- ```
5
+ ### Visit **[DOCS SITE](https://baileys.giftedtech.web.id)** for more details.
8
6
 
9
- Using yarn
10
- ```
11
- yarn add @giftedtech/baileys@latest
12
- ```
13
-
14
- Then import your code using:
15
- - Commonjs:
16
- ```javascript
17
- const { default: makeWASocket } = require("@giftedtech/baileys")
18
- ```
19
-
20
- - Module:
21
- ``` ts
22
- import makeWASocket from '@giftedtech/baileys'
23
- ```
24
-
25
-
26
- # Index
27
-
28
- - [Connecting Account](#connecting-account)
29
- - [Connect with QR-CODE](#starting-socket-with-qr-code)
30
- - [Connect with Pairing Code](#starting-socket-with-pairing-code)
31
- - [Receive Full History](#receive-full-history)
32
- - [Important Notes About Socket Config](#important-notes-about-socket-config)
33
- - [Caching Group Metadata (Recommended)](#caching-group-metadata-recommended)
34
- - [Improve Retry System & Decrypt Poll Votes](#improve-retry-system--decrypt-poll-votes)
35
- - [Receive Notifications in Whatsapp App](#receive-notifications-in-whatsapp-app)
36
-
37
- - [Save Auth Info](#saving--restoring-sessions)
38
- - [Handling Events](#handling-events)
39
- - [Example to Start](#example-to-start)
40
- - [Decrypt Poll Votes](#decrypt-poll-votes)
41
- - [Summary of Events on First Connection](#summary-of-events-on-first-connection)
42
- - [Implementing a Data Store](#implementing-a-data-store)
43
- - [Whatsapp IDs Explain](#whatsapp-ids-explain)
44
- - [Utility Functions](#utility-functions)
45
- - [Sending Messages](#sending-messages)
46
- - [Non-Media Messages](#non-media-messages)
47
- - [Buttons Message](#buttons-message)
48
- - [Buttons Flow](#buttons-flow)
49
- - [Interactive Message](#interactive-message)
50
- - [Text Message](#text-message)
51
- - [Quote Message](#quote-message-works-with-all-types)
52
- - [Mention User](#mention-user-works-with-most-types)
53
- - [Mention Status](#mention-status)
54
- - [Result Poll From Newsletter](#result-poll-from-newsletter)
55
- - [SendAlbumMessage](#send-album-message)
56
- - [Interactive Response](#interactive-response)
57
- - [Request Payment](#request-payment)
58
- - [Event Message](#event-message)
59
- - [Interactive](#interactive)
60
- - [Forward Messages](#forward-messages)
61
- - [Location Message](#location-message)
62
- - [Contact Message](#contact-message)
63
- - [Reaction Message](#reaction-message)
64
- - [Pin Message](#pin-message)
65
- - [Poll Message](#poll-message)
66
- - [Sending with Link Preview](#sending-messages-with-link-previews)
67
- - [Media Messages](#media-messages)
68
- - [Gif Message](#gif-message)
69
- - [Video Message](#video-message)
70
- - [Audio Message](#audio-message)
71
- - [Image Message](#image-message)
72
- - [ViewOnce Message](#view-once-message)
73
- - [Modify Messages](#modify-messages)
74
- - [Delete Messages (for everyone)](#deleting-messages-for-everyone)
75
- - [Edit Messages](#editing-messages)
76
- - [Manipulating Media Messages](#manipulating-media-messages)
77
- - [Thumbnail in Media Messages](#thumbnail-in-media-messages)
78
- - [Downloading Media Messages](#downloading-media-messages)
79
- - [Re-upload Media Message to Whatsapp](#re-upload-media-message-to-whatsapp)
80
- - [Reject Call](#reject-call)
81
- - [Send States in Chat](#send-states-in-chat)
82
- - [Reading Messages](#reading-messages)
83
- - [Update Presence](#update-presence)
84
- - [Modifying Chats](#modifying-chats)
85
- - [Archive a Chat](#archive-a-chat)
86
- - [Mute/Unmute a Chat](#muteunmute-a-chat)
87
- - [Mark a Chat Read/Unread](#mark-a-chat-readunread)
88
- - [Delete a Message for Me](#delete-a-message-for-me)
89
- - [Delete a Chat](#delete-a-chat)
90
- - [Star/Unstar a Message](#starunstar-a-message)
91
- - [Disappearing Messages](#disappearing-messages)
92
- - [User Querys](#user-querys)
93
- - [Check If ID Exists in Whatsapp](#check-if-id-exists-in-whatsapp)
94
- - [Query Chat History (groups too)](#query-chat-history-groups-too)
95
- - [Fetch Status](#fetch-status)
96
- - [Fetch Profile Picture (groups too)](#fetch-profile-picture-groups-too)
97
- - [Fetch Bussines Profile (such as description or category)](#fetch-bussines-profile-such-as-description-or-category)
98
- - [Fetch Someone's Presence (if they're typing or online)](#fetch-someones-presence-if-theyre-typing-or-online)
99
- - [Change Profile](#change-profile)
100
- - [Change Profile Status](#change-profile-status)
101
- - [Change Profile Name](#change-profile-name)
102
- - [Change Display Picture (groups too)](#change-display-picture-groups-too)
103
- - [Remove display picture (groups too)](#remove-display-picture-groups-too)
104
- - [Groups](#groups)
105
- - [Create a Group](#create-a-group)
106
- - [Add/Remove or Demote/Promote](#addremove-or-demotepromote)
107
- - [Change Subject (name)](#change-subject-name)
108
- - [Change Description](#change-description)
109
- - [Change Settings](#change-settings)
110
- - [Leave a Group](#leave-a-group)
111
- - [Get Invite Code](#get-invite-code)
112
- - [Revoke Invite Code](#revoke-invite-code)
113
- - [Join Using Invitation Code](#join-using-invitation-code)
114
- - [Get Group Info by Invite Code](#get-group-info-by-invite-code)
115
- - [Query Metadata (participants, name, description...)](#query-metadata-participants-name-description)
116
- - [Join using groupInviteMessage](#join-using-groupinvitemessage)
117
- - [Get Request Join List](#get-request-join-list)
118
- - [Approve/Reject Request Join](#approvereject-request-join)
119
- - [Get All Participating Groups Metadata](#get-all-participating-groups-metadata)
120
- - [Toggle Ephemeral](#toggle-ephemeral)
121
- - [Change Add Mode](#change-add-mode)
122
- - [Privacy](#privacy)
123
- - [Block/Unblock User](#blockunblock-user)
124
- - [Get Privacy Settings](#get-privacy-settings)
125
- - [Get BlockList](#get-blocklist)
126
- - [Update LastSeen Privacy](#update-lastseen-privacy)
127
- - [Update Online Privacy](#update-online-privacy)
128
- - [Update Profile Picture Privacy](#update-profile-picture-privacy)
129
- - [Update Status Privacy](#update-status-privacy)
130
- - [Update Read Receipts Privacy](#update-read-receipts-privacy)
131
- - [Update Groups Add Privacy](#update-groups-add-privacy)
132
- - [Update Default Disappearing Mode](#update-default-disappearing-mode)
133
- - [Broadcast Lists & Stories](#broadcast-lists--stories)
134
- - [Send Broadcast & Stories](#send-broadcast--stories)
135
- - [Query a Broadcast List's Recipients & Name](#query-a-broadcast-lists-recipients--name)
136
- - [Writing Custom Functionality](#writing-custom-functionality)
137
- - [Enabling Debug Level in Baileys Logs](#enabling-debug-level-in-baileys-logs)
138
- - [How Whatsapp Communicate With Us](#how-whatsapp-communicate-with-us)
139
- - [Register a Callback for Websocket Events](#register-a-callback-for-websocket-events)
140
-
141
- ## Connecting Account
142
-
143
- 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.
144
-
145
- ### Starting socket with **QR-CODE**
146
-
147
- > [!TIP]
148
- > 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)**
149
-
150
- ```javascript
151
- const { default: makeWASocket } = require("@giftedtech/baileys")
152
-
153
-
154
- const sock = makeWASocket({
155
- // can provide additional config here
156
- browser: Browsers.ubuntu('Gifted'),
157
- printQRInTerminal: true
158
- })
159
- ```
160
-
161
- 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!
162
-
163
- ### Starting socket with **Pairing Code**
164
-
165
-
166
- > [!IMPORTANT]
167
- > 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)
168
-
169
- The phone number can't have `+` or `()` or `-`, only numbers, you must provide country code
170
-
171
- ```javascript
172
- const { default: makeWASocket } = require("@giftedtech/baileys")
173
-
174
- const sock = makeWASocket({
175
- // can provide additional config here
176
- printQRInTerminal: false //need to be false
177
- })
178
-
179
- - Normal Pairing
180
- if (!sock.authState.creds.registered) {
181
- const number = 'XXXXXXXXXXX'
182
- const code = await sock.requestPairingCode(number)
183
- console.log(code)
184
- }
185
-
186
- - Costum Pairing
187
- if (!sock.authState.creds.registered) {
188
- const pair = "12345678" // only 8 digit numbers or letters (no more or less)
189
- const number = 'XXXXXXXXXXX'
190
- const code = await sock.requestPairingCode(number, pair)
191
- console.log(code)
192
- }
193
- ```
194
-
195
- ### Receive Full History
196
-
197
- 1. Set `syncFullHistory` as `true`
198
- 2. Baileys, by default, use chrome browser config
199
- - If you'd like to emulate a desktop connection (and receive more message history), this browser setting to your Socket config:
200
-
201
- ```javascript
202
- const sock = makeWASocket({
203
- ...otherOpts,
204
- // can use Windows, Ubuntu here too
205
- browser: Browsers.macOS('Desktop'),
206
- syncFullHistory: true
207
- })
208
- ```
209
-
210
- ## Important Notes About Socket Config
211
-
212
- ### Caching Group Metadata (Recommended)
213
- - If you use baileys for groups, we recommend you to set `cachedGroupMetadata` in socket config, you need to implement a cache like this:
214
-
215
- ```javascript
216
- const groupCache = new NodeCache({stdTTL: 5 * 60, useClones: false})
217
-
218
- const sock = makeWASocket({
219
- cachedGroupMetadata: async (jid) => groupCache.get(jid)
220
- })
221
-
222
- sock.ev.on('groups.update', async ([event]) => {
223
- const metadata = await sock.groupMetadata(event.id)
224
- groupCache.set(event.id, metadata)
225
- })
226
-
227
- sock.ev.on('group-participants.update', async (event) => {
228
- const metadata = await sock.groupMetadata(event.id)
229
- groupCache.set(event.id, metadata)
230
- })
231
- ```
232
-
233
- ### Improve Retry System & Decrypt Poll Votes
234
- - 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:
235
- ```javascript
236
- const sock = makeWASocket({
237
- getMessage: async (key) => await getMessageFromStore(key)
238
- })
239
- ```
240
-
241
- ### Receive Notifications in Whatsapp App
242
- - If you want to receive notifications in whatsapp app, set `markOnlineOnConnect` to `false`
243
- ```javascript
244
- const sock = makeWASocket({
245
- markOnlineOnConnect: false
246
- })
247
- ```
248
- ## Saving & Restoring Sessions
249
-
250
- You obviously don't want to keep scanning the QR code every time you want to connect.
251
-
252
- So, you can load the credentials to log back in:
253
- ```javascript
254
- const makeWASocket = require("@giftedtech/baileys").default;
255
- const { useMultiFileAuthState } = require("@giftedtech/baileys");
256
-
257
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
258
-
259
- // will use the given state to connect
260
- // so if valid credentials are available -- it'll connect without QR
261
- const sock = makeWASocket({ auth: state })
262
-
263
- // this will be called as soon as the credentials are updated
264
- sock.ev.on('creds.update', saveCreds)
265
- ```
266
-
267
- > [!IMPORTANT]
268
- > `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.
269
-
270
- > [!NOTE]
271
- > 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.
272
-
273
- ## Handling Events
274
-
275
- - Baileys uses the EventEmitter syntax for events.
276
- They're all nicely typed up, so you shouldn't have any issues with an Intellisense editor like VS Code.
277
-
278
- > [!IMPORTANT]
279
- > **The events are [these](https://baileys.whiskeysockets.io/types/BaileysEventMap.html)**, it's important you see all events
280
-
281
- You can listen to these events like this:
282
- ```javascript
283
- const sock = makeWASocket()
284
- sock.ev.on('messages.upsert', ({ messages }) => {
285
- console.log('got messages', messages)
286
- })
287
- ```
288
-
289
- ### Example to Start
290
-
291
- > [!NOTE]
292
- > This example includes basic auth storage too
293
-
294
- ```javascript
295
- const makeWASocket = require("@giftedtech/baileys").default;
296
- const { DisconnectReason, useMultiFileAuthState } = require("@giftedtech/baileys");
297
- const Boom = require('@hapi/boom');
298
-
299
- async function connectToWhatsApp () {
300
- const { state, saveCreds } = await useMultiFileAuthState('auth_info_baileys')
301
- const sock = makeWASocket({
302
- // can provide additional config here
303
- auth: state,
304
- printQRInTerminal: true
305
- })
306
- sock.ev.on('connection.update', (update) => {
307
- const { connection, lastDisconnect } = update
308
- if(connection === 'close') {
309
- const shouldReconnect = (lastDisconnect.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut
310
- console.log('connection closed due to ', lastDisconnect.error, ', reconnecting ', shouldReconnect)
311
- // reconnect if not logged out
312
- if(shouldReconnect) {
313
- connectToWhatsApp()
314
- }
315
- } else if(connection === 'open') {
316
- console.log('opened connection')
317
- }
318
- })
319
- sock.ev.on('messages.upsert', event => {
320
- for (const m of event.messages) {
321
- console.log(JSON.stringify(m, undefined, 2))
322
-
323
- console.log('replying to', m.key.remoteJid)
324
- await sock.sendMessage(m.key.remoteJid!, { text: 'Hello Word' })
325
- }
326
- })
327
-
328
- // to storage creds (session info) when it updates
329
- sock.ev.on('creds.update', saveCreds)
330
- }
331
- // run in main file
332
- connectToWhatsApp()
333
- ```
334
-
335
- > [!IMPORTANT]
336
- > In `messages.upsert` it's recommended to use a loop like `for (const message of event.messages)` to handle all messages in array
337
-
338
- ### Decrypt Poll Votes
339
-
340
- - By default poll votes are encrypted and handled in `messages.update`
341
- - That's a simple example
342
- ```javascript
343
- sock.ev.on('messages.update', event => {
344
- for(const { key, update } of event) {
345
- if(update.pollUpdates) {
346
- const pollCreation = await getMessage(key)
347
- if(pollCreation) {
348
- console.log(
349
- 'got poll update, aggregation: ',
350
- getAggregateVotesInPollMessage({
351
- message: pollCreation,
352
- pollUpdates: update.pollUpdates,
353
- })
354
- )
355
- }
356
- }
357
- }
358
- })
359
- ```
360
-
361
- - `getMessage` is a [store](#implementing-a-data-store) implementation (in your end)
362
-
363
- ### Summary of Events on First Connection
364
-
365
- 1. When you connect first time, `connection.update` will be fired requesting you to restart sock
366
- 2. Then, history messages will be received in `messaging.history-set`
367
-
368
- ## Implementing a Data Store
369
-
370
- - 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.
371
-
372
- > [!IMPORTANT]
373
- > I highly recommend building your own data store, as storing someone's entire chat history in memory is a terrible waste of RAM.
374
-
375
- It can be used as follows:
376
-
377
- ```javascript
378
- const makeWASocket = require("@giftedtech/baileys").default;
379
- const { makeInMemoryStore } = require("@giftedtech/baileys");
380
- // the store maintains the data of the WA connection in memory
381
- // can be written out to a file & read from it
382
- const store = makeInMemoryStore({ })
383
- // can be read from a file
384
- store.readFromFile('./baileys_store.json')
385
- // saves the state to a file every 10s
386
- setInterval(() => {
387
- store.writeToFile('./baileys_store.json')
388
- }, 10_000)
389
-
390
- const sock = makeWASocket({ })
391
- // will listen from this socket
392
- // the store can listen from a new socket once the current socket outlives its lifetime
393
- store.bind(sock.ev)
394
-
395
- sock.ev.on('chats.upsert', () => {
396
- // can use 'store.chats' however you want, even after the socket dies out
397
- // 'chats' => a KeyedDB instance
398
- console.log('got chats', store.chats.all())
399
- })
400
-
401
- sock.ev.on('contacts.upsert', () => {
402
- console.log('got contacts', Object.values(store.contacts))
403
- })
404
-
405
- ```
406
-
407
- The store also provides some simple functions such as `loadMessages` that utilize the store to speed up data retrieval.
408
-
409
- ## Whatsapp IDs Explain
410
-
411
- - `id` is the WhatsApp ID, called `jid` too, of the person or group you're sending the message to.
412
- - It must be in the format ```[country code][phone number]@s.whatsapp.net```
413
- - Example for people: ```+19999999999@s.whatsapp.net```.
414
- - For groups, it must be in the format ``` 123456789-123345@g.us ```.
415
- - For broadcast lists, it's `[timestamp of creation]@broadcast`.
416
- - For stories, the ID is `status@broadcast`.
417
-
418
- ## Utility Functions
419
-
420
- - `getContentType`, returns the content type for any message
421
- - `getDevice`, returns the device from message
422
- - `makeCacheableSignalKeyStore`, make auth store more fast
423
- - `downloadContentFromMessage`, download content from any message
424
-
425
- ## Sending Messages
426
-
427
- - Send all types of messages with a single function
428
- - **[Here](https://baileys.whiskeysockets.io/types/AnyMessageContent.html) you can see all message contents supported, like text message**
429
- - **[Here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html) you can see all options supported, like quote message**
430
-
431
- ```javascript
432
- const jid: string
433
- const content: AnyMessageContent
434
- const options: MiscMessageGenerationOptions
435
-
436
- sock.sendMessage(jid, content, options)
437
- ```
438
-
439
- ### Non-Media Messages
440
-
441
- #### Buttons Message
442
- ```javascript
443
- // send a buttons message!
444
- sock.sendMessage(jid, {
445
- text: "Hello World !",
446
- footer: "Gifted Tech - 2025",
447
- buttons: [
448
- {
449
- buttonId: `🚀`,
450
- buttonText: {
451
- displayText: '🗿'
452
- },
453
- type: 1
454
- }
455
- ],
456
- headerType: 1,
457
- viewOnce: true
458
- },{ quoted: null })
459
- ```
460
-
461
- #### Buttons Flow
462
- ```javascript
463
- sock.sendMessage(jid, {
464
- text: "Hello Wolrd !;",
465
- footer: "© Gifted Tech",
466
- buttons: [
467
- {
468
- buttonId: '.tes',
469
- buttonText: {
470
- displayText: 'TESTING BOT'
471
- },
472
- type: 1,
473
- },
474
- {
475
- buttonId: ' ',
476
- buttonText: {
477
- displayText: 'PRIVATE SCRIPT'
478
- },
479
- type: 1,
480
- },
481
- {
482
- buttonId: 'action',
483
- buttonText: {
484
- displayText: 'ini pesan interactiveMeta'
485
- },
486
- type: 4,
487
- nativeFlowInfo: {
488
- name: 'single_select',
489
- paramsJson: JSON.stringify({
490
- title: 'message',
491
- sections: [
492
- {
493
- title: 'Gifted Tech - 2025',
494
- highlight_label: '😜',
495
- rows: [
496
- {
497
- header: 'HEADER',
498
- title: 'TITLE',
499
- description: 'DESCRIPTION',
500
- id: 'YOUR ID',
501
- },
502
- {
503
- header: 'HEADER',
504
- title: 'TITLE',
505
- description: 'DESCRIPTION',
506
- id: 'YOUR ID',
507
- },
508
- ],
509
- },
510
- ],
511
- }),
512
- },
513
- },
514
- ],
515
- headerType: 1,
516
- viewOnce: true
517
- }, { quoted: m });
518
- ```
519
-
520
- #### Interactive Message
521
- ```javascript
522
- let msg = generateWAMessageFromContent(m.chat, {
523
- viewOnceMessage: {
524
- message: {
525
- "messageContextInfo": {
526
- "deviceListMetadata": {},
527
- "deviceListMetadataVersion": 2
528
- },
529
- interactiveMessage: proto.Message.InteractiveMessage.create({
530
- body: proto.Message.InteractiveMessage.Body.create({
531
- text: "Gifted Tech"
532
- }),
533
- footer: proto.Message.InteractiveMessage.Footer.create({
534
- text: "Bot"
535
- }),
536
- header: proto.Message.InteractiveMessage.Header.create({
537
- title: "Igna",
538
- subtitle: "test",
539
- hasMediaAttachment: false
540
- }),
541
- nativeFlowMessage: proto.Message.InteractiveMessage.NativeFlowMessage.create({
542
- buttons: [
543
- {
544
- "name": "single_select",
545
- "buttonParamsJson": "{\"title\":\"title\",\"sections\":[{\".menu\":\".play dj webito\",\"highlight_label\":\"label\",\"rows\":[{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"},{\"header\":\"header\",\"title\":\"title\",\"description\":\"description\",\"id\":\"id\"}]}]}"
546
- },
547
- {
548
- "name": "cta_reply",
549
- "buttonParamsJson": "{\"display_text\":\"quick_reply\",\"id\":\"message\"}"
550
- },
551
- {
552
- "name": "cta_url",
553
- "buttonParamsJson": "{\"display_text\":\"url\",\"url\":\"https://www.google.com\",\"merchant_url\":\"https://www.google.com\"}"
554
- },
555
- {
556
- "name": "cta_call",
557
- "buttonParamsJson": "{\"display_text\":\"call\",\"id\":\"message\"}"
558
- },
559
- {
560
- "name": "cta_copy",
561
- "buttonParamsJson": "{\"display_text\":\"copy\",\"id\":\"123456789\",\"copy_code\":\"message\"}"
562
- },
563
- {
564
- "name": "cta_reminder",
565
- "buttonParamsJson": "{\"display_text\":\"Recordatorio\",\"id\":\"message\"}"
566
- },
567
- {
568
- "name": "cta_cancel_reminder",
569
- "buttonParamsJson": "{\"display_text\":\"cta_cancel_reminder\",\"id\":\"message\"}"
570
- },
571
- {
572
- "name": "address_message",
573
- "buttonParamsJson": "{\"display_text\":\"address_message\",\"id\":\"message\"}"
574
- },
575
- {
576
- "name": "send_location",
577
- "buttonParamsJson": ""
578
- }
579
- ],
580
- })
581
- })
582
- }
583
- }
584
- }, {})
585
-
586
- return sock.relayMessage(msg.key.remoteJid, msg.message, { messageId: msg.key.id })
587
- ```
588
-
589
- #### Text Message
590
- ```javascript
591
- await sock.sendMessage(jid, { text: 'hello word' })
592
- ```
593
-
594
- #### Quote Message (works with all types)
595
- ```javascript
596
- await sock.sendMessage(jid, { text: 'hello word' }, { quoted: message })
597
- ```
598
-
599
- #### Mention User (works with most types)
600
- - @number is to mention in text, it's optional
601
- ```javascript
602
- await sock.sendMessage(
603
- jid,
604
- {
605
- text: '@12345678901',
606
- mentions: ['12345678901@s.whatsapp.net']
607
- }
608
- )
609
- ```
610
-
611
- #### Mention Status
612
- - [ jid ] If the Jid Group and Jid Private Chat are included in the JID list, try to make the JID group first starting from the Jid Private Chat or Jid Private Chat in the middle between the group Jid
613
- ```javascript
614
- await sock.StatusMentions(
615
- {
616
- text: "Hello", // or image / video / audio ( url or buffer )
617
- },
618
- [
619
- "123456789123456789@g.us",
620
- "123456789@s.whatsapp.net",
621
- // Enter jid chat here
622
- ]
623
- )
624
- ```
625
-
626
- #### Result Poll From Newsletter
627
- ```javascript
628
- await client.sendMessage(
629
- jid,
630
- {
631
- pollResult: {
632
- name: "Text poll",
633
- votes: [["Options 1", 10], ["Options 2", 10]], // 10 For Fake Polling Count Results
634
- }
635
- }, { quoted : message }
636
- )
637
- ```
638
-
639
- #### Send Album Message
640
- - url or buffer ( image or video )
641
- ```javascript
642
- await sock.sendAlbumMessage(
643
- jid,
644
- [
645
- {
646
- image: { url: "https://example.jpg" }, // or buffer
647
- caption: "Hello World",
648
- },
649
- {
650
- video: { url: "https://example.mp4" }, // or buffer
651
- caption: "Hello World",
652
- },
653
- ],
654
- {
655
- quoted : message,
656
- delay : 2000 // number in seconds
657
- }
658
- )
659
-
660
- ```
661
-
662
- #### Interactive Response
663
- ```javascript
664
- await client.sendMessage(
665
- jid,
666
- {
667
- buttonReply: {
668
- text: 'Text',
669
- nativeFlow: {
670
- version: 3,
671
- },
672
- },
673
- type: 'interactive',
674
- ephemeral: true,
675
- }
676
- )
677
-
678
- ```
679
-
680
- #### Request Payment
681
- ```javascript
682
- - Example non media sticker
683
- await client.sendMessage(
684
- jid,
685
- {
686
- requestPayment: {
687
- currency: "IDR",
688
- amount: "10000000",
689
- from: "123456@s.whatsapp.net",
690
- note: "Hai Guys",
691
- background: { ...background of the message }
692
- }
693
- },
694
- { quoted : message }
695
- )
696
-
697
- - with media sticker buffer
698
- await client.sendMessage(
699
- jid,
700
- {
701
- requestPayment: {
702
- currency: "IDR",
703
- amount: "10000000",
704
- from: "123456@s.whatsapp.net",
705
- sticker: Buffer,
706
- background: { ...background of the message }
707
- }
708
- },
709
- { quoted : message }
710
- )
711
-
712
- - with media sticker url
713
- await client.sendMessage(
714
- jid,
715
- {
716
- requestPayment: {
717
- currency: "IDR",
718
- amount: "10000000",
719
- from: "123456@s.whatsapp.net",
720
- sticker: { url: Sticker Url },
721
- background: { ...background of the message }
722
- }
723
- },
724
- { quoted : message }
725
- )
726
- ```
727
-
728
- #### Event Message
729
- ```javascript
730
- await client.sendMessage(
731
- jid,
732
- {
733
- event: {
734
- isCanceled: false, // or true for cancel event
735
- name: "Name Event",
736
- description: "Description Event",
737
- location: {
738
- degressLatitude: -0,
739
- degressLongitude: - 0
740
- },
741
- link: Call Link,
742
- startTime: m.messageTimestamp.low,
743
- endTime: m.messageTimestamp.low + 86400, // 86400 is day in seconds
744
- extraGuestsAllowed: true // or false
745
- }
746
- },
747
- { quoted : message }
748
- )
749
- ```
750
-
751
- #### Interactive
752
- ```javascript
753
- - Example non header media
754
- await client.sendMessage(
755
- jid,
756
- {
757
- text: "Description Of Messages", //Additional information
758
- title: "Title Of Messages",
759
- subtitle: "Subtitle Message",
760
- footer: "Footer Messages",
761
- interactiveButtons: [
762
- {
763
- name: "quick_reply",
764
- buttonParamsJson: JSON.stringify({
765
- display_text: "Display Button",
766
- id: "ID"
767
- })
768
- },
769
- {
770
- name: "cta_url",
771
- buttonParamsJson: JSON.stringify({
772
- display_text: "Display Button",
773
- url: "https://www.example.com"
774
- })
775
- }
776
- ]
777
- },
778
- {
779
- quoted : message
780
- }
781
- )
782
-
783
- - Example with media
784
- await client.sendMessage(
785
- jid,
786
- {
787
- image: { url : "https://example.jpg" }, // Can buffer
788
- caption: "Description Of Messages", //Additional information
789
- title: "Title Of Messages",
790
- subtitle: "Subtile Message",
791
- footer: "Footer Messages",
792
- media: true,
793
- interactiveButtons: [
794
- {
795
- name: "quick_reply",
796
- buttonParamsJson: JSON.stringify({
797
- display_text: "Display Button",
798
- id: "ID"
799
- })
800
- },
801
- {
802
- name: "cta_url",
803
- buttonParamsJson: JSON.stringify({
804
- display_text: "Display Button",
805
- url: "https://www.example.com"
806
- })
807
- }
808
- ]
809
- },
810
- {
811
- quoted : message
812
- }
813
- )
814
-
815
- - Example with header product
816
- await client.sendMessage(
817
- jid,
818
- {
819
- product: {
820
- productImage: { url: "https://example.jpg }, //or buffer
821
- productImageCount: 1,
822
- title: "Title Product",
823
- description: "Description Product",
824
- priceAmount1000: 20000 * 1000,
825
- currencyCode: "IDR",
826
- retailerId: "Retail",
827
- url: "https://example.com",
828
- },
829
- businessOwnerJid: "1234@s.whatsapp.net",
830
- caption: "Description Of Messages", //Additional information
831
- title: "Title Of Messages",
832
- footer: "Footer Messages",
833
- media: true,
834
- interactiveButtons: [
835
- {
836
- name: "quick_reply",
837
- buttonParamsJson: JSON.stringify({
838
- display_text: "Display Button",
839
- id: "ID"
840
- })
841
- },
842
- {
843
- name: "cta_url",
844
- buttonParamsJson: JSON.stringify({
845
- display_text: "Display Button",
846
- url: "https://www.example.com"
847
- })
848
- }
849
- ]
850
- },
851
- {
852
- quoted : message
853
- }
854
- )
855
- ```
856
-
857
- #### Forward Messages
858
- - 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
859
- ```javascript
860
- const msg = getMessageFromStore() // implement this on your end
861
- await sock.sendMessage(jid, { forward: msg }) // WA forward the message!
862
- ```
863
-
864
- #### Location Message
865
- ```javascript
866
- await sock.sendMessage(
867
- jid,
868
- {
869
- location: {
870
- degreesLatitude: 24.121231,
871
- degreesLongitude: 55.1121221
872
- }
873
- }
874
- )
875
- ```
876
- #### Contact Message
877
- ```javascript
878
- const vcard = 'BEGIN:VCARD\n' // metadata of the contact card
879
- + 'VERSION:3.0\n'
880
- + 'FN:Jeff Singh\n' // full name
881
- + 'ORG:Ashoka Uni;\n' // the organization of the contact
882
- + 'TEL;type=CELL;type=VOICE;waid=911234567890:+91 12345 67890\n' // WhatsApp ID + phone number
883
- + 'END:VCARD'
884
-
885
- await sock.sendMessage(
886
- id,
887
- {
888
- contacts: {
889
- displayName: 'Jeff',
890
- contacts: [{ vcard }]
891
- }
892
- }
893
- )
894
- ```
895
-
896
- #### Reaction Message
897
- - 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
898
- ```javascript
899
- await sock.sendMessage(
900
- jid,
901
- {
902
- react: {
903
- text: '💖', // use an empty string to remove the reaction
904
- key: message.key
905
- }
906
- }
907
- )
908
- ```
909
-
910
- #### Pin Message
911
- - 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
912
-
913
- - Time can be:
914
-
915
- | Time | Seconds |
916
- |-------|----------------|
917
- | 24h | 86.400 |
918
- | 7d | 604.800 |
919
- | 30d | 2.592.000 |
920
-
921
- ```javascript
922
- await sock.sendMessage(
923
- jid,
924
- {
925
- pin: {
926
- type: 1, // 0 to remove
927
- time: 86400
928
- key: message.key
929
- }
930
- }
931
- )
932
- ```
933
-
934
- #### Poll Message
935
- ```javascript
936
- await sock.sendMessage(
937
- jid,
938
- {
939
- poll: {
940
- name: 'My Poll',
941
- values: ['Option 1', 'Option 2', ...],
942
- selectableCount: 1,
943
- toAnnouncementGroup: false // or true
944
- }
945
- }
946
- )
947
- ```
948
-
949
- ### Sending Messages with Link Previews
950
-
951
- 1. By default, wa does not have link generation when sent from the web
952
- 2. Baileys has a function to generate the content for these link previews
953
- 3. To enable this function's usage, add `link-preview-js` as a dependency to your project with `yarn add link-preview-js`
954
- 4. Send a link:
955
- ```javascript
956
- await sock.sendMessage(
957
- jid,
958
- {
959
- text: 'Hi, this was sent using https://npmjs.com/package/@giftedtech/baileys'
960
- }
961
- )
962
- ```
963
-
964
- ### Media Messages
965
-
966
- Sending media (video, stickers, images) is easier & more efficient than ever.
967
-
968
- > [!NOTE]
969
- > 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)
970
-
971
- - When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.
972
-
973
- > [!TIP]
974
- > It's recommended to use Stream or Url to save memory
975
-
976
- #### Gif Message
977
- - Whatsapp doesn't support `.gif` files, that's why we send gifs as common `.mp4` video with `gifPlayback` flag
978
- ```javascript
979
- await sock.sendMessage(
980
- jid,
981
- {
982
- video: fs.readFileSync('Media/ma_gif.mp4'),
983
- caption: 'hello word',
984
- gifPlayback: true
985
- }
986
- )
987
- ```
988
-
989
- #### Video Message
990
- ```javascript
991
- await sock.sendMessage(
992
- id,
993
- {
994
- video: {
995
- url: './Media/ma_gif.mp4'
996
- },
997
- caption: 'hello word',
998
- ptv: false // if set to true, will send as a `video note`
999
- }
1000
- )
1001
- ```
1002
-
1003
- #### Audio Message
1004
- - To audio message work in all devices you need to convert with some tool like `ffmpeg` with this flags:
1005
- ```bash
1006
- codec: libopus //ogg file
1007
- ac: 1 //one channel
1008
- avoid_negative_ts
1009
- make_zero
1010
- ```
1011
- - Example:
1012
- ```bash
1013
- ffmpeg -i input.mp4 -avoid_negative_ts make_zero -ac 1 output.ogg
1014
- ```
1015
- ```javascript
1016
- await sock.sendMessage(
1017
- jid,
1018
- {
1019
- audio: {
1020
- url: './Media/audio.mp3'
1021
- },
1022
- mimetype: 'audio/mp4'
1023
- }
1024
- )
1025
- ```
1026
-
1027
- #### Image Message
1028
- ```javascript
1029
- await sock.sendMessage(
1030
- id,
1031
- {
1032
- image: {
1033
- url: './Media/ma_img.png'
1034
- },
1035
- caption: 'hello word'
1036
- }
1037
- )
1038
- ```
1039
-
1040
- #### View Once Message
1041
-
1042
- - You can send all messages above as `viewOnce`, you only need to pass `viewOnce: true` in content object
1043
-
1044
- ```javascript
1045
- await sock.sendMessage(
1046
- id,
1047
- {
1048
- image: {
1049
- url: './Media/ma_img.png'
1050
- },
1051
- viewOnce: true, //works with video, audio too
1052
- caption: 'hello word'
1053
- }
1054
- )
1055
- ```
1056
-
1057
- ## Modify Messages
1058
-
1059
- ### Deleting Messages (for everyone)
1060
-
1061
- ```javascript
1062
- const msg = await sock.sendMessage(jid, { text: 'hello word' })
1063
- await sock.sendMessage(jid, { delete: msg.key })
1064
- ```
1065
-
1066
- **Note:** deleting for oneself is supported via `chatModify`, see in [this section](#modifying-chats)
1067
-
1068
- ### Editing Messages
1069
-
1070
- - You can pass all editable contents here
1071
- ```javascript
1072
- await sock.sendMessage(jid, {
1073
- text: 'updated text goes here',
1074
- edit: response.key,
1075
- });
1076
- ```
1077
-
1078
- ## Manipulating Media Messages
1079
-
1080
- ### Thumbnail in Media Messages
1081
- - 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`.
1082
- - Thumbnails for videos can also be generated automatically, though, you need to have `ffmpeg` installed on your system.
1083
-
1084
- ### Downloading Media Messages
1085
-
1086
- If you want to save the media you received
1087
- ```javascript
1088
- const { createWriteStream } = require('fs');
1089
- const { downloadMediaMessage, getContentType } = require("@giftedtech/baileys");
1090
-
1091
- sock.ev.on('messages.upsert', async ({ [m] }) => {
1092
- if (!m.message) return // if there is no text or media message
1093
- const messageType = getContentType(m) // get what type of message it is (text, image, video...)
1094
-
1095
- // if the message is an image
1096
- if (messageType === 'imageMessage') {
1097
- // download the message
1098
- const stream = await downloadMediaMessage(
1099
- m,
1100
- 'stream', // can be 'buffer' too
1101
- { },
1102
- {
1103
- logger,
1104
- // pass this so that baileys can request a reupload of media
1105
- // that has been deleted
1106
- reuploadRequest: sock.updateMediaMessage
1107
- }
1108
- )
1109
- // save to file
1110
- const writeStream = createWriteStream('./my-download.jpeg')
1111
- stream.pipe(writeStream)
1112
- }
1113
- }
1114
- ```
1115
-
1116
- ### Re-upload Media Message to Whatsapp
1117
-
1118
- - 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:
1119
- ```javascript
1120
- await sock.updateMediaMessage(msg)
1121
- ```
1122
-
1123
- ## Reject Call
1124
-
1125
- - You can obtain `callId` and `callFrom` from `call` event
1126
-
1127
- ```javascript
1128
- await sock.rejectCall(callId, callFrom)
1129
- ```
1130
-
1131
- ## Send States in Chat
1132
-
1133
- ### Reading Messages
1134
- - A set of message [keys](https://baileys.whiskeysockets.io/types/WAMessageKey.html) must be explicitly marked read now.
1135
- - You cannot mark an entire 'chat' read as it were with Baileys Web.
1136
- This means you have to keep track of unread messages.
1137
-
1138
- ```javascript
1139
- const key: WAMessageKey
1140
- // can pass multiple keys to read multiple messages as well
1141
- await sock.readMessages([key])
1142
- ```
1143
-
1144
- The message ID is the unique identifier of the message that you are marking as read.
1145
- On a `WAMessage`, the `messageID` can be accessed using ```messageID = message.key.id```.
1146
-
1147
- ### Update Presence
1148
-
1149
- - ``` presence ``` can be one of [these](https://baileys.whiskeysockets.io/types/WAPresence.html)
1150
- - The presence expires after about 10 seconds.
1151
- - This lets the person/group with `jid` know whether you're online, offline, typing etc.
1152
-
1153
- ```javascript
1154
- await sock.sendPresenceUpdate('available', jid)
1155
- ```
1156
-
1157
- > [!NOTE]
1158
- > If a desktop client is active, WA doesn't send push notifications to the device. If you would like to receive said notifications -- mark your Baileys client offline using `sock.sendPresenceUpdate('unavailable')`
1159
-
1160
- ## Modifying Chats
1161
-
1162
- WA uses an encrypted form of communication to send chat/app updates. This has been implemented mostly and you can send the following updates:
1163
-
1164
- > [!IMPORTANT]
1165
- > 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.
1166
-
1167
- ### Archive a Chat
1168
- ```javascript
1169
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1170
- await sock.chatModify({ archive: true, lastMessages: [lastMsgInChat] }, jid)
1171
- ```
1172
- ### Mute/Unmute a Chat
1173
-
1174
- - Supported times:
1175
-
1176
- | Time | Miliseconds |
1177
- |-------|-----------------|
1178
- | Remove | null |
1179
- | 8h | 86.400.000 |
1180
- | 7d | 604.800.000 |
1181
-
1182
- ```javascript
1183
- // mute for 8 hours
1184
- await sock.chatModify({ mute: 8 * 60 * 60 * 1000 }, jid)
1185
- // unmute
1186
- await sock.chatModify({ mute: null }, jid)
1187
- ```
1188
- ### Mark a Chat Read/Unread
1189
- ```javascript
1190
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1191
- // mark it unread
1192
- await sock.chatModify({ markRead: false, lastMessages: [lastMsgInChat] }, jid)
1193
- ```
1194
-
1195
- ### Delete a Message for Me
1196
- ```javascript
1197
- await sock.chatModify(
1198
- {
1199
- clear: {
1200
- messages: [
1201
- {
1202
- id: 'ATWYHDNNWU81732J',
1203
- fromMe: true,
1204
- timestamp: '1654823909'
1205
- }
1206
- ]
1207
- }
1208
- },
1209
- jid
1210
- )
1211
-
1212
- ```
1213
- ### Delete a Chat
1214
- ```javascript
1215
- const lastMsgInChat = await getLastMessageInChat(jid) // implement this on your end
1216
- await sock.chatModify({
1217
- delete: true,
1218
- lastMessages: [
1219
- {
1220
- key: lastMsgInChat.key,
1221
- messageTimestamp: lastMsgInChat.messageTimestamp
1222
- }
1223
- ]
1224
- },
1225
- jid
1226
- )
1227
- ```
1228
- ### Pin/Unpin a Chat
1229
- ```javascript
1230
- await sock.chatModify({
1231
- pin: true // or `false` to unpin
1232
- },
1233
- jid
1234
- )
1235
- ```
1236
- ### Star/Unstar a Message
1237
- ```javascript
1238
- await sock.chatModify({
1239
- star: {
1240
- messages: [
1241
- {
1242
- id: 'messageID',
1243
- fromMe: true // or `false`
1244
- }
1245
- ],
1246
- star: true // - true: Star Message; false: Unstar Message
1247
- }
1248
- },
1249
- jid
1250
- )
1251
- ```
1252
-
1253
- ### Disappearing Messages
1254
-
1255
- - Ephemeral can be:
1256
-
1257
- | Time | Seconds |
1258
- |-------|----------------|
1259
- | Remove | 0 |
1260
- | 24h | 86.400 |
1261
- | 7d | 604.800 |
1262
- | 90d | 7.776.000 |
1263
-
1264
- - You need to pass in **Seconds**, default is 7 days
1265
-
1266
- ```javascript
1267
- // turn on disappearing messages
1268
- await sock.sendMessage(
1269
- jid,
1270
- // this is 1 week in seconds -- how long you want messages to appear for
1271
- { disappearingMessagesInChat: WA_DEFAULT_EPHEMERAL }
1272
- )
1273
-
1274
- // will send as a disappearing message
1275
- await sock.sendMessage(jid, { text: 'hello' }, { ephemeralExpiration: WA_DEFAULT_EPHEMERAL })
1276
-
1277
- // turn off disappearing messages
1278
- await sock.sendMessage(
1279
- jid,
1280
- { disappearingMessagesInChat: false }
1281
- )
1282
- ```
1283
-
1284
- ## User Querys
1285
-
1286
- ### Check If ID Exists in Whatsapp
1287
- ```javascript
1288
- const [result] = await sock.onWhatsApp(jid)
1289
- if (result.exists) console.log (`${jid} exists on WhatsApp, as jid: ${result.jid}`)
1290
- ```
1291
-
1292
- ### Query Chat History (groups too)
1293
-
1294
- - You need to have oldest message in chat
1295
- ```javascript
1296
- const msg = await getOldestMessageInChat(jid)
1297
- await sock.fetchMessageHistory(
1298
- 50, //quantity (max: 50 per query)
1299
- msg.key,
1300
- msg.messageTimestamp
1301
- )
1302
- ```
1303
- - Messages will be received in `messaging.history-set` event
1304
-
1305
- ### Fetch Status
1306
- ```javascript
1307
- const status = await sock.fetchStatus(jid)
1308
- console.log('status: ' + status)
1309
- ```
1310
-
1311
- ### Fetch Profile Picture (groups too)
1312
- - To get the display picture of some person/group
1313
- ```javascript
1314
- // for low res picture
1315
- const ppUrl = await sock.profilePictureUrl(jid)
1316
- console.log(ppUrl)
1317
-
1318
- // for high res picture
1319
- const ppUrl = await sock.profilePictureUrl(jid, 'image')
1320
- ```
1321
-
1322
- ### Fetch Bussines Profile (such as description or category)
1323
- ```javascript
1324
- const profile = await sock.getBusinessProfile(jid)
1325
- console.log('business description: ' + profile.description + ', category: ' + profile.category)
1326
- ```
1327
-
1328
- ### Fetch Someone's Presence (if they're typing or online)
1329
- ```javascript
1330
- // the presence update is fetched and called here
1331
- sock.ev.on('presence.update', console.log)
1332
-
1333
- // request updates for a chat
1334
- await sock.presenceSubscribe(jid)
1335
- ```
1336
-
1337
- ## Change Profile
1338
-
1339
- ### Change Profile Status
1340
- ```javascript
1341
- await sock.updateProfileStatus('Hello World!')
1342
- ```
1343
- ### Change Profile Name
1344
- ```javascript
1345
- await sock.updateProfileName('My name')
1346
- ```
1347
- ### Change Display Picture (groups too)
1348
- - To change your display picture or a group's
1349
-
1350
- > [!NOTE]
1351
- > 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)
1352
-
1353
- ```javascript
1354
- await sock.updateProfilePicture(jid, { url: './new-profile-picture.jpeg' })
1355
- ```
1356
- ### Remove display picture (groups too)
1357
- ```javascript
1358
- await sock.removeProfilePicture(jid)
1359
- ```
1360
-
1361
- ## Groups
1362
-
1363
- - To change group properties you need to be admin
1364
-
1365
- ### Create a Group
1366
- ```javascript
1367
- // title & participants
1368
- const group = await sock.groupCreate('My Fab Group', ['1234@s.whatsapp.net', '4564@s.whatsapp.net'])
1369
- console.log('created group with id: ' + group.gid)
1370
- await sock.sendMessage(group.id, { text: 'hello there' }) // say hello to everyone on the group
1371
- ```
1372
- ### Add/Remove or Demote/Promote
1373
- ```javascript
1374
- // id & people to add to the group (will throw error if it fails)
1375
- await sock.groupParticipantsUpdate(
1376
- jid,
1377
- ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1378
- 'add' // replace this parameter with 'remove' or 'demote' or 'promote'
1379
- )
1380
- ```
1381
- ### Change Subject (name)
1382
- ```javascript
1383
- await sock.groupUpdateSubject(jid, 'New Subject!')
1384
- ```
1385
- ### Change Description
1386
- ```javascript
1387
- await sock.groupUpdateDescription(jid, 'New Description!')
1388
- ```
1389
- ### Change Settings
1390
- ```javascript
1391
- // only allow admins to send messages
1392
- await sock.groupSettingUpdate(jid, 'announcement')
1393
- // allow everyone to send messages
1394
- await sock.groupSettingUpdate(jid, 'not_announcement')
1395
- // allow everyone to modify the group's settings -- like display picture etc.
1396
- await sock.groupSettingUpdate(jid, 'unlocked')
1397
- // only allow admins to modify the group's settings
1398
- await sock.groupSettingUpdate(jid, 'locked')
1399
- ```
1400
- ### Leave a Group
1401
- ```javascript
1402
- // will throw error if it fails
1403
- await sock.groupLeave(jid)
1404
- ```
1405
- ### Get Invite Code
1406
- - To create link with code use `'https://chat.whatsapp.com/' + code`
1407
- ```javascript
1408
- const code = await sock.groupInviteCode(jid)
1409
- console.log('group code: ' + code)
1410
- ```
1411
- ### Revoke Invite Code
1412
- ```javascript
1413
- const code = await sock.groupRevokeInvite(jid)
1414
- console.log('New group code: ' + code)
1415
- ```
1416
- ### Join Using Invitation Code
1417
- - Code can't have `https://chat.whatsapp.com/`, only code
1418
- ```javascript
1419
- const response = await sock.groupAcceptInvite(code)
1420
- console.log('joined to: ' + response)
1421
- ```
1422
- ### Get Group Info by Invite Code
1423
- ```javascript
1424
- const response = await sock.groupGetInviteInfo(code)
1425
- console.log('group information: ' + response)
1426
- ```
1427
- ### Query Metadata (participants, name, description...)
1428
- ```javascript
1429
- const metadata = await sock.groupMetadata(jid)
1430
- console.log(metadata.id + ', title: ' + metadata.subject + ', description: ' + metadata.desc)
1431
- ```
1432
- ### Join using `groupInviteMessage`
1433
- ```javascript
1434
- const response = await sock.groupAcceptInviteV4(jid, groupInviteMessage)
1435
- console.log('joined to: ' + response)
1436
- ```
1437
- ### Get Request Join List
1438
- ```javascript
1439
- const response = await sock.groupRequestParticipantsList(jid)
1440
- console.log(response)
1441
- ```
1442
- ### Approve/Reject Request Join
1443
- ```javascript
1444
- const response = await sock.groupRequestParticipantsUpdate(
1445
- jid, // group id
1446
- ['abcd@s.whatsapp.net', 'efgh@s.whatsapp.net'],
1447
- 'approve' // or 'reject'
1448
- )
1449
- console.log(response)
1450
- ```
1451
- ### Get All Participating Groups Metadata
1452
- ```javascript
1453
- const response = await sock.groupFetchAllParticipating()
1454
- console.log(response)
1455
- ```
1456
- ### Toggle Ephemeral
1457
-
1458
- - Ephemeral can be:
1459
-
1460
- | Time | Seconds |
1461
- |-------|----------------|
1462
- | Remove | 0 |
1463
- | 24h | 86.400 |
1464
- | 7d | 604.800 |
1465
- | 90d | 7.776.000 |
1466
-
1467
- ```javascript
1468
- await sock.groupToggleEphemeral(jid, 86400)
1469
- ```
1470
-
1471
- ### Change Add Mode
1472
- ```javascript
1473
- await sock.groupMemberAddMode(
1474
- jid,
1475
- 'all_member_add' // or 'admin_add'
1476
- )
1477
- ```
1478
-
1479
- ## Privacy
1480
-
1481
- ### Block/Unblock User
1482
- ```javascript
1483
- await sock.updateBlockStatus(jid, 'block') // Block user
1484
- await sock.updateBlockStatus(jid, 'unblock') // Unblock user
1485
- ```
1486
- ### Get Privacy Settings
1487
- ```javascript
1488
- const privacySettings = await sock.fetchPrivacySettings(true)
1489
- console.log('privacy settings: ' + privacySettings)
1490
- ```
1491
- ### Get BlockList
1492
- ```javascript
1493
- const response = await sock.fetchBlocklist()
1494
- console.log(response)
1495
- ```
1496
- ### Update LastSeen Privacy
1497
- ```javascript
1498
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1499
- await sock.updateLastSeenPrivacy(value)
1500
- ```
1501
- ### Update Online Privacy
1502
- ```javascript
1503
- const value = 'all' // 'match_last_seen'
1504
- await sock.updateOnlinePrivacy(value)
1505
- ```
1506
- ### Update Profile Picture Privacy
1507
- ```javascript
1508
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1509
- await sock.updateProfilePicturePrivacy(value)
1510
- ```
1511
- ### Update Status Privacy
1512
- ```javascript
1513
- const value = 'all' // 'contacts' | 'contact_blacklist' | 'none'
1514
- await sock.updateStatusPrivacy(value)
1515
- ```
1516
- ### Update Read Receipts Privacy
1517
- ```javascript
1518
- const value = 'all' // 'none'
1519
- await sock.updateReadReceiptsPrivacy(value)
1520
- ```
1521
- ### Update Groups Add Privacy
1522
- ```javascript
1523
- const value = 'all' // 'contacts' | 'contact_blacklist'
1524
- await sock.updateGroupsAddPrivacy(value)
1525
- ```
1526
- ### Update Default Disappearing Mode
1527
-
1528
- - Like [this](#disappearing-messages), ephemeral can be:
1529
-
1530
- | Time | Seconds |
1531
- |-------|----------------|
1532
- | Remove | 0 |
1533
- | 24h | 86.400 |
1534
- | 7d | 604.800 |
1535
- | 90d | 7.776.000 |
1536
-
1537
- ```javascript
1538
- const ephemeral = 86400
1539
- await sock.updateDefaultDisappearingMode(ephemeral)
1540
- ```
1541
-
1542
- ## Broadcast Lists & Stories
1543
-
1544
- ### Send Broadcast & Stories
1545
- - Messages can be sent to broadcasts & stories. You need to add the following message options in sendMessage, like this:
1546
- ```javascript
1547
- await sock.sendMessage(
1548
- jid,
1549
- {
1550
- image: {
1551
- url: url
1552
- },
1553
- caption: caption
1554
- },
1555
- {
1556
- backgroundColor: backgroundColor,
1557
- font: font,
1558
- statusJidList: statusJidList,
1559
- broadcast: true
1560
- }
1561
- )
1562
- ```
1563
- - Message body can be a `extendedTextMessage` or `imageMessage` or `videoMessage` or `voiceMessage`, see [here](https://baileys.whiskeysockets.io/types/AnyRegularMessageContent.html)
1564
- - You can add `backgroundColor` and other options in the message options, see [here](https://baileys.whiskeysockets.io/types/MiscMessageGenerationOptions.html)
1565
- - `broadcast: true` enables broadcast mode
1566
- - `statusJidList`: a list of people that you can get which you need to provide, which are the people who will get this status message.
1567
-
1568
- - You can send messages to broadcast lists the same way you send messages to groups & individual chats.
1569
- - Right now, WA Web does not support creating broadcast lists, but you can still delete them.
1570
- - Broadcast IDs are in the format `12345678@broadcast`
1571
- ### Query a Broadcast List's Recipients & Name
1572
- ```javascript
1573
- const bList = await sock.getBroadcastListInfo('1234@broadcast')
1574
- console.log (`list name: ${bList.name}, recps: ${bList.recipients}`)
1575
- ```
1576
-
1577
- ## Writing Custom Functionality
1578
- Baileys is written with custom functionality in mind. Instead of forking the project & re-writing the internals, you can simply write your own extensions.
1579
-
1580
- ### Enabling Debug Level in Baileys Logs
1581
- First, enable the logging of unhandled messages from WhatsApp by setting:
1582
- ```javascript
1583
- const sock = makeWASocket({
1584
- logger: P({ level: 'debug' }),
1585
- })
1586
- ```
1587
- This will enable you to see all sorts of messages WhatsApp sends in the console.
1588
-
1589
- ### How Whatsapp Communicate With Us
1590
-
1591
- > [!TIP]
1592
- > If you want to learn whatsapp protocol, we recommend to study about Libsignal Protocol and Noise Protocol
1593
-
1594
- - **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:
1595
- ```
1596
- {
1597
- "level": 10,
1598
- "fromMe": false,
1599
- "frame": {
1600
- "tag": "ib",
1601
- "attrs": {
1602
- "from": "@s.whatsapp.net"
1603
- },
1604
- "content": [
1605
- {
1606
- "tag": "edge_routing",
1607
- "attrs": {},
1608
- "content": [
1609
- {
1610
- "tag": "routing_info",
1611
- "attrs": {},
1612
- "content": {
1613
- "type": "Buffer",
1614
- "data": [8,2,8,5]
1615
- }
1616
- }
1617
- ]
1618
- }
1619
- ]
1620
- },
1621
- "msg":"communication"
1622
- }
1623
- ```
1624
-
1625
- The `'frame'` is what the message received is, it has three components:
1626
- - `tag` -- what this frame is about (eg. message will have 'message')
1627
- - `attrs` -- a string key-value pair with some metadata (contains ID of the message usually)
1628
- - `content` -- the actual data (eg. a message node will have the actual message content in it)
1629
- - read more about this format [here](/src/WABinary/readme.md)
1630
-
1631
- ### Register a Callback for Websocket Events
1632
-
1633
- > [!TIP]
1634
- > Recommended to see `onMessageReceived` function in `socket.ts` file to understand how websockets events are fired
1635
-
1636
- ```javascript
1637
- // for any message with tag 'edge_routing'
1638
- sock.ws.on('CB:edge_routing', (node: BinaryNode) => { })
1639
-
1640
- // for any message with tag 'edge_routing' and id attribute = abcd
1641
- sock.ws.on('CB:edge_routing,id:abcd', (node: BinaryNode) => { })
1642
-
1643
- // for any message with tag 'edge_routing', id attribute = abcd & first content node routing_info
1644
- sock.ws.on('CB:edge_routing,id:abcd,routing_info', (node: BinaryNode) => { })
1645
- ```
7
+ # Disclaimer
8
+ This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates.
9
+ Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.