Sei interessato ai nostri servizi di consulenza?

1 Clicca nella sezione contatti
2 Compila il form
3 Ti ricontattiamo

Se hai bisogno urgente del nostro intervento puoi contattarci al numero 370 148 9430

RENOR & Partners

I nostri orari
Lun-Ven 9:00AM - 18:PM

WhatsApp Business API

by Simone Renzi / April 27, 2025
Post Image

This post is also available in: Italiano (Italian)

Until not long ago, the WhatsApp Business API was reserved exclusively for large enterprises. Access required the use of third-party services such as Zapier, Twilio, and similar platforms. Today, it is possible to integrate solutions based on the WhatsApp Business API for virtually any type of business—the only real limitation is the technical skill required for implementation.

First, let’s start by defining the requirements…

  • A phone number dedicated to the WhatsApp Business API (it can be a virtual number, as long as it supports integration with WhatsApp).
  • A webhook to which WhatsApp sends the messages received from the user’s contact, allowing them to be processed by the backend.
  • A logic for sending messages from the user to Meta’s API.

The implementation of the WhatsApp API begins on Meta’s developer portal: https://developers.facebook.com

Here, the developer must log in using their own Facebook credentials, or the credentials of their company. Alternatively, if they are working on behalf of a company, the company must share administrative access to the WhatsApp API profile with the developer’s Facebook account.

Once logged in, you need to create a new App.

We add a new phone number and authenticate it (you’ll receive a message containing a code to enter in the developers section).

I always recommend having an environment variables file (.env) that is protected from public read and write access, and encapsulated so that only the backend can access it through a dedicated method.

When developing in PHP, I recommend using the Composer library vlucas/phpdotenv.

It is invoked within the class as follows:


use Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();

Once the number is registered, we need to retrieve the following parameters:

WHATSAPP_VERIFY_TOKEN={a token we create arbitrarily, used to subscribe to the service}
WHATSAPP_ACCESS_TOKEN={the access token generated from Facebook’s developers portal}
WHATSAPP_PHONE_NUMBER_ID={the ID Facebook assigns to our previously registered phone number}
WHATSAPP_NUMBER={the phone number we registered}

An important note… The phone number registered on the WhatsApp Business API can no longer be used to access WhatsApp on a mobile phone.
At that point, the user can choose to store messages in a database in order to reply through a web interface, or to add a trained LLM that autonomously handles responses to the contact.

In this article, we will explore exactly this scenario.

Once all this data has been obtained, we need to send our first message to a phone number (for example, our personal number).

In the Facebook Developers console, go to the WhatsApp → > API Configuration menu (where we created our token).
Let me open a brief parenthesis here.
The access token generated from this interface is a temporary token with a 60-day expiration.
If you want to generate a token with no expiration, you need to register the user as a System User from business.facebook.com, grant them administrative permissions for the app you created in Developers, and then generate a token with unlimited validity.

From here, we enter our country code and the number of our personal mobile phone where we want to receive the first message, and by clicking on Send Message, if everything has been set up correctly, we should receive the WhatsApp message.

At the bottom, in step 2, Facebook also provides a cURL instruction for sending messages, which we can reuse to create a message-sending method using cURL to the WhatsApp API endpoint.

We’ve handled the part where we send a message. Now we need to handle the part where the user sends a message to us.

We move to Webhook and, in the dropdown, select Product: WhatsApp Business Account.

Here we will need to enter our Callback URL, which corresponds to the URI of our webhook.

As the verification token, we enter the token we created in the WHATSAPP_VERIFY_TOKEN environment variable in the .env file.

By clicking on Verify and Save, WhatsApp will call our API to check that the webhook is active and functioning, and will then register it correctly with the service.

If we want to observe what WhatsApp is sending us, I recommend using reverse-proxy techniques—such as with Ngrok—and replacing the webhook address with the one provided by Ngrok.

The webhook is where the magic happens. We can simply log the received messages in a database with a timestamp, or we can instruct a neural network in OpenAI to have an LLM respond to user questions for which the model has been custom-trained. Depending on the topic it needs to handle, it’s also possible to use OpenAI’s native models (for less demanding tasks, I recommend the GPT-4o-mini model, which is the most cost-effective). As of today, the cost is approximately €0.15 per million input tokens and €0.60 per million output tokens. In a simple chat, you could exchange thousands of messages before reaching even one euro, assuming an average of 500 tokens per request.

We haven’t talked about the costs of WhatsApp yet…

For chats initiated by customers, the service is completely free within a 24-hour session. On WhatsApp, sessions that are opened last 24 hours before they expire. If we are the ones initiating a chat with a customer, the cost is about €0.05 per session opened toward a unique phone number. Once the session is open, the number of messages sent doesn’t matter—WhatsApp charges only for the session itself.

To give a practical example: if a customer contacts our bot at 1:00 PM on April 12, 2025, they are the one initiating a session, which will be free and will expire at 12:59:59 PM on April 13, 2025. If we respond after this time, we will be the ones opening a new session, which becomes chargeable (€0.05), allowing us to exchange as many messages as we like over the next 24 hours. If we send another message after those 24 hours, a new session will be opened at the cost of €0.05.

In short, the cost of conversations on the WhatsApp Business API depends solely on who initiates the session. If it’s a customer? Zero cost. If we use the API to initiate? €0.05 per 24-hour session.

On the WhatsApp API, it’s also possible to launch guided procedures—for example, identifying the user requesting information through a login form. This process uses WhatsApp Flows, which will be the subject of a dedicated article.

 

Simone Renzi
Seguimi

Scegli un'area

CONTATTACI

Ti risponderemo entro 24 ore

TORNA SU