The Asterisk Gateway Interface (AGI) allows you to extend your phone system with custom logic written in virtually any programming language. From database lookups to complex call routing, AGI opens a world of possibilities.
What is AGI?
AGI (Asterisk Gateway Interface) is a protocol that allows Asterisk to communicate with external programs. When an AGI script runs:
- Asterisk passes call information to the script
- The script can read variables, play sounds, collect digits
- The script returns commands to Asterisk
- Call flow continues based on script results
Common AGI Use Cases
Database Integration
Look up caller information in your CRM or database and route accordingly. Greet callers by name or route VIP customers to priority queues.
Payment Processing
Build automated payment IVR systems that securely collect credit card information and process transactions.
Appointment Scheduling
Let callers check availability and book appointments without speaking to staff.
Order Status
Provide automated order tracking by connecting to your inventory or shipping systems.
Survey Collection
Gather customer feedback through automated post-call surveys.
AGI Languages
AGI scripts can be written in any language that can read STDIN and write to STDOUT:
- PHP: Popular choice with phpagi library
- Python: Clean syntax with pyst2 library
- Perl: Traditional choice, Asterisk::AGI module
- Node.js: Async handling with agi-node
- Bash: Simple scripts for basic tasks
Simple AGI Example (PHP)
<?php // Simple AGI script to greet caller by name require_once 'phpagi.php'; $agi = new AGI(); $callerid = $agi->request['agi_callerid']; // Look up caller in database $name = lookupCaller($callerid); if ($name) { $agi->stream_file('hello'); $agi->say_alpha($name); } else { $agi->stream_file('welcome'); } ?>
FastAGI vs Standard AGI
Standard AGI spawns a new process for each call, which can be resource-intensive. FastAGI connects to a persistent server:
- Standard AGI: Simpler to implement, higher overhead
- FastAGI: Better performance, connection pooling, scalable
For high-volume systems, FastAGI is recommended.
Security Considerations
- Validate all input to prevent injection attacks
- Use parameterized queries for database access
- Limit AGI script permissions
- Log all AGI activity for auditing
- Secure FastAGI connections with proper authentication
Need Custom Phone System Integration?
Our team specializes in building custom AGI solutions that integrate your phone system with your business applications. From simple lookups to complex automation, we can help.
Discuss Your Project →