on dtmf.md
import { CodeTabs } from '../views/docs/CodeTabs';
import { Callout, NextLink, PropTable } from '../views/docs/prose';
export const ON_DTMF_SIG_PY = `@agent.on_dtmf
def on_dtmf(call: guava.Call, event: DTMFPressedEvent) -> None:
...`;
export const ON_DTMF_SIG_TS = `agent.onDtmf((call: guava.Call, event: DTMFPressedEvent) => Promise<void>);`;
## on_dtmf()
Register a handler that fires whenever the **caller** presses a DTMF digit (0–9, *, #, A–D) on their keypad.
> **Caller keypresses only.** `on_dtmf` fires for digits pressed by the caller. To enable the agent itself to send DTMF tones (e.g. to navigate an IVR system it has called into), use `call.set_agent_dtmf(enabled=True)` instead.
The `DTMFPressedEvent` is a pydantic model imported from `guava.events`:
```python
from guava.events import DTMFPressedEvent
class DTMFPressedEvent(BaseEvent):
event_type: Literal["dtmf"] = "dtmf"
digit: Literal["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#", "A", "B", "C", "D"]
Signature
<CodeTabs python={{ code: ON_DTMF_SIG_PY, filename: "signature" }} typescript={{ code: ON_DTMF_SIG_TS, filename: "signature" }} />
<PropTable rows={[
{
name: "call",
type: "Call",
desc: "The active call object.",
},
{
name: "event",
type: "DTMFPressedEvent",
desc: 'Contains digit (string): the key the caller pressed — one of "0"–"9", "*", "#", "A", "B", "C", or "D".',
},
]} />
Return value: None