Handling Invalid DTMF Input and Response Timeouts in an Asterisk Dialplan
Learn how to handle invalid DTMF digits and caller response timeouts in an Asterisk IVR using the i and t special extensions.
An Asterisk system is an open-source communications platform whose call-routing behavior is commonly configured with a dialplan. A dialplan is the set of instructions that controls what happens to a call. In a simple IVR, callers press DTMF touch-tone keys to select a destination.
This lesson uses a menu reachable through extension 500. The menu accepts choices 1 through 5. It also shows how to handle two conditions that otherwise can end the call unexpectedly: an unsupported digit and no response before the input timer expires.
Why IVR Input Error Handling Is Necessary
A menu that accepts only a defined set of choices needs an explicit result for every likely caller action. A caller may press a key that the menu does not offer, or may listen without pressing anything.
When Asterisk evaluates input, it looks for a matching extension in the active context. A context is a named grouping of dialplan extensions that organizes and limits the routes available to a channel. If no matching extension or special handler exists, call processing may terminate instead of giving the caller useful guidance.
For the menu at extension 500, the desired behavior is:
- Digits 1 through 5 route to their normal destinations.
- An unsupported digit such as 6 goes to the i special extension.
- No digit before the response timeout goes to the t special extension.
The extensions.conf file is a commonly used location for this dialplan configuration. Before using the examples, make sure you understand basic Asterisk dialplans, contexts, and extensions.
How Contexts and Extension Matching Work
An extension is a dialplan match with an ordered list of actions. It can represent a phone number, a menu digit, a pattern, or a special condition. A priority is the execution order of an action inside an extension.
When a caller enters a digit in an IVR, Asterisk compares that input with the extensions available in the current context. Therefore, the menu choices and the invalid-input and timeout handlers must be defined in the same context.
Ordinary numbered extensions, such as 1 and 5, represent regular menu choices. The i and t extensions are different: they are Asterisk special extensions selected for particular input conditions.
Build the Example Menu
The following example places the menu in a context named main-menu. Background() plays the menu prompt while allowing the caller to enter DTMF digits. The five numbered extensions represent valid choices.
[main-menu]
exten => 500,1,Answer()
same => n,Background(main-menu-prompt)
exten => 1,1,Playback(option-one)
same => n,Hangup()
exten => 2,1,Playback(option-two)
same => n,Hangup()
exten => 3,1,Playback(option-three)
same => n,Hangup()
exten => 4,1,Playback(option-four)
same => n,Hangup()
exten => 5,1,Playback(option-five)
same => n,Hangup()
The syntax same => n adds the next sequential priority to the current extension. For example, after Playback(option-one), the next step for extension 1 is Hangup(). More information about execution order is available in the lesson on dialplan priorities.
Handle Invalid Input with the i Extension
The i extension is selected when the entered digits do not match a valid extension in the current context. In this menu, pressing 6 is invalid because only 1 through 5 are defined.
Define the handler with priority 1 in the same context as extension 500 and its menu choices:
exten => i,1,Playback(pbx-invalid)
same => n,Hangup()
Playback() delivers a prerecorded sound prompt. Sound names are normally written without an audio filename extension, so Playback(pbx-invalid) refers to a sound asset whose base name is pbx-invalid. The actual prompt must be installed and available in the deployment's configured sound language.
Hangup() explicitly closes the channel after the prompt. In this basic design, a caller who presses 6 hears the invalid-selection recording and then receives a controlled hangup rather than an unexplained disconnect.
Handle No Input with the t Extension
The t extension is selected when the caller does not provide input before the response timeout expires. The default response timeout is commonly 10 seconds, although dialplan applications and timeout settings can change it.
Add the timeout handler to the same menu context:
exten => t,1,Playback(press-button-again)
same => n,Hangup()
The timeout prompt should tell the caller what to do next, such as trying again or pressing a button. If the caller remains silent while the menu application waits for DTMF input, Asterisk routes the call to t, plays the prompt, and then hangs up in this minimal implementation.
The timeout path is meaningful only when the preceding application actually waits for input. A menu that merely plays audio without collecting DTMF may not produce the expected timeout event.
Complete Basic Configuration
Here is the relevant structure with both special extensions alongside the ordinary menu choices:
[main-menu]
exten => 500,1,Answer()
same => n,Background(main-menu-prompt)
exten => 1,1,Playback(option-one)
same => n,Hangup()
exten => 2,1,Playback(option-two)
same => n,Hangup()
exten => 3,1,Playback(option-three)
same => n,Hangup()
exten => 4,1,Playback(option-four)
same => n,Hangup()
exten => 5,1,Playback(option-five)
same => n,Hangup()
; Invalid DTMF input
exten => i,1,Playback(pbx-invalid)
same => n,Hangup()
; No input before the timeout
exten => t,1,Playback(press-button-again)
same => n,Hangup()
Use prompt names that exist on your system. The example names are placeholders for installed recordings and must correspond to available sound assets.
Menu Input Outcomes and Dialplan Handlers
Apply and Test the Dialplan
- Save the changes in the appropriate dialplan file, commonly
extensions.conf. - Reload or otherwise apply the dialplan changes. From a shell, one commonly used command is:
asterisk -rx "dialplan reload"
- Check the Asterisk CLI for parsing errors after the reload.
- Call the menu access extension 500.
- Press a valid option, such as 1, and confirm that normal routing still works.
- Call 500 again and press 6. Confirm that
pbx-invalidplays and that the call then ends cleanly. - Call 500 again and do not press a key. Wait for the configured response timeout. Confirm that
press-button-againplays and that the call then follows the intended controlled hangup behavior.
Use the management method appropriate to your deployment. During testing, verbose CLI output can show the active context and the path Asterisk follows.
Improving the Basic Behavior
Hanging up after one error is a valid minimal implementation, but it may not be the best caller experience. A more helpful design returns the caller to extension 500 after an invalid digit or a timeout.
For example, each handler could play its condition-specific prompt and then use a routing step to return to the menu. The invalid prompt should explain that the selection was not recognized. The timeout prompt should explain that no key was received. Separate prompts make the feedback meaningful.
Retry loops need a limit. Without a counter or another state-tracking rule, repeatedly returning from i and t can create an endless loop. After the maximum number of failed attempts, route the caller to an operator, voicemail, another service, or Hangup(). A retry design should also account for both invalid input and silence.
Troubleshooting
An unsupported digit disconnects without an announcement
- Verify that the
iextension exists. - Confirm that it is in the same context as extension 500 and choices 1 through 5.
- Reload the dialplan and inspect CLI messages for parsing errors.
- Confirm that the input application permits the expected DTMF collection behavior.
No input does not reach the timeout prompt
- Confirm that the
textension is present in the active context. - Verify that the menu application actually waits for DTMF input.
- Check relevant response and digit timeout settings; the effective value may differ from the commonly used 10-second default.
- Watch verbose CLI output during a test call to identify another dialplan path that may handle the condition.
The handler runs but no audio is heard
- Verify that the sound asset exists in the configured sounds directory and language.
- Use the correct base name without an audio filename extension.
- Test
Playback()with a known working prompt to separate a missing file from a channel, codec, or media-path problem.
A retry implementation loops forever
- Add a retry counter or other state variable.
- Set a maximum number of attempts for both
iandtpaths. - After the limit, route the call to a human operator, queue, voicemail, or a controlled hangup.
Key Terms and Exam Notes
- DTMF: Touch-tone keypad signaling sent when a caller presses telephone keys.
- Response timeout: The amount of time Asterisk waits for caller input before treating the interaction as timed out.
- i: The special extension for invalid or unmatched input.
- t: The special extension for expired caller-input timing.
- Playback(): Plays a specified prerecorded prompt.
- Hangup(): Ends the current call channel.
- Background(): Plays audio while allowing the caller to enter DTMF digits, making it commonly useful for IVR menus.
For related practice, review Background(), Playback(), and Hangup().