A Node.js application designed to automate sending WhatsApp messages based on a schedule, utilizing the Baileys library.
This is a simple whatsApp bot for academic purpose using a library called Baileys.
- Direct WhatsApp Integration: Connects directly to WhatsApp servers using the Baileys WebSocket interface.
- Scheduled Messaging: Sends messages automatically based on a defined schedule.
- Contact & Group Support: Can send messages to both individual contacts (JIDs) and group chats (Group JIDs).
- Session Persistence: Saves authentication data to avoid pairing the code everytime the code runs.
- Node.js (v16.x or higher recommended)
- JavaScript (Vanilla)
- Libraries:
@whiskeysockets/baileys: Core library for WhatsApp interaction. [Verify exact package name in yourpackage.json]pino: Logger, often used with Baileys.zustand: State management..
- Node.js: Make sure you have Node.js (version 16 or newer is recommended for modern Baileys) and npm (or yarn) installed. Download from nodejs.org.
- WhatsApp Account: A working WhatsApp account (ideally not your primary personal number, due to the risks mentioned above).
-
Clone the repository:
git clone https://github.com/MowlandCodes/ti_whatsapp_bot.git cd ti_whatsapp_bot -
Install dependencies:
npm install # or if you use yarn: # yarn install
-
Start the bot:
npm start # or directly using node: # node app.js
-
Pairing Device (First Run):
- The first time you run the script (or if the session files are deleted/invalid), a message appeared to pair the bot to your whatsApp account by inserting your number then write the generated code from the terminal.
- Open WhatsApp on your phone, go to
Settings>Linked Devices>Link a Device, and insert the generated code.
-
Bot Running:
- Once connected, the bot will initialize. You should see log messages indicating it's connected and running.
- It will then monitor the chat withing the group you apply to.
- When a scheduled time matches, it will use Baileys functions (like
sock.sendMessage) to send the message to the specified JID.
- Initialization: The script initializes the Baileys socket connection (
makeWASocket). - Authentication: It handles the connection events:
connection.update: Listens for updates like generated code to pair the bot to your device.- Session credentials are saved upon successful connection (
creds.update).
- Data Loading: Loads the schedule and message data from the terminal logs.
- Job Execution: When the scheduler triggers:
- It checks the current time and day.
- It compares this against the loaded schedule data.
- If a match is found, it constructs the message and uses
sock.sendMessage(targetJid, { text: messageContent })to send the message via the active Baileys connection.
- Logging: Throughout the process, information, warnings, and errors are logged to the console (likely using
pino).
Contributions are welcome! If you have suggestions for improvements or find bugs, please feel free to:
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Project Link: https://github.com/MowlandCodes/ti_whatsapp_bot