Integration with external applications using AGI

Recently we had a customer that requested for integration with their CRM web application (based on .NET framework and MSSQL). They wanted to get the caller id of the caller and the number which they have called. Here is a simple approach to get this done. In this example, I have used AGI to get the CLID and channel number and then I use the cURL method of PHP to POST the 2 parameters to the URL on the other side.

Continue reading

AGI sample – currency converter using web service

Bellow is an AGI sample to convert currency using a web service:

Step 1) create an extension in /etc/asterisk/extensions_custom.conf

[ext-local-custom]
exten => *777,1,AGI(currency.php)
exten => *777,n,hangup()

Step 2) Create currency.php in /var/lib/asterisk/agi-bin

#!/usr/bin/php -q
answer();

//fetch the web service and store the result into $curr
$fromCurrency="USD";
$toCurrency="MYR";
$res=file_get_contents("http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=$fromCurrency&ToCurrency=$toCurrency");
$xml = new SimpleXMLElement($res);
$curr=$xml[0];

$agi->text2wav("Currency rate from $fromCurrency to $toCurrency is");
$agi->say_number($curr);
$agi->text2wav("Thank you");
$agi->hangup();
?>