Upgrade 3CX to v18 and get it hosted free!

hunt-dial macro

Author image

This macro helps to define an outbound hunting group for the outbound dialing. In the situation where you have multiple PSTN lines registered as multiple SIP channels (e.g. SIP/line1, SIP/line2, SIP/line3, etc…), on the same or multiple gateways, and you wants to arrange them into an ordered hunting group for outbound calling. You can use the following hunt-dial macro.

This solution is brought to you by Makecall4U Telecom, your Asterisk solution provider in Hong Kong.


[default]
include => pstn-out

[macro-hunt-dial]
; ${ARG1} channel
; ${ARG2} Dialed Number

exten => s,1,SetGroup(${ARG1}) ; increment GROUPCOUNT
exten => s,2,GetGroupCount()
exten => s,3,NoOp(GROUPCOUNT:${GROUPCOUNT})
exten => s,4,GotoIf($~np~["${GROUPCOUNT}"~/np~ = "1"]?5:6) ; if GROUPCOUNT = 1, then it's free for dialing.
exten => s,5,Dial(SIP/${ARG2}@${ARG1}) ; use it to call out.
exten => s,6,NoOp(${ARG1} is inused)


[pstn-out]
exten => _XXXXXXXX,1,Macro(hunt-dial,line1,${EXTEN}) ; list your SIP channels here in the hunting order
exten => _XXXXXXXX,n,Macro(hunt-dial,line2,${EXTEN})
exten => _XXXXXXXX,n,Macro(hunt-dial,line3,${EXTEN})
exten => _XXXXXXXX,n,Macro(hunt-dial,line4,${EXTEN})
.
.
.
exten => _XXXXXXXX,n,NoOp("No Channel available")
exten => _XXXXXXXX,n,Hangup()

Hunt Dialout Macro using AstDB

The above macro has been helpful in giving me the basic idea to create this macro.
The alternative macro below may be of use to you if you want to use AstDB to store your dialout SIP device information, which you may edit or add dynamically without modifying your extensions.conf

This macro is brought to you by Ossteq.com, an Asterisk Contact Center and Linux BPO Service provider in Singapore.

Store your SIP Device Info on AstDB:
Family : Key : Value
ossteq_dialout : 1 : SIP/1001
ossteq_dialout : 2 : SIP/1003
ossteq_dialout : n : SIP/XXXX


[macro-huntdialout]
exten => s,1,Set(DBKEY=0)
exten => s,n(increment),Set(DBKEY=$~np~[${DBKEY} + 1]~/np~)
exten => s,n,Set(OUTBOUNDTRUNK=${DB(ossteq_dialout/${DBKEY})})		; retrieve value from AstDB
exten => s,n,GotoIf($~np~[${ISNULL(${OUTBOUNDTRUNK})}]~/np~?giveup:)		; no more available channels - give up!
exten => s,n,Dial(${OUTBOUNDTRUNK}/${ARG1})
exten => s,n,GotoIf($~np~["${DIALSTATUS}" = "CHANUNAVAIL"]~/np~?increment:)	; next 4 lines are channel error trap
exten => s,n,GotoIf($~np~["${DIALSTATUS}" = "BUSY"]~/np~?increment:)		; then iterate to next available 

channel
exten => s,n,GotoIf($~np~["${DIALSTATUS}" = "CONGESTION"]~/np~?increment:)
exten => s,n,GotoIf($~np~["${DIALSTATUS}" = "NOANSWER"]~/np~?increment:)
exten => s,n(giveup),Playback(am-fem/sorry)
exten => s,n,Playback(am-fem/all-circuits-busy-now)
exten => s,n,Playback(am-fem/pls-try-call-later)
exten => s,n,Congestion( )


[outbound-local]
ignorepat => 9
exten => 911,1,Macro(huntdialout,911)			; Examples on how to call the macro
exten => _9NXXXXXXX,1,Macro(huntdialout,${EXTEN:1})	

Related Posts:

Get 3CX - Absolutely Free!
Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.