Technical
WhatsApp with Odoo: Cloud API, Templates, Opt-In and Two-Way Chat
How to connect Odoo to the WhatsApp Business Platform (Cloud API): approved templates, opt-in rules, sending order and invoice updates, handling replies, and what Odoo offers out of the box versus third-party apps.
Kalvyai Engineering · · 7 min read

On this page
Customers read WhatsApp messages faster than email. That makes it a good channel for order confirmations, shipping updates, invoices and support replies. It also comes with rules: Meta controls which messages you can send, when, and to whom.
This post covers how the WhatsApp Business Platform (Cloud API) works, how templates and opt-in fit in, how to send order and invoice updates from Odoo, how to receive replies, and what you get from Odoo itself versus third-party apps.
The pieces you need
Before any Odoo work, you need these on the Meta side:
- A Meta Business account (Business Manager / Business Portfolio), ideally verified.
- A WhatsApp Business Account (WABA) inside it.
- A phone number registered to the WABA. A number already used in the regular WhatsApp or WhatsApp Business mobile app has to be migrated or removed from it first.
- A Meta app with the WhatsApp product added. This gives you the app secret used to verify webhooks.
- A permanent access token, usually from a System User in Business Manager, with WhatsApp messaging and management permissions. Temporary tokens from the developer dashboard expire and are only for testing.
- The IDs: Phone Number ID (used to send messages) and WABA ID (used to manage templates).
- A public HTTPS URL on your Odoo instance for the webhook, so Meta can deliver incoming messages and status updates.
Use the official Cloud API, or a provider built on it. Tools that automate WhatsApp Web or the mobile app are not part of the official platform and put your number at risk of being blocked.
How the Cloud API works
The Cloud API is a REST API hosted by Meta on the Graph API. You send messages with a POST to the phone number's messages endpoint, and Meta sends you events (incoming messages, delivery statuses) through a webhook.
A minimal send from Python looks like this:
import requests
GRAPH_VERSION = "v21.0" # set to the current Graph API version
PHONE_NUMBER_ID = "123456789012345"
TOKEN = "EAAG..." # system user token, stored securely, never in code
def send_template(to, template_name, lang, components):
url = f"https://graph.facebook.com/{GRAPH_VERSION}/{PHONE_NUMBER_ID}/messages"
payload = {
"messaging_product": "whatsapp",
"to": to, # E.164 format, e.g. 919812345678
"type": "template",
"template": {
"name": template_name,
"language": {"code": lang},
"components": components,
},
}
resp = requests.post(url, json=payload, timeout=15,
headers={"Authorization": f"Bearer {TOKEN}"})
resp.raise_for_status()
return resp.json()["messages"][0]["id"] # the wamid, keep itThe returned message ID (wamid...) matters. Status webhooks refer to it, so store it against the Odoo record that triggered the message.
Templates and the 24-hour window
WhatsApp separates two kinds of outbound messages.
- Free-form messages (text, images, documents) can only be sent inside the customer service window: 24 hours from the customer's last message to you.
- Template messages are pre-approved by Meta and are the only way to start a conversation or message someone outside that window.
So an order confirmation sent an hour after checkout is a template. A reply to a customer who just asked "where is my parcel?" can be free-form.
Template categories
When you submit a template you choose a category:
- Utility: tied to a specific transaction or account the user already has. Order confirmations, shipping updates, invoice notices and payment reminders belong here.
- Marketing: promotions, offers, announcements, re-engagement.
- Authentication: one-time passcodes.
Meta reviews the template and can recategorise it. A "shipping update" that ends with a discount code will likely be treated as marketing. Meta charges per message based on category and the recipient's country, so keep utility templates strictly transactional.
An example utility template
Templates use numbered placeholders. A shipping template might be:
Name: order_shipped
Category: Utility
Language: en
Body:
Hi {{1}}, your order {{2}} has shipped.
Tracking number: {{3}}
Reply to this message if you have any questions.At send time you fill the placeholders in order:
[
{
"type": "body",
"parameters": [
{"type": "text", "text": "Asha"},
{"type": "text", "text": "S00042"},
{"type": "text", "text": "AWB123456789"}
]
}
]Tips that save review cycles:
- Give Meta sample values for every placeholder when submitting.
- Do not start or end the body with a placeholder.
- Create one template per language you need. The language code at send time must match an approved translation.
- Name templates by purpose (
invoice_posted,order_shipped), not by date or campaign.
Opt-in rules
Meta requires opt-in before you send business-initiated messages. In practice that means:
- The customer actively agrees to receive WhatsApp messages from your business. A pre-ticked box is a bad idea.
- The opt-in states your business name and that messages will come over WhatsApp.
- You keep a record of when and where consent was given.
- Opting out is easy, and you honour it.
Local privacy and marketing laws may add more requirements on top of Meta's policy.
In Odoo, store this on the contact rather than relying on memory. A simple approach is a checkbox plus a timestamp and source on res.partner, filled from the website checkout, a portal form or a sales order. Then make every automated send check it. Separate transactional consent from marketing consent if you plan to send both.
Quality matters too. If many recipients block or report your number, Meta lowers its quality rating and can restrict how many conversations you start. Sending only what people asked for is the best protection.
Sending order and invoice updates from Odoo
Here is a pattern we use for transactional messages.
- Pick the trigger. Order confirmed (
sale.order), delivery validated (stock.picking), invoice posted (account.move). - Check eligibility. Partner has a mobile number in E.164 format and a WhatsApp opt-in.
- Queue, don't send inline. Create a log record (state
queued) in the same transaction as the business action. A scheduled action sends queued messages afterwards. - Send the template and store the returned
wamidon the log. - Update status from webhooks:
sent,delivered,read,failed. - Show it in the chatter so staff can see what the customer received.
Queuing matters. If you call Meta inside action_post() and the transaction later rolls back, the customer gets a message about an invoice that does not exist. Queuing also keeps the user's click fast when Meta is slow.
A sketch of the trigger side:
from odoo import models
class AccountMove(models.Model):
_inherit = "account.move"
def action_post(self):
res = super().action_post()
Log = self.env["wa.message.log"] # your own model
for move in self.filtered(lambda m: m.move_type == "out_invoice"):
partner = move.partner_id
if partner.wa_opt_in and partner.mobile:
Log.create({
"res_model": move._name,
"res_id": move.id,
"partner_id": partner.id,
"template_name": "invoice_posted",
"state": "queued",
})
return resAttaching the invoice PDF
A template can have a document header. At send time you pass the file either as a public link or as a media id previously uploaded to the Cloud API media endpoint:
{
"type": "header",
"parameters": [
{
"type": "document",
"document": {
"id": "MEDIA_ID_FROM_UPLOAD",
"filename": "INV-2024-00123.pdf"
}
}
]
}Uploading the PDF and sending by media ID avoids exposing a public URL to the invoice. If you use a portal link instead, remember that anyone with that link can open the document.
Two-way chat: receiving messages
Incoming messages and delivery statuses arrive at your webhook. Meta first verifies the URL with a GET request, then sends events by POST, signed with your app secret in the X-Hub-Signature-256 header.
A minimal Odoo controller:
import hashlib
import hmac
import json
from odoo import http
from odoo.http import request
class WhatsAppWebhook(http.Controller):
@http.route("/wa/webhook", type="http", auth="public",
methods=["GET"], csrf=False)
def verify(self, **kw):
token = request.env["ir.config_parameter"].sudo().get_param("wa.verify_token")
if kw.get("hub.mode") == "subscribe" and kw.get("hub.verify_token") == token:
return kw.get("hub.challenge")
return request.make_response("forbidden", status=403)
@http.route("/wa/webhook", type="http", auth="public",
methods=["POST"], csrf=False)
def receive(self, **kw):
raw = request.httprequest.get_data()
secret = request.env["ir.config_parameter"].sudo().get_param("wa.app_secret")
expected = "sha256=" + hmac.new(secret.encode(), raw, hashlib.sha256).hexdigest()
header = request.httprequest.headers.get("X-Hub-Signature-256", "")
if not hmac.compare_digest(expected, header):
return request.make_response("bad signature", status=401)
data = json.loads(raw)
for entry in data.get("entry", []):
for change in entry.get("changes", []):
value = change.get("value", {})
request.env["wa.inbox"].sudo().store_raw(value) # process later
return request.make_response("ok", status=200)Points that matter in production:
- Return 200 quickly. Store the payload and process it in a scheduled job. Slow responses lead to retries.
- Deduplicate. The same event can be delivered more than once. Use the message ID as a unique key.
- Match the sender. Incoming messages carry the sender's number. Normalise numbers on
res.partnerso lookups work; otherwise create a lead or an unassigned conversation. - Track the 24-hour window. Store the time of the customer's last message. Your reply box should switch to "template only" once the window closes.
- Route conversations. Decide who sees a new message: the salesperson on the latest order, a support team, or a shared inbox.
- Multi-database setups. With
dbfilterand several databases, make sure the webhook URL resolves to the right one.
What Odoo offers out of the box versus third-party apps
Odoo has an official WhatsApp app. Details vary by version and edition, so verify them for your setup.
Area | Odoo WhatsApp app | Third-party / custom |
|---|---|---|
Edition | Enterprise | Community and Enterprise, depending on the app |
Connection | WhatsApp Business Platform via your own Meta account | Usually Cloud API; some use other providers |
Templates | Defined in Odoo per model, submitted to and synced with Meta | Varies by app |
Sending from records | Send from records such as orders and invoices | Varies |
Automation | Automation rules / server actions can send templates | Varies, often custom |
Two-way chat | Replies appear in Discuss | Varies |
Opt-in tracking | Check your version | Often needs custom fields |
If you are on Enterprise and your needs are standard (a few templates, replies handled by staff in Discuss), start with the official app. Third-party or custom work makes sense when you run Community, need explicit opt-in tracking, need routing rules, want to sell inside the chat, or need WhatsApp to drive workflows in custom modules.
When evaluating any third-party app, check:
- It uses the official Cloud API or a Meta-approved provider.
- Webhook signatures are verified.
- Message IDs and statuses are stored per record.
- The 24-hour window is enforced in the UI.
- Access tokens are stored as system parameters or secrets, not in code or views readable by every user.
For Community builds, our free WhatsApp Base module is a reusable Meta WhatsApp Cloud API base for sending and receiving messages in Odoo, which you can build your own flows on. If you want customers to buy inside the chat, WhatsApp AI Commerce lets you sell on WhatsApp with checkout and stock coming from Odoo.
A short go-live checklist
- Business verified, number registered, permanent token issued.
- Templates approved in every language you need, with correct categories.
- Opt-in captured and stored on contacts, with an opt-out path.
- Phone numbers normalised to E.164.
- Outbound sends queued, logged and shown in the chatter.
- Webhook verified, signed, deduplicated and returning 200 quickly.
- Failed messages visible to someone who will act on them.
- A test run with real phones before switching on automation for all customers.
How Kalvyai can help
We build WhatsApp integrations for Odoo: Cloud API setup, template design, opt-in tracking, order and invoice notifications, two-way inboxes, and AI agents that draft replies for staff to approve, with budgets and an audit trail. See our Odoo services, browse our apps at store.kalvyai.com, or contact us to talk through your setup.
- Odoo
- WhatsApp Cloud API
- Integrations
- Webhooks
- Odoo Development
Kalvyai Engineering · Engineering team
The engineers who build, connect and fix business systems at Kalvyai: Odoo, ERPNext, Shopify and AI agents that work inside them with approvals, budgets and an audit trail.



Comments
No comments yet. Questions and corrections are welcome.
Rate this post or leave a comment