Run a php script when a call comes in

hi everyone, i need to run a php script when a call comes in, but whatever i put in extensions_custom.conf is not executed. do you have any ideas?

content of extensions_custom.conf

exten => 600,3,noop(test inserimento riga da extensions_custom.conf)
exten => 600,2,AGI(/var/lib/asterisk/agi-bin/incoming.php,${CALLERID(all)})

include => incoming

600 is the extensions group

Welcome to the forum!

Referencing a block of custom dialplan can be done with a custom destination, like this example: Announce current time as part of call flow - #4 by lgaetz

If your ask is more complex, you might want to look at using a dialplan hook: Hooking for fun and income

thanks for the support!!
i dont want to send to a custom destination. currently the incoming calls go to a call group, then when the phones ring I would like to run a php script to intercept the sender’s number and send it to a web application. in fact I created incoming.php:

    $query = $argv[1];
    $file = fopen("/tmp/phone", "w");

and put it in /var/lib/asterisk/agi-bin
what am I doing wrong?

To do this with dialplan alone, you want to use a dialplan hook, see the thread linked above.

I use FreePBX macros are deprecated?

so i just put this inside extensions_custom.conf?

exten => 600,2,noop(test insert)
exten => 600,3,AGI(/var/lib/asterisk/agi-bin/incoming.php,${CALLERID(all)})
exten => 600,n,MacroExit

600 is the ring group

I solved it like this:


exten => s,1,noop(test inserimento riga da extensions_custom.conf)

exten => s,2,AGI(/var/lib/asterisk/agi-bin/incoming.php,${CALLERID(number):2})

exten => s,n,MacroExit

now, in addition to passing the telephone number to the incoming.php file, I would also like to pass the number of the extension that answers the call. it’s possible?

Not easy to do in dialplan in FreePBX, unless you want to do it after the channel hangs up with a hangup handler.

Very curious to what ends you’re using this.

I don’t know any way to get that in dialplan. If you are using desk phones, basiaclly all brands have event handlers. In Yealink, it is called Action URL.

because I need to pass 2 variables: both the callerid and the extension that answers the call

yes I have seen. to centralize the work it would be convenient for me to work with AGI on the pbx

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