Skip to content
Phone Guides

Build an Asterisk auto attendant with bounded menu choices

An auto attendant directs callers to a small set of destinations. Decide the choices, prompt and failure paths before writing a dialplan. A transactional IVR that looks up customer records adds separate application, privacy and dependency decisions.

Source-reviewed, 18 October 2026. Prepared from the cited documentation. These examples have not been independently tested by Phone Guides. Scope: Asterisk 22, configured internal endpoints 6001/6002, and a locally installed custom sound file.

Define the menu contract

This example offers option 1 for endpoint 6001 and option 2 for endpoint 6002. It makes one menu attempt. Invalid input and no input both end the call; a business deployment may choose an operator or other explicitly authorised destination instead.

Prepare a prompt that says those choices accurately. Install it as custom/pg-main-menu beneath the effective Asterisk sounds location in a supported audio format. Use the base name without a file extension in BackGround(). Do not use the example before the actual file exists and is readable.

Read the menu example


[pg-menu]
exten => s,1,Answer()
 same => n,BackGround(custom/pg-main-menu)
 same => n,WaitExten(5)
 same => n,Hangup()

exten => 1,1,Dial(PJSIP/6001,20)
 same => n,Hangup()

exten => 2,1,Dial(PJSIP/6002,20)
 same => n,Hangup()

exten => i,1,Hangup()
exten => t,1,Hangup()

BackGround() plays a prompt while accepting extension input. WaitExten(5) provides a further input window after the prompt. The BackGround reference describes missing-file handling and playback/input behaviour. The WaitExten reference documents its wait argument.

The i and t extensions handle invalid input and the relevant response timeout. They are not interchangeable with a general call-duration limit. The special extension reference also explains s; it is not a catch-all match for arbitrary called numbers.

Enter the menu deliberately

An existing authorised inbound route can transfer execution with Goto(pg-menu,s,1). Do not assume that assigning a trunk's context to pg-menu causes every delivered DID to begin at s. Map the provider's delivered destination using an explicit inbound route.

Keep the menu context separate from paid outbound routes and broad internal includes. Allowing a menu choice is a permission decision; an anonymous caller should not inherit the office phones' full dialplan just because both use the same Asterisk server.

Check input and failure behaviour

Read back dialplan show pg-menu after a file-based reload. In your own deployment, check option 1, option 2, an invalid key and no input. Try input during the prompt as well as after it. Verify the spoken labels match the selected destination and that call clearing behaves correctly.

If digits are not recognised, investigate the negotiated DTMF method and actual endpoint/provider path before increasing every timeout. If the sound is missing or wrong, inspect filename, language, format, permissions and active sounds directory. Do not record caller information or fetch external URLs merely to troubleshoot a simple menu.

If later adding retries, use a counter with a defined maximum and an explicit exit. Avoid a loop that can keep an unattended caller connected indefinitely. Preserve the previous route and prompt so a failed menu change can be reversed.

Return to Asterisk documentation or first troubleshooting checks.