Page Contents
- Dial()
- Synopsis
- Description
- Example 1: Simple use case
- Dial macros
- Return codes
- Example 3: Dial multiple channels, partially delayed
- Example 4: Answering machine (by dsfr aka Chris Hozian)
- Example 5: Using Bristuff
- Example 6: Using IAX2 friends
- Return values in channel variables
- Version comments
- Support for specific hardware
- See also
Dial()
Synopsis
Attempts to establish a new outgoing connection on a channel, and then link it to the existing input channel.Description
Dial(type/identifier, timeout, options, URL)Dial(type1/identifier1[&type2/identifier2[&type3/identifier3... ] ], timeout, options, URL)
RetryDial(announce|sleep|loops|Technology/resource[&Technology2/resource2...][|[timeout][|[options][|URL]]])
Attempts to "dial out" on all the specified channels (each specified by a type and identifier) simultaneously. The first channel that answers "wins", and all the other outgoing channels are hung up. The originating channel that triggered this Dial command is then Answered, if necessary, and the two channels are connected together ("bridged") allowing a conversation to take place between them. When the channel that triggered the Dial command hangs up, the Dial command exits.
RetryDial was added in Asterisk v1.2 together with the 'd' flag.
Parameters
- Jumping in Asterisk v1.2.14: In [general] you can set priorityjumping=yes/no. The default as of 1.2.14 is "yes". When set to "yes", the dialplan will jump to priority +101 on busy, congested, and channel unavailable. The wiki "used" to imply that the default was "no" if priorityjumping was not set. This does not appear to be the case in 1.2.14.
- New in Asterisk 1.2.0: If you don't want to modify options on each app that used to have jumping behavior, you can set "priorityjumping=yes" in the [general] section of extensions.conf which will enforce the old behavior globally. As far as the Dial() application is concerned you can control the behavior with the 'j' option (see below).
- New in Asterisk v1.2.0: The Caller*ID of the outbound leg is now the extension that was called, rather than the Caller*ID of the inbound leg of the call. The "o" flag for Dial can be used to restore the original behavior if desired. Note that if you are looking for the originating callerid from the manager event, there is a new manager event "Dial" which provides the source and destination channels and callerid.
- type specifies the channel type. It should be one of the registered channel types, such as "Zap", "SIP", "IAX2", and so on.
- identifier specifies the "phone number" to dial on that channel. The format of the "phone number" depends on the channel, and may contain additonal parameters (e.g. a distinctive ring parameter) specific to the channel module in question; the Dial command simply passes identifier to the channel module to process in whatever way is appropriate. See the documentation for the individual channel modules to learn about the correct format for specifying the identifier for the Dial command, and the options available to you when doing so. If you need a .5 second pause while dialing a number you can insert a w in the appropriate place.
- If you wish to specify more than one channel for the Dial command to try — remembering that it will dial out on all of them simultaneously — separate them with the & symbol (there must not be a space before and after the ampersand). The channels can be different types; see Examples, below. Note that call progress information is not consistantly handled with multiple channels.. consider using the 'r' option.
- The timeout parameter is optional. If not specifed, the Dial command will wait indefinitely, exiting only when the originating channel hangs up, or all the dialed channels return a busy or error condition. Otherwise it specifies a maximum time, in seconds, that the Dial command is to wait for a channel to answer.
- The options parameter, which is optional, is a string containging zero or more of the following flags and parameters:
- t: Allow the called user to transfer the call by hitting the blind xfer keys (features.conf)
- If you have set the variable GOTO_ON_TRANSFER then the transferrer will be sent to the context|exten|pri (you can use ^ to represent | to avoid escapes), example: SetVar(GOTO_ON_TRANSFER=woohoo^s^1); works with both t and T
- WARNING: GOTO_ON_TRANSFER does not exist in any version of ASTERISK and will not! the variable is called GOTO_ON_BLINDXFR see http://svn.digium.com/view/asterisk?rev=5495&view=rev and http://bugs.digium.com/view.php?id=4056 for details. THX to the person who shared the information above!
- T: Allow the calling user to transfer the call by hitting the blind xfer keys (features.conf)
- r: Generate a ringing tone for the calling party, passing no audio from the called channel(s) until one answers. Without this option, Asterisk will generate ring tones automatically where it is appropriate to do so; however, "r" will force Asterisk to generate ring tones, even if it is not appropriate. For example, if you used this option to force ringing but the line was busy the user would hear "RING RIBEEP BEEP BEEP" (thank you tzanger), which is potentially confusing and/or unprofessional. However, the option is necessary in a couple of places. For example, when you're dialing multiple channels, call progress information is not consistantly passed back.
- R: Indicate ringing to the calling party when the called party indicates ringing, pass no audio until answered. This is available only if you are using kapejod's Bristuff.
- m: Provide Music on Hold to the calling party until the called channel answers. This is mutually exclusive with option 'r', obviously. Use m(class) to specify a class for the music on hold.
- n: (Asterisk 1.1 and later) July 2005 bug 752 was included in CVS (Asterisk 1.1) and enhances the privacy manager considerably. As part of this patch, the 'n' flag to Dial got changed to be used as part of the privacy features, instead of being the 'dont jump to +101' flag. That flag is now 'j'.
- o: Restore the Asterisk v1.0 CallerId behaviour (send the original caller's ID) in Asterisk v1.2 (default: send this extension's number)
- j: Asterisk 1.2 and later: Jump to priority n+101 if all of the requested channels were busy (just like behaviour in Asterisk 1.0.x)
- M(x): Executes the macro (x) upon connect of the call (i.e. when the called party answers). IMPORTANT - The CDR 'billsecs' field is set to zero if the callee answers the call, but hangs up whilst the macro is still running (if the callee answers and the macro finishes, 'billsecs' contains the correct value).
- h: Allow the callee to hang up by dialing *
- H: Allow the caller to hang up by dialing *
- i: Asterisk will ignore any forwarding requests it may receive on this dial attempt. (new in 1.4) Useful if you are ringing a group of people and one person has set their phone to forwarded direct to voicemail on their cell or something which normally prevents any of the other phones from ringing.
- C: Reset the CDR (Call Detail Record) for this call. This is like using the NoCDR command
- p: This option enables screening mode. This is basically Privacy mode without memory of how to handle the caller. It looks for the file sounds/priv-callerintros/${IF($[ "${CALLERID(num)}" != "" ]?${CALLERID(num)}:NOCALLERID_${EXTEN}${CUT(CHANNEL,/,1)}=${CUT(CHANNEL,/,2)})}.gsm and if it is not found, prompts the caller to say his name. It then rings the called party and plays sounds/priv-callpending, sounds/priv-callerintros/<see-above>, and sounds/screen-callee-options. If the called party enters 1, the call is accepted, 2, the DIAL command exits with ${DIALSTATUS} set to NOANSWER, 3, set to TORTURE and 4, set to DONTCALL. If no valid entry is made, the DIAL command exits with ${DIALSTATUS} set to ANSWER. The check for pre-existence of the name recording may not be what you want. For example, everyone from the same number is not necessarily the same person, especially if the number is OUTOFAREA, but if the file is there, no new name will be recorded. Since the files are never removed, you may wish to remove them with a System(rm /var/lib/asterisk/sounds/priv-callerintros/${IF($[ "${CALLERID(num)}" != "" ]?${CALLERID(num)}:NOCALLERID_${EXTEN}${CUT(CHANNEL,/,1)}=${CUT(CHANNEL,/,2)})}.*) right before the Dial command and clean up old ones with a cron job.
- P(x): Use the PrivacyManager, using x as the database (x is optional)
- g: When the called party hangs up, exit to execute more commands in the current context.
- G(context^exten^pri): If the call is answered, transfer both parties to the specified context and extension. The calling party is transferred to priority x, and the called party to priority x+1. This allows the dialplan to distinguish between the calling and called legs of the call (new in v1.2).
- A(x): Play an announcement (x.gsm) to the called party.
- S(n): Hangup the call n seconds AFTER called party picks up.
- d: This flag trumps the 'H' flag and intercepts any dtmf while waiting for the call to be answered and returns that value on the spot. This allows you to dial a 1-digit exit extension while waiting for the call to be answered - see also RetryDial
- D(digits): After the called party answers, send digits as a DTMF stream, then connect the call to the originating channel. (You can also use 'w' to produce .5 second pauses.)
- L(x[:y][:z]): Limit the call to 'x' ms, warning when 'y' ms are left, repeated every 'z' ms) Only 'x' is required, 'y' and 'z' are optional. The following special variables are optional for limit calls: (pasted from app_dial.c)
- LIMIT_PLAYAUDIO_CALLER - yes|no (default yes) - Play sounds to the caller.
- LIMIT_PLAYAUDIO_CALLEE - yes|no - Play sounds to the callee.
- LIMIT_TIMEOUT_FILE - File to play when time is up.
- LIMIT_CONNECT_FILE - File to play when call begins.
- LIMIT_WARNING_FILE - File to play as warning if 'y' is defined. If LIMIT_WARNING_FILE is not defined, then the default behaviour is to announce ("You have [XX minutes] YY seconds").
- f: forces callerid to be set as the extension of the line making/redirecting the outgoing call. For example, some PSTNs don't allow callerids from other extensions than the ones that are assigned to you.
- w: Allow the called user to start recording after pressing *1 or what defined in features.conf (Asterisk v1.2.x); requires Set(DYNAMIC_FEATURES=automon)
- W: Allow the calling user to start recording after pressing *1 or what defined in features.conf (Asterisk v1.2.x); requires Set(DYNAMIC_FEATURES=automon)
- k: Allow the called party to enable parking of the call by sending the DTMF sequence defined for call parking in features.conf (Asterisk v1.4.x)
- K: Allow the calling party to enable parking of the call by sending the DTMF sequence defined for call parking in features.conf (Asterisk v1.4.x)
- The optional URL parameter will also be sent to the called party upon successful connection, if the channel technology supports the sending of URLs in this way.
Example 1: Simple use case
exten => 1265,1,Dial(Phone/phone0,15)
exten => s,3,Dial(SIP/oej,20)
exten => _908.,1,Dial(Modem/ttyI0:${EXTEN:1})
exten => 233,1,Dial(SIP/4029&SIP/4027&Zap/4&IAX/jaz,15,tTr)
exten => 500,1,Dial(Zap/2r2,20,crh)
exten => 20,1,Dial(Zap/3/5551234)
exten => s,3,Dial(SIP/oej,20)
exten => _908.,1,Dial(Modem/ttyI0:${EXTEN:1})
exten => 233,1,Dial(SIP/4029&SIP/4027&Zap/4&IAX/jaz,15,tTr)
exten => 500,1,Dial(Zap/2r2,20,crh)
exten => 20,1,Dial(Zap/3/5551234)
Dial macros
Introduced in/for Asterisk 1.2, see bug/patch 2905You can now add args to the macro by using a '^' char
Dial(Zap/1|60|M(mymacro^cat^dog^bark))
Also, the macro can set the MACRO_RESULT variable to do the following:
ABORT - Hangup both legs of the call
BUSY
CONTINUE - Hangup the called party and continue on in the dialplan from where you called Dial
GOTO:<context>^<exten>^<priority> - Transfer the call.
Note: If you want the call to be bridged upon completion of the macro, you should NOT set the MACRO_RESULT variable to anything. IF MACRO_RESULT is not defined, the thread of execution falls off the end of the macro and bridges the call. Setting it to CONTINUE causes the call NOT to be bridged, and execution to resume at n+1 priority in the calling context. Of course setting it to BUSY or GOTO has the implied results (and of course the call is not bridged).
(I found this a bit confusing because my mental model expected some kind of explicit case for "bridge the call", such as setting MACRO_RESULT to "BRIDGE" or "CONNECT" or something like that. It's the ABSENCE of any value that causes the call to be bridged.)
Example 2: Dial macro
screen-record: Please record your name press pound when finished.
screen-from: You have a call from
screen-accept: Press 1 to accept this call or any other key to reject.
exten => 890,1,Wait(0.2)
exten => 890,n,Playback(screen-record)
exten => 890,n,SetVar(SCREEN_FILE=/tmp/${CALLERID(number)}-${EPOCH})
exten => 890,n,Record(${SCREEN_FILE}.gsm|6|25)
exten => 890,n,Dial(SIP/16|60|gM(screen^${SCREEN_FILE}))
exten => 890,n,Voicemail(10@default)
[macro-screen]
exten => s,1,Wait(0.2)
exten => s,n,Playback(screen-from)
exten => s,n,Playback(${ARG1})
exten => s,n,Read(ACCEPT|screen-accept|1)
exten => s,n,GotoIf($[${ACCEPT} = 1 ] ?yes:no)
exten => s,n(yes),SetVar(MACRO_RESULT=CONTINUE)
exten => s,n(no),System(/bin/rm ${ARG1})
screen-from: You have a call from
screen-accept: Press 1 to accept this call or any other key to reject.
exten => 890,1,Wait(0.2)
exten => 890,n,Playback(screen-record)
exten => 890,n,SetVar(SCREEN_FILE=/tmp/${CALLERID(number)}-${EPOCH})
exten => 890,n,Record(${SCREEN_FILE}.gsm|6|25)
exten => 890,n,Dial(SIP/16|60|gM(screen^${SCREEN_FILE}))
exten => 890,n,Voicemail(10@default)
[macro-screen]
exten => s,1,Wait(0.2)
exten => s,n,Playback(screen-from)
exten => s,n,Playback(${ARG1})
exten => s,n,Read(ACCEPT|screen-accept|1)
exten => s,n,GotoIf($[${ACCEPT} = 1 ] ?yes:no)
exten => s,n(yes),SetVar(MACRO_RESULT=CONTINUE)
exten => s,n(no),System(/bin/rm ${ARG1})
Notes:
- Do not put spaces between the arguments to the Dial command, it will not work.
- When options t, T", "h", "H", "w", "W" or "L" (with multiple arguments) are applied, Asterisk will remain in the media path, even if canreinvite=yes'' (a SIP channel option) has been specified.
Return codes
Dial sets DIALSTATUS to indicate its success or failure. However, under some circumstances, execution will jump to priority n+101 in the current context. This happens when:
- All channels dialed were busy
- There is exists something at n+101 in the current context
- You are running asterisk 1.0.x, priorityjumping=yes is set in extensions.conf, or the j option is specificed in the dial command
Note that in Asterisk v1.2+ priorityjumping is considered "off" by default, which is a change from previous versions.
If the g option is specified, and the called party hangs up before the calling party, then Dial continues execution at priority n+1.
Do Answer() before calling Dial() if you want asterisk to go in-band (in order to use playtones configured in indications.conf etc.)
Note: The bristuff patches change the dial behaviour slightly and jump to n+201 if the dialed destination isn't connected (e.g. a SIP softphone is not up and running, or hasn't registered).
- DIALSTATUS - For more details see Asterisk Variable DIALSTATUS
${DIALSTATUS} will be one of:
- CHANUNAVAIL : Channel unavailable (for example in sip.conf, when using qualify=, the SIP chan is unavailable)
- BUSY : Returned busy
- NOANSWER : No Answer (i.e SIP 480 or 604 response)
- ANSWER : Call was answered
- CANCEL : Call attempt cancelled (i.e user hung up before the call connected)
- DONTCALL : Privacy manager don't call
- TORTURE : Privacy manager torture menu
- CONGESTION : Means Congestion, or anything else (some other error setting up the call)
Example 3: Dial multiple channels, partially delayed
Idea: Make a special extension where you could provide the delay and the numbers you want to dial, for example:
exten => _900XXXXX,1,Wait(${EXTEN:3:2})
exten => _900XXXXX,2,Dial(SIP/${EXTEN:5})
exten => _900XXXXX,2,Dial(SIP/${EXTEN:5})
Then in the incoming context you could use the Local channel construct and dial:
exten => s,1,Dial(SIP/200&SIP/201&LOCAL/90015300&LOCAL/90015301)
In the above example 200 and 201 extension will ring immediately, and 300 and 301 will start ringing after 15 seconds. After to 900 the first two digits are for the delay before start ringing and the last three are the extension that should be called. The trick here is that instead of simply using two Dial statements after each other we make sure we ring each phone only once; that prevents a) potential problems with SIP devices needing some wrap up time before being able to take another call, and b) avoids too many "missed call" entires in the phone's interface.
Look at ForkCDR and/or ResetCDR if you are not happy with the resulting CDRs of this example.
Example 4: Answering machine (by dsfr aka Chris Hozian)
Can be used for home answering machine with call screen. Provides CallerID to handset even if you don't pay for CallerID. Must associate CID name with number in Asterisk database in order to work.[from-iax-fwd]
exten => night-mode,1,WaitForRing(30)
exten => night-mode,n,Goto(s|night-mode-start)
exten => ${FWD-HOME-NUMBER},1,Set(INVALID-PRIVACY-TRIES=0) ; used for determining number of invalid tries used during privacymanager.
exten => ${FWD-HOME-NUMBER},n,Set(TIMEOUT(response)=20)
exten => ${FWD-HOME-NUMBER},n,Set(TIMEOUT(digit)=7)
exten => ${FWD-HOME-NUMBER},n,SetMusicOnHold(default)
exten => ${FWD-HOME-NUMBER},n,GotoIfTime(20:00-7:59|*|*|*?night-mode|1)
exten => ${FWD-HOME-NUMBER},n,Answer
exten => ${FWD-HOME-NUMBER},n,Wait(2)
exten => ${FWD-HOME-NUMBER},n,Zapateller
exten => ${FWD-HOME-NUMBER},n,Goto(skip-night-mode)
exten => ${FWD-HOME-NUMBER},n(night-mode-start),Answer
exten => ${FWD-HOME-NUMBER},n,Wait(2)
exten => ${FWD-HOME-NUMBER},n(skip-night-mode),Playback(dsfr-hozian-residence) ; welcome the caller.
exten => ${FWD-HOME-NUMBER},n,Playback(dsfr-greeting) ; welcome the caller.
exten => ${FWD-HOME-NUMBER},n,NoOp(Pre Privacy Manager Number ${CALLERID})
exten => ${FWD-HOME-NUMBER},n(privacy-manager),PrivacyManager
exten => ${FWD-HOME-NUMBER},s+101,GotoIf($[${INVALID-PRIVACY-TRIES} = ${MAX-PRIVACY-TRIES}] ?i|1)
exten => ${FWD-HOME-NUMBER},n,Playback(dsfr-privacy-invalid) ; explain that # is not valid and that 10 digits must be entered.
exten => ${FWD-HOME-NUMBER},n,Set(INVALID-PRIVACY-TRIES=$[${INVALID-PRIVACY-TRIES} + 1])
exten => ${FWD-HOME-NUMBER},n,Goto(privacy-manager)
exten => ${FWD-HOME-NUMBER},privacy-manager+1,NoOp(Post Privacy Manager Number ${CALLERID})
exten => ${FWD-HOME-NUMBER},n,LookupCIDName
exten => ${FWD-HOME-NUMBER},n,NoOp(Post LookupCIDName ${CALLERID})
exten => ${FWD-HOME-NUMBER},n,Playback(pls-rcrd-name-at-tone)
exten => ${FWD-HOME-NUMBER},n,Playback(and-prs-pound-whn-finished)
exten => ${FWD-HOME-NUMBER},n,Set(SCREEN-FILE=/var/lib/asterisk/tmp/${TIMESTAMP}-${CALLERIDNUM})
exten => ${FWD-HOME-NUMBER},n,Record(${SCREEN-FILE}.gsm|${SILENCE-SECONDS}|${SCREEN-FILE-SECONDS})
exten => ${FWD-HOME-NUMBER},n,Playback(this-call-may-be-monitored-or-recorded)
exten => ${FWD-HOME-NUMBER},n,Playback(pls-hold-while-try)
exten => ${FWD-HOME-NUMBER},n,Dial(${PHONE-1}|${INCOMING-RING-SECONDS}|gmM(from-iax-fwd-screen^${SCREEN-FILE}^${UNIQUEID}^${CALLERIDNUM}))
exten => ${FWD-HOME-NUMBER},n,GotoIf($[${${UNIQUEID}} = 1] ?hangup) ; checks whether bypass voicemail option is set in macro-from-iax-fwd-screen.
exten => ${FWD-HOME-NUMBER},n(from-iax-fwd-ivr),System(/bin/rm ${SCREEN-FILE}.gsm)
exten => ${FWD-HOME-NUMBER},n,Goto(from-iax-fwd-ivr|s|1)
exten => ${FWD-HOME-NUMBER},n(hangup),System(/bin/rm ${SCREEN-FILE}.gsm)
exten => ${FWD-HOME-NUMBER},n,Hangup
exten => i,1,System(/bin/rm ${SCREEN-FILE}.gsm)
exten => i,n,Playback(call-terminated)
exten => i,n,Playback(goodbye)
exten => i,n,Hangup
exten => t,1,System(/bin/rm ${SCREEN-FILE}.gsm)
exten => t,n,Playback(call-terminated)
exten => t,n,Playback(goodbye)
exten => t,n,Hangup
exten => h,1,System(/bin/rm ${SCREEN-FILE}.gsm)
[macro-from-iax-fwd-screen]
exten => s,1,Set(MACRO_RESULT=GOTO:from-iax-fwd^${FWD-HOME-NUMBER}^from-iax-fwd-ivr)
exten => s,n,Set(TIMEOUT(response)=15)
exten => s,n,Playback(call)
exten => s,n,Playback(from)
exten => s,n(repeat-screen),Playback(${ARG1})
exten => s,n(repeat-options),Read(ACCEPT-CALL|dsfr-macro-from-iax-fwd-options|1)
exten => s,n,GotoIf($["${ACCEPT-CALL}" = ""] ?t|1)
exten => s,n,GotoIf($[${ACCEPT-CALL} = 1] ?call-accepted)
exten => s,n,GotoIf($[${ACCEPT-CALL} = 5] ?repeat-screen)
exten => s,n,GotoIf($[${ACCEPT-CALL} = 9] ?call-declined:repeat-options)
exten => s,n(call-declined),Playback(dsfr-screen-declined) ; declined - caller will be sent to ivr.
exten => s,n,GotoIf($[${MACRO_RESULT} = GOTO:from-iax-fwd^${FWD-HOME-NUMBER}^from-iax-fwd-ivr] ?skip-monitor)
exten => s,n(call-accepted),Playback(dsfr-screen-accepted) ; accepted - call will be bridged momentarily.
exten => s,n,Set(MACRO_RESULT=)
exten => s,n,Set(${ARG2}=1|g) ; if set to 1 then bypass voicemail.
exten => s,n,Playback(this-call-may-be-monitored-or-recorded)
exten => s,n,Monitor(wav49|${TIMESTAMP}-${ARG3}|mb)
exten => s,n(skip-monitor),NoOp
exten => t,1,Playback(connection-timed-out)
exten => t,n,Goto(s|call-declined)
[from-iax-fwd-ivr]
exten => s,1,Set(INVALID-IVR-TRIES=0) ; used for determining number of invalid tries used during ivr.
exten => s,n,Set(RETRIES-FWD-WORK=0) ; used for determining number of retry attempts when calling fwd home.
exten => s,n,Set(RETRIES-WEATHER-SERVICE=0) ; used for determing number of retry attempts when checking weather service.
exten => s,n,Set(RETRIES-VOICEMAIL=0) ; used for determing number of retry attempts when checking voicemail.
exten => s,n,Set(TIMEOUT(response)=20)
exten => s,n,Set(TIMEOUT(digit)=7)
exten => s/1000,n,Background(dsfr-personalized-greeting-test1)
exten => s/0123456789,s,Background(dsfr-personalized-greeting-test2)
exten => s/123456789,s,Background(dsfr-personalized-greeting-test2)
exten => s/0987654321,s,Background(dsfr-personalized-greeting-test3)
exten => s/987654321,s,Background(dsfr-personalized-greeting-test3)
exten => s,s,NoOp(This caller does not have a personalized greeting.)
exten => s,n(ivr-options),Background(dsfr-from-iax-fwd-ivr) ; provide various ivr options excluding voicemail and admin-auth extensions.
exten => s,n,WaitExten
exten => 1,1,Voicemail(${PERSONAL-1-VMBOX}|u)
exten => 2,1,Voicemail(${PERSONAL-2-VMBOX}|u)
exten => 3,1,Playback(dsfr-ivr-fwd-info) ; explain that fwd work phone is experimental, will ring for 90 seconds, then come back to ivr.
exten => 3,n,SetCallerId(${FWD-HOME-CID})
exten => 3,n,Monitor(wav49|${TIMESTAMP}-${CALLERIDNUM}-FWD-WORK|mb)
exten => 3,n,Dial(IAX2/to-iax-fwd/${FWD-WORK-NUMBER}|${OUTGOING-RING-SECONDS}|rg)
exten => 3,n,Macro(from-iax-fwd-ivr-retries|RETRIES-FWD-WORK)
exten => 4,1,Playback(dsfr-weather-service) ; explain that there will be a pause while the Huntsville, AL weather information is downloaded.
exten => 4,n,System(/usr/bin/curl -s ftp://weather.noaa.gov/data/forecasts/city/al/huntsville.txt > /var/lib/asterisk/tmp/weather.txt)
exten => 4,n,System(/usr/bin/text2wave /var/lib/asterisk/tmp/weather.txt -F 8000 -o /var/lib/asterisk/tmp/weather.wav)
exten => 4,n,Playback(/var/lib/asterisk/tmp/weather)
exten => 4,n,Macro(from-iax-fwd-ivr-retries|RETRIES-WEATHER-SERVICE)
exten => 9,1,Playback(dsfr-emergency-phone-info) ; explain that emergency phone will ring for 90 seconds then come back to ivr.
exten => 9,n,Monitor(wav49|${TIMESTAMP}-${CALLERIDNUM}-EMERGENCY|mb)
exten => 9,n,Dial(${PHONE-1}${EMERGENCY-RING-TONE}|${EMERGENCY-RING-SECONDS}|r)
exten => 9,n,Goto(s|ivr-options)
exten => 8500,1,VoicemailMain
exten => 8500,n,Macro(from-iax-fwd-ivr-retries|RETRIES-VOICEMAIL)
exten => i,1,GotoIf($[${INVALID-IVR-TRIES} = ${MAX-IVR-INVALID-TRIES}] ?from-iax-fwd|i|1)
exten => i,n,Playback(invalid)
exten => i,n,Set(INVALID-IVR-TRIES=$[${INVALID-IVR-TRIES} + 1])
exten => i,n,Goto(s|ivr-options)
exten => t,1,Goto(from-iax-fwd|t|1)
exten => h,1,Goto(from-iax-fwd|h|1)
[macro-from-iax-fwd-ivr-retries]
exten => s,1,GotoIf($[${${ARG1}} = ${MAX-IVR-RETRIES}] ?from-iax-fwd|i|1)
exten => s,n,Set(${ARG1}=$[${${ARG1}} + 1])
exten => s,n,Goto(from-iax-fwd-ivr|s|ivr-options)
exten => night-mode,1,WaitForRing(30)
exten => night-mode,n,Goto(s|night-mode-start)
exten => ${FWD-HOME-NUMBER},1,Set(INVALID-PRIVACY-TRIES=0) ; used for determining number of invalid tries used during privacymanager.
exten => ${FWD-HOME-NUMBER},n,Set(TIMEOUT(response)=20)
exten => ${FWD-HOME-NUMBER},n,Set(TIMEOUT(digit)=7)
exten => ${FWD-HOME-NUMBER},n,SetMusicOnHold(default)
exten => ${FWD-HOME-NUMBER},n,GotoIfTime(20:00-7:59|*|*|*?night-mode|1)
exten => ${FWD-HOME-NUMBER},n,Answer
exten => ${FWD-HOME-NUMBER},n,Wait(2)
exten => ${FWD-HOME-NUMBER},n,Zapateller
exten => ${FWD-HOME-NUMBER},n,Goto(skip-night-mode)
exten => ${FWD-HOME-NUMBER},n(night-mode-start),Answer
exten => ${FWD-HOME-NUMBER},n,Wait(2)
exten => ${FWD-HOME-NUMBER},n(skip-night-mode),Playback(dsfr-hozian-residence) ; welcome the caller.
exten => ${FWD-HOME-NUMBER},n,Playback(dsfr-greeting) ; welcome the caller.
exten => ${FWD-HOME-NUMBER},n,NoOp(Pre Privacy Manager Number ${CALLERID})
exten => ${FWD-HOME-NUMBER},n(privacy-manager),PrivacyManager
exten => ${FWD-HOME-NUMBER},s+101,GotoIf($[${INVALID-PRIVACY-TRIES} = ${MAX-PRIVACY-TRIES}] ?i|1)
exten => ${FWD-HOME-NUMBER},n,Playback(dsfr-privacy-invalid) ; explain that # is not valid and that 10 digits must be entered.
exten => ${FWD-HOME-NUMBER},n,Set(INVALID-PRIVACY-TRIES=$[${INVALID-PRIVACY-TRIES} + 1])
exten => ${FWD-HOME-NUMBER},n,Goto(privacy-manager)
exten => ${FWD-HOME-NUMBER},privacy-manager+1,NoOp(Post Privacy Manager Number ${CALLERID})
exten => ${FWD-HOME-NUMBER},n,LookupCIDName
exten => ${FWD-HOME-NUMBER},n,NoOp(Post LookupCIDName ${CALLERID})
exten => ${FWD-HOME-NUMBER},n,Playback(pls-rcrd-name-at-tone)
exten => ${FWD-HOME-NUMBER},n,Playback(and-prs-pound-whn-finished)
exten => ${FWD-HOME-NUMBER},n,Set(SCREEN-FILE=/var/lib/asterisk/tmp/${TIMESTAMP}-${CALLERIDNUM})
exten => ${FWD-HOME-NUMBER},n,Record(${SCREEN-FILE}.gsm|${SILENCE-SECONDS}|${SCREEN-FILE-SECONDS})
exten => ${FWD-HOME-NUMBER},n,Playback(this-call-may-be-monitored-or-recorded)
exten => ${FWD-HOME-NUMBER},n,Playback(pls-hold-while-try)
exten => ${FWD-HOME-NUMBER},n,Dial(${PHONE-1}|${INCOMING-RING-SECONDS}|gmM(from-iax-fwd-screen^${SCREEN-FILE}^${UNIQUEID}^${CALLERIDNUM}))
exten => ${FWD-HOME-NUMBER},n,GotoIf($[${${UNIQUEID}} = 1] ?hangup) ; checks whether bypass voicemail option is set in macro-from-iax-fwd-screen.
exten => ${FWD-HOME-NUMBER},n(from-iax-fwd-ivr),System(/bin/rm ${SCREEN-FILE}.gsm)
exten => ${FWD-HOME-NUMBER},n,Goto(from-iax-fwd-ivr|s|1)
exten => ${FWD-HOME-NUMBER},n(hangup),System(/bin/rm ${SCREEN-FILE}.gsm)
exten => ${FWD-HOME-NUMBER},n,Hangup
exten => i,1,System(/bin/rm ${SCREEN-FILE}.gsm)
exten => i,n,Playback(call-terminated)
exten => i,n,Playback(goodbye)
exten => i,n,Hangup
exten => t,1,System(/bin/rm ${SCREEN-FILE}.gsm)
exten => t,n,Playback(call-terminated)
exten => t,n,Playback(goodbye)
exten => t,n,Hangup
exten => h,1,System(/bin/rm ${SCREEN-FILE}.gsm)
[macro-from-iax-fwd-screen]
exten => s,1,Set(MACRO_RESULT=GOTO:from-iax-fwd^${FWD-HOME-NUMBER}^from-iax-fwd-ivr)
exten => s,n,Set(TIMEOUT(response)=15)
exten => s,n,Playback(call)
exten => s,n,Playback(from)
exten => s,n(repeat-screen),Playback(${ARG1})
exten => s,n(repeat-options),Read(ACCEPT-CALL|dsfr-macro-from-iax-fwd-options|1)
exten => s,n,GotoIf($["${ACCEPT-CALL}" = ""] ?t|1)
exten => s,n,GotoIf($[${ACCEPT-CALL} = 1] ?call-accepted)
exten => s,n,GotoIf($[${ACCEPT-CALL} = 5] ?repeat-screen)
exten => s,n,GotoIf($[${ACCEPT-CALL} = 9] ?call-declined:repeat-options)
exten => s,n(call-declined),Playback(dsfr-screen-declined) ; declined - caller will be sent to ivr.
exten => s,n,GotoIf($[${MACRO_RESULT} = GOTO:from-iax-fwd^${FWD-HOME-NUMBER}^from-iax-fwd-ivr] ?skip-monitor)
exten => s,n(call-accepted),Playback(dsfr-screen-accepted) ; accepted - call will be bridged momentarily.
exten => s,n,Set(MACRO_RESULT=)
exten => s,n,Set(${ARG2}=1|g) ; if set to 1 then bypass voicemail.
exten => s,n,Playback(this-call-may-be-monitored-or-recorded)
exten => s,n,Monitor(wav49|${TIMESTAMP}-${ARG3}|mb)
exten => s,n(skip-monitor),NoOp
exten => t,1,Playback(connection-timed-out)
exten => t,n,Goto(s|call-declined)
[from-iax-fwd-ivr]
exten => s,1,Set(INVALID-IVR-TRIES=0) ; used for determining number of invalid tries used during ivr.
exten => s,n,Set(RETRIES-FWD-WORK=0) ; used for determining number of retry attempts when calling fwd home.
exten => s,n,Set(RETRIES-WEATHER-SERVICE=0) ; used for determing number of retry attempts when checking weather service.
exten => s,n,Set(RETRIES-VOICEMAIL=0) ; used for determing number of retry attempts when checking voicemail.
exten => s,n,Set(TIMEOUT(response)=20)
exten => s,n,Set(TIMEOUT(digit)=7)
exten => s/1000,n,Background(dsfr-personalized-greeting-test1)
exten => s/0123456789,s,Background(dsfr-personalized-greeting-test2)
exten => s/123456789,s,Background(dsfr-personalized-greeting-test2)
exten => s/0987654321,s,Background(dsfr-personalized-greeting-test3)
exten => s/987654321,s,Background(dsfr-personalized-greeting-test3)
exten => s,s,NoOp(This caller does not have a personalized greeting.)
exten => s,n(ivr-options),Background(dsfr-from-iax-fwd-ivr) ; provide various ivr options excluding voicemail and admin-auth extensions.
exten => s,n,WaitExten
exten => 1,1,Voicemail(${PERSONAL-1-VMBOX}|u)
exten => 2,1,Voicemail(${PERSONAL-2-VMBOX}|u)
exten => 3,1,Playback(dsfr-ivr-fwd-info) ; explain that fwd work phone is experimental, will ring for 90 seconds, then come back to ivr.
exten => 3,n,SetCallerId(${FWD-HOME-CID})
exten => 3,n,Monitor(wav49|${TIMESTAMP}-${CALLERIDNUM}-FWD-WORK|mb)
exten => 3,n,Dial(IAX2/to-iax-fwd/${FWD-WORK-NUMBER}|${OUTGOING-RING-SECONDS}|rg)
exten => 3,n,Macro(from-iax-fwd-ivr-retries|RETRIES-FWD-WORK)
exten => 4,1,Playback(dsfr-weather-service) ; explain that there will be a pause while the Huntsville, AL weather information is downloaded.
exten => 4,n,System(/usr/bin/curl -s ftp://weather.noaa.gov/data/forecasts/city/al/huntsville.txt > /var/lib/asterisk/tmp/weather.txt)
exten => 4,n,System(/usr/bin/text2wave /var/lib/asterisk/tmp/weather.txt -F 8000 -o /var/lib/asterisk/tmp/weather.wav)
exten => 4,n,Playback(/var/lib/asterisk/tmp/weather)
exten => 4,n,Macro(from-iax-fwd-ivr-retries|RETRIES-WEATHER-SERVICE)
exten => 9,1,Playback(dsfr-emergency-phone-info) ; explain that emergency phone will ring for 90 seconds then come back to ivr.
exten => 9,n,Monitor(wav49|${TIMESTAMP}-${CALLERIDNUM}-EMERGENCY|mb)
exten => 9,n,Dial(${PHONE-1}${EMERGENCY-RING-TONE}|${EMERGENCY-RING-SECONDS}|r)
exten => 9,n,Goto(s|ivr-options)
exten => 8500,1,VoicemailMain
exten => 8500,n,Macro(from-iax-fwd-ivr-retries|RETRIES-VOICEMAIL)
exten => i,1,GotoIf($[${INVALID-IVR-TRIES} = ${MAX-IVR-INVALID-TRIES}] ?from-iax-fwd|i|1)
exten => i,n,Playback(invalid)
exten => i,n,Set(INVALID-IVR-TRIES=$[${INVALID-IVR-TRIES} + 1])
exten => i,n,Goto(s|ivr-options)
exten => t,1,Goto(from-iax-fwd|t|1)
exten => h,1,Goto(from-iax-fwd|h|1)
[macro-from-iax-fwd-ivr-retries]
exten => s,1,GotoIf($[${${ARG1}} = ${MAX-IVR-RETRIES}] ?from-iax-fwd|i|1)
exten => s,n,Set(${ARG1}=$[${${ARG1}} + 1])
exten => s,n,Goto(from-iax-fwd-ivr|s|ivr-options)
See also voicemail live: Listen to incoming caller during voicemail recording
Example 5: Using Bristuff
If you are using kapejod's Bristuff, you will have a n + 201 priority as well. Dial goes to this priority if no one is logged in on the called extension. I.e. giving an unavailable message instead of a busy message when no phone is connected to the extension.exten => 4000,1,Dial(SIP/${EXTEN},15)
exten => 4000,2,Voicemail(u${EXTEN})
exten => 4000,102,Voicemail(b${EXTEN})
exten => 4000,202,Voicemail(u${EXTEN})
exten => 4000,2,Voicemail(u${EXTEN})
exten => 4000,102,Voicemail(b${EXTEN})
exten => 4000,202,Voicemail(u${EXTEN})
Example 6: Using IAX2 friends
I keep forgeting how to set this up, so I wanted to contribute a good example to explain the syntax a little clearer and make this information easier to find. I'm going to give example excerpts from iaxhost1's and iaxhost2's iax.conf and extensions.conf files. I'm going to use names that are fairly generic but very unique to this example. I also have instructions on how to do this with Asterisk@Home (at least with 2.5) (now known as TrixBox), so please pay attention.Excerpt from iaxhost1's iax.conf:
[value1]
type=friend
secret=value2 ; <-- VERY important with friend types to get this to work properly
auth=plaintext
host=172.16.5.1 ; Example private address space
context=iaxhost2-in ; Always nice to be able to control access rights.
qualify=yes ; Optional, but usually a good idea.
... ; Whatever else you want including allow/disallow for codecs.
Excerpt from iaxhost2's iax.conf:
type=friend
secret=value2 ; <-- VERY important with friend types to get this to work properly
auth=plaintext
host=172.16.5.1 ; Example private address space
context=iaxhost2-in ; Always nice to be able to control access rights.
qualify=yes ; Optional, but usually a good idea.
... ; Whatever else you want including allow/disallow for codecs.
[value3]
type=friend
secret=value4 ; <-- VERY important with friend types to get this to work properly
auth=plaintext
host=172.16.5.2 ; Example private address space
context=iaxhost1-in ; Always nice to be able to control access rights.
qualify=yes ; Optional, but usually a good idea.
... ; Whatever else you want including allow/disallow for codecs.
type=friend
secret=value4 ; <-- VERY important with friend types to get this to work properly
auth=plaintext
host=172.16.5.2 ; Example private address space
context=iaxhost1-in ; Always nice to be able to control access rights.
qualify=yes ; Optional, but usually a good idea.
... ; Whatever else you want including allow/disallow for codecs.
Excerpt from iaxhost1's extensions.conf
[default]
...
include => iaxhost1-out ; Always a good idea to seperate contexts
...
[iaxhost2-in]
exten => 99104,1,DateTime() ; DateTime() is always good for testing
exten => 98104,1,NoOp(${EXTEN})
exten => 98104,2,DateTime() ; DateTime() is always good for testing
[iaxhost1-out]
exten => 99205,1,Dial(IAX2/value3:value4@value1/99105)
; A more complicated extension example:
exten => 982XX,1,Dial(IAX2/value3:value4@value1/991${EXTEN:3})
...
include => iaxhost1-out ; Always a good idea to seperate contexts
...
[iaxhost2-in]
exten => 99104,1,DateTime() ; DateTime() is always good for testing
exten => 98104,1,NoOp(${EXTEN})
exten => 98104,2,DateTime() ; DateTime() is always good for testing
[iaxhost1-out]
exten => 99205,1,Dial(IAX2/value3:value4@value1/99105)
; A more complicated extension example:
exten => 982XX,1,Dial(IAX2/value3:value4@value1/991${EXTEN:3})
Excerpt from iaxhost2's extensions.conf
[default]
...
include => iaxhost2-out ; Always a good idea to seperate contexts
...
[iaxhost1-in]
exten => 99105,1,DateTime() ; DateTime() is always good for testing
exten => 98105,1,NoOp(${EXTEN})
exten => 98105,2,DateTime() ; DateTime() is always good for testing
[iaxhost2-out]
exten => 99204,1,Dial(IAX2/value1:value2@value3/99104)
; A more complicated extension example:
exten => 982XX,1,Dial(IAX2/value1:value2@value3/991${EXTEN:3})
...
include => iaxhost2-out ; Always a good idea to seperate contexts
...
[iaxhost1-in]
exten => 99105,1,DateTime() ; DateTime() is always good for testing
exten => 98105,1,NoOp(${EXTEN})
exten => 98105,2,DateTime() ; DateTime() is always good for testing
[iaxhost2-out]
exten => 99204,1,Dial(IAX2/value1:value2@value3/99104)
; A more complicated extension example:
exten => 982XX,1,Dial(IAX2/value1:value2@value3/991${EXTEN:3})
Using IAX2 friends with Asterisk@Home AMP
The way I propose the solution here may seem a little strange. If there is a better way (without using peer/user) to do this with A@H AMP, edit this section and fix it!For the purposes of this example, We're going to iax to iaxhost2 with A@H being iaxhost1.
- Ok, start up your AMP web portal and go into Setup (enter username and password as appropriate).
- Go into your trunks and Add IAX2 Trunk. This trunk will NEVER be used in Outbound Routing. This trunk is merely a placeholder so it can be used by the custom trunk below.
- Don't worry about Outgoing Dial Rules for now, we'll worry about that later.
- In the Outgoing Settings section set the Trunk Name to value1.
- Put the contents of the [value1] heading (from above) in the PEER Details
- Change the line context=iaxhost2-in to context=from-internal
- Remove everything from the USER Details textbox.
- No other settings should need to be adjusted, so we'll Submit Changes now.
- Now we need to Add Custom Trunk.
- Setup the Outgoing Dial Rules here. We're going to just enter 99205 & 982XX; each on their own line.
- Enter the Custom Dial String as IAX2/value3:value4@value1/$OUTNUM$
- (Optional) Setup any of the other fields that you didn't in the previous trunk now.
- Now we can Submit Changes to save this custom trunk.
- Time to setup Outbound Routing.
- Enter iaxhost2-ext as the Route Name. Leave the Route Password blank.
- Enter the dial patterns from the Custom Trunk above to the Dial Patterns here. It may be redundant, but so what.
- Select the Custom Trunk above in the Trunk Sequence.
- Submit Changes
- (Optional) Adjust the routing priority with the Up/Down arrows in the top right (assuming you have more than 1 route).
- You're all set on this server. Use the configs above for iaxhost2 and you are done.
Both servers should now be able to dial each other's extensions as provided in this example.
Notes:
- Asterisk@Home's AMP has a really nifty feature for Dial Patterns. Try out the Insert dropdown and select Lookup Local Prefixes. Now enter a local prefix in your area. You'll see all of the local dialing possibilities!
Return values in channel variables
- For PRI connections over a ZAP channel, as well as IAX2 channels, the hangup result code will be found the HANGUPCAUSE variable.
- Note that causecode 0 is effectively a notice that the causecode has not been set. Causecode 16 is not an error, but simply a notice that the call went through and was terminated normally.
- For all channels, the DIALSTATUS variable contains the result of the call, which may be used for dial plan logic
- The variables DIALEDTIME and ANSWEREDTIME contains timing for billing (as in CDR records)
Version comments
- Option A and S: added to CVS after release 0.7.2
- Option D: in CVS since May 2004
- Option f: added to CVS in June/July 2004
- Variables DIALSTATUS, ANSWEREDTIME and DIALEDTIME: added to CVS head in june 2004
Support for specific hardware
- Set variable ALERT_INFO to change ring cadence on Cisco 79xx phones. See also MySQL custom ringtones
- Phones running the SCCP (skinny) firmware have some support for pushing XML pages. If you want to test it, set the variable VXML_URL to point to a Cisco XML file on a web server.
- For distinctive ringing on Cisco Ata, see Asterisk phone cisco ATA18x
See also
- Asterisk Visual Dialplan, visual development platform for Asterisk dialplan development
- Asterisk cmd RetryDial
- Asterisk cmd FollowMe
- Asterisk auto-dial out
- For a Least Cost (and Failsafe) Dial Command see Application LCDial
- Configuration
- The Dialplan - extensions.conf
Asterisk | Applications | Functions | Variables | Expressions | Asterisk FAQ


Comments
333Ignore forward
333Ignore forward
exten => 9999,1,Dial(SIP/600&SIP/601,10,i)
exten => 9999,2,Dial(SIP/600&SIP/601&SIP/603&SIP/605&SIP/607,120,i)
333Sorry, I uploaded previous comment twice
333Option C doesn't act like NoCDR()
I was trying to limit the length of an incoming call, so I decided to Dial a Local Channel (to use option L) after some initial checking.
I wasn't needing a new CDR, as the one of the original call was OK, so I tried using this 'C' option. It doesn't act like a NoCDR() statement, probably it will 'reset' the CDR (but I haven't tested it).
So, I created a new subcontext ad-hoc and I Dial to it.
Just remember that all channel variables set before the Dial must begin with '_' (or '__') to allow its values to be inherited by the dialed context.
example:
default
...
exten => _X.,n,Dial(Local/${EXTEN}@default-dialed,20,L(??:??:??))
default-dialed
exten => _X.,1,Answer()
exten => _X.,n,NoCDR()
exten => _X.,n,Goto(whatever your app really start)
333Use g options with S() or L() within Dial
333Infinite timeout?
333Dial a 1-digit extension AFTER answered??
No worries about which caller can do it in this application, the doorphone has no pad (but a pocket tonedialer would be a bad thing). But could the tones also be only audible on the tone-dialer's channel's side?
If this is can even be done...
333outbound call, send/receive information from caller/callee
The first thing that I tried was to use the macro options parameter M(x) that is available from the Dial() application command. In this setup, I both dial the outbound number and call the macro from the Dial() command. The line in the dial plan looks something like:
exten => s,1,Dial(${MyConnectionString}/${MyPhoneNumber}||M(MyMacro))
Whenever I run a macro, there is silence on both ends of the line until the macro exits. I would have expected (and liked) the macro to run in the background while the caller and the callee continued their conversation.
The second thing that I attempted was to connect the caller and the callee in a MeetMe conference and run an agi script in the background. In order to connect the caller and the callee in a MeetMe conference, I transferred them both to a new extension after executing the Dial() application command, and from that extension sent them both to the same MeetMe conference room. The caller and the callee were transferred to a new extension using the G(context|exten|priority) options parameter available from the Dial() application command. The line in the dial plan looks something like:
exten => s,1,Set(MEETME_AGI_BACKGROUND=/etc/asterisk/conference.agi|g)
exten => s,2,Dial(${MyConnectionString}/${MyPhoneNumber}||G(SetupMeetMeConference|s|1))
........
SetupMeetMeConference
exten => s,1,MeetMe(1|b)
exten => s,2,MeetMe(1) ; this line is to take care of a bug that sends the callee to this extension
Whenever I attempt to run the AGI script in the background, there is silence on both ends of the line until the AGI script exits. I know that both callers are being transferred to the same MeetMe conference because if I remove the AGI script options parameter b, then I hear the announcement "You are the only one in this conference room" after which I can have a normal conversation with the person I am trying to call.
I was going to make another attempt using the AGI() application command, but I saw this statement
"If the AGI application dials outward, the script returns execution to the dial plan and loses contact with the asterisk server."
on the voip-info wiki (http://www.voip-info.org/wiki/index.php?page=Asterisk+AGI).
If you have any suggestions on how I can make this work, please contact me.
Regards,
Dave
333"connect" signal and 2 outgoing calls bridging
(this feature uses for “callback� services, and, for example, cellular operators use this feature to announce that subscriber you calling to is unavailable). Is it possible in Asterisk? In Dial command description I didn’t find any information about it.
Another question I interested in is bridging of 2 outgoing calls, Jay McGrath tried to do this using G() option of Dial command (Jay McGrath on Monday 23 of January, 2006 04:46:38). Dear Jay McGrath, if you have solved this, please let me know how.
Thanks in advance
333"g" option doesn't work properly