Hopefully someone can help me here. Reading forums and tutorials all day and still cannot figure this out.
What I’m trying to do:
Receive a call from a specific phone number (as the local phone number service allways routes return calls to the same number),
Trigger an agi script (PHP) to query a database and and find the last extension that called the this number,
Forward the call to that extension.
What I’ve done.
I have set up a custom destination under Admin/Custom Destinations using lt-inbound,s,1 as the destination.
I have added the below code to extensions_custom.conf
exten => s,1,AGI(lt-inbound.php)
I have set up an inbound route for the phone number as the CallerID
Number and the DID number blank. In this inbound route I have added the custom destination that I created as the destination.
I have made sure that lt-inbound.php is in /var/lib/asterisk/agi-bin and that the permissions and ownership are correct.
The lt-inbound.php script has a query that I know works that should be inserting a record into the database, however the record is not being inserted and I see no mention of the script when I check the logs. All I can assume is that the agi script is not being called.
I’m sure I am missing something simple here but I just cannot figure out what it is.
As with everything related to AGI, start off with setting debug on
agi set debug on
include noops in your script to further refine, if you cared to post your script someone might comment, otherwise we can’t mindread
I’m pretty sure that if any active call runs into your [lt-inbound] context it will be exposed in the asterisk CLI as you have at least an s (start) exten, if it doesn’t get to that context it just won’t run.
However the AGI script doesnt seem to execute anything. Right now I am just trying to create a text file with php however it appears as though it never runs. I have tried a number of ways to write to the log file but have had no luck.
I’m not entirely sure how to run the script at the trunk level. You are correct in assuming that all calls should arrive exclusively on that trunk. I don’t see anywhere to set a destination for a trunks inbound settings. Although if this is the cleaner way to do it, I would prefer to do things correctly.
Here is the script
#!/usr/bin/env php -q
$myfile = fopen("/var/www/html/test.txt", "w") or die("Unable to open file!");
$txt = "Line 1\n";
$txt = "Line 2\n";
Since the log appears to say that the script was launched and completed this should be creating a test.txt file and yet it does not.
Is there a way that I can write to the log from the AGI script to debug this?