;!
;! Automatically generated configuration file
;! Filename: extensions.conf (/etc/asterisk/extensions_macro.conf)
;! Generator: Manager
;! Creation Date: Mon Mar 18 04:12:42 2013
;!
[macro-dundi-e164]
;
; ARG1 is the extension to Dial
;
; Extension "s" is not a wildcard extension that matches "anything".
; In macros, it is the start extension. In most other cases, 
; you have to goto "s" to execute that extension.
;
; For wildcard matches, see above - all pattern matches start with
; an underscore.
exten => s,1,Goto(${ARG1},1)
include => dundi-e164-lookup

;
; Here are the entries you need to participate in the IAXTEL
; call routing system.  Most IAXTEL numbers begin with 1-700, but
; there are exceptions.  For more information, and to sign
; up, please go to www.gnophone.com or www.iaxtel.com
;
[macro-trunkdial]
;
; Standard trunk dial macro (hangs up on a dialstatus that should 
; terminate call)
;   ${ARG1} - What to dial
;
exten => s,1,Dial(${ARG1})
exten => s,n,Goto(s-${DIALSTATUS},1)
exten => s-NOANSWER,1,Hangup
exten => s-BUSY,1,Hangup
exten => _s-.,1,NoOp

[stdexten]
;
; Standard extension subroutine:
;   ${EXTEN} - Extension
;   ${ARG1} - Device(s) to ring
;   ${ARG2} - Optional context in Voicemail (if empty, then "default")
;
; Note that the current version will drop through to the next priority in the
; case of their pressing '#'.  This gives more flexibility in what do to next:
; you can prompt for a new extension, or drop the call, or send them to a
; general delivery mailbox, or...
;
; The use of the LOCAL() function is purely for convenience.  Any variable
; initially declared as LOCAL() will disappear when the innermost Gosub context
; in which it was declared returns.  Note also that you can declare a LOCAL()
; variable on top of an existing variable, and its value will revert to its
; previous value (before being declared as LOCAL()) upon Return.
;
exten => _X.,50000(stdexten),NoOp(Start stdexten)
exten => _X.,n,Set(LOCAL(ext)=${EXTEN})
exten => _X.,n,Set(LOCAL(dev)=${ARG1})
exten => _X.,n,Set(LOCAL(cntx)=${ARG2})

exten => _X.,n,Set(LOCAL(mbx)="${ext}"$["${cntx}" ? "@${cntx}" :: ""])
exten => _X.,n,Dial(${dev},20)  ; Ring the interface, 20 seconds maximum
exten => _X.,n,Goto(stdexten-${DIALSTATUS},1)  ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => stdexten-NOANSWER,1,Voicemail(${mbx},u)  ; If unavailable, send to voicemail w/ unavail announce
exten => stdexten-NOANSWER,n,NoOp(Finish stdexten NOANSWER)
exten => stdexten-NOANSWER,n,Return()  ; If they press #, return to start

exten => stdexten-BUSY,1,Voicemail(${mbx},b)
; If busy, send to voicemail w/ busy announce
exten => stdexten-BUSY,n,NoOp(Finish stdexten BUSY)
exten => stdexten-BUSY,n,Return()  ; If they press #, return to start

exten => _stdexten-.,1,Goto(stdexten-NOANSWER,1)  ; Treat anything else as no answer

exten => a,1,VoicemailMain(${mbx})  ; If they press *, send the user into VoicemailMain
exten => a,n,Return()

