Asterisk dialplan sample - quick office dialplan

Quick Office dialplan description

This sample dialplan shows how a simple small to medium company may have implement Asterisk dialplan.
It provides basic capabilities of IVR, inbound and outbound calling, voicemail, DISA and other Asterisk functionalities.

The sample is developed using Visual Dialplan for Asterisk.
Full functional free of charge trial of this software is available for the download (see below) together with this sample.
However, you may also use the output of Visual Dialplan, standard Asterisk "extensions.conf" file (see below), and deploy it to your Asterisk server wihtout downloading and using Visual Dialplan.


This context is intended for placing the SIP outbound calls. This enables local SIP endpoints to dial out.

The first entry component matches all the extensions in the following format 1XX (e.g. 100, 101, 102 … 199). Calls that land on these extensions will be forwarded to the dial-ext context, which is used to dial the SIP endpoint.
Second entry point component matches the extension *1 and invokes the voicemail main application (administrative voicemail application). The caller is sent to the administrative interface for the voice mailbox based on the caller ID number.
This means that the employee on extension 101 will be sent to the administrative voicemail application for the voice mailbox 101.
The third entry point component matches all other extensions and dials that number over the ZAP channel from group 1 (Zap/g1/${EXTEN}).

This context is used for dialing the local extensions.

After the call is logged for debugging purposes (Log component), appropriate Sip extension is dialed.
In case of the busy, unavailable or no answer response, the call is sent to the voice mailbox for the dialed extension.

This context accepts all incoming calls coming through the ZAP lines.

All inbound calls (landing the “s” extension) are first answered and presented with a welcome message, after which the main menu is played and caller input is expected.
The caller can choose from one of the following options:
0 – A call is sent to the dial-attendant context in order to dial employee based on the caller ID number.
1 – A call is sent to the dial-employee context to allow the caller to choose the employee extension that should be dialed dial.
2 – Allow employees to check the voicemail. A call is sent to the VoicemailMain application, without parameters, meaning that the application will ask the caller for both mailbox number and password.
3 – Allow employees to dial out. The call I sent to the DISA (Direct Inward Dialing Application) application. The caller is expected to type the password “123” after which he is allowed to dial-out as if he was using the local SIP phone.

If no choice I made by the caller within the RESP_TOUT (10 seconds), the call is hanged up.
In case the caller hangs up the caller, before making any choice, a debug message I logged using the Log component.

This context dials one of the employees based on the caller’s area code.

This very simple context sets the first four digits of the caller ID number to the area_code channel variable.
The select-attendant macro is call with the area_code value in order to find appropriate employee.
The last step of this context is dialing the SIP endpoint returned as a result of the previous macro call.

This context enables external caller to reach an extension.

The caller is prompted to type in the three digit extension of the employee he wishes to reach. If caller types the valid extension, the call is sent to the dial-ext context, otherwise the call is terminated.

Global variables

Dial timeout - 20sec.

Digit timeout - 3sec.

Response timeout - 10sec.

Channel variables

Selected Sip extension for this call. This variable is set by the select-attendant macro.

This variable holds the first four digits of the caller ID number.

Default mailbox for the SIP peer.


This macro selects extension based on the first four digits of the caller ID. The associated extension is read from the database.

If no value is passed in the area_code argument, this macro will read the default extension. If the value of the area_code argument is not empty, the macro will read the associated extension for that area code.
After the value is read from the database, the macro returns the control to the calling context.

In order to function properly, sample dialplan requires that some of the resources are already configured in the Asterisk server (i.e. SIP endpoints, voice mailboxes, sound files…).

Quick Office dialplan

You can use this code below and deploy it to your Asterisk server or use VDP file (Visual Dialplan file) and deploy it from Visual Dialplan with a single press of a button.

; Generated with Visual Dialplan Professional.


; Dial timeout - 20sec.
; Digit timeout - 3sec.
; Response timeout - 10sec.

; Context for the SIP outbound calls.

exten => _1XX,1,Goto(dial-ext,${EXTEN},1)
exten => *1,1,Set(mailbox=${CALLERID(number)})
exten => *1,n,VoicemailMain(${mailbox})
exten => *1,n,Hangup()
exten => _X.,1,Dial(Zap/g1/${EXTEN},${DIAL_TOUT},HrS(600)TWK)

; Context used for dialing the local extensions.

exten => _1XX,1,Log(DEBUG,Dialing local extension ${EXTEN})
exten => _1XX,n,Dial(SIP/${EXTEN},${DIAL_TOUT},htwk)
exten => _1XX,n,GotoIf($["${DIALSTATUS}" = "CHANUNAVAIL"]?lbl_dial-ext_1:)
exten => _1XX,n,GotoIf($["${DIALSTATUS}" = "NOANSWER"]?lbl_dial-ext_1:)
exten => _1XX,n,GotoIf($["${DIALSTATUS}" = "BUSY"]?lbl_dial-ext_1:)
exten => _1XX,n(lbl_dial-ext_0),Hangup()
exten => _1XX,n(lbl_dial-ext_1),MailboxExists(${EXTEN})
exten => _1XX,n,GotoIf($["${VMBOXEXISTSSTATUS}" = "FAILED"]?lbl_dial-ext_2:)
exten => _1XX,n,VoiceMail(${EXTEN},u)
exten => _1XX,n,GotoIf($["${VMSTATUS}" = "FAILED"]?lbl_dial-ext_3:)
exten => _1XX,n,Goto(lbl_dial-ext_0)
exten => _1XX,n(lbl_dial-ext_3),Log(ERROR,Caller ${CALLERID(all)} failed to leave a voicemail for ${EXTEN} mailbox.)
exten => _1XX,n,Goto(lbl_dial-ext_0)
exten => _1XX,n(lbl_dial-ext_2),Hangup()

; Context for incoming external (zap) calls.

exten => s,1,Answer()
exten => s,n,Playback(welcome)
exten => s,n(lbl_dial-in_0),Set(TIMEOUT(response)=10)
exten => s,n,Set(TIMEOUT(digit)=3)
exten => s,n,Background(main-menu,m)
exten => s,n,WaitExten(${RESP_TOUT})
exten => s,n,Hangup()
exten => 0,1,Goto(dial-attendant,s,1)
exten => h,1,Log(VERBOSE,Caller ${CALLERID(all)} hung up.)
exten => h,n,Hangup()
exten => 2,1,VoicemailMain()
exten => 2,n,Goto(s,lbl_dial-in_0)
exten => 1,1,Goto(dial-employee,s,1)
exten => 3,1,DISA(123,sip)

; Dial attendant.

exten => s,1,Set(area_code=${CALLERID(number):0:4})
exten => s,n,Macro(select-attendant,${area_code})
exten => s,n,RetryDial(,5,2,SIP/${attendant},${DIAL_TOUT},A(attendant-msg)hm()twk)

; Dial employee.

exten => s,1,Set(TIMEOUT(response)=${RESP_TOUT})
exten => s,n,Set(TIMEOUT(digit)=${DIGIT_TOUT})
exten => s,n,Background(select-emp)
exten => s,n,WaitExten(${RESP_TOUT})
exten => s,n,Playback(goodbye)
exten => s,n,Hangup()
exten => _1XX,1,Goto(dial-ext,${EXTEN},1)

; This macro selects attendant based on the first four digit of the caller ID.

exten => s,1,GotoIf($["${LEN(${ARG1})}" = "0"]?:lbl_macro-select-attendant_0)
exten => s,n,Set(attendant=${DB(attendant/default)})
exten => s,n(lbl_macro-select-attendant_1),MacroExit()
exten => s,n(lbl_macro-select-attendant_0),Set(attendant=${DB(attendant/${ARG1})})
exten => s,n,Goto(lbl_macro-select-attendant_1)

About Visual Dialplan

Visual Dialplan for Asterisk® is modern rapid application development platform for Asterisk dial plan development.

It comes with drag-and-drop visual modeling environment and large component library, handy dial plan samples, powerful validation engine, and single button deployment functionality. It even learns about Asterisk server configuration - Asterisk server configuration reading module connects to the Asterisk server, pools the server configuration data and then pre-populates library components with configuration objects. Visual Dialplan detects remote Asterisk server version and accommodates its behavior accordingly. And there are other cool features like export graphical presentation of the dial plan to image file etc.

Visual Dialplan is the only Asterisk GUI that provides full access to Asterisk dial plan potential.

About Visual Dialplan Code Zone

Visual Dialplan Code Zone is a website for developers to find solutions, share ideas and solve problems.
It includes a wiki containing tutorials, code snippets, dial plan examples and tools to simplify development and testing.
Visual Dialplan Code Zone

Download full functional trial

Full functional free of charge trial version of Visual Dialplan is available for the download.
Download Visual Dialplan, or learn more at

Created by: mich.davis, Last modification: Tue 29 of Sep, 2009 (11:21)
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+