This is a WhatsApp service for Ta-vivo or any other project to send and receive messages via WhatsApp business.
yarnCreate the .env file into api directory, use the example.env file;
cp example.env .envCreate a simple JWT to make requests;
node src/utils/createJWT.jsNow follow the Meta documentation to get the WHATSAPP_PHONE_ID and WHATSAPP_TOKEN;
From the documentation follow the steps;
-
- Set up Developer Assets and Platform Access
-
- Configure a Webhook
https://developers.facebook.com/docs/whatsapp/cloud-api/get-started
Note: The WHATSAPP_PHONE_ID is on Send and receive messages section inside the WhatsApp product in Meta for developers page. The VERIFY_TOKEN is a string create by yourself, this can be any string, this is used to verify the callback URL.
yarn devWhatsApp business no accepted callback url without HTTPS, so you can use ngrok https://ngrok.com/download login and get the token for ngrok, now you can install ngrok and start it;
ngrok http 5009 # or the port of this serviceNow you get a callback url with HTTPS mapped to the port of this service, now you can use this url as callback url;
The principal functions of the service are:
- POST
/messages/send-message: Send a message to a WhatsApp user;
{
"phone": "18099982632",
"message": "Test the endpoint"
}- POST
/messages/send-message-template: Send a template message;
{
"phone": "18099982632",
"template": {
"name": "unique_code_request",
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "unicode or the message"
}
]
}
]
}
}Read more about the templates here
For development you can use the docker-compose.dev.yml file;
docker-compose -f docker-compose.dev.yml upFor production you can use the docker-compose.yml file;
docker-compose up❤️