Build a Twilio + Odoo Integration for WhatsApp

December 08, 2025
Written by
Alvin Lee
Contributor
Opinions expressed by Twilio contributors are their own
Reviewed by

Build a Twilio + Odoo Integration for WhatsApp

 

Odoo is an open-source ERP and CRM platform that handles everything from sales to inventory and accounting. Twilio's WhatsApp Business API allows you to send and receive messages through the widely popular messaging app. By combining Odoo with Twilio, you can automate customer communications via WhatsApp directly from your business workflows.

In this tutorial, you'll learn how to integrate Twilio's WhatsApp API with Odoo to send automated notifications. You'll use Twilio's WhatsApp Sandbox, which lets you start testing immediately before going through the WhatsApp Business API approval process. By the end, you'll be able to use Twilio to send order confirmation notifications to your customers via WhatsApp, all triggered automatically from within Odoo.

Prerequisites

Before you begin, make sure you have the following:

  • A Twilio account (click here to sign up)
  • A server with an instance of Odoo ( Community or Enterprise) running
  • Admin access to Odoo, to install apps/modules
  • Ability to install Python packages on the server
  • A smartphone with WhatsApp installed for testing

High-Level Architecture/What You'll Build

Here's how the integration works:

Business action in Odoo ➜ Odoo triggers notification ➜ Twilio API ➜ WhatsApp ➜ Customer receives message

When a specific event occurs in Odoo (like confirming a sales order), your custom Python code will call Twilio's API, which then delivers the message to your customer's WhatsApp account.

Tutorial

Step 1: Set Up Twilio WhatsApp Sandbox

The WhatsApp Sandbox is Twilio's testing environment, which allows you to experiment with WhatsApp messaging without requiring approval from Meta. It's perfect for building and testing your integration.

  1. Log in to your Twilio Console.
  2. Navigate to Messaging > Try it out > Send a WhatsApp message.
Account Dashboard with options to send SMS or WhatsApp messages under the Messaging section.

3. You'll see your Sandbox connection information, with your sandbox phone number, your unique join code, and a QR code that you can scan from your mobile device to join the sandbox.

Twilio Sandbox setup screen with QR code and instructions.

4. On your mobile device, open WhatsApp and send the join code message to the sandbox number shown, or scan the QR code.

5. You will receive a confirmation message that you've successfully joined the sandbox.

WhatsApp chat showing Twilio Sandbox setup confirmation message and instructions.

Note: Anyone who wants to receive messages from your sandbox will first need to join the sandbox by sending this code. This is a sandbox-only requirement; production WhatsApp numbers don't need this step.

Step 2: Get Your Twilio Credentials

