AiPBX

External databases & IVR data steps

AiPBX can connect to external SQL databases and HTTP endpoints to look up caller information in real time during an incoming call and branch the call flow accordingly.

Database connections

Store encrypted credentials to query external SQL databases from IVR call flows or custom plugins.

Supported engines and security

Connection settings

Setting Description Range / Options
Connection Name System label 1–100 characters
Driver Database system MySQL / MariaDB, PostgreSQL
Host / IP Address Server hostname or IP address Letters, digits, dots, dashes
Port Listening port 1–65535 (defaults: MySQL 3306, PostgreSQL 5432)
Database Name Name of the database Letters, digits, _, $, ., -
Username Database user 1–128 characters
Password Account password Encrypted on save; leave empty to keep existing
Timeout Connection timeout 1–10 seconds (default 3 s)
Charset Character encoding utf8mb4, utf8, latin1, latin5
SSL Mode TLS connection security Prefer, Require, Disable

Test connection

Click Test Connection on the form or in the connection list to verify network connectivity, credentials, and latency. The test runs a lightweight SELECT 1 ping query and displays the round-trip latency in milliseconds.

A database connection that is currently in use by an IVR data step cannot be deleted.


IVR data steps

An IVR data step executes a fast data lookup during an active call, stores the retrieved value in an Asterisk channel variable, and routes the call to different destinations depending on the result.

Input sources

Data sources

Channel variable and cleaning

The returned result is cleaned to prevent dialplan injection: line breaks, control characters, and pipe symbols (|) are removed, and the value is truncated to at most 64 characters. It is stored in the chosen channel variable (default IVR_DATA_VAL), accessible downstream in dialplans, queue scripts, or CRM popups.

Routing branches

Each data step routes the call to one of three destination branches:

  1. Found (Match): A row was found in the database, or the HTTP request returned HTTP 2xx with a non-empty value.
  2. Not Found: The database returned 0 rows, or the HTTP request returned HTTP 404.
  3. Timeout / Error: The remote server did not respond within 2.5 seconds, could not be reached, or returned an error.

Each branch can route to any destination (extension, ring group, queue, another IVR, announcement, or hang up).

A data step currently selected as a destination in any IVR key, inbound route, time condition, or ring group cannot be deleted.


Worked example: VIP customer routing

Look up incoming callers in a CRM database and route VIP customers directly to a priority queue:

  1. Create the database connection:
    • Under Integrations → Database connections, click New Connection.
    • Set Name to CRM Read Replica, choose MySQL / MariaDB, enter the replica server host, database name crm, and read-only credentials.
    • Click Test Connection to confirm connectivity, then save.
  2. Create the IVR data step:
    • Go to PBX → IVRs, click Data Steps, then click New Data Step.
    • Step Name: VIP Customer Check
    • Input Source: The caller's number
    • Data Source: External database
    • Database Connection: Select CRM Read Replica.
    • SQL Query:
      SELECT tier FROM customers WHERE phone = :caller_id LIMIT 1
      
    • Channel Variable Name: CUSTOMER_TIER
    • Found (Match): Queue → VIP Support
    • Not Found: Queue → General Support
    • Timeout / Error: Queue → General Support
    • Save the step and click Apply Changes.
  3. Route calls to the step:
    • On Inbound Routes, select your main incoming DID.
    • Set Destination to IVR Data Step → VIP Customer Check.

When a customer calls, AiPBX checks their number in the CRM. If their record exists, the call is routed instantly to VIP Support, while new numbers fall back to General Support without caller delay.