on_caller_dtmf()

Register a handler that fires whenever the caller presses a DTMF digit (0–9, *, #, A–D) on their keypad.

Caller keypresses only. on_caller_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, and register on_agent_dtmf to observe the digits it presses.

Previously on_dtmf: this callback was named on_dtmf before on_agent_dtmf existed. The old name still registers the same handler and keeps working — it just no longer says which side of the call pressed the keys.

The DTMFPressedEvent is a pydantic model imported from guava.events:

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"]
    recent_digits: str = ''

Signature

signature
@agent.on_caller_dtmf
def on_caller_dtmf(call: guava.Call, event: DTMFPressedEvent) -> None:
    ...
ParameterTypeDefaultDescription
callCall—The active call object.
eventDTMFPressedEvent—Contains `digit` (string): the key the caller pressed — one of "0"–"9", "*", "#", "A", "B", "C", or "D"; and `recent_digits` (string): the digits pressed so far in this run of keypresses, including this one.

Return value: None

Example

controller.py
import logging

from guava.events import DTMFPressedEvent

@agent.on_caller_dtmf
def on_caller_dtmf(call: guava.Call, event: DTMFPressedEvent):
    logging.info("Caller pressed %s (so far: %s)", event.digit, event.recent_digits)

Questions? hi@goguava.ai