TABLA DE CONTENIDOS
(/)
Prerequisites
Sending messages with the cloud API
Receiving messages with webhooks
WhatsApp API with Python: Integration Creating a basic chatbot
Tutorial [2026] DIY Approach Limitations
Conclusion
Víctor Mollá (/blog/author/victor-molla) · May 2, 2026 · 7 min read
Prueba gratuita ([Link]
If you're a developer and want to connect your application
directly with WhatsApp, the combination of WhatsApp Cloud API
Demo gratuita
+ Python is the most direct path. In this tutorial you'll understand
how to send messages, receive notifications via webhooks,
manage templates, and build a basic chatbot -- all through
Meta's official REST API. It's not about copying and pasting code:
it's understanding the architecture so you can adapt it to your
use case. You'll need Python 3.9+, a verified Meta Business
account, and access to the WhatsApp Business API. If you're still
not clear what the API is or how it fits in the ecosystem, start with
the complete WhatsApp Business API guide (/blog/whatsapp-business
-api-guide).
Home (/) › Blog (/blog) › Chatbot Whatsapp Business (/blog/guia-completa-chatbot-whatsapp) ›
WhatsApp API with Python: Integration Tutorial [2026]
Prerequisites
Before writing a single line of code, you need to have the following have everything ready.
prepared:
Python 3.9 or higher installed in your development
environment.
Sending messages with the cloud API
A verified Meta Business account. Without business
verification you won't have production access. Sending messages reduces to a POST call against Meta's REST
Access to the WhatsApp Cloud API through the Meta API. The endpoint is
Developer panel, or through a BSP (Business Solution Provider) [Link] .
that provides you credentials. You need two headers: Authorization with your access token in
Bearer format and Content-Type as application/json .
Your access token generated from the Meta Developer
dashboard. It's the temporary token for testing; for production To send a plain text message, the request body in JSON includes
you'll need a permanent system token with OAuth four fields: messaging_product always as "whatsapp" , to with
authentication. the recipient's number in international format (e.g., 34612345678 (
A phone number registered in the WhatsApp Business API. It x-apple-data-detectors://3) ), type as "text" , and a text object with
can be the test number Meta provides in the sandbox or your the body field containing the message content.
verified business number.
To send an approved template -- mandatory when you initiate
Python libraries: requests for synchronous HTTP calls, flask
the conversation without the user having written first -- you
to mount the webhook server, and python-dotenv to securely
change the type to "template" and include an object with the
manage environment variables. If you prefer working in
template name, language, and dynamic components (header,
async, replace requests with httpx and flask with FastAPI.
body, and button variables). Templates allow massive
personalization: a single approved format can serve for
If you need a step-by-step guide to obtain these credentials and
thousands of different sends by injecting variables at runtime.
configure your Meta account, check how to configure WhatsApp
Business API (/blog/setup-whatsapp-api). Here we assume you already
Want to see this in action? Receiving messages with webhooks
GuruSup automates customer support with AI agents — try it free.
Sending messages is half the equation. The other half is receiving
them, and for that you need a webhook server. A webhook is an
Try GuruSup free
HTTP endpoint on your server that Meta sends POST notifications
to each time an event occurs: a customer writes you, a message
is delivered, read, or fails.
The API response returns a message_id that you'll use to track
delivery status. If there's an error, you receive a specific code:
Configuration has two phases. First, verification: when you register
131047 indicates the number isn't valid, 131026 that the user
your webhook URL in the Meta panel, it sends a GET request with a
doesn't have WhatsApp, 130429 that you've exceeded the rate
hub.verify_token parameter you define and a [Link]
limit. Properly handling these errors is what separates a test
you must return. It's a handshake to confirm the endpoint is
integration from a production one.
yours. With Flask or FastAPI you set up this route in minutes.
On performance: Meta establishes a rate limit of 80 messages
Second, event reception: each incoming message arrives as a
per second for standard tier and up to 1,000 for accounts with
POST with a JSON payload structured in
higher volume. If you need bulk sending, implement a queue with
entry[].changes[].[Link][] . From each message you
exponential retries. For synchronous calls use the requests
extract the sender's number ( from ), type ( text , image ,
library; for high volume where you need concurrency without
document , interactive , location ), and content. A text message
blocking, httpx with async is the right option. If you want to
brings the body field; an image brings an id you must
understand more about how messages flow through the
download with another API call.
architecture, check how WhatsApp Business API works (/blog/how-w
hatsapp-api-works). Security: Meta signs each notification with an X-Hub-Signature-
256 header. You must verify this signature using your
application's secret to confirm the request really comes from
Meta and not from an attacker. In Python, this is resolved with
hmac and hashlib comparing the SHA-256 hash of the payload. status; if it contains "hours," you return hours. For something
more sophisticated, you integrate a language model like
The golden webhook rule: respond with HTTP 200 immediately.
OpenAI's GPT-5.4 or Anthropic's Claude through their API,
Process business logic asynchronously -- in a secondary thread,
sending the conversation context and receiving a generated
a Celery task, or an internal queue. If you take more than 20
response.
seconds to respond, Meta considers your server failed and retries,
3. You query your internal data: database, CRM, order system,
causing duplicate messages and state problems.
calendar.
4. You compose the response and send it back through the
Cloud API.
Creating a basic chatbot For an AI-powered chatbot, the flow adds an intermediate call to
the language model. You send the conversation history as
context, receive the generated response, format it, and send it via
WhatsApp. This converts a rigid-flow chatbot into a
Still researching? Try it yourself.
conversational AI agent capable of understanding natural
Set up your first AI agent in minutes. No code, no credit card. language, handling ambiguity, and resolving complex queries. If
you want to automate this architecture with no-code tools, check
Try GuruSup free
how to do it with n8n and AI agents (/blog/n8n-ai-agent).
For real production -- with conversational memory management,
With sending and receiving working, building a chatbot is connected tools, human escalation, and analytics -- a platform
connecting both flows with intermediate logic. The pattern is: like GuruSup solves in minutes what developing from scratch
takes weeks.
1. You receive a message through the webhook.
2. You analyze the user's intent. In its simplest version, keyword
matching: if the message contains "order," you query order
DIY Approach Limitations
Building the integration from scratch with Python is ideal for
learning and prototyping. But for production it means
maintaining a 24/7 webhook server, managing errors and retries,
storing conversation state, implementing analytics, building
multi-agent inbox, and designing human escalation. All that is
code you maintain.
For specific connectors, the direct approach makes sense. For
customer service at scale, a BSP provider (/blog/whatsapp-api-bsp-pro
viders) with complete platform saves months of development.
Conclusion
Python + WhatsApp Cloud API give you total control over
message sending, webhook reception, and chatbot building --
from simple flows to advanced AI agents. It's the technical
foundation on which any serious integration is built. For the
complete ecosystem overview, return to the WhatsApp Business
API guide (/blog/whatsapp-business-api-guide).
GuruSup converts all this architecture into a production-ready
platform: AI agents on WhatsApp, integrations with your CRM,