Sign inSign up

luizeof/code-chat-br-whatsapp-api

By luizeof

β€’Updated over 3 years ago

Image
1

1.0K

luizeof/code-chat-br-whatsapp-api repository overview

⁠CodeChat Api Pro

It is a version of this API with advanced features like message queue management, send processing status, integration with n8n⁠ unique models and much more! Check it out⁠ πŸ˜‰!



Telegram Group Whatsapp Group License Support Support

⁠WhatsApp-Api-NodeJs

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.

⁠Node n8n⁠

⁠Infrastructure

⁠Nvm installation
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
# or
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

After finishing, restart the terminal to load the new information.

⁠Docker installation [optional]
curl -fsSL https://get.docker.com -o get-docker.sh

sudo sh get-docker.sh

sudo usermod -aG docker ${USER}
⁠Nodejs installation
nvm install 16.17.0
⁠pm2 installation
npm i -g pm2
docker --version

node --version

⁠MongoDb [optional]

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.

⁠Application startup

Cloning the Repository

git clone https://github.com/code-chat-br/whatsapp-api.git

Go to the project directory and install all dependencies.

cd whatsapp-api

npm i

Finally, run the command below to start the application:

# Under development
npm run start

# In production
npm run start:prod

# pm2
pm2 start 'npm run start:prod' --name ApiCodechat

⁠Authentication

You can define two authentication types for the routes in the env file⁠. Authentications must be inserted in the request header.

  1. apikey

  2. 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.

⁠Connection
⁠Create an instance
⁠HTTP

NOTE: This key must be inserted in the request header to create an instance.

POST /instance/create HTTP/1.1
Host: localhost:8080
Content-Type: application/json
apikey: t8OOEeISKzpmc3jjcMqBWYSaJH2PIxns

{
  "instanceName": "codechat"
}
⁠cURL
curl --location --request POST 'http://localhost:8080/instance/create' \
--header 'Content-Type: application/json' \
--header 'apikey: t8OOEeISKzpmc3jjcMqBWYSaJH2PIxns' \
--data-raw '{
  "instanceName": "codechat"
}'
⁠Response
{
  "instance": {
    "instanceName": "codechat",
    "status": "created"
  },
  "hash": {
    "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. [...]"

    // or
    // "apikey": "88513847-1B0E-4188-8D76-4A2750C9B6C3"
  }
}
⁠Connection with qrcode
⁠HTTP
GET /instance/connect/codechat HTTP/1.1
Host: localhost:8080
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. [...]
GET /instance/connect/codechat HTTP/1.1
Host: localhost:8080
apikey: 88513847-1B0E-4188-8D76-4A2750C9B6C3
⁠cURL
curl --location --request GET 'http://localhost:8080/instance/connect/codechat' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9. [...]'
curl --location --request GET 'http://localhost:8080/instance/connect/codechat' \
--header 'apikey: 88513847-1B0E-4188-8D76-4A2750C9B6C3'
⁠Response
{
  "code": "2@nXSUgRJSBY6T0XJmiFKZ0 [...] ,XsgJhJHYa+0MPpXANdPHHt6Ke/I7O2QyXT/Lsge0uSg=",
  "base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhE [...] LkMtqAAAAABJRU5ErkJggg=="
}
⁠App in Docker

After building the application, in the same directory as the files above, run the following command:

docker-compose up

⁠Send Messages

Send Textβœ”
Send Buttonsβœ”
Send Template❌
Send Media: audio - video - image - document - gif

base64: true
βœ”
Send Media File❌
Send Audio type WhatsAppβœ”
Send Locationβœ”
Send Listβœ”
Send Link Preview❌
Send Contactβœ”
Send Reaction - emojiβœ”

⁠Postman collections

⁠Webhook Events

NameEventTypeDataDescription
QRCODE_UPDATEDqrcode.updatedjsonSends the base64 of the qrcode for reading
CONNECTION_UPDATEconnection.updatejsonInforms the status of the connection with whatsapp
MESSAGES_SETmessage.setjsonSends a list of all your messages uploaded on whatsapp
This event occurs only once
MESSAGES_UPSERTmessage.upsertjsonNotifies you when a message is received
MESSAGES_UPDATEmessage.updatejsonTells you when a message is updated
SEND_MESSAGEsend.messagejsonNotifies when a message is sent
CONTACTS_SETcontacts.setjsonPerforms initial loading of all contacts
This event occurs only once
CONTACTS_UPSERTcontacts.upsertjsonReloads all contacts with additional information
This event occurs only once
CONTACTS_UPDATEcontacts.updatejsonInforms you when the chat is updated
PRESENCE_UPDATEpresence.updatejsonInforms if the user is online, if he is performing some action like writing or recording and his last seen
'unavailable'
CHATS_SETchats.setjsonSend a list of all loaded chats
CHATS_UPDATEchats.updatejsonInforms you when the chat is updated
CHATS_UPSERTchats.upsertjsonSends any new chat information
GROUPS_UPSERTgroups.upsertJSONNotifies when a group is created
GROUPS_UPDATEgroups.updateJSONNotifies when a group has its information updated
GROUP_PARTICIPANTS_UPDATEgroup-participants.updateJSONNotifies when an action occurs involving a participant
'add'
NEW_TOKENnew.jwtJSONNotifies when the token (jwt) is updated

⁠Env File

See additional settings that can be applied through the env file by clicking here⁠.

⚠️Attention⚠️: rename the dev-env.yml file to env.yml.

⁠SSL

To install the SSL certificate, follow the instructions⁠ below.

⁠Note

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.

⁠Donate to the project.

⁠Pix: 2b526ada-4ef4-4db4-bbeb-f60da2421fce
⁠PicPay

Tag summary

Content type

Image

Digest

sha256:0909cf089…

Size

550.1 MB

Last updated

over 3 years ago

docker pull luizeof/code-chat-br-whatsapp-api