Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry for the long code sample, but more than half of it is debugging code to help you get it set up.</p> <p>I'm assuming your server already has a modern version of PHP (at <code>/usr/bin/php</code>) with the PDO library, and that you have a database table named <code>fwd_table</code> with columns <code>caller_id</code> and <code>destination</code>.</p> <p>In /var/lib/asterisk/agi-bin get a copy of the <a href="http://sourceforge.net/projects/phpagi/" rel="nofollow noreferrer">PHP AGI</a> library. Then create a file named something like <code>forward_by_callerid.agi</code> that contains:</p> <pre><code>#!/usr/bin/php &lt;?php ini_set('display_errors','false'); //Supress errors getting sent to the Asterisk process require('phpagi.php'); $agi = new AGI(); try { $pdo = new PDO('mysql:host='.$db_hostname.';dbname='.$db_database.';charset=UTF-8', $db_user, $db_pass); } catch (PDOException $e) { $agi-&gt;conlog("FAIL: Error connecting to the database! " . $e-&gt;getMessage()); die(); } $find_fwd_by_callerid = $pdo-&gt;prepare('SELECT destination FROM fwd_table WHERE caller_id=? '); $caller_id = $agi-&gt;request['agi_callerid']; if($callerid=="unknown" or $callerid=="private" or $callerid==""){ $agi-&gt;conlog("Call came in without caller id, I give up"); exit; }else{ $agi-&gt;conlog("Call came in with caller id number $caller_id."); } if($find_fwd_by_callerid-&gt;execute(array($caller_id)) === false){ $agi-&gt;conlog("Database problem searching for forward destination (find_fwd_by_callerid), croaking"); exit; } $found_fwds = $find_fwd_by_callerid-&gt;fetchAll(); if(count($found_fwds) &gt; 0){ $destination = $found_contacts[0]['destination']; $agi-&gt;set_variable('FWD_TO', $destination); $agi-&gt;conlog("Caller ID matched, setting FWD_TO variable to ''"); } ?&gt; </code></pre> <p>Then from the dial plan you can call it like this:</p> <pre><code>AGI(forward_by_callerid.agi) </code></pre> <p>And if your database has a match, it will set the variable <code>FWD_TO</code> with goodness. Please edit your question if you need more help getting this integrated into your dial plan.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload