A WhatsApp-bot that automatically replies WhatsApp messages.
- Install Node.js
- Install Yarn (optional)
- Install Git
- Clone this repository with cmd or tarminal command
git clone https://github.com/sajidmahamud835/whatsapp-bot.git
in the folder you want to install the bot - Run
yarn install
ornpm install
in the repository folder - Run
yarn start
ornpm start
in the repository folder - Open
http://localhost:3000
in your browser.
- Install Heroku CLI
- Clone this repository with cmd or tarminal command
git clone https://github.com/sajidmahamud835/whatsapp-bot.git
in the folder you want to install the bot (or download the repository as zip and extract it). - Run
heroku login
in the repository folder to login to heroku. - Run
heroku create
in the repository folder to create a heroku app. - Run
git push heroku master
in the repository folder to deploy to heroku. - Run
heroku ps:scale web=1
in the repository folder for starting the bot. - Run
heroku open
in the repository folder
- Install Vercel CLI
- Clone this repository with cmd or tarminal command
git clone https://github.com/sajidmahamud835/whatsapp-bot.git
in the folder you want to install the bot (or download the repository as zip and extract it). - Run
vercel login
in the repository folder to login to vercel. - Run
vercel
in the repository folder to deploy to staging. - Run
vercel --prod
in the repository folder to deploy to production. - Open the link that is shown in the terminal.
- Install aaPanel on your server if you haven't already.
- Open aaPanel and go to the "App Store" tab.
- Search for "Node.js version manager" and install it.
- Open aaPanel and go to the "File Manager" tab.
- Create a new folder in the "www" folder.
- Open the folder you created and upload the files from the repository.
- Create a .env file in the folder you created and add the following lines to it:
PORT=8585 # The port you want to run the bot on
- Open aaPanel and go to the "Website" tab.
- Click on the "Node Project" button.
- Click on the "Add Node Project" button.
- Select the folder you created in step 5.
- Select the port you want to run the bot on in step 7.
- Select a domain for the bot (optional).
- Click on the "Confirm" button.
- Open aaPanel and go to the "Security" tab and add the port you selected in step 12.
- Now open the domain you selected in step 13 or the ip address of your server with the port you selected in step 12 in your browser.
- The bot will automatically post all messages to the api you provided, and will reply with the response from the api.
- You can start the instance with
/{instance_id}/init
(GET method). - You can stop the instance with
/{instance_id}/stop
(GET method). - You can login with
/{instance_id}/qr
(GET method). Scan the QR code with your phone. - You can logout with
/{instance_id}/logout
(GET method). - Send a message to the phone number you are using with the bot (e.g. "Hi"). The bot will reply with predefined messages (e.g. "Hello").
- You can send a message with the bot with
/{instance_id}/send
(POST method). The bot will send the message from the phone number you are using with the bot. The body should be like this:
{"number": "[email protected]", "message": "Hello"}
The number is the number you want to send the message to. The message is the message you want to send. The number should be in this format: [email protected]
. Here @c.us
is the domain of the number. You can use @c.us
, @s.whatsapp.net
, @g.us
. You can use @c.us
for personal chats, @s.whatsapp.net
for group chats, and @g.us
for broadcast lists.
- You can send media with the bot with
/{instance_id}/sendMedia
(POST method). The bot will send the media from the phone number you are using with the bot. The body should be like this:
{"number": "[email protected]", "mediaUrl": "https://example.com/image.jpg"}
- You can get all chats with
/{instance_id}/getChats
(GET method). - You can get all messages from a chat with
/{instance_id}/getChatMessages/{whatsapp_id}
(GET method). The whatsapp_id is the id of the chat you want to get messages from. (e.g.[email protected]
).
The bot will automatically post all messages to the api you provided, and will reply with the response from the api. The api should be a POST method with the following body:
{
"instanceid": "2",
"_data": {
"id": {
"fromMe": false,
"remote": "[email protected]",
"id": "3EB0E8E1B3B9BE46xxxx",
"_serialized": "[email protected]_3EB0E8E1B3B9BE46xxxx"
},
"body": "ok",
"type": "chat",
"t": 1671010000,
"notifyName": "WhatsApp Bot Ltd.",
"from": "[email protected]",
"to": "[email protected]",
"self": "in",
"ack": 1,
"isNewMsg": true,
"star": false,
"kicNotified": false,
"recvFresh": true,
"isFromTemplate": false,
"pollInvalidated": false,
"latestEditMsgKey": null,
"latestEditSenderTimestampMs": null,
"broadcast": false,
"mentionedJidList": [],
"isVcardOverMmsDocument": false,
"isForwarded": false,
"hasReaction": false,
"ephemeralOutOfSync": false,
"productHeaderImageRejected": false,
"lastPlaybackProgress": 0,
"isDynamicReplyButtonsMsg": false,
"isMdHistoryMsg": false,
"stickerSentTs": 0,
"isAvatar": false,
"requiresDirectConnection": false,
"pttForwardedFeaturesEnabled": true,
"isEphemeral": false,
"isStatusV3": false,
"links": []
},
"id": {
"fromMe": false,
"remote": "[email protected]",
"id": "3EB0E8E1B3B9BE46xxxx",
"_serialized": "[email protected]_3EB0E8E1B3B9BE46xxxx"
},
"ack": 1,
"hasMedia": false,
"body": "ok",
"type": "chat",
"timestamp": 1671010000,
"from": "[email protected]",
"to": "[email protected]",
"deviceType": "web",
"isForwarded": false,
"forwardingScore": 0,
"isStatus": false,
"isStarred": false,
"broadcast": false,
"fromMe": false,
"hasQuotedMsg": false,
"vCards": [],
"mentionedIds": [],
"isGif": false,
"isEphemeral": false,
"links": []
}
You can return a response with the following body:
{
"instanceid": "2",
"reply": "Hello",
"replyMedia": "https://example.com/image.jpg"
}
- Send a message to the bot.
- Get all chats.
- Get all messages from a chat.
- Automatically post all messages to the api you provided, and will reply with the response from the api.
GNU General Public License v3.0
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Add your name here if you contribute to this project.