A bot that listens to messages from specified WhatsApp groups and forwards them to a designated API.
- QR Authentication: Easily scan and connect.
- Auto Reconnection: Handles disconnects and errors seamlessly.
- API Integration: Forwards group messages to an API.
- Popup Handling: Automatically dismisses any dialog popups.
-
Clone the Repository:
git clone https://github.com/your_username/whatsapp-web-bot.git cd whatsapp-web-bot
-
Install Dependencies:
npm install
-
Configuration:
Create a config.json
in the root directory with the following format:
{
"url": "YOUR_API_ENDPOINT",
"authorization": "YOUR_API_AUTHORIZATION_HEADER",
"groupsIds": ["GROUP_ID1", "GROUP_ID2"]
}
Alternatively, you can set groupsIds to empty array to listen to all groups.
{
"url": "YOUR_API_ENDPOINT",
"authorization": "YOUR_API_AUTHORIZATION_HEADER",
"groupsIds": []
}
-
Run the Bot:
npm start
-
Scan the QR Code:
- Open WhatsApp on your phone.
- Go to
Settings > Linked devices > Link a device
. - Scan the QR code displayed in the terminal.
-
Start Chatting:
- Send a message to any of the groups specified in
config.json
. - The bot will forward the message to the API.
- Send a message to any of the groups specified in
The bot will send a POST request to the API with the following format:
-
On new message:
{ "group_id": "GROUP_ID", "message": "MESSAGE", "group_name": "GROUP_NAME", "phone_number": "PHONE_NUMBER", "type": "message" }
Optional response:
{ "react": "REACT EMOJI" }
-
On group member join (the bot or a new member):
{ "newMembers": ["PHONE_NUMBER1", "PHONE_NUMBER2"], "joinOrAdded": "Boolean, indicating if the member joined or was added", "group_id": "GROUP_ID", "group_name": "GROUP_NAME", "amIJoined": "Boolean, indicating if the bot joined the group", "allParticipants": ["PHONE_NUMBER1", "PHONE_NUMBER2"], "type": "group_join" }
-
On group member leave (the bot or a member):
{ "leaveMembers": ["PHONE_NUMBER1", "PHONE_NUMBER2"], "leaveOrKicked": "Boolean, indicating if the member left or was kicked", "group_id": "GROUP_ID", "group_name": "GROUP_NAME", "amILeave": "Boolean, indicating if the bot left the group", "allParticipants": ["PHONE_NUMBER1", "PHONE_NUMBER2"], "type": "group_leave" }
-
On group join request (the bot should be an admin):
{ "group_id": "GROUP_ID", "group_name": "GROUP_NAME", "requester": "PHONE_NUMBER", "type": "group_membership_request" }
Optional response:
{ "approve": "Boolean, indicating if the request should be accepted", "reject": "Boolean, indicating if the request should be rejected" }
- Ensure your phone maintains connection with WhatsApp Web.
- If the bot doesn't connect, try restarting or scanning the QR code again.
Pull requests are welcome. For major changes, please open an issue first.
This project is licensed under the MIT License - see the LICENSE.md file for details.