2

So I have a VOIP system set up through a FreePBX server. I want to have it so that when a new call is picked up by FreePBX, asterisks will send the caller ID and the call ID to a php script, which will then use that information to gather ticket information for the account related to that caller ID. It will then update a database with the found information. When a user answers the phone, I then want to send the user's extension and the call ID to another php script and update the database with the new information.

I have looked into PHPARI, but the documentation is lacking for me. I just need it to go one way, and PHPARI and similar libraries seem to focus on going both ways, from what I've understood.

My internet searches have yielded nothing, so I turn to you guys for help and guidance.

FreePBX Version: 13.0.83 Asterisk Version: 13.7.1

CaptainQuint
  • 332
  • 6
  • 22

1 Answers1

4

Have a look at Asterisk AGI you should be able to script it through the dial plan (extensions.conf) and include any vars like caller ID.

I've done a quick test from my extension.conf;

s is used to catch where no called number is used in the context.

exten => s,1,Verbose(Incoming call from Sip line CallerID=${CALLERID(all)})
exten => s,2,AGI(phone.php,${CALLERID(all)})
exten => s,3,Goto(internal-ext,3001,1)

my phone.php is located at /var/lib/asterisk/agi-bin/phone.php Pass your vars as script.php,<var>,<var>...

Don't use script.php?callNum= as that's only valid for web applications, this should be treated as command line.

That script writes to a file at /tmp/phone which is updated with the calling caller id.

In my php script I did the following;

#!/usr/bin/php

<?php
    $query = $argv[1];
    $file = fopen("/tmp/phone", "w");
        fwrite($file,$query);
        fclose($file);
?>
user3788685
  • 2,943
  • 5
  • 26
  • 45
  • This looks promising, thanks. I'll update this question when I've made progress or lack thereof. – CaptainQuint Mar 17 '16 at 18:11
  • no worries. I'll try and find the link I had somewhere that explained how to get vars (like caller id) if I do I'll update my answer. – user3788685 Mar 17 '16 at 18:39
  • Thank you. This is all new to me, and it's the final piece of the puzzle for my project. Once I get this asterisks integration, then I can polish my applications front end up more. – CaptainQuint Mar 17 '16 at 18:44
  • So to pass a Asterisk variable to the php script, I need to use the Set function to do that? I can't just put the variables in the path for PHP script then use $_GET to get the required information? – CaptainQuint Mar 17 '16 at 20:06
  • yes I think you can just get the right var. check https://wiki.asterisk.org/wiki/display/AST/Asterisk+Standard+Channel+Variables I've not had any free time to do any testing though as yet – user3788685 Mar 17 '16 at 22:24
  • So I haven't had a chance to test this out yet, but I was wondering if you could help me understand it more. I've read through the provided links, but am still confused on one or two things. First off, the first value is the extension, so what does `s` do in this context. Secondly, when I set the variables, do I do it by `Set()` as a separate line in the extensions.conf, or when I call the file path, and put something like, `AGI(test.php?callNum=${CALLERID(num)})` ? – CaptainQuint Mar 21 '16 at 18:36
  • 1
    have updated my answer with a working example. check it out. The only time you need to set anything is if its not already a var in asterisk. – user3788685 Mar 21 '16 at 21:17