A VPS for a WhatsApp bot on the official API: webhook, HTTPS and platform rules
There are two ways to connect a bot to WhatsApp, and only one of them is legitimate. The official way is the WhatsApp Business Platform with the Cloud API: a business registers a number, gets an access token and exchanges messages over HTTPS. The second way is unofficial libraries that pretend to be the WhatsApp Web browser version and control an ordinary account. Such clients violate the WhatsApp terms of use: the platform detects them and bans the numbers, sometimes together with their chat history. Bulk messaging to people who haven't given consent is forbidden by the rules in either case and leads to a ban just as quickly. Everything below concerns only the official API.
What your server does
With the Cloud API, the platform itself stores and delivers messages, so the bot's server is responsible only for the logic. Its tasks are to:
- receive webhooks: HTTP requests from the platform about incoming messages and delivery and read statuses;
- decide what to reply: a scripted flow, a lookup in the order database, a handover to a human agent;
- send replies as POST requests to the API with the access token;
- store conversation history and customer state in a database.
No browser, phone emulation or persistent session is needed, so the load is small. A Node.js or Python process with Nginx and PostgreSQL fits in 1–2 GB of memory; you'll need more if a CRM, task queues or a workflow builder such as self-hosted n8n runs alongside it.
Webhook requirements
The webhook address must be public and served over HTTPS with a valid certificate from a trusted certificate authority; the platform won't accept a self-signed certificate. The usual setup is a domain, Nginx on port 443 with a free Let's Encrypt certificate, and requests proxied to the application. Then the details matter:
- Address verification. When you connect, the platform sends a GET request with the parameters
hub.mode,hub.verify_tokenandhub.challenge. The server checks the token against the one you set and returns the value ofhub.challenge. - Signature. Every event arrives with an
X-Hub-Signature-256header, an HMAC-SHA256 of the request body keyed with the app secret. Verify the signature before processing, otherwise anyone who learns the address can feed the bot fake messages. - Fast response. Reply with a 200 code immediately and put the processing in a queue. If the server takes too long to respond, the platform retries delivery.
- Duplicates. The same event may arrive twice. Remember the IDs of processed messages so the bot doesn't reply to a customer twice.
Server downtime means events pile up on the platform's side and arrive late. So set the application up as a service with automatic restart and keep an eye on the certificate's expiry date: an expired certificate stops message delivery as reliably as a switched-off server.
Rules that shape the architecture
- The 24-hour window. A free-form reply can be sent within 24 hours of the customer's last message. After that, only a pre-approved template, so store the time of the last incoming message for each conversation.
- Recipient consent. You may message first only people who have themselves agreed to receive messages from the business. The bot must be able to record consent and handle opt-outs.
- Quality rating and limits. A number has a daily limit on business-initiated conversations, and it depends on the quality rating. Complaints and blocks from users lower the rating and the limit. These restrictions must not be circumvented; the right answer is to message only people who expect it.
Keys and data
The permanent access token and the app secret give full control over the business number. Keep them in environment variables or a secrets manager, not in code or a repository, and log in to the server with an SSH key. Don't write full message texts and phone numbers to logs: more people read logs than the database, and logs are kept longer. For development, set up a separate test app with a test number and a separate webhook address so experiments don't touch the production number and its quality rating. If the bot's database accumulates names, phone numbers and addresses of customers from Russia, take into account the 152-FZ requirements for storing them; see the VPS for 152-FZ page. Elsewhere, check your local data protection law. The server for the official API itself can be in any country: latency to the platform has almost no effect on how fast the customer gets a reply.
If you are choosing a platform for your bot, compare the requirements on the VPS for a Telegram bot and VPS for a VK bot pages: they also have official APIs and webhooks, but their own rules.