late-businessperson-58140
10/28/2025, 6:15 AMtall-airline-16756
10/28/2025, 6:15 AMtall-airline-16756
10/28/2025, 6:15 AMsip_dtmf_received event. You can listen for this event to capture the input and respond accordingly—for instance, pressing '1' might transfer the call to Billing, while '2' could route it to Technical Support.
• Sending DTMF from the Agent: If an agent needs to send DTMF tones, they can use the publish_dtmf method. This is especially handy when navigating external IVR systems on behalf of the user.
To get everything set up, here’s what you’ll want to do:
1. Configure a SIP trunk with a provider such as Twilio and connect it to your LiveKit instance.
2. Set up your environment variables like API keys and phone numbers in your configuration.
3. Use event handlers to process the DTMF input and take the right actions based on user input.
If you'd like to dive into more detailed examples and step-by-step configuration, the LiveKit DTMF documentation is a fantastic resource to guide you through.
Sources: Company directory phone assistant | LiveKit Docs | Handling DTMF | LiveKit Docs | sip-refer/README.mdoc | README.mdlate-businessperson-58140
10/28/2025, 6:17 AMtall-airline-16756
10/28/2025, 6:17 AMfrom livekit import rtc
import asyncio
@room.on("sip_dtmf_received")
def handle_dtmf(dtmf_event: rtc.SipDTMF):
digit = dtmf_event.digit
print(f"DTMF received - Digit: '{digit}'")
# Handle input based on pressed digit
if digit == "1":
asyncio.create_task(say("Transferring you to Billing."))
elif digit == "2":
asyncio.create_task(say("Transferring you to Technical Support."))
else:
asyncio.create_task(say("Invalid option, please try again."))
Sending DTMF Tones
import time
last_dtmf_press = 0
async def send_dtmf_code(code: int):
global last_dtmf_press
current_time = time.time()
if current_time - last_dtmf_press < 3: # 3-second cooldown
print("DTMF code rejected due to cooldown")
return
last_dtmf_press = current_time
await ctx.room.local_participant.publish_dtmf(
code=code,
digit=str(code)
)
Full Example
def start_agent(self, participant: rtc.Participant):
self.model = openai.realtime.RealtimeModel(
instructions=(
"You are a friendly assistant. "
"Please inform users they can:\n"
"- Press 1 for Billing\n"
"- Press 2 for Technical Support\n"
"- Press 3 for Customer Service"
),
modalities=["audio", "text"],
voice="sage"
)
self.assistant = MultimodalAgent(model=self.model)
self.assistant.start(self.context.room, participant)
greeting = "Hi, thanks for calling. Press 1 for Billing, 2 for Support, or 3 for Customer Service."
asyncio.create_task(self.say(greeting))
Just a quick reminder to ensure your SIP trunk and environment variables are set up properly. If you run into any questions or need a hand with anything else, please don't hesitate to reach out—I'm here to help!