[stdPrivacyexten]
;
; Standard extension subroutine:
;   ${ARG1} - Extension
;   ${ARG2} - Device(s) to ring
;   ${ARG3} - Optional DONTCALL context name to jump to (assumes the s,1 extension-priority)
;   ${ARG4} - Optional TORTURE context name to jump to (assumes the s,1 extension-priority)`
;   ${ARG5} - Context in voicemail (if empty, then "default")
;
; See above note in stdexten about priority handling on exit.
;
exten => _X.,60000(stdPrivacyexten),NoOp(Start stdPrivacyexten)
exten => _X.,n,Set(LOCAL(ext)=${ARG1})
exten => _X.,n,Set(LOCAL(dev)=${ARG2})
exten => _X.,n,Set(LOCAL(dontcntx)=${ARG3})
exten => _X.,n,Set(LOCAL(tortcntx)=${ARG4})
exten => _X.,n,Set(LOCAL(cntx)=${ARG5})

exten => _X.,n,Set(LOCAL(mbx)="${ext}"$["${cntx}" ? "@${cntx}" :: ""])
exten => _X.,n,Dial(${dev},20,p)  ; Ring the interface, 20 seconds maximum, call screening 
; option (or use P for databased call _X.creening)
exten => _X.,n,Goto(stdexten-${DIALSTATUS},1)  ; Jump based on status (NOANSWER,BUSY,CHANUNAVAIL,CONGESTION,ANSWER)

exten => stdexten-NOANSWER,1,Voicemail(${mbx},u)  ; If unavailable, send to voicemail w/ unavail announce
exten => stdexten-NOANSWER,n,NoOp(Finish stdPrivacyexten NOANSWER)
exten => stdexten-NOANSWER,n,Return()  ; If they press #, return to start

exten => stdexten-BUSY,1,Voicemail(${mbx},b)  ; If busy, send to voicemail w/ busy announce
exten => stdexten-BUSY,n,NoOp(Finish stdPrivacyexten BUSY)
exten => stdexten-BUSY,n,Return()  ; If they press #, return to start

exten => stdexten-DONTCALL,1,Goto(${dontcntx},s,1)  ; Callee chose to send this call to a polite "Don't call again" script.

exten => stdexten-TORTURE,1,Goto(${tortcntx},s,1)  ; Callee chose to send this call to a telemarketer torture script.

exten => _stdexten-.,1,Goto(stdexten-NOANSWER,1)  ; Treat anything else as no answer

exten => a,1,VoicemailMain(${mbx})  ; If they press *, send the user into VoicemailMain
exten => a,n,Return

[macro-page];
;
; Paging macro:
;
;       Check to see if SIP device is in use and DO NOT PAGE if they are
;
;   ${ARG1} - Device to page

exten => s,1,ChanIsAvail(${ARG1},s)  ; s is for ANY call
exten => s,n,GoToIf([${AVAILSTATUS} = "1"]?autoanswer:fail)
exten => s,n(autoanswer),Set(_ALERT_INFO="RA")  ; This is for the PolyComs
exten => s,n,SIPAddHeader(Call-Info: Answer-After=0)  ; This is for the Grandstream, Snoms, and Others
exten => s,n,NoOp()  ; Add others here and Post on the Wiki!!!!
exten => s,n,Dial(${ARG1})
exten => s,n(fail),Hangup

[page]
exten => _X.,1,Macro(page,SIP/${EXTEN})

[mainmenu]
;
; Example "main menu" context with submenu
;
exten => s,1,Answer
exten => s,n,Background(thanks)  ; "Thanks for calling press 1 for sales, 2 for support, ..."
exten => s,n,WaitExten
exten => 1,1,Goto(submenu,s,1)
exten => 2,1,Hangup
include => default
;
[submenu]
exten => s,1,Ringing  ; Make them comfortable with 2 seconds of ringback
exten => s,n,Wait,2
exten => s,n,Background(submenuopts)  ; "Thanks for calling the sales department.  Press 1 for steve, 2 for..."
exten => s,n,WaitExten
exten => 1,1,Goto(default,steve,1)
exten => 2,1,Goto(default,mark,2)


[macro-phone]
exten => s,1,Dial(SIP/${MACRO_EXTEN}&IAX2/${MACRO_EXTEN},25)
exten => s,n,Goto(${DIALSTATUS},1)
exten => ANSWER,1,Hangup
exten => CANCEL,1,Hangup
exten => NOANSWER,1,Voicemail(${MACRO_EXTEN}@default,u)
exten => BUSY,1,Voicemail(${MACRO_EXTEN}@default,b)
exten => CONGESTION,1,Voicemail(${MACRO_EXTEN}@default,b)
exten => CHANUNAVAIL,1,Voicemail(${MACRO_EXTEN}@default,u)
exten => a,1,VoicemailMain(${MACRO_EXTEN}@default)

[macro-pagingintercom]
exten = s,1,SIPAddHeader(Alert-Info: ${PAGING_HEADER})
exten = s,2,Page(${ARG1},${ARG2})
exten = s,3,Hangup


[macro-stsdialresult]
; **** this is not complete - but a good start ****
;       603 Refused - hangup
;       404 Failed, Invalid user, no skype credit (Can't tell the difference) - hangup
;       408 UNPLACED whatever that means, try next channel
;       600 Busy - hangup
;       403 Anything else - hangup

;ISUP Cause value                        SIP response
;  ----------------                        ------------
;  1  unallocated number                   404 Not Found
;  2  no route to network                  404 Not found
;  3  no route to destination              404 Not found
;  16 normal call clearing                 --- (*)
;  17 user busy                            486 Busy here
;  18 no user responding                   408 Request Timeout
;  19 no answer from the user              480 Temporarily unavailable
;  20 subscriber absent                    480 Temporarily unavailable
;  21 call rejected                        403 Forbidden (+)
;  22 number changed (w/o diagnostic)      410 Gone
;  22 number changed (w/ diagnostic)       301 Moved Permanently
;  23 redirection to new destination       410 Gone
;  26 non-selected user clearing           404 Not Found (=)
;  27 destination out of order             502 Bad Gateway
;  28 address incomplete                   484 Address incomplete
;  29 facility rejected                    501 Not implemented
;  31 normal unspecified                   480 Temporarily unavailable
exten => s,1,NoOp(HANGUPCAUSE is ${HANGUPCAUSE} and DIALSTATUS is ${DIALSTATUS})
exten => s,2(debug1),Verbose(1,debug1 "${HANGUPCAUSE}:${DIALSTATUS}")
exten => s,3,Set(TIMEOUT(absolute)=120)
exten => s,4,GotoIf($[${HANGUPCAUSE} = 0]?s,6)
exten => s,5,Goto(cause-${HANGUPCAUSE},1)
exten => s,6,GotoIf($[${DIALSTATUS} = NOANSWER]?cause-19,1)
exten => s,7,GotoIf($[${DIALSTATUS} = BUSY]?cause-2,1)
exten => s,8,GotoIf($[${DIALSTATUS} = CHANUNAVAIL]?cause-0,1)
exten => s,9,GotoIf($[${DIALSTATUS} = ANSWER]?exit-1,1)
exten => s,10,Goto(cause-0,1)

exten => cause-0,1,NoOp(AST_CAUSE_NOTDEFINED)
exten => cause-0,n,Verbose(1,debug "cause-0")
exten => cause-0,n,Playback(error)
;exten => cause-0,n,Congestion
exten => cause-0,n,Goto(exit-1,1)

exten => cause-1,1,NoOp(AST_CAUSE_FAILURE)
exten => cause-1,n,Verbose(1,debug "cause-1 invalid destination")
exten => cause-1,n,Playback(invalid)
exten => cause-1,n,Hangup

exten => cause-2,1,NoOp(AST_CAUSE_BUSY)
exten => cause-2,n,Verbose(1,debug "cause-2 busy")
exten => cause-2,n,Busy

exten => cause-3,1,NoOp(AST_CAUSE_FAILURE)
exten => cause-3,n,Verbose(1,debug "cause-3")
;exten => cause-3,n,Playback(error)
exten => cause-3,n,Goto(exit-1,1)

exten => cause-4,1,NoOp(AST_CAUSE_CONGESTION)
exten => cause-4,n,Verbose(1,debug "cause-4")
exten => cause-4,n,Goto(exit-1,1)

exten => cause-5,1,NoOp(AST_CAUSE_UNALLOCATED)
exten => cause-5,n,Verbose(1,debug "cause-5 invalid destination")
exten => cause-5,n,Playback(invalid)
exten => cause-5,n,Hangup

exten => cause-18,1,NoOp(AST_CAUSE_CALL_UNPLACED)
exten => cause-18,n,Verbose(1,debug "cause-18 unplaced")
exten => cause-18,n,Goto(exit-1,1)

exten => cause-19,1,NoOp(AST_CAUSE_NO_ANSWER)
exten => cause-19,n,Verbose(1,debug "cause-19 noanswer")
exten => cause-19,n,Playback(noanswer)
exten => cause-19,n,Hangup

exten => cause-21,1,NoOp(AST_CAUSE_CALL_REJECTED)
exten => cause-21,n,Verbose(1,debug "cause-21 rejected")
exten => cause-21,n,Playback(rejected)
exten => cause-21,n,Hangup

exten => _cause-X,1,NoOp(UNKNOWN_CAUSECODE)
exten => _cause-X,n,Verbose(1,debug "cause-X")
exten => _cause-X,n,Playback(error)
;exten => _cause-X,n,Congestion
exten => _cause-X,n,Goto(exit-1,1)

exten => exit,1(exit),Noop

[custom-wakeup]
exten => *62,1,agi(wakeup.php)
exten => *62,n,Hangup

[macro-senddigits]
exten => s,1,Wait(10)  ; wait 5 second
exten => s,n,SendDTMF(${hkno})  ; send the number

[macro-senddigits1]
exten => s,1,Wait(10)  ; wait 5 second
exten => s,n,SendDTMF(${hkno})  ; send the number

[macro-nomusic]
exten => s,1,NoOp(Turn off MOH for this channel)
exten => s,2,SetMusicOnHold(none)


[queue-member-manager]
exten = handle_member,1,Verbose(2, Looping through queues to log in or out queue members)
exten = handle_member,n,Set(thisActiveMember=${CHANNEL(channeltype)}/${CHANNEL(peername)})
exten = handle_member,n,Set(queue_field=1)
exten = handle_member,n,Set(thisQueueXtn=${CUT(QUEUES,\,,${queue_field})})
exten = handle_member,n,While($[${EXISTS(${thisQueueXtn})}])
exten = handle_member,n,Macro(member-loginlogout)
exten = handle_member,n,Set(queue_field=$[${queue_field} + 1])
exten = handle_member,n,Set(thisQueueXtn=${CUT(QUEUES,\,,${queue_field})})
exten = handle_member,n,EndWhile()

[macro-member-loginlogout]
exten = s,1,Verbose(2, Logging queue member in or out of the request queue)
exten = s,n,Set(thisQueue=${thisQueueXtn})
exten = s,n,Set(queueMembers=${QUEUE_MEMBER_LIST(${thisQueue})})
exten = s,n,MacroIf("${queueMembers}" = ""]?q_login)
exten = s,n,Set(field=1)
exten = s,n,Set(logged_in=0)
exten = s,n,Set(thisQueueMember=${CUT(queueMembers,\,,${field})})
exten = s,n,While($[${EXISTS(${thisQueueMember})}])
exten = s,n,GotoIf($["${thisQueueMember}" != "${thisActiveMember}"]?check_next)
exten = s,n,Set(logged_in=1)
exten = s,n,ExitWhile()
exten = s,n(check_next),Set(field=$[${field} + 1])
exten = s,n,Set(thisQueueMember=${CUT(queueMembers,\,,${field})})
exten = s,n,EndWhile()
exten = s,n,MacroIf($[${logged_in} = 0]?q_login:q_logout)

[macro-q_login]
exten = s,1,Verbose(2, Logging ${thisActiveMember} into the ${thisQueue} queue)
exten = s,n,AddQueueMember(${thisQueue},${thisActiveMember})
exten = s,n,Playback(silence/1)
exten = s,n,ExecIf($["${AQMSTATUS}" = "ADDED"]?Playback(agent-loginok):Playback(an-error-has-occurred))

[macro-q_logout]
exten = s,1,Verbose(2, Logged ${thisActiveMember} out of ${thisQueue} queue)
exten = s,n,RemoveQueueMember(${thisQueue},${thisActiveMember})
exten = s,n,Playback(silence/1)
exten = s,n,ExecIf($["${AQMSTATUS}" = "REMOVED"]?Playback(agent-loggedoff):Playback(an-error-has-occurred))

[macro-undefined]
exten = s,1,Set(CALLERID(all)=${IF($[${LEN(${ARG4})} > 2]?${ARG4}:)})
exten = s,n,Goto(${ARG1},${ARG2},${ARG3})

[macro-trunkdial-failover-record]
exten = s,1,Set(CALLERID(num)=${IF($[${LEN(${CID_${CALLERID(num)}})} > 2]?${CID_${CALLERID(num)}}:)})
exten = s,n,Set(TOUCH_MIXMONITOR=${ARG5}-${ARG6}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
exten = s,n,Set(TOUCH_MIXMONITOR_FORMAT=${RECORD_FORMAT})
exten = s,n,MixMonitor(${ARG5}-${ARG6}-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}.${RECORD_FORMAT}|b|)
exten = s,n,GotoIf($[${LEN(${CALLERID(num)})} > 6]?1-dial,1)
exten = s,n,Set(CALLERID(all)=${IF($[${LEN(${CID_${ARG3}})} > 6]?${CID_${ARG3}}:${GLOBAL_OUTBOUNDCID})})
exten = s,n,Goto(1-dial,1)
exten = 1-dial,1,Dial(${ARG1},${RINGTIMEOUTBOUND},${DIALOPTIONS})
exten = 1-dial,n,Gotoif(${LEN(${ARG2})} > 0 ?1-${DIALSTATUS},1:1-out,1)
exten = 1-CHANUNAVAIL,1,Dial(${ARG2})
exten = 1-CHANUNAVAIL,n,Hangup()
exten = 1-CONGESTION,1,Dial(${ARG2})
exten = 1-CONGESTION,n,Hangup()
exten = 1-NOANSWER,1,Dial(${ARG2})
exten = 1-NOANSWER,n,Hangup()
exten = 1-out,1,Hangup()

[macro-stdexten]
exten = s,1,Set(__DYNAMIC_FEATURES=${FEATURES})
exten = s,2,Set(ORIG_ARG1=${ARG1})
exten = s,3,GotoIf($["${FOLLOWME_${ARG1}}" = "1"]?6:4)
exten = s,4,Dial(${ARG2},${RINGTIME},${DIALOPTIONS})
exten = s,5,Goto(s-${DIALSTATUS},1)
exten = s,6,Macro(stdexten-followme,${ARG1},${ARG2})
exten = s-NOANSWER,1,Voicemail(${ORIG_ARG1},u)
exten = s-NOANSWER,2,Goto(default,s,1)
exten = s-BUSY,1,Voicemail(${ORIG_ARG1},b)
exten = s-BUSY,2,Goto(default,s,1)
exten = _s-.,1,Goto(s-NOANSWER,1)
exten = a,1,VoicemailMain(${ORIG_ARG1})
[macro-stdexten-followme]
exten = s,1,Answer
exten = s,2,Set(ORIG_ARG1=${ARG1})
exten = s,3,Dial(${ARG2},${RINGTIME},${DIALOPTIONS})
exten = s,4,Set(__FMCIDNUM=${CALLERID(num)})
exten = s,5,Set(__FMCIDNAME=${CALLERID(name)})
exten = s,6,Followme(${ORIG_ARG1},${FOLLOWMEOPTIONS})
exten = s,7,Voicemail(${ORIG_ARG1},u)
exten = s-NOANSWER,1,Voicemail(${ORIG_ARG1},u)
exten = s-BUSY,1,Voicemail(${ORIG_ARG1},b)
exten = s-BUSY,2,Goto(default,s,1)
exten = _s-.,1,Goto(s-NOANSWER,1)
exten = a,1,VoicemailMain(${ORIG_ARG1})

[macro-local-callingrule-cid-0.1]
exten = s,1,Set(CALLERID(all)=${IF($[${LEN(${ARG4})} > 2]?${ARG4}:)})
exten = s,n,Goto(${ARG1},${ARG2},${ARG3})

[macro-superdial]
; add some abilities to Dial(Technology/resource[&Technology2/resource2...][|timeout][|options][|URL]):
;       ${ARG1} - Technology/resource[&Technology2/resource2...] (like SIP/2201)
;       ${ARG2} - timeout in seconds
;       ${ARG3} - Dial command options
;       ${ARG4} - URL (see Dial command for info)
;       ${ARG5} - Group name (used if you want to limit the number of calls in any way)
;       ${ARG6} - Max. group number (maximum number of concurrent calls you want to allow for that group)
;       ${ARG7} - Caller ID name (typically for outgoing calls only)
;       ${ARG8} - Caller ID number (typically for outgoing calls only)
;       ${ARG9} - CDR account name (over-rides account group setting in sip.conf or iax.conf)
;       ${ARG10} - voicemail to send to if noanswer (typically for incoming calls only)
; Usage instructions:
;       for an outgoing call, in extensions.conf you just list multiple lines like:
;               exten => s,1,Macro(superdial,IAX2/voipjet/${tfnumber},,,,voip,${MAXVOIPCALLS},yourname,8005551234,voipjet)
;               exten => s,2,Macro(superdial,IAX2/alpeh-com/${tfnumber},,,,voip,${MAXVOIPCALLS},yourname,8005551234,aleph)
;       and it will take the first one that is available
;
;       it also works for incoming like so ..
;               exten => s,1,Wait(2)
;               exten => s,2,Macro(superdial,${PHONE1},15,Ttm,,pstn,${MAXPSTNCALLS},${CALLERIDNAME},${CALLERIDNUM},pstn,u${GENERALVM})
;               exten => s,3,Macro(superdial,${PHONE1},15,Ttm,,pstn,${MAXPSTNCALLS},${CALLERIDNAME},${CALLERIDNUM},pstn,u${GENERALVM})
;               exten => s,4,Voicemail(b${GENERALVM})
;       and then goes to unavailable voicemail if one times out .. otherwise (eg if busy) it tries the next extension
;       if all are busy or unavailable .. it gets to the last priority which is the busy voicemail
;
exten => s,1,Set(GROUP()=${ARG5})
exten => s,2,Set(GROUPCOUNT=${GROUP_COUNT(${ARG5})})
exten => s,3,GotoIf($[${GROUPCOUNT} > ${ARG6}]?104)
exten => s,4,GotoIf($["${ARG7}" = ""]?macro-superdial,s,6)
exten => s,5,Set(CALLERID(name)=${ARG7})  ; skip this if ARG7 is empty
exten => s,6,GotoIf($["${ARG8}" = ""]?macro-superdial,s,8)
exten => s,7,Set(CALLERID(number)=${ARG8})  ; skip this if ARG8 is empty
exten => s,8,GotoIf($["${ARG9}" = ""]?macro-superdial,s,10)
exten => s,9,SetAccount(${ARG9})  ; skip this if ARG9 is empty
exten => s,10,Dial(${ARG1},${ARG2},${ARG3},${ARG4})
exten => s,11,Goto(s-${DIALSTATUS},1)
exten => s,104,Goto(s-CHANUNAVAIL,1)
exten => s-BUSY,1,Noop
exten => s-NOANSWER,1,GotoIf($["${ARG10}" = ""]?macro-superdial,s-NOANSWER,3)
exten => s-NOANSWER,2,Voicemail(${ARG10})
exten => s-NOANSWER,3,Noop
exten => _s-.,1,Noop

[macro-trunkdial-failover-0.3]
exten = s,1,GotoIf($[${LEN(${FMCIDNUM})} > 6]?1-fmsetcid,1)
exten = s,n,GotoIf($[${LEN(${GLOBAL_OUTBOUNDCIDNAME})} > 1]?1-setgbobname,1)
exten = s,n,Set(CALLERID(num)=${IF($[${LEN(${CID_${CALLERID(num)}})} > 2]?${CID_${CALLERID(num)}}:)})
exten = s,n,Set(CALLERID(all)=${IF($[${LEN(${ARG5})} > 2]?${ARG5}:)})
exten = s,n,GotoIf($[${LEN(${CALLERID(num)})} > 6]?1-dial,1)
exten = s,n,Set(CALLERID(all)=${IF($[${LEN(${CID_${ARG3}})} > 6]?${CID_${ARG3}}:${GLOBAL_OUTBOUNDCID})})
exten = s,n,Set(CALLERID(all)=${IF($[${LEN(${ARG5})} > 2]?${ARG5}:)})
exten = s,n,Goto(1-dial,1)
exten = 1-setgbobname,1,Set(CALLERID(name)=${GLOBAL_OUTBOUNDCIDNAME})
exten = 1-setgbobname,n,Goto(s,3)
exten = 1-fmsetcid,1,Set(CALLERID(num)=${FMCIDNUM})
exten = 1-fmsetcid,n,Set(CALLERID(name)=${FMCIDNAME})
exten = 1-fmsetcid,n,Goto(s,4)
exten = 1-dial,1,Dial(${ARG1})
exten = 1-dial,n,Gotoif(${LEN(${ARG2})} > 0 ?1-${DIALSTATUS},1:1-out,1)
exten = 1-CHANUNAVAIL,1,Dial(${ARG2})
exten = 1-CHANUNAVAIL,n,Hangup()
exten = 1-CONGESTION,1,Dial(${ARG2})
exten = 1-CONGESTION,n,Hangup()
exten = 1-out,1,Hangup()


[macro-trunkdial-failover-0.3a]
exten = s,1, Set(GROUP()=OUTBOUND_GROUP)
exten = s,2, Noop(${GROUP_COUNT(OUTBOUND_GROUP)})
exten = s,3, GotoIf($[${GROUP_COUNT(OUTBOUND_GROUP)} > 1]?1-CHANUNAVAIL,1)
exten = s,4,Set(CALLERID(num)=${IF($[${LEN(${CID_${CALLERID(num)}})} > 2]?${CID_${CALLERID(num)}}:)})
exten = s,n,GotoIf($[${LEN(${CALLERID(num)})} > 6]?1-dial,1)
exten = s,n,Set(CALLERID(all)=${IF($[${LEN(${CID_${ARG3}})} > 6]?${CID_${ARG3}}:${GLOBAL_OUTBOUNDCID})})
exten = s,n,Goto(1-dial,1)
exten = 1-dial,1,Dial(${ARG1})
exten = 1-dial,n,Gotoif(${LEN(${ARG2})} > 0 ?1-${DIALSTATUS},1:1-out,1)
exten = 1-CHANUNAVAIL,1,Dial(${ARG2})
exten = 1-CHANUNAVAIL,n,Hangup()
exten = 1-CONGESTION,1,Dial(${ARG2})
exten = 1-CONGESTION,n,Hangup()
exten = 1-NOANSWER,1,Dial(${ARG2})
exten = 1-NOANSWER,n,Hangup()
exten = 1-out,1,Hangup()
