Skip to main content

DTMF Events

DTMF (Dual-Tone Multi-Frequency) events happen when a caller presses keys (0–9, *, #) on their phone or SIP device during a call. AI agents can listen for these events to capture user input, run specific actions, or respond to the caller based on the key they pressed. DTMF provides a simple and reliable way for users to interact with the agent during a call.

How It Works

  • DTMF Event Detection: The agent detects key presses (0–9, *, #) from the caller during a call session.
  • Real-Time Processing: Each key press generates a DTMF event that is delivered to the agent immediately.
  • Callback Integration: A user-defined callback function handles incoming DTMF events.
  • Action Execution: The agent executes actions or triggers workflows based on the received DTMF input like building IVR flows, collecting user input, or triggering actions in your application.

How to enable DTMF Events

Step 1 : Activate DTMF Detection

DTMF event detection can be enabled in two ways:

When creating an Inbound SIP gateway in the VideoSDK dashboard, enable the DTMF option.

dtmf-event

Step 2 : Implementation

To set up inbound calls, outbound calls, and routing rules check out the Quick Start Example.

main.py
from videosdk.agents import AgentSession, DTMFHandler

async def entrypoint(ctx: JobContext):

async def dtmf_callback(digit: int):
if digit == 1:
agent.instructions = "You are a Sales Representative. Your goal is to sell our products"
await agent.session.say(
"Routing you to Sales. Hi, I'm from Sales. How can I help you today?"
)
elif digit == 2:
agent.instructions = "You are a Support Specialist. Your goal is to help customers with technical issues."
await agent.session.say(
"Routing you to Support. Hi, I'm from Support. What issue are you facing?"
)
else:
await agent.session.say(
"Invalid input. Press 1 for Sales or 2 for Support."
)

dtmf_handler = DTMFHandler(dtmf_callback)

session = AgentSession(
dtmf_handler = dtmf_handler,
)

Example - Try It Yourself

Got a Question? Ask us on discord