When Odoo makes Twilio API calls, it will need your Twilio credentials for authentication. You'll need your Account SID and Auth Token.

  1. From the Admin menu in the Twilio Console, navigate to Account management.
  2. In the left sidebar menu, navigate to API keys & tokens.
  3. At the bottom of the page, you will see "Auth Tokens." Find the Live credentials. Copy the values for Account SID and Auth Token. Store them securely (you'll need them in Step 5).
API dashboard showing auth tokens section with account details and token options.

Important: Never share your Auth Token publicly or commit it to version control. Treat it like a password.

Step 3: Install Twilio SDK in Odoo

The Twilio Python SDK makes it easy to interact with Twilio's APIs from Python code. You'll need to install it in your Odoo server environment. This walkthrough assumes you installed Odoo via a package manager (such as Debian/Ubuntu). Run the following command:

sudo apt install python3-twilio

After installation, restart your Odoo server to ensure the library is available:

sudo systemctl restart odoo

Or

sudo service odoo restart

Step 4: Create a Simple Odoo Module

Odoo's functionality is organized into modules. To add WhatsApp integration, we'll create a custom module that contains our integration logic.

First, navigate to your Odoo addons folder, as specified in your oodo.conf file ( /etc/odoo/odoo.conf for Linux installations). The default addon location is /usr/lib/python3/dist-packages/odoo/addons.

Then, back in your terminal, navigate to this new addons folder and inside it, create a new folder for your module:

mkdir whatsapp_twilio_integration &&
           cd whatsapp_twilio_integration

Create the module manifest file __manifest__.py, with the following contents:

{     'name': 'WhatsApp Twilio Integration',     'version': '1.0',     'category': 'Tools',     'summary': 'Send WhatsApp notifications via Twilio',     'description': """         This module integrates Twilio's WhatsApp API with Odoo         to send automated notifications to customers.""",     'depends': ['base', 'sale'],     'data': [],     'installable': True,     'application': False, }

Create an __init__.py, with the following contents, file to initialize the module:

from . import models

Create a models subfolder.

mkdir models && cd models

In the models subfolder, create a file called __init__.py, and add the following contents:

from . import whatsapp_sender

Now you have the basic structure for your Odoo module.

Step 5: Configure Twilio Credentials in Odoo

Rather than hardcoding your Twilio credentials in your code, you'll store them securely in Odoo's system parameters. This makes it easier to update credentials without requiring code modifications.

In Odoo, activate Developer Mode. Go to Settings. Scroll to the bottom and click Activate the developer mode. Click Save at the top of the page.

Screenshot of Odoo settings page showing Developer Tools options for activating developer mode.

In the Settings menu at the top, navigate to Technical > System Parameters.

Settings menu showing Technical settings with System Parameters selected

Click New to add your Twilio Account SID as a new parameter. Set the Key to twilio.account_sid. For the value, paste your Account SID from Step 2.

Add a second parameter by clicking New again. Set the key to

twilio.auth_token and paste the Auth Token from Step 2 as the value.

Add a third parameter by clicking New again. Set the key to

twilio.whatsapp_from and the value to whatsapp:+14151234567 (use your actual sandbox number with the whatsapp:` prefix).
Screenshot of a table displaying Twilio system parameters and their values with partially masked information.

Step 6: Build the Send Message Function

Next, create the Python code that actually sends WhatsApp messages through Twilio's API. In your module's models folder, create a file named whatsapp_sender.pywith the following code:

from odoo import models, api from twilio.rest import Client import logging  _logger = logging.getLogger(__name__)  class WhatsAppSender(models.AbstractModel):   _name = 'whatsapp.sender'   _description = 'WhatsApp Message Sender via Twilio'    @api.model    def send_whatsapp_message(self, to_number, message_body):     """     Send a WhatsApp message using Twilio API     :param to_number: Recipient's phone number (format: +1234567890)     :param message_body: Text content of the message     :return: Message SID if successful, False otherwise     """      try:       # Retrieve Twilio credentials from system parameters       IrConfigParameter = self.env['ir.config_parameter'].sudo()       account_sid = IrConfigParameter.get_param('twilio.account_sid')       auth_token = IrConfigParameter.get_param('twilio.auth_token')       from_whatsapp_number = IrConfigParameter.get_param('twilio.whatsapp_from')        # Validate that credentials exist       if not all([account_sid, auth_token, from_whatsapp_number]):         _logger.error("Twilio credentials not properly configured in system parameters")         return False        # Initialize Twilio client       client = Client(account_sid, auth_token)        # Format recipient number with WhatsApp prefix       to_whatsapp_number = f'whatsapp:{to_number}'        # Send the message       message = client.messages.create(         body=message_body,         from_=from_whatsapp_number,         to=to_whatsapp_number       )        _logger.info(f"WhatsApp message sent successfully. SID: {message.sid}")       return message.sid      except Exception as e:       _logger.error(f"Failed to send WhatsApp message: {str(e)}")       return False

This code creates a reusable function that:

  • Retrieves your Twilio credentials from system parameters
  • Initializes the Twilio client
  • Formats phone numbers with the required whatsapp: prefix
  • Sends the message via Twilio's API
  • Logs success or failure for debugging

Step 7: Trigger Notifications from Odoo Events

Lastly, you'll connect your WhatsApp sender to actual Odoo events. For this example, we'll send a notification when a sales order is confirmed.

Create a new file in your models folder called sale_order.py with the following code:

from odoo import models, api  class SaleOrder(models.Model):   _inherit = 'sale.order'    def action_confirm(self):     """     Override the confirm action to send WhatsApp notification     """      # Call the original confirmation method     res = super(SaleOrder, self).action_confirm()      # Send WhatsApp notification after confirmation     self.send_order_confirmation_whatsapp()      return res    def send_order_confirmation_whatsapp(self):     """     Send a WhatsApp notification to the customer when order is confirmed     """      whatsapp_sender = self.env['whatsapp.sender']     for order in self:       # Check if customer has a phone number       phone_number = order.partner_id.phone or order.partner_id.mobile if hasattr(order.partner_id, 'mobile') else None                    if phone_number:         # Create the message         message = f"""Hello {order.partner_id.name}, Your order {order.name} has been confirmed! Order Total: {order.amount_total} {order.currency_id.name} Thank you for your business!"""          # Send the message         whatsapp_sender.send_whatsapp_message(           to_number=phone_number,           message_body=message         )

Update your models/__init__.py to include this new file:

from . import whatsapp_sender from . import sale_order

This code:

  • Extends Odoo's sales order model
  • Overrides the action_confirm method, which is triggered when the Confirm button is clicked
  • Sends a personalized WhatsApp message with order details
  • Uses the customer's mobile number from their contact record

Step 8: Test Your Integration

You're ready to test your integration and see it in action.

Update your module list. In Odoo, go to Apps. Click Update Apps List at the top of the page. Click Update on the modal that pops up.

Pop-up window prompting to update a module with an Update button in a software dashboard.

After the update completes, search the modules for whatsapp.

Cursor hovering over Search Module for

You'll see your newly added integration. Click Activate to install it.

Screenshot of WhatsApp Twilio Integration module with activate button in a dashboard interface.

After the module has been installed, you can see its information by clicking Module Info.

Screenshot of the WhatsApp Twilio Integration module details with options to upgrade or uninstall.

Ensure that the Sales app is also activated. If it is not yet activated, click Activate.

Screenshot of activating the sales management module in a software app with a cursor on the Activate button.

To test the integration, navigate to Contacts. Find an existing contact and update their phone number to match the one you used to join the WhatsApp sandbox. Ensure the format is +1234567890 (include country code, no spaces).

Dashboard displaying contact details of Brian Barton with email and phone number.

Finally, create a test sales order. Navigate to the Sales page. Then, navigate to Orders > Quotations.

Mouse cursor selecting Quotations from dropdown menu under Orders tab in a software interface.

Click New to open a new sales order quote. Select your test customer. Add a product or service. Click Confirm.

Sales software interface showing a new quotation with product details, pricing, and customer information.

Within a few seconds, you should receive a WhatsApp message with your order confirmation.

Screenshot of WhatsApp messages from Twilio Sandbox confirming order 60030 for Brian Barton.

You can also verify the WhatsApp message was sent in the Twilio Console. Navigate to Monitor > Messaging, where you will see your Programmable Messaging Logs.

Troubleshooting tips

If you don't receive the message, try the following tips to troubleshoot:

  • Confirm you've joined the WhatsApp sandbox with the correct join code.
  • Check Odoo's log files for error messages ( /var/log/odoo/odoo-server.log).
  • Check that your Twilio credentials are correct in Odoo's system parameters.
  • Confirm that the twilio.whatsapp_from system parameter is probably formatted, with the whatsapp: prefix followed by the phone number with country code (Example: whatsapp:+14151234567).
  • Verify the phone number format for the customer contact is correct, including the country code (Example: +12223334444).

Moving from sandbox to production

Once you've thoroughly tested your integration and are ready to use it in production, you will transition from using the sandbox to using a WhatsApp sender with Twilio. This will require a WhatsApp Business Account (WABA) and completing Business Verification with Meta. Learn more about how to register a WhatsApp sender with Twilio using Self Sign-Up.

The technical integration code remains the same; you'll just update the twilio.whatsapp_from system parameter with your production WhatsApp number.

What's Next?

Now that you have basic notifications working, you can expand your integration in several ways:

  • Create custom notification triggers for different Odoo modules like invoicing, shipping, or support tickets.
  • Explore Twilio's message templates for richer content with images, buttons, and formatted text.
  • Add error handling and retry logic for failed message deliveries.
  • Create a user interface in Odoo for manually sending WhatsApp messages to customers.

Summary

You've successfully built a working integration that sends WhatsApp notifications from Odoo using Twilio's API. This powerful combination enables automated customer communication through one of the world's most popular messaging platforms. You can use this for order updates, invoices, and other business notifications—all managed directly from your Odoo system and powered with Twilio.