IP telephony is the core of corporate communication, but an isolated PBX doesn't provide analytics and automation. Without AI, you lose up to 40% of insights from phone calls: manual analysis is impossible with 1000+ calls per day. Integrating AI components (speech recognition, synthesis, NLU) with Asterisk/FreePBX/3CX solves this without full infrastructure replacement. Example: a restaurant chain with 30 outlets was losing 70% of incoming calls during peak hours. After deploying a voice bot based on LLaMA 3, wait time dropped from 5 minutes to 10 seconds, and booking conversion increased by 40%. Our experience: 5+ years and 50+ implementations. Let's dive into architectural approaches, model selection, and common pitfalls.
What architectural approaches exist for integrating AI with IP telephony?
There are three key approaches: AMI for call management, AGI for embedding scripts into the dialplan, and webhook integration for 3CX. The choice depends on the tasks: real-time processing, post-call analytics, or hybrid.
AMI (Asterisk Manager Interface)
Call management over TCP. Suitable for initiating calls from external systems (bulk dialing, surveys). Example code:
import asterisk.manager as ami
manager = ami.Manager()
manager.connect("asterisk-server")
manager.login("admin", "secret")
# Initiate an outbound call
manager.originate(
channel="SIP/1001",
exten="s",
context="ai-bot",
priority=1,
caller_id="AI Bot <0800>",
variables={"CUSTOMER_ID": "12345"}
)
AGI (Asterisk Gateway Interface)
Script runs on incoming call. Allows executing arbitrary code in Python, Bash, etc. with channel access:
from asterisk.agi import AGI
def handle_call():
agi = AGI()
agi.answer()
agi.set_variable("CHANNEL(audioreadformat)", "slin16")
# Play TTS
tts_audio = synthesize_greeting()
agi.stream_file(save_as_asterisk_audio(tts_audio))
# Record response
agi.record_file("/tmp/response", "wav", "#", 5000)
transcript = transcribe("/tmp/response.wav")
# Process and reply
reply = process_intent(transcript)
reply_audio = synthesize(reply)
agi.stream_file(save_as_asterisk_audio(reply_audio))
FreePBX with custom modules
We connect a dialplan hook via PHP:
// FreePBX dialplan hook
function ai_bot_dialplan_hook($exten, $context) {
if ($context == 'from-internal' && $exten == '9000') {
return [
'AGI,agi://127.0.0.1/ai_voice_bot',
'Hangup'
];
}
}
3CX integration via Call Flow Designer
Use a webhook step at each IVR stage, calling the AI API:
{
"type": "webhook",
"url": "https://ai-api.company.com/3cx/ivr-step",
"method": "POST",
"body": {
"caller": "{{CallerId}}",
"extension": "{{Extension}}",
"speech_input": "{{SpeechInput}}"
}
}
SIP Trunk for media streaming
For real-time tasks (voice bot, live transcription), intercept RTP via a media proxy:
Caller → Asterisk/3CX → SIP Trunk → Media Proxy (RTP) → AI Engine
↑
Intercept RTP stream,
process in AI,
return synthesized audio
How to choose between AMI, AGI, and webhook?
| Criteria | AMI | AGI | Webhook (3CX) |
|---|---|---|---|
| Call management | Yes (initiate, terminate) | No | Partial (via API) |
| Real-time processing | No (control only) | Yes | Yes (via external server) |
| Implementation complexity | Medium | Medium | Low |
| Latency | Low (TCP) | Medium (AGI script) | Depends on network |
| VoIP platform support | Asterisk, FreePBX | Asterisk, FreePBX | 3CX |
AMI suits scenarios where calls need to be initiated from an external system — for example, mass dialing. AGI is indispensable when you need to capture audio during a call, pass it to AI, and return a synthesized answer in real time. If you use 3CX, webhook integration is simpler and faster but gives less control over the media stream.
What AI models are optimal for voice bots?
For STT we use OpenAI Whisper (large-v3) — accuracy >95% on Russian, supports 80+ languages. Transcription with Whisper large-v3 is 2x more accurate than standard Google Speech-to-Text. For NLU — LLaMA 3 or GPT-4o: they consistently extract intents without hallucinations. For TTS — Coqui TTS (open-source) or ElevenLabs (high quality but proprietary). All models are deployed with vLLM to optimize throughput and reduce latency.
| Model | Purpose | Latency p99 | Accuracy | License |
|---|---|---|---|---|
| Whisper large-v3 | STT | <500 ms | >95% | MIT |
| LLaMA 3 | NLU | <800 ms | 90%+ | LLaMA |
| GPT-4o | NLU | <1 s | 95%+ | Proprietary |
| Coqui TTS | TTS | <400 ms | High | MIT |
| ElevenLabs | TTS | <600 ms | Very high | Proprietary |
Why integrate an AI contact center with an existing IP PBX?
Without AI, you lose up to 40% of insights from phone calls. Manual analysis is impossible with 1000+ calls per day. AI solves this: automatic transcription of all calls with accuracy >95% (Whisper large-v3), sentiment detection, speaker diarization, key phrase extraction, summary generation, and automatic CRM filling. Compared to manual processing, AI reduces call handling time by 60% and improves issue identification accuracy from 30% to 85%.
| Parameter | Without AI | With AI |
|---|---|---|
| Time per call (full cycle) | 15–20 min | 3–5 min |
| Accuracy of identifying customer issues | 30% | 85% |
| CRM integration | manual entry | automatic |
| Scaling | hire operators | fine-tune model |
Our certified engineers with 10+ years of experience implement integration without downtime. We provide a 6-month warranty.
Integration process and timeline
We offer a turnkey solution. Here are the steps:
- Audit of current telephony infrastructure (Asterisk/FreePBX/3CX, versions, extensions).
- Architecture design of the AI module: model selection, latency optimization, processing pipeline.
- Development of AGI/AMI/webhook scripts, media proxy setup (RTP capture).
- Integration with CRM via REST API or webhooks.
- Testing on a test bench (up to 7 days).
- Production deployment with monitoring (Prometheus + Grafana).
- Team training and documentation.
Timeline: from 2 weeks (AGI integration with a single scenario) to 1.5 months (full media proxy + multilingual voice bot). Cost is calculated individually — typical projects range from $5,000 to $25,000. Write to us for a free consultation and we will evaluate your project.
What's included in the work
- Architectural documentation (HLD/LLD) with detailed integration descriptions.
- Access to a Git repository with scripts and configurations.
- Prototype on a test bench for acceptance.
- Production deployment.
- CRM integration via webhook or API.
- Training for administrators and operators.
- Technical support and a 6-month warranty.
Typical mistakes when integrating on your own
Three most common issues. First — not accounting for latency. If the model responds longer than 500 ms, the customer hears an echo. Use vLLM with optimization and low-latency GPU. Second — lack of failover. On AI module failure, calls must go to a live operator. Set up cascading switching via AMI. Third — insufficient security. An open AGI port is a risk. Use TLS and IP whitelisting.
Get a consultation on integrating AI into your PBX. Contact our engineers to evaluate your project — we will prepare the architecture and estimate the cost. We deliver turnkey AI integration for Asterisk, FreePBX, and 3CX, and include a 6-month warranty.







