`

Asterisk拨号函数Dial()详解

 
阅读更多

Asterisk的拨号函数/命令是Dial,下面就介绍一下这个函数的用法。 
Dial() 
摘要 
在一个通道上发起一个新的外拨呼叫,然后把它连接到当前通道上。 
语法 
                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]]])  
        说明: 
                同时外呼所有指定的通道,第一个应答的通道将占用,其他通道挂机,然后触发Dial命令的通道被应答(Answered),按照需要把两条通道连接起来。触发Dial命令的通道挂机后,将退出Dial命令。 
                在成功连接两个通道后,如果Dial函数的参数里有g 和 G,那么不会继续执行余下的流程。如果连接失败,那么可以跳转到下一个流程,或j参数指定的节点。 
参数说明 
        可选参数部分,即上述语法里的options,可以是空,或者是下面这些参数或标志: 
                A(x): Play an announcement (x.gsm) to the called party. 
                C: Reset the CDR (Call Detail Record) for this call. This is like using the NoCDR command 
                c: Sets the channel driver flag that the "call is answered elsewhere" if Dial() cancels the call 
                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). You can also provide digits after a colon - all digits before the colon are sent to the called channel, all digits after the colon are sent to the calling channel (all digits are sent to the called channel if there is no colon present). 
                d: This flag trumps the 'H' flag and intercepts any single DTMF tone while waiting for the call to be answered and jumps to that extension if it exists. This allows you to dial a 1-digit exit extension while waiting for the call to be answered - see also RetryDial. This uses the current context unless ${EXITCONTEXT} is defined. 
                e: Execute "h" as the peer when this call ends 
                F(context^exten^pri): When the caller hangs up, transfer the called party to the specified context and extension and continue execution. 
                f: forces callerid to be set based on a dialplan "hint" for the current channel. For example, some PSTNs don't allow callerids from other extensions than the ones that are assigned to you. 
                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). You cannot use any options that would affect the post-answer state if this option is used. 
                g: When the called party hangs up, continue to execute commands in the current context at the next priority. 
                H: Allow the caller to hang up by dialing * 
                h: Allow the callee 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. 
                j: Asterisk 1.2 and later (1.6???): Jump to priority n+101 if all of the requested channels were busy (just like behaviour in Asterisk 1.0.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) 
                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) 
                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. Numbers must be integers- beware of AGI scripts that may return long integers in scientific notation (esp PHP 5.2.5&6) 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"). 
                M(x): Executes the macro (x) upon connect of the call (i.e. when the called party answers). See also U. 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). The macro can set ${MACRO_RESULT} to the following: 
ABORT: Hang up both legs 
CONGESTION: Signal congestion to the caller 
BUSY: Signal busy to the caller 
CONTINUE: Hangup the called party but continue execution at the next priority in the dialplan for the caller 
GOTO: Transfer the execution to context^exten^pri 
                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: Modifies the privacy manager - turns off call screening if caller ID information is present 
                n(delete): (Asterisk 1.6) If delete is 0 or not specified, delete the privacy manager introduction if the caller hangs up before the call is answered. If set to 1, delete the recording even if the call is answered. 
                O(mode): If mode is set to 1 or isn't specified, ringback immediately if the originator hangs up. If mode is set to 2, ring back when the operator flashes the trunk. This is only valid when the caller and called channels are DAHDIchannels. It is intended for calling an operator station. 
                o: Restore the Asterisk v1.0 CallerId behaviour (send the original caller's ID) in Asterisk v1.2 (default: send this extension's number) 
                P(x): Use the PrivacyManager, using x as the database (x is optional and will default to the current extension) 
                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. 
                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. 
                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. Look at Progress(), the progressinband setting in sip.conf or Ringing() if you would like to avoid the use of 'r' but have issues with the ringback behaviour of Dial(). 
                S(n): Hangup the call n seconds AFTER called party picks up. 
                T: Allow the calling user to transfer the call by hitting the blind xfer keys (features.conf). Does not affect transfers initiated through other methods. 
If you have set the variable GOTO_ON_BLINDXFR then the transferrer will be sent to the context|exten|pri (you can use ^ to represent | to avoid escapes), example: SetVar(GOTO_ON_BLINDXFR=woohoo^s^1); works with both t and T 
                t: Allow the called user to transfer the call by hitting the blind xfer keys (features.conf) Does not affect transfers initiated through other methods. 
If you have set the variable GOTO_ON_BLINDXFR then the transferrer will be sent to the context|exten|pri (you can use ^ to represent | to avoid escapes), example: SetVar(GOTO_ON_BLINDXFR=woohoo^s^1); works with both t and T 
                U(x): Executes, via gosub, routine x on the called channel. This is similar to M above, but a gosub rather than a macro. The subroutine can set ${GOSUB_RESULT}__ to the following: 
ABORT: Hang up both legs 
CONGESTION: Signal congestion to the caller 
BUSY: Signal busy to the caller 
CONTINUE: Hangup the called party but continue execution at the next priority in the dialplan for the caller 
GOTO: Transfer the execution to context^exten^pri 
                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) 
                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) 
                X: Allow the calling user to start recording using automixer after pressing *1 or what defined in features.conf (Asterisk v1.6) 
                x: Allow the called user to start recording using automixer after pressing *1 or what defined in features.conf (Asterisk v1.6) 
 
例子 
        Example 1: 简单的例子 

复制代码
  1. exten => 1265,1,Dial(Phone/phone0,15)
  2. exten => s,3,Dial(SIP/oej,20)
  3. exten => _908.,1,Dial(Modem/ttyI0:${EXTEN:1})
  4. exten => 233,1,Dial(SIP/4029&SIP/4027&Zap/4&IAX/jaz,15,tTr)
  5. exten => 500,1,Dial(Zap/2r2,20,crh)
  6. exten => 20,1,Dial(Zap/3/5551234)

 
 
Dial macros 
        Dial(Zap/1|60|M(mymacro^cat^dog^bark)) 
     Example 2: Dial macro  

复制代码
  1. ;语音文件
  2. ;screen-record: Please record your name press pound when finished.
  3. ;screen-from: You have a call from
  4. ;screen-accept: Press 1 to accept this call or any other key to reject.
  5. exten => 890,1,Wait(0.2)
  6. exten => 890,n,Playback(screen-record)
  7. exten => 890,n,SetVar(SCREEN_FILE=/tmp/${CALLERID(number)}-${EPOCH})
  8. exten => 890,n,Record(${SCREEN_FILE}.gsm|6|25)
  9. exten => 890,n,Dial(SIP/16|60|gM(screen^${SCREEN_FILE}))
  10. exten => 890,n,Voicemail(10@default)
  11. [macro-screen]
  12. exten => s,1,Wait(0.2)
  13. exten => s,n,Playback(screen-from)
  14. exten => s,n,Playback(${ARG1})
  15. exten => s,n,Read(ACCEPT|screen-accept|1)
  16. exten => s,n,GotoIf($[${ACCEPT} = 1 ] ?yes:no)
  17. exten => s,n(yes),SetVar(MACRO_RESULT=CONTINUE)
  18. 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 Progress() before calling Dial() if you want asterisk to go in-band (in order to use playtones configured in indications.conf etc.). In some cases you may have to use Answer(), but that is to be avoided because it "charges", prevents auto-redial, 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 
 
 

复制代码
  1. ;Idea: Make a special extension where you could provide the delay and the numbers you want to dial, for example:
  2. exten => _900XXXXX,1,Wait(${EXTEN:3:2})
  3. ;exten => _900XXXXX,2,Dial(SIP/${EXTEN:5})
  4. ;Then in the incoming context you could use the Local channel construct and dial:
  5. 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.  

复制代码
  1. [from-iax-fwd]
  2. exten => night-mode,1,WaitForRing(30)
  3. exten => night-mode,n,Goto(s|night-mode-start)
  4. exten => ${FWD-HOME-NUMBER},1,Set(INVALID-PRIVACY-TRIES=0) ; used for determining number of invalid tries used during privacymanager.
  5. exten => ${FWD-HOME-NUMBER},n,Set(TIMEOUT(response)=20)
  6. exten => ${FWD-HOME-NUMBER},n,Set(TIMEOUT(digit)=7)
  7. exten => ${FWD-HOME-NUMBER},n,SetMusicOnHold(default)
  8. exten => ${FWD-HOME-NUMBER},n,GotoIfTime(20:00-7:59|*|*|*?night-mode|1)
  9. exten => ${FWD-HOME-NUMBER},n,Answer
  10. exten => ${FWD-HOME-NUMBER},n,Wait(2)
  11. exten => ${FWD-HOME-NUMBER},n,Zapateller
  12. exten => ${FWD-HOME-NUMBER},n,Goto(skip-night-mode)
  13. exten => ${FWD-HOME-NUMBER},n(night-mode-start),Answer
  14. exten => ${FWD-HOME-NUMBER},n,Wait(2)
  15. exten => ${FWD-HOME-NUMBER},n(skip-night-mode),Playback(dsfr-hozian-residence) ; welcome the caller.
  16. exten => ${FWD-HOME-NUMBER},n,Playback(dsfr-greeting) ; welcome the caller.
  17. exten => ${FWD-HOME-NUMBER},n,NoOp(Pre Privacy Manager Number ${CALLERID})
  18. exten => ${FWD-HOME-NUMBER},n(privacy-manager),PrivacyManager
  19. exten => ${FWD-HOME-NUMBER},s+101,GotoIf($[${INVALID-PRIVACY-TRIES} = ${MAX-PRIVACY-TRIES}] ?i|1)
  20. exten => ${FWD-HOME-NUMBER},n,Playback(dsfr-privacy-invalid) ; explain that # is not valid and that 10 digits must be entered.
  21. exten => ${FWD-HOME-NUMBER},n,Set(INVALID-PRIVACY-TRIES=$[${INVALID-PRIVACY-TRIES} + 1])
  22. exten => ${FWD-HOME-NUMBER},n,Goto(privacy-manager)
  23. exten => ${FWD-HOME-NUMBER},privacy-manager+1,NoOp(Post Privacy Manager Number ${CALLERID})
  24. exten => ${FWD-HOME-NUMBER},n,LookupCIDName
  25. exten => ${FWD-HOME-NUMBER},n,NoOp(Post LookupCIDName ${CALLERID})
  26. exten => ${FWD-HOME-NUMBER},n,Playback(pls-rcrd-name-at-tone)
  27. exten => ${FWD-HOME-NUMBER},n,Playback(and-prs-pound-whn-finished)
  28. exten => ${FWD-HOME-NUMBER},n,Set(SCREEN-FILE=/var/lib/asterisk/tmp/${TIMESTAMP}-${CALLERIDNUM})
  29. exten => ${FWD-HOME-NUMBER},n,Record(${SCREEN-FILE}.gsm|${SILENCE-SECONDS}|${SCREEN-FILE-SECONDS})
  30. exten => ${FWD-HOME-NUMBER},n,Playback(this-call-may-be-monitored-or-recorded)
  31. exten => ${FWD-HOME-NUMBER},n,Playback(pls-hold-while-try)
  32. exten => ${FWD-HOME-NUMBER},n,Dial(${PHONE-1}|${INCOMING-RING-SECONDS}|gmM(from-iax-fwd-screen^${SCREEN-FILE}^${UNIQUEID}^${CALLERIDNUM}))
  33. exten => ${FWD-HOME-NUMBER},n,GotoIf($[${${UNIQUEID}} = 1] ?hangup) ; checks whether bypass voicemail option is set in macro-from-iax-fwd-screen.
  34. exten => ${FWD-HOME-NUMBER},n(from-iax-fwd-ivr),System(/bin/rm ${SCREEN-FILE}.gsm)
  35. exten => ${FWD-HOME-NUMBER},n,Goto(from-iax-fwd-ivr|s|1)
  36. exten => ${FWD-HOME-NUMBER},n(hangup),System(/bin/rm ${SCREEN-FILE}.gsm)
  37. exten => ${FWD-HOME-NUMBER},n,Hangup
  38. exten => i,1,System(/bin/rm ${SCREEN-FILE}.gsm)
  39. exten => i,n,Playback(call-terminated)
  40. exten => i,n,Playback(goodbye)
  41. exten => i,n,Hangup
  42. exten => t,1,System(/bin/rm ${SCREEN-FILE}.gsm)
  43. exten => t,n,Playback(call-terminated)
  44. exten => t,n,Playback(goodbye)
  45. exten => t,n,Hangup
  46. exten => h,1,System(/bin/rm ${SCREEN-FILE}.gsm)
  47. [macro-from-iax-fwd-screen]
  48. exten => s,1,Set(MACRO_RESULT=GOTO:from-iax-fwd^${FWD-HOME-NUMBER}^from-iax-fwd-ivr)
  49. exten => s,n,Set(TIMEOUT(response)=15)
  50. exten => s,n,Playback(call)
  51. exten => s,n,Playback(from)
  52. exten => s,n(repeat-screen),Playback(${ARG1})
  53. exten => s,n(repeat-options),Read(ACCEPT-CALL|dsfr-macro-from-iax-fwd-options|1)
  54. exten => s,n,GotoIf($["${ACCEPT-CALL}" = ""] ?t|1)
  55. exten => s,n,GotoIf($[${ACCEPT-CALL} = 1] ?call-accepted)
  56. exten => s,n,GotoIf($[${ACCEPT-CALL} = 5] ?repeat-screen)
  57. exten => s,n,GotoIf($[${ACCEPT-CALL} = 9] ?call-declined:repeat-options)
  58. exten => s,n(call-declined),Playback(dsfr-screen-declined) ; declined - caller will be sent to ivr.
  59. exten => s,n,GotoIf($[${MACRO_RESULT} = GOTO:from-iax-fwd^${FWD-HOME-NUMBER}^from-iax-fwd-ivr] ?skip-monitor)
  60. exten => s,n(call-accepted),Playback(dsfr-screen-accepted) ; accepted - call will be bridged momentarily.
  61. exten => s,n,Set(MACRO_RESULT=)
  62. exten => s,n,Set(${ARG2}=1|g) ; if set to 1 then bypass voicemail.
  63. exten => s,n,Playback(this-call-may-be-monitored-or-recorded)
  64. exten => s,n,Monitor(wav49|${TIMESTAMP}-${ARG3}|mb)
  65. exten => s,n(skip-monitor),NoOp
  66. exten => t,1,Playback(connection-timed-out)
  67. exten => t,n,Goto(s|call-declined)
  68. [from-iax-fwd-ivr]
  69. exten => s,1,Set(INVALID-IVR-TRIES=0) ; used for determining number of invalid tries used during ivr.
  70. exten => s,n,Set(RETRIES-FWD-WORK=0) ; used for determining number of retry attempts when calling fwd home.
  71. exten => s,n,Set(RETRIES-WEATHER-SERVICE=0) ; used for determing number of retry attempts when checking weather service.
  72. exten => s,n,Set(RETRIES-VOICEMAIL=0) ; used for determing number of retry attempts when checking voicemail.
  73. exten => s,n,Set(TIMEOUT(response)=20)
  74. exten => s,n,Set(TIMEOUT(digit)=7)
  75. exten => s/1000,n,Background(dsfr-personalized-greeting-test1)
  76. exten => s/0123456789,s,Background(dsfr-personalized-greeting-test2)
  77. exten => s/123456789,s,Background(dsfr-personalized-greeting-test2)
  78. exten => s/0987654321,s,Background(dsfr-personalized-greeting-test3)
  79. exten => s/987654321,s,Background(dsfr-personalized-greeting-test3)
  80. exten => s,s,NoOp(This caller does not have a personalized greeting.)
  81. exten => s,n(ivr-options),Background(dsfr-from-iax-fwd-ivr) ; provide various ivr options excluding voicemail and admin-auth extensions.
  82. exten => s,n,WaitExten
  83. exten => 1,1,Voicemail(${PERSONAL-1-VMBOX}|u)
  84. exten => 2,1,Voicemail(${PERSONAL-2-VMBOX}|u)
  85. 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.
  86. exten => 3,n,SetCallerId(${FWD-HOME-CID})
  87. exten => 3,n,Monitor(wav49|${TIMESTAMP}-${CALLERIDNUM}-FWD-WORK|mb)
  88. exten => 3,n,Dial(IAX2/to-iax-fwd/${FWD-WORK-NUMBER}|${OUTGOING-RING-SECONDS}|rg)
  89. exten => 3,n,Macro(from-iax-fwd-ivr-retries|RETRIES-FWD-WORK)
  90. exten => 4,1,Playback(dsfr-weather-service) ; explain that there will be a pause while the Huntsville, AL weather information is downloaded.
  91. exten => 4,n,System(/usr/bin/curl -s ftp://weather.noaa.gov/data/forecasts/city/al/huntsville.txt > /var/lib/asterisk/tmp/weather.txt)
  92. exten => 4,n,System(/usr/bin/text2wave /var/lib/asterisk/tmp/weather.txt -F 8000 -o /var/lib/asterisk/tmp/weather.wav)
  93. exten => 4,n,Playback(/var/lib/asterisk/tmp/weather)
  94. exten => 4,n,Macro(from-iax-fwd-ivr-retries|RETRIES-WEATHER-SERVICE)
  95. exten => 9,1,Playback(dsfr-emergency-phone-info) ; explain that emergency phone will ring for 90 seconds then come back to ivr.
  96. exten => 9,n,Monitor(wav49|${TIMESTAMP}-${CALLERIDNUM}-EMERGENCY|mb)
  97. exten => 9,n,Dial(${PHONE-1}${EMERGENCY-RING-TONE}|${EMERGENCY-RING-SECONDS}|r)
  98. exten => 9,n,Goto(s|ivr-options)
  99. exten => 8500,1,VoicemailMain
  100. exten => 8500,n,Macro(from-iax-fwd-ivr-retries|RETRIES-VOICEMAIL)
  101. exten => i,1,GotoIf($[${INVALID-IVR-TRIES} = ${MAX-IVR-INVALID-TRIES}] ?from-iax-fwd|i|1)
  102. exten => i,n,Playback(invalid)
  103. exten => i,n,Set(INVALID-IVR-TRIES=$[${INVALID-IVR-TRIES} + 1])
  104. exten => i,n,Goto(s|ivr-options)
  105. exten => t,1,Goto(from-iax-fwd|t|1)
  106. exten => h,1,Goto(from-iax-fwd|h|1)
  107. [macro-from-iax-fwd-ivr-retries]
  108. exten => s,1,GotoIf($[${${ARG1}} = ${MAX-IVR-RETRIES}] ?from-iax-fwd|i|1)
  109. exten => s,n,Set(${ARG1}=$[${${ARG1}} + 1])
  110. 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.  
 

复制代码
  1. exten => 4000,1,Dial(SIP/${EXTEN},15)
  2. exten => 4000,2,Voicemail(u${EXTEN})
  3. exten => 4000,102,Voicemail(b${EXTEN})
  4. 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:  

复制代码
  1. [value1]
  2. type=friend
  3. secret=value2 ; <-- VERY important with friend types to get this to work properly
  4. auth=plaintext
  5. host=172.16.5.1 ; Example private address space
  6. context=iaxhost2-in ; Always nice to be able to control access rights.
  7. qualify=yes ; Optional, but usually a good idea.
  8. ... ; Whatever else you want including allow/disallow for codecs.
  9. Excerpt from iaxhost2's iax.conf:
  10. [value3]
  11. type=friend
  12. secret=value4 ; <-- VERY important with friend types to get this to work properly
  13. auth=plaintext
  14. host=172.16.5.2 ; Example private address space
  15. context=iaxhost1-in ; Always nice to be able to control access rights.
  16. qualify=yes ; Optional, but usually a good idea.
  17. ... ; Whatever else you want including allow/disallow for codecs.

 
Excerpt from iaxhost1's extensions.conf  

复制代码
  1. [default]
  2. ...
  3. include => iaxhost1-out ; Always a good idea to seperate contexts
  4. ...
  5. [iaxhost2-in]
  6. exten => 99104,1,DateTime() ; DateTime() is always good for testing
  7. exten => 98104,1,NoOp(${EXTEN})
  8. exten => 98104,2,DateTime() ; DateTime() is always good for testing
  9. [iaxhost1-out]
  10. exten => 99205,1,Dial(IAX2/value3:value4@value1/99105)
  11. ; A more complicated extension example:
  12. exten => 982XX,1,Dial(IAX2/value3:value4@value1/991${EXTEN:3})

 
Excerpt from iaxhost2's extensions.conf  

复制代码
  1. [default]
  2. ...
  3. include => iaxhost2-out ; Always a good idea to seperate contexts
  4. ...
  5. [iaxhost1-in]
  6. exten => 99105,1,DateTime() ; DateTime() is always good for testing
  7. exten => 98105,1,NoOp(${EXTEN})
  8. exten => 98105,2,DateTime() ; DateTime() is always good for testing
  9. [iaxhost2-out]
  10. exten => 99204,1,Dial(IAX2/value1/99104)
  11. ; A more complicated extension example:
  12. exten => 982XX,1,Dial(IAX2/value1/991${EXTEN:3})

 
 
Dial() together with openining Jack ports for callee 
 

复制代码
  1. ;Nescesarry if you want to "capture" a record in leg B with SoundPatty
  2. exten => _X.,n,Dial(SIP/$PROVIDER/${EXTEN},60,M(connect-jack)
  3. [macro-connect-jack]
  4. exten => s,1,NoOp(${CHANNEL}) ; This is leg A, skip
  5. exten => s,2,Set(JACK_HOOK(manipulate,i(${CHANNEL}:input),o(${CHANNEL}:output))=on)

 
Note: only for asterisk 1.6.x  
 
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 types, except LOCAL, 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 
 
Dial with A(x&y&z) multiple playback files 
 
Diff file its a copy/paste from app_playback.c in Asterisk-1.6.1.2 
 
复制代码

  1.  
    1. --- app_dial.c    2009-03-19 17:33:19.000000000 -0300
    2. +++ /app_dial.c    2009-09-23 16:40:00.000000000 -0300
    3. @@ -1706,4 +1706,18 @@ static int dial_exec_full(struct ast_cha
    4. /* Now Stream the File */
    5. -     if (!res)
    6. -     res = ast_streamfile(peer, opt_args[OPT_ARG_ANNOUNCE], peer->language);
    7. +     if (!res){
    8. +     char *front;
    9. +     char *args= opt_args[OPT_ARG_ANNOUNCE];
    10. +     ast_log(LOG_INFO, "Dial Annoucement String: %s\n",opt_args[OPT_ARG_ANNOUNCE]);
    11. +     while(front = strsep(&args, "&")){
    12. +     res = ast_streamfile(peer, front, peer->language);
    13. + if (!res) {
    14. + res = ast_waitstream(peer, "");
    15. + ast_stopstream(peer);
    16. + } else {
    17. + ast_log(LOG_INFO, "ast_streamfile failed on %s\n", chan->name);
    18. + res = 0;
    19. +     }
    20. +     ast_log(LOG_WARNING, "Stream File %s\n",front);
    21. +     }
    22. +     }
    23. if (!res) {

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics