As mentioned in the Asterisk Community Running a python script when call is answered, if you want to run a script as soon as the called party answered, use the U dial option.
U
( x^arg )
- Execute viaGosub
the routine x for the called channel before connecting to the calling channel. Arguments can be specified to theGosub
using^
as a delimiter. TheGosub
routine can set the variableGOSUB_RESULT
to specify the following actions after theGosub
returns.
NOTE: You cannot use any additional action post answer options in conjunction with this option. Also, pbx services are run on the called channel, so you will not be able to set timeouts via theTIMEOUT()
function in this routine.
GOSUB_RESULT
- ABORT - Hangup both legs of the call.
- CONGESTION - Behave as if line congestion was encountered.
- BUSY - Behave as if a busy signal was encountered.
- CONTINUE - Hangup the called party and allow the calling party to continue dialplan execution at the next priority.
- GOTO:[[<CONTEXT>^]<EXTEN>^]<PRIORITY> - Transfer the call to the specified destination.
x
- Name of the subroutine context to execute viaGosub
. The subroutine execution starts in the named context at the s exten and priority 1.arg
[^arg
…] - Arguments for theGosub
routine
You would probably want to change the dial options using the predial hook. Hooking for fun and income