VoIP.info Guide

Building a small Asterisk IVR

Separate menu matching from variable collection, then prove each valid, invalid and timeout path without exposing privileged routes.

Reviewed 2026-10-12Asterisk 22 branch application and dialplan documentation reviewed October 1, 2026; no PBX, prompt, DTMF, call, destination or media path was testedIntermediateDocumentation based · not lab tested

Draw the route and authorization boundary first

List every advertised choice, its destination, its business-hours behavior and its unavailable outcome before writing dialplan. Keep the inbound menu in a context that contains only those permitted choices plus explicit invalid, timeout and staffed-fallback paths. Do not include privileged outbound dial strings merely because another internal context can reach them.

Treat the prompt, digit map and destination ownership as one change record. A recording that says press 3 while the dialplan routes 3 elsewhere is a failed release even if both artifacts work independently.

A call follows a dialplan context
An incoming channel enters a context, matches an extension and then runs applications in priority order. A permitted destination can be another endpoint, a trunk or voicemail.

Contexts form a call-permission boundary. Keep untrusted inbound routes separate from privileged outbound patterns.

Choose extension matching or variable collection

Use BackGround() when prompt interruption should begin matching extensions in a named context, followed by WaitExten() when the caller needs more time after playback. A missing sound file can terminate processing, and BACKGROUNDSTATUS distinguishes documented success from failure. An explicit context limits where collected digits can exit.

Use Read() when the result must be stored in a variable instead. Set maxdigits, attempts and timeout deliberately; zero maximum digits waits for the terminator and is not a sensible implicit menu limit. The default terminator is #, while the application's options can change or remove it. Validate the finished value against a fixed allow-list rather than interpolating it into an unrestricted destination or command.

Give each timeout and exception one meaning

WaitExten() waits for an extension after the prompt. The special i extension handles digits that cannot match the current context, while t handles response timeout when the current extension has no next priority. The T extension is for absolute call timeout and is not the same event. An e exception handler can substitute for missing i, t or T handling, so document which model the context uses.

For Read(), branch on READSTATUS: OK, ERROR, HANGUP, INTERRUPTED, SKIPPED and TIMEOUT are different outcomes. Bound retries, end the call or reach a staffed destination deterministically, and never loop indefinitely between the same prompt and input step.

Keep prompt, answer and DTMF evidence separate

Confirm the selected sound file exists in an installed format and decide whether the channel should already be answered or use an approved early-media design. Audible prompt playback does not prove that DTMF events reach Asterisk, and recognized digits do not prove the caller heard the complete prompt. If audio succeeds but digits fail, inspect the negotiated DTMF method and the actual event evidence before changing the route.

One-digit menus and multi-digit collection have different ambiguity and inter-digit timing. Test an early key press, a key during silence, terminator use where configured and the exact timeout boundary. Do not infer the caller experience from dialplan syntax alone.

Verify the loaded context before a call

Validate that every referenced sound file and destination exists, reload through the site's controlled procedure, and inspect the exact loaded context rather than only the source file or generated configuration. Confirm that advertised digits, i, t and any e handler resolve where expected and that no privileged route is reachable from that context.

Log a bounded test window with the selected extension or READSTATUS, channel and call identifiers needed for correlation. Generated text, successful reload, loaded priorities, a matched choice, a ringing destination and an answered conversation remain separate evidence stages.

Run the failure matrix and preserve the result

Exercise every valid choice, an invalid digit, no input, an early digit, the configured retry limit and a busy or unavailable destination. Include a missing-prompt rehearsal in a nonproduction context, plus internal and external callers, the supported DTMF modes, business-hours transitions and the behavior after reload or restart.

Record expected and observed prompt, digit, branch and destination for each case. Retain the menu map with rollback instructions. No prompt, dialplan, PBX, endpoint, DTMF path, call, destination or media stream was inspected or tested for this guide.

Treat prompt interruption as an asynchronous state transition

For an ARI-owned menu, keep the current Playback resource, the channel's DTMF event and the application state together. Stop the exact prompt, tolerate finish and stop crossing in flight, and prevent late events from advancing a newer menu state.

Treat the prompt and digit window as separate IVR stages

The BackGround and WaitExten guide distinguishes interruptible playback from the later waiting period, then separates received DTMF from destination-context and extension-match evidence.

Sources & applicability

Primary references for the technical details above. Operational examples and planning checklists are VoIP.info editorial guidance.

Examples require adaptation to your topology. No live PBX or hardware testing is claimed.