Back to articles
AI & Cloud

Guide to Deploying an AI Auto-Attendant System with Asterisk and VapiRetell API on VPS

A detailed guide to deploying an AI auto-attendant system using Asterisk and VapiRetell API on a VPS, covering installation, configuration, testing, and performance optimization for...

DPTCloud Engineering4 min read
Guide to Deploying an AI Auto-Attendant System with Asterisk and VapiRetell API on VPS

Image credit: geralt · Pixabay Content License

Introduction to the AI Auto-Attendant System

An AI auto-attendant system enables businesses to automate calls, handle customer requests, and improve service experience. In this guide, we deploy an AI call system using Asterisk—a popular open-source PBX platform—combined with VapiRetell API for speech-to-text (STT) and text-to-speech (TTS) processing. The entire system runs on a VPS with sufficient resources to handle AI workloads.

Prerequisites Before Deployment

To successfully deploy the system, you need:

  • A VPS (Cloud VPS) with at least 4GB RAM and 2 CPU cores.
  • Access to a Linux operating system (Ubuntu 20.04 or 22.04).
  • Familiarity with Linux command line and network configuration.
  • A VapiRetell account to obtain an API key.
  • Git, Node.js, and Python (version 3.8+) installed.

Deployment Steps

Step 1: Install and Configure Asterisk

Update the system and install Asterisk:

sudo apt update
sudo apt install -y asterisk
sudo systemctl enable asterisk
sudo systemctl start asterisk

Verify Asterisk is running:

sudo asterisk -rv

Run core show version to confirm the version. If details appear, Asterisk is operational.

Step 2: Install VapiRetell API Client

Create a new directory and install the VapiRetell library:

mkdir ai-voice-agent
cd ai-voice-agent
npm init -y
npm install axios

Create a file agent.js and add the following code:

const axios = require('axios');

const API_KEY = 'YOUR_VAPI_RETLL_API_KEY';
const BASE_URL = 'https://api.vapi.ai';

async function callVoiceAgent(text) {
  const response = await axios.post(`${BASE_URL}/voice`, {
    text: text,
    model: 'vapi-voice',
    apiKey: API_KEY
  });
  return response.data;
}

callVoiceAgent('Hello, you are calling the AI auto-attendant system.');

Replace YOUR_VAPI_RETLL_API_KEY with your actual API key.

Step 3: Connect Asterisk with VapiRetell API

In Asterisk, create the configuration file extensions.conf in /etc/asterisk/:

[default]
exten => 100,1,Dial(SIP/agent)
exten => 100,n,Answer()
exten => 100,n,Playback(greeting)
exten => 100,n,Set(VoiceAgentText=Welcome to the AI auto-attendant system)
exten => 100,n,Exec(/usr/bin/node /home/ai-voice-agent/agent.js ${VoiceAgentText})
exten => 100,n,Hangup()

This script triggers the VapiRetell API to process speech when a caller dials 100.

Testing the System

To verify the system:

  1. Run sudo systemctl restart asterisk to restart the service.
  2. Call extension 100 from a phone or computer.
  3. Listen to the AI response generated via VapiRetell API.

Performance Optimization

To ensure stable operation:

  • Use htop to monitor CPU and RAM usage.
  • Optimize Asterisk configuration in asterisk.conf.
  • Set up logging with logger to detect errors.

Troubleshooting

If issues arise:

  • API not responding: Check network connectivity and API key.
  • Asterisk not answering calls: Verify extensions.conf and sip.conf.
  • Speech errors: Review VapiRetell configuration and model settings.

References

Related infrastructure & engineering guides: Building an Uptime Kuma Cluster: Mutual Monitoring Solution Between VPS for Enterprises

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478