How to intercept DTMF events with Livekit? For exa...
# ask-ai
w
How to intercept DTMF events with Livekit? For example, if a user presses a number, I want to detect that.
t
Thanks for reaching out, Someshwar. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to detect when a user presses a phone keypad digit in LiveKit. You can intercept those DTMF events by listening for the room's
sip_dtmf_received
event and handling the
SipDTMF
payload. Quick steps: 1. Register a listener on the Room for
sip_dtmf_received
. ◦ Example (Python):
Copy code
@room.on("sip_dtmf_received")
     def dtmf_received(dtmf: rtc.SipDTMF):
         logging.info(f"DTMF from {dtmf.participant.identity}: {dtmf.digit} / {dtmf.code}")
1. Read the event data: ◦ `digit`: the key pressed as a string (
"0"-"9"
,
"*"
,
"#"
). ◦ `code`: numeric RFC‑4733 code (e.g.,
10
for
*
,
11
for
#
). ◦ `participant`: identity of the SIP caller. 1. If you need async handling (e.g., to interrupt speech or route choices), create an async task from the sync callback:
Copy code
async def _async_handle_dtmf(dtmf_event: rtc.SipDTMF):
       await phone_assistant.session.interrupt()
       # process dtmf_event.digit

   @room.on("sip_dtmf_received")
   def handle_dtmf(dtmf_event: rtc.SipDTMF):
       asyncio.create_task(_async_handle_dtmf(dtmf_event))
1. Optional: enable IVR detection in an AgentSession with
ivr_detection=True
to help with IVR workflows and DTMF relay. Note:
sip_dtmf_received
is emitted for SIP participants (phone callers). If you need DTMF from WebRTC clients, let me know your use case and environment so I can suggest alternatives. Would you like code examples for another language or help wiring this into your IVR/menu logic? Sources: Handling DTMF | LiveKit docs | Company directory phone assistant | LiveKit docs
w
aside: is this code valid? are the parameters valid agent = Agent( region="eu-central", # Agent deployment sip_region="india", # SIP calls pinned to India stts=deepgram.STT(), # Use India-friendly providers llm=google.Gemini(), tts=rime.TTS() ) is this how we can set region & sip region?
t
You're right to ask — that code is not valid. • The
Agent
constructor does not accept
region
or
sip_region
. You cannot set deployment region or SIP routing from the Agent object. • To deploy an agent in a region, use the CLI during creation:
Copy code
lk agent create --region eu-central
• To pin SIP calls to a region, configure region-based SIP endpoints (e.g., your provider uses
{subdomain}.india.sip.livekit.cloud
) or set
destination_country="in"
for outbound trunks. You can keep choosing STT/LLM/TTS providers in your agent config (e.g.,
stt=deepgram.STT()
), but those do not control agent deployment region or SIP routing. Do you want the exact Agent init pattern for your SDK/language so I can show a corrected example? Sources: Deploying to production | LiveKit Docs | SIP cloud and region pinning | LiveKit docs | Agents and handoffs | LiveKit docs | Agents telephony integration | LiveKit docs | OpenAI LLM models | LiveKit Docs