This project is a simple WhatsApp bot built using the whatsapp-web.js library. The bot automates sending a specified message to a target contact repeatedly.
- QR code-based authentication using
whatsapp-web.js
andLocalAuth
. - Sends a predefined message to a specified contact.
- Logs various client states, including authentication status and connection state.
- Node.js (v14 or later)
- A WhatsApp account
-
Clone the repository:
git clone https://github.com/AbubakarWebDev/whatsapp-bot-nodejs cd https://github.com/AbubakarWebDev/whatsapp-bot-nodejs
-
Install the dependencies:
npm install whatsapp-web.js qrcode-terminal
- Open the source code (
index.js
or equivalent). - Set the following variables:
chatName
: Replace<--- Person Contact Name --->
with the contact name as it appears in your WhatsApp chat list.msg
: Replace"Hello How Are You?"
with the message you want to send.
-
Start the bot:
node index.js
-
Scan the QR code displayed in the terminal using your WhatsApp app to authenticate.
-
Once authenticated, the bot will:
- Search for the target contact in your chat list.
- Send the specified message repeatedly to the contact (1000 times).
- QR Code Authentication: The bot generates a QR code for authentication. You need to scan this code using the WhatsApp app.
- Message Sending: Once authenticated and the client is ready, the bot searches for the target contact by name and sends the specified message repeatedly.
client.on('qr', qr)
: Generates and displays the QR code for authentication.client.on('ready')
: Triggered when the client is ready to send messages.client.on('message', message)
: Logs incoming messages.client.on('disconnected', reason)
: Logs the reason for disconnection.
- The bot uses the
LocalAuth
strategy to persist the session locally, so you won’t need to scan the QR code again unless the session is cleared. - Ensure the contact name in
chatName
matches exactly as it appears in WhatsApp.
This project is intended for educational purposes only. Use responsibly and comply with WhatsApp's terms of service.
MIT License