mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
cde7a9e768c7ab949167f7eef135e77e09eccdd2
Baileys
Reverse Engineered WhatsApp Web API in Node.js. Baileys does not require Selenium or any other browser to be interface with WhatsApp Web, it does so directly using WebSockets.
Thank you to Sigalor for writing the guide reverse engineering WhatsApp Web and to the go reimplementation written by Rhymen
Baileys is super easy to use:
- Import using
const WhatsAppWeb = require('Baileys') - Create an instance of Baileys & connect using
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!
let client = new WhatsAppWeb() client.connect() - Implement the following event handlers in your code:
-
client.handlers.onConnected = () => { /* when you're successfully authenticated with the WhatsApp Web servers */ } -
client.handlers.onUnreadMessage = (message) => { /* called when you have a pending unread message or recieve a new message */ } -
client.handlers.onError = (error) => { /* called when there was an error */ } -
client.handlers.onDisconnect = () => { /* called when internet gets disconnected */ }
-
- Send a text message using
The id is the phone number of the person the message is being sent to, it must be in the format '[country code][phone number]@s.whatsapp.net', for example '+19999999999@s.whatsapp.net'
client.sendTextMessage(id, txtMessage) - Send a read reciept using
The id is in the same format as above. The message ID is the unique identifier of the message that you are marking as read
client.sendReadReceipt(id, messageID) - Tell someone what your status is right now by using
Presence can be one of the following:
client.updatePresence(id, presence)static Presence = { available: "available", // "online" unavailable: "unavailable", // offline composing: "composing", // "typing..." recording: "recording", // "recording..." paused: "paused" // I have no clue }
Check out test.js to see example usage of all these.
Note
I am in no way affiliated with WhatsApp. This was written for educational purposes. Use at your own discretion.
Languages
JavaScript
91%
TypeScript
9%