An IVR (Interactive Voice Response) menu answers calls, plays a greeting and routes callers based on the keys they press. In Asterisk, an IVR is built in the dialplan with a handful of applications. This tutorial walks through a clean, simple design you can adapt.
The plan
We'll build a menu that says: "Thanks for calling. Press 1 for sales, 2 for support, or 0 for the operator." Invalid choices and silence are handled gracefully, and the caller can hear the menu again.
Prepare the prompts
Record or generate short audio files, for example main-menu, invalid and goodbye, and place them in Asterisk's sounds directory (or a custom folder) in a supported format such as WAV (8 kHz, mono, 16-bit) or ulaw. Keep the menu prompt short: callers remember three or four options at most.
The dialplan
In extensions.conf (or extensions_custom.conf if you use FreePBX), create a context for the IVR. The logic looks like this:
- Answer the call and wait a moment so the caller doesn't miss the start of the greeting.
- Set timeouts:
TIMEOUT(digit)for the gap between key presses andTIMEOUT(response)for how long to wait after the prompt. - Background(main-menu): plays the prompt while listening for key presses. Unlike Playback, Background lets callers press a key before the prompt finishes.
- WaitExten: waits for the caller's choice.
- Extensions for each option:
1goes to the sales queue,2to support,0to the operator. - The
iextension handles invalid input: play "invalid" and return to the menu. - The
textension handles timeouts: replay the menu once or twice, then transfer to the operator or say goodbye.
Use a counter variable to limit how many times the menu repeats, so callers aren't stuck in a loop.
Routing the options
Each option can dial a ring group, send the call to a Queue (best for teams), go to voicemail, or jump to another menu with Goto. For team routing, queues give hold music, position announcements and fair distribution. See setting up call queues in Asterisk.
Business hours
Use GotoIfTime before the menu to send after-hours calls to a different prompt or to voicemail. Remember to account for holidays.
Test thoroughly
- Press every option, including invalid ones.
- Stay silent to test the timeout path.
- Press a key during the greeting to confirm callers can skip ahead.
- Call after hours to test the time condition.
- Watch the Asterisk CLI while testing to see each step.
Design tips
- Put the most common reason for calling as option 1.
- Don't announce your website or long legal text before the options.
- Always offer a way to reach a person.
- Keep menus one level deep where possible.
- Review call reports: if many callers press 0 or hang up, the menu needs work.
If callers' needs don't fit neatly into a few options, an AI voice agent may serve them better. See AI voice agent vs IVR.
Summary
An Asterisk IVR is a context with Answer, Background, WaitExten, an extension per option, and the i and t extensions for invalid input and timeouts. Keep it short, test every path, and give callers a quick route to a human.
Need help with VICIdial, Asterisk or AI voice agents?
SmartAiCalls sets up, secures and supports calling systems for call centers and growing businesses. Talk to us or request a free demo.