Hi. I’ve trying for a month by now to write a dial plan that Receives call from A Party and sends it to B-Party, but the SIP 200 should be forwarded conditionally from B-Party to A , based on the time difference between the SIP 180 and SIP 200 received from the B- Party.
Below is the Extensions.conf context.
Calls arrive from 10.10.1.5 (A-Party)—> (Asterisk- 10.10.1.11)—> 10.10.1.1 ( B-Party)
[public]
exten => _0.,1,Dial(SIP/10.10.1.1/${EXTEN},M(macro-track-time))
[macro-macro-track-time]
exten => s,1,NoOp(Answering the call)
same => n,Set(__START_TIME=${STRFTIME(${EPOCH},%Y%m%d%H%M%S)})
same => n,Verbose(START_TIME set to: ${__START_TIME})
same => n,Answer()
same => n,Wait(1)
same => n,Verbose(SIP 200 OK response received)
same => n,Set(__SIP_200_TIME=STRFTIME(${EPOCH},%Y%m%d%H%M%S)})
same => n,Verbose(SIP 200 OK response time set to: ${__SIP_200_TIME})
same => n,Macro(check-difference,s,1)
same => n,NoOp(Continuing with the call)
[macro-check-difference]
exten => s,1,Set(__DIFFERENCE=${DIFF(${__SIP_200_TIME},${__START_TIME})})
same => n,NoOp(Difference value before calculation: ${__DIFFERENCE})
same => n,Verbose(Difference between START_TIME and SIP_200_TIME: ${__DIFFERENCE} seconds)
same => n,GotoIf($[${__DIFFERENCE}=0]?hangup)
same => n,Return()
exten => s,n(hangup),Hangup()
[sip-messages]
exten => _.,1,NoOp(SIP message received)
same => n,GotoIf($[“${MESSAGE}”=“SIP/2.0 200 OK”]?hangup:)
exten => hangup,1,NoOp(Hanging up)
same => n,Hangup()