Running a python script when call is answered

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 via Gosub the routine x for the called channel before connecting to the calling channel. Arguments can be specified to the Gosub using ^ as a delimiter. The Gosub routine can set the variable GOSUB_RESULT to specify the following actions after the Gosub 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 the TIMEOUT() 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 via Gosub . The subroutine execution starts in the named context at the s exten and priority 1.
    • arg [^ arg …] - Arguments for the Gosub routine

You would probably want to change the dial options using the predial hook. Hooking for fun and income

1 Like