I am using if in python and there is a case where if user dont have the number we will disconnect the call. Sadly I cant run any function inside if command for dont know what reason so . I need to pass a hang up and disconnect call. How will i do that.
i tried the command " EXEC Dial hangup()"
In the dial plan i have
inside agi i tried executing the command
cmd_record2 = “EXEC Dial hangup()”
my dial plan is
exten=>4114,1,Answer()
same=>n,AGI(/root/code_base/Communication/comm2.py, beng)
same=>n,hangup() <<<< this is what i want to execute through command or disconnect
Setting the return code non-zero when exiting, should result in dialplan execution terminating, which will result in a hangup, unless you don’t have auto fallthrough enabled.
Your attempt implies you are not using an AGI library. This is the first mistake most ‘new to AGI’ users make. A library will save you a boatload of time.
The second mistake most users make is not understanding the AGI protocol. It is ‘you request Asterisk to do something’ (via STDOUT) and ‘Asterisk returns a response’ (via STDIN) that you must read. Any other I/O on STDIN/STDOUT (like a quick printf to see the value of a variable) will break the protocol.
I was assuming that the return code from the script would be passed by to the PBX. It seems not.
It would appear that setting a no-zero code sets the variable AGISTATUS to FAILURE, and the actual value is discarded. One should probably ask whether the OP is checking AGISTATUS.
Thinking about it, getting an AGISTATUS failure, and checking in the dialplan is better, as you are not hiding a major side effect of the AGI execution.
The status code returned from the waitpid for the AGI process (i.e. the return value from the AGI script itself (modified by any signal causing termination)) isn’t passed back as the return code from app_agi. Instead, it is used to set an AGI failed status, which is, eventually written into the AGISTATUS channel variable.
The actual return code from app_agi is set based on whether an internal flag, indicating the controlling channel hung up, is set.