Prevent SIP 200 OK from beeing sent on AMD

Hi, im trying to prevent asterisk from sending SIP 200 OK when call is recognized as machine/robot. I made it so call goes to test-in context and creates local channel so caller side still remains in ringing status while callee side can pickup phone and AMD can perform its test. It determined that it’s a machine (no SIP 200 OK reached callee side) until when i execute Hangup(34) it sends SIP 200 OK to callee side (miliseconds before BYE). How to prevent it? I want to send SIP 503 or 603 when call is detected as machine.

[test-in]
exten => _+[123456789]X.,1,Verbose(1,----->KPT in: exten: ${EXTEN})
 same => n,Dial(Local/${EXTEN}@amd-check,30)  ; Dial the Local channel
 same => n,Hangup()

exten => _[123456789]X.,1,Verbose(1,----->KPT in: exten: ${EXTEN})
 same => n,Dial(Local/${EXTEN}@amd-check,30)  ; Dial the Local channel
 same => n,Hangup()

[amd-check]
exten => _+[123456789]X.,1,NoOp(Intermediary context for AMD)
 same => n,Dial(PJSIP/KPT${EXTEN}@Opensips_5060,30,U(amd-handler^s^1))  ; Dial the callee and handle with amd-handler on answer
 same => n,Return()

exten => _[123456789]X.,1,NoOp(Intermediary context for AMD)
 same => n,Dial(PJSIP/KPT${EXTEN}@Opensips_5060,30,U(amd-handler^s^1))  ; Dial the callee and handle with amd-handler on answer
 same => n,Return()


[amd-handler]
exten => s,1,NoOp(Call answered, performing AMD)
 same => n,AMD()                               ; Run Answering Machine Detection
 same => n,GotoIf($[${AMDSTATUS}=HUMAN]?human:machine)
 same => n(machine),Verbose(1, ${ARG1} We've got a machine detected...!)
 same => n,Hangup(34)
 same => n,Return()
 same => n(human),Verbose(1, ${ARG1} We've got a human on the line!)
 same => n,Bridge()                            ; Bridge the intermediary call to the original caller
 same => n,Return()

You’re using the ‘U’ option of Dial in an undefined way. It’s meant to execute a bit of logic and return. Not call Hangup in it, not call Bridge in it. Instead you use the GOSUB_RESULT dialplan variable[1] to control the result.

[1] Dial - Asterisk Documentation

Sorry, i don’t understand where :<

this part [test-in] creates local channel so caller side stays in ringing status:

[test-in]
exten => _+[123456789]X.,1,Verbose(1,----->KPT in: exten: ${EXTEN})
 same => n,Dial(Local/${EXTEN}@amd-check,30)  ; Dial the Local channel
 same => n,Hangup()

exten => _[123456789]X.,1,Verbose(1,----->KPT in: exten: ${EXTEN})
 same => n,Dial(Local/${EXTEN}@amd-check,30)  ; Dial the Local channel
 same => n,Hangup()

while this part calls gsm mobile phone via carrier to check if it’s human or machine:

[amd-check]
exten => _+[123456789]X.,1,NoOp(Intermediary context for AMD)
 same => n,Dial(PJSIP/KPT${EXTEN}@Opensips_5060,30,U(amd-handler^s^1))  ; Dial the callee and handle with amd-handler on answer
 same => n,Return()

exten => _[123456789]X.,1,NoOp(Intermediary context for AMD)
 same => n,Dial(PJSIP/KPT${EXTEN}@Opensips_5060,30,U(amd-handler^s^1))  ; Dial the callee and handle with amd-handler on answer
 same => n,Return()

and this is AMD subrutine:

[amd-handler]
exten => s,1,NoOp(Call answered, performing AMD)
same => n,AMD() ; Run Answering Machine Detection
same => n,GotoIf($[${AMDSTATUS}=HUMAN]?human:machine)
same => n(machine),Verbose(1, ${ARG1} We’ve got a machine detected…!)
same => n,Hangup(34)
same => n,Return()
same => n(human),Verbose(1, ${ARG1} We’ve got a human on the line!)
same => n,Bridge() ; Bridge the intermediary call to the original caller
same => n,Return()

All this allows for caller side to remain in SIP 180 Ringing status while AMD determines if its human or machine. If human it bridges local channel [test-in] with [amd-check] channel. But if its machine it hangsup.

I know Hangup(34) should send SIP 503 but it wont if Asterisk sends SIP 200 OK - it has to send BYE. So this whole keeping caller side in ringing status prevents asterisk from sending SIP 200 OK, but somehow after AMD when i try tu hangup it wit cause 34 Asterisk send 200 OK and then BYE, I’m trying to understand and prevent if possible sending SIP 200 OK if AMD finds callee to be machine.

So should i return to [test-in] with AMD result and perform hangu there? If yes how? Can you describe more what i’m dooing wrong with Dial “U”, i’m still learning sorry.

You have configured Dial to execute the amd-handler subroutine. Calling Hangup(34) there won’t work or do what you want. Calling Bridge there is undefined and a bad idea and also probably won’t do what you want. You are supposed to set the GOSUB_RESULT dialplan variable in the subroutine with what you want to happen when the subroutine ends. If you don’t set it, the call will bridge like normal.

Did you write the contents of amd-handler or get it from somewhere?

I wrote it, somehow it works it detects human machine, and if machine sends bye and if human bridges channel and call with audio continues until it one side hangs up

That doesn’t change the fact you’re using it in an improper undefined way. It should be written how I stated.

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