This code is an implementation of Baileys, as a RestFull Api service, which controls whatsapp functions.
With this one you can create multiservice chats, service bots or any other system that uses whatsapp. With this code you don't need to know javascript for nodejs , just start the server and make the language requests that you feel most comfortable with.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
# or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
After finishing, restart the terminal to load the new information.
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker ${USER}
nvm install 20
npm i -g pm2
docker --version
node --version
After installing docker and docker-compose, up the container.
In the same directory where the file is located, run the following command:
bash docker.sh
Using the database is optional.
Cloning the Repository
git clone https://github.com/code-chat-br/whatsapp-api.git
Go to the project directory and install all dependencies.
O aplicativo aproveita o Prisma ORM para lidar com operações de banco de dados. O Prisma simplifica o acesso, a migração e o gerenciamento de banco de dados.
Em ambiente de desenvolvimento:
npx prisma migrate dev
Em ambiente de produção:
npx prisma migrate deploy
Veja os seus dados:
npx prisma studio
Give preference to npm as it has greater compatibility.
cd whatsapp-api-v2
npm install --force
Finally, run the command below to start the application:
npm run start:dev
npm run start:prod
# pm2
pm2 start 'npm run start:prod' --name ApiCodechat
- Route:
http://localhost:8083/docs
- YAML file: swagger.yaml
You can define two authentication types for the routes in the env file. Authentications must be inserted in the request header.
- jwt: A JWT is a standard for authentication and information exchange defined with a signature.
Authentications are generated at instance creation time.
Note: There is also the possibility to define a global api key, which can access and control all instances.
After building the application, in the same directory as the files above, run the following command:
docker-compose up
Send Text | ✔ |
Send Buttons | ❌ |
Send Template | ❌ |
Send Media: audio - video - image - document - gif base64: true |
✔ |
Send Media File | ✔ |
Send Audio type WhatsApp | ✔ |
Send Audio type WhatsApp - File | ✔ |
Send Location | ✔ |
Send List | ❌ |
Send Link Preview | ❌ |
Send Contact | ✔ |
Send Reaction - emoji | ✔ |
Name | Event | TypeData | Description |
---|---|---|---|
QRCODE_UPDATED | qrcode.updated | json | Sends the base64 of the qrcode for reading |
CONNECTION_UPDATE | connection.update | json | Informs the status of the connection with whatsapp |
MESSAGES_SET | message.set | json | Sends a list of all your messages uploaded on whatsapp This event occurs only once |
MESSAGES_UPSERT | message.upsert | json | Notifies you when a message is received |
MESSAGES_UPDATE | message.update | json | Tells you when a message is updated |
SEND_MESSAGE | send.message | json | Notifies when a message is sent |
CONTACTS_SET | contacts.set | json | Performs initial loading of all contacts This event occurs only once |
CONTACTS_UPSERT | contacts.upsert | json | Reloads all contacts with additional information This event occurs only once |
CONTACTS_UPDATE | contacts.update | json | Informs you when the chat is updated |
PRESENCE_UPDATE | presence.update | json | Informs if the user is online, if he is performing some action like writing or recording and his last seen 'unavailable' |
CHATS_SET | chats.set | json | Send a list of all loaded chats |
CHATS_UPDATE | chats.update | json | Informs you when the chat is updated |
CHATS_UPSERT | chats.upsert | json | Sends any new chat information |
GROUPS_UPSERT | groups.upsert | JSON | Notifies when a group is created |
GROUPS_UPDATE | groups.update | JSON | Notifies when a group has its information updated |
GROUP_PARTICIPANTS_UPDATE | group-participants.update | JSON | Notifies when an action occurs involving a participant 'add' |
NEW_TOKEN | new.jwt | JSON | Notifies when the token (jwt) is updated |
See additional settings that can be applied through the env file by clicking here.
⚠️ Attention⚠️ : copy the .env.dev file to .env.
To install the SSL certificate, follow the instructions below.
This code is in no way affiliated with WhatsApp. Use at your own discretion. Don't spam this.
This code was produced based on the baileys library and it is still under development.