This project provides a simple WhatsApp API using whatsapp-web.js. The service is containerized using Docker for easy deployment and scalability.
- Docker installed on your system
- Access to the terminal/command prompt
Use the following command to build the Docker image:
docker build -t whatsapp-api:v1 .
Run the Docker container and expose the service on port 5000:
docker run -p 3000:3000 --name whatsapp-api --restart unless-stopped whatsapp-api:v1
The service will be accessible at:
http://localhost:3000/api/send
Make a POST request to the /api/send
endpoint with user credentials:
curl -X POST http://localhost:3000/api/send \
-H "Content-Type: application/json" \
-H "Authorization: <your-token>" \
-d '{
"phone": "+6201111111111",
"message": "Alo"
}'
If authentication fails, you will receive an error message:
{
"status": "false",
"message": "Error",
"meta": "Not Authorized"
}
To stop the running container:
docker stop whatsapp-api
To remove the container:
docker rm whatsapp-api
- Ensure that port
3000
is not being used by other services. - Use
--restart unless-stopped
to automatically restart the container if it stops unexpectedly.