Hello, been working on a dialplan which effective has two gosubs.
- Loop through some SIP destinations
- Write CDRs where 1 will succeed or fail
I wont get into it but yes I am forced to use chan_sip at this stage as much as I would love to just be using pjsip here.
At the line
same => n,Dial(SIP/${DIALED_EXTEN}@${SRV_HOSTNAME},120,o)
IF the call is answered, when I hangup i receive the below and it does not proceed in the dialplan any further
Spawn extension (srv-lookup-sub, s, 25) exited non-zero on ‘SIP/TestSoftphone-0000bb46’
IF the call loops through failures like CHANNELUNAVAIL, the CDRs are written on all attempts as expected in the [write-cdr-sub]
[internal]
exten => _11XX,1,NoOp(Start manual SRV lookup)
same => n,Gosub(srv-lookup-sub,s,1(${EXTEN}))
same => n,NoOp(Returned from gosub)
same => n,Hangup()
;Hangup Rules for internal context
exten => h,1,NoOp("Call Duration: ${CDR(billsec)}")
same => n,Gosub(write-cdr-sub,s,1)
;gosub1
[srv-lookup-sub]
exten => s,1,Verbose("Starting SRV Subrouting for ${SRV_RECORD}")
same => n,Set(SRVQUERY_RESULT=${SRVQUERY(${SRV_RECORD})})
same => n,Set(SRV_RECORD_COUNT=${SRVRESULT(${SRVQUERY_RESULT},getnum)})
same => n,Set(SRV_COUNT=1)
;Build a list of SRV Records and put in in priority order - I am not considering weight
same => n,While($[${SRV_COUNT} <= ${SRV_RECORD_COUNT}])
same => n,Set(SRV_PRIORITY=${SRVRESULT(${SRVQUERY_RESULT},${SRV_COUNT},priority)})
same => n,Set(SRV_HOST=${SRVRESULT(${SRVQUERY_RESULT},${SRV_COUNT},host)})
; Debug message to verify SRV record details
same => n,NoOp(SRV Record ${SRV_COUNT}:${SRV_HOST} with priority ${SRV_PRIORITY})
same => n,Set(SRV_KEY=${SRV_HOST}:${SRV_PRIORITY})
same => n,NoOp(SRV_KEY ${SRV_COUNT} is ${SRV_KEY})
; Add priority as a key to the list in a specific format for future sorting
same => n,Set(PRIORITY_LIST="${PRIORITY_LIST},${SRV_KEY}")
same => n,Set(SRV_COUNT=$[${SRV_COUNT} + 1])
same => n,EndWhile()
same => n,Set(PRIORITY_LIST_SORTED=${SORT(${PRIORITY_LIST})})
same => n,NoOp("SRV List Sorted: ${PRIORITY_LIST_SORTED}")
same => n,Set(COUNT=1)
same => n,While($[${COUNT} <= ${SRV_RECORD_COUNT}])
same => n,Set(SRV_HOSTNAME=${CUT(PRIORITY_LIST_SORTED,",",${COUNT})})
same => n,NoOp(Dialing ${COUNT}: ${SRV_HOSTNAME})
same => n,Dial(SIP/${DIALED_EXTEN}@${SRV_HOSTNAME},120,o)
same => n,GotoIf($["${DIALSTATUS}" = "ANSWER"]?success,1)
same => n,GotoIf($[${COUNT} = ${SRV_RECORD_COUNT}]?exit_loop)
same => n,NoOp(Call failed to ${DIALED_EXTEN}, writing CDR and moving to next priority)
same => n,Gosub(write-cdr-sub,s,1)
same => n,Set(COUNT=$[${COUNT} + 1])
same => n,EndWhile()
same => n(exit_loop),NoOp(Exiting loop as all attempts failed)
same => n,Return()
exten => success,1,NoOp(Call successfully connected to ${DIALED_EXTEN}@${SRV_HOSTNAME})
same => n,Return()
;gosub2
[write-cdr-sub]
exten => s,1,Verbose("Call Duration: ${CDR(billsec)}")
;write some cdrs
same => n,Return()