MOH while retry dial


My trunk provider fails a lot (PJSIP 407 error only with Asterisk). One of the issues is that when calling outside, it may fail to establish the call. Right now my only way to handle it is by retrying multiple times (usually, each second during 1min) in order to finally be able to make the call.

However, I would like to play some music during this process. Right now, if I try to use a MusicOnHold (MOH), it gets interrupted when I Dial()

same    =>                 n,Answer()
same    =>                 n,StartMusicOnHold(mymusic)
;same    =>                 n,Wait(10) ; Wait to make sure that music is playing
same    =>                 n,Dial(PJSIP/${ARG2}@sfr-out,,)
same    =>                 n,Log(NOTICE, Call result: ${DIALSTATUS})
same    =>                 n,Wait(12) ; simulate the loop retrying the call
same    =>                 n,StopMusicOnHold() ; once I'm able to call, stop music
same    =>                 n,Hangup()

My idea is to later implement some loop of retrying based on DIALSTATUS

My main problem is that the MOH automatically stop when Dial is executed. Do I have some alternative to it?

If I use Parking, it will be blocked in the Park() step, so I will not be able to do the retries. And using the RetryDial() only plays music before doing the Dial attempt, which is not acceptable for my case.

Thank you in advance

you could use a Local channel

same => n,Progress()
same => n,Dial(Local/${ARG2}@Trunk,,m(mymusic))


[Trunk] ;loadbalacing and failover
exten => _[0-9s#*+]!,1,Set(Num=${FIELDQTY(Trunk,\,)})
same => n,Set(CHANNEL(hangup_handler_push)=Hangup_Handler,${FILTER(+1234567890#*,${EXTEN})},1)          ; enable that we show hangup reason in the log
same => n,ExecIf($[${EXISTS(${PJSIP_HEADER(read,Privacy)})} & "${PJSIP_HEADER(read,Privacy)}" != "none"]?Set(_Number_pres="prohib"))    ; Privacy: id;user;header
same => n,Set(Count=0)
same => n,Set(Current=${RAND(1,${Num})})                                                                ; select a random place to start (load balacing)
same => n,While($[${INC(Count)} <= ${Num}])
same => n,Set(Current=$[${MATH(${Current}%${Num},i)}+1])                                                ; fancy modulus stuff to loop the list of hosts
same => n,ExecIf($["${DEVICE_STATE(PJSIP/${CUT(Trunk,\,,${Current})})}"="UNAVAILABLE"]?ContinueWhile()) ; check where the device in responding to option
same => n,ExecIf($["${DEVICE_STATE(PJSIP/${CUT(Trunk,\,,${Current})})}"="INVALID"]?ContinueWhile())     ; check that the device exists
same => n,Dial(PJSIP/${EXTEN}@${CUT(Trunk,\,,${Current})},${DialTimeout},iS(${MaxCallTime})b(Dial_Handler^${EXTEN}^1))
same => n,ExecIf($["${NoFailoverCause}"!="${LISTFILTER(NoFailoverCause,",",${HANGUPCAUSE})}"]?ExitWhile())      ; check if we should failover or not
same => n,EndWhile()
same => n,ExecIf($["${HANGUPCAUSE}"!="0"]?Hangup(${HANGUPCAUSE}):Hangup(38))                            ; 38    NETWORK_OUT_OF_ORDER

Thank you a lot!

That’s working well. I just adapted for my needs, but the music sounds while is doing stuff. Great!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.