The OutboundSession provides methods to interact with the media stream:
session.playback(file, block=True): Plays an audio file.- If
block=True (default), the execution flow waits until the file finishes playing. - If
block=False, the method returns immediately, allowing you to perform other tasks (like API calls) in the background while the audio plays.
session.play_and_get_digits(...): Plays audio and waits for the caller to press DTMF digits. This method is blocking.- Parameters include various patterns, timeouts, and audio files for success/failure.
response_timeout: Use this to account for the length of the audio being played.
session.uuid_break(): Stops the current media playback (e.g., stopping Music on Hold) to return control to your application logic.
# Blocking playback
session.playback('ivr/ivr-welcome', block=True)
# Non-blocking playback (e.g., for Music on Hold)
session.playback('local_stream://default', block=False)
# Get digits (blocking)
digit = session.play_and_get_digits('1', '1', '3', '5000', '#', 'conf.wav', 'inv.wav', 'test', '\d', '1000', "''", block=True, response_timeout=5)
# Stop background playback
session.uuid_break()