Skip to main content

Create a call programmatically

Bridge a specific user to a customer number; the method picks the user’s SIP/Client target, caller ID, recording, and callbacks automatically.
settings = env["connect.settings"]

call = settings.originate_call(
    "+15551234567",
    res_model="res.partner",
    res_id=42,        # link call to this partner (optional)
    user=env.user,    # which Odoo user to ring first
)
print(call.sid)

Voice message with TwiML <Say>

If you just want to call a customer and play a message, create the call with your own TwiML payload.
from twilio.rest import Client

settings = env["connect.settings"]
client = settings.get_client(user=env.user)  # Twilio REST client with Connect auth/edge

twiml = """<?xml version="1.0" encoding="UTF-8"?>
<Response>
  <Say voice="alice" language="en-US">
    Hi! This is a reminder about your upcoming appointment.
  </Say>
</Response>"""

call = client.calls.create(
    to="+15551234567",
    from_=env.user.connect_user.outgoing_callerid.number,
    twiml=twiml,
)
You can swap <Say> with <Play> or any other TwiML to deliver custom voice prompts; Connect still logs the outbound call.

WhatsApp calls and messages

  • Place a WhatsApp call (Connect handles the TwiML <Dial><WhatsApp> under the hood):
settings = env["connect.settings"]

call = settings.originate_call(
    "+15551234567",
    user=env.user,
    whatsapp_call=True,
)
print(call.sid)
  • Send a WhatsApp message (using Connect models, no direct Twilio client):
Sender = env["connect.whatsapp_sender"]
sender = Sender.get_default_sender(env.user.connect_user)

message = sender.send_whatsapp(
    recipient="whatsapp:+15551234567",
    body="Hello from Oduist Connect via WhatsApp!",
    res_model="res.partner",
    res_id=42,
)
print(message.sid)

SMS/MMS messages

Use the Connect message model to send SMS/MMS while keeping records linked to Odoo.
Message = env["connect.message"]

message = Message.send(
    recipient="+15551234567",
    body="Thanks for your order! Reply with any questions.",
    res_model="sale.order",
    res_id=123,
    outgoing_callerid=env.user.connect_user.outgoing_callerid.id,
)
print(message.sid)