AI prompts
base on This project is a REST API wrapper for the whatsapp-web.js library, providing an easy-to-use interface to interact with the WhatsApp Web platform. # WhatsApp REST API
REST API wrapper for the [whatsapp-web.js](https://github.com/pedroslopez/whatsapp-web.js) library, providing an easy-to-use interface to interact with the WhatsApp Web platform.
It is designed to be used as a docker container, scalable, secure, and easy to integrate with other non-NodeJs projects.
This project is a work in progress: star it, create issues, features or pull requests ❣️
**NOTE**: I can't guarantee you will not be blocked by using this method, although it has worked for me. WhatsApp does not allow bots or unofficial clients on their platform, so this shouldn't be considered totally safe.
## Table of Contents
[1. Quick Start with Docker](#quick-start-with-docker)
[2. Features](#features)
[3. Run Locally](#run-locally)
[4. Testing](#testing)
[5. Documentation](#documentation)
[6. Deploy to Production](#deploy-to-production)
[7. Contributing](#contributing)
[8. License](#license)
[9. Star History](#star-history)
## Quick Start with Docker
[![dockeri.co](https://dockerico.blankenship.io/image/chrishubert/whatsapp-web-api)](https://hub.docker.com/r/chrishubert/whatsapp-web-api)
1. Clone the repository:
```bash
git clone https://github.com/chrishubert/whatsapp-api.git
cd whatsapp-api
```
3. Run the Docker Compose:
```bash
docker-compose pull && docker-compose up
```
4. Visit http://localhost:3000/session/start/ABCD
5. Scan the QR on your console using WhatsApp mobile app -> Linked Device -> Link a Device (it may take time to setup the session)
6. Visit http://localhost:3000/client/getContacts/ABCD
7. EXTRA: Look at all the callbacks data in `./session/message_log.txt`
![Quick Start](./assets/basic_start.gif)
## Features
1. API and Callbacks
| Actions | Status | Sessions | Status | Callbacks | Status |
| ----------------------------| ------| ----------------------------------------| ------| ----------------------------------------------| ------|
| Send Image Message | ✅ | Initiate session | ✅ | Callback QR code | ✅ |
| Send Video Message | ✅ | Terminate session | ✅ | Callback new message | ✅ |
| Send Audio Message | ✅ | Terminate inactive sessions | ✅ | Callback status change | ✅ |
| Send Document Message | ✅ | Terminate all sessions | ✅ | Callback message media attachment | ✅ |
| Send File URL | ✅ | Healthcheck | ✅ | | |
| Send Button Message | ✅ | Local test callback | | | |
| Send Contact Message | ✅ | | | | |
| Send List Message | ✅ | | | | |
| Set Status | ✅ | | | | |
| Send Button With Media | ✅ | | | | |
| Is On Whatsapp? | ✅ | | | | |
| Download Profile Pic | ✅ | | | | |
| User Status | ✅ | | | | |
| Block/Unblock User | ✅ | | | | |
| Update Profile Picture | ✅ | | | | |
| Create Group | ✅ | | | | |
| Leave Group | ✅ | | | | |
| All Groups | ✅ | | | | |
| Invite User | ✅ | | | | |
| Make Admin | ✅ | | | | |
| Demote Admin | ✅ | | | | |
| Group Invite Code | ✅ | | | | |
| Update Group Participants | ✅ | | | | |
| Update Group Setting | ✅ | | | | |
| Update Group Subject | ✅ | | | | |
| Update Group Description | ✅ | | | | |
3. Handle multiple client sessions (session data saved locally), identified by unique id
4. All endpoints may be secured by a global API key
5. On server start, all existing sessions are restored
6. Set messages automatically as read
7. Disable any of the callbacks
## Run Locally
1. Clone the repository:
```bash
git clone https://github.com/chrishubert/whatsapp-api.git
cd whatsapp-api
```
2. Install the dependencies:
```bash
npm install
```
3. Copy the `.env.example` file to `.env` and update the required environment variables:
```bash
cp .env.example .env
```
4. Run the application:
```bash
npm run start
```
5. Access the API at `http://localhost:3000`
## Testing
Run the test suite with the following command:
```bash
npm run test
```
## Documentation
API documentation can be found in the [`swagger.json`](https://raw.githubusercontent.com/chrishubert/whatsapp-api/master/swagger.json) file. See this file directly into [Swagger Editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/chrishubert/whatsapp-api/master/swagger.json) or any other OpenAPI-compatible tool to view and interact with the API documentation.
This documentation is straightforward if you are familiar with whatsapp-web.js library (https://docs.wwebjs.dev/)
If you are still confused - open an issue and I'll improve it.
Also, there is an option to run the documentation endpoint locally by setting the `ENABLE_SWAGGER_ENDPOINT` environment variable. Restart the service and go to `/api-docs` endpoint to see it.
By default, all callback events are delivered to the webhook defined with the `BASE_WEBHOOK_URL` environment variable.
This can be overridden by setting the `*_WEBHOOK_URL` environment variable, where `*` is your sessionId.
For example, if you have the sessionId defined as `DEMO`, the environment variable must be `DEMO_WEBHOOK_URL`.
By setting the `DISABLED_CALLBACKS` environment variable you can specify what events you are **not** willing to receive on your webhook.
### Scanning QR code
In order to validate a new WhatsApp Web instance you need to scan the QR code using your mobile phone. Official documentation can be found at (https://faq.whatsapp.com/1079327266110265/?cms_platform=android) page. The service itself delivers the QR code content as a webhook event or you can use the REST endpoints (`/session/qr/:sessionId` or `/session/qr/:sessionId/image` to get the QR code as a png image).
## Deploy to Production
- Load the docker image in docker-compose, or your Kubernetes environment
- Disable the `ENABLE_LOCAL_CALLBACK_EXAMPLE` environment variable
- Set the `API_KEY` environment variable to protect the REST endpoints
- Run periodically the `/api/terminateInactiveSessions` endpoint to prevent useless sessions to take up space and resources(only in case you are not in control of the sessions)
## Contributing
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
## Disclaimer
This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with WhatsApp or any of its subsidiaries or its affiliates. The official WhatsApp website can be found at https://whatsapp.com. "WhatsApp" as well as related names, marks, emblems and images are registered trademarks of their respective owners.
## License
This project is licensed under the MIT License - see the [LICENSE.md](./LICENSE.md) file for details.
## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=chrishubert/whatsapp-api&type=Date)](https://star-history.com/#chrishubert/whatsapp-api&Date)
", Assign "at most 3 tags" to the expected json: {"id":"11806","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"