Tech

Server controlled prompts and call flow through IVR

Published on:

March 4, 2025

Vodia's IVR has become even more powerful with JavaScript control, enabling dynamic prompts and call flow adjustments directly from a server. By leveraging HTTP requests, the IVR can fetch responses in real-time, allowing customized greetings, prompts, and call transfers based on caller input. For example, customer codes entered via DTMF can be validated through a server, triggering personalized responses and directing calls to the appropriate destination. This flexibility enhances automation and improves customer interactions, making Vodia’s IVR a highly adaptable and intelligent solution for businesses.

Vodia IVR has become more powerful and intuitive with javascript control and call flow.

Apart from communicating with AI (through voice) and powerful call flow (which is covered in another blog), it can also be used much more flexibly (thanks to javascript) in a variety of other ways. One of them is to control the prompts and call flow from the server.

IVR Setup

To set up a Vodia IVR node to use Javascript, simply choose “Javascript” from the dropdown in the IVR node settings and save. A text area will appear where you can enter your javascript code - if you want to do anything with the call that's connected to this IVR (say from an outside trunk number that ended up in this IVR), use the call object as shown below.

Play prompts from a Server

To play a prompt, you can use Text to Speech in the call object. For example, to greet someone in a call connected to the IVR, simply call the “say” function of the call object:

call.say(“Hi, you have reached company ABC, how may I help you today?”)

The above text will be converted to speech and played for the caller.

Similarly, this text can come from a server in response to an HTTP request based on different situations, e.g., what code (through DTMF) the caller provided as a customer, etc.

HTTP example

Here is how to POST an HTTP request to a server (replace SERVER_UTL with your server url) with a body of some numbers. It accepts a javascript function as a callback, which is called when a response is received from the server with the code, response, and headers - as you can see below. In this example, the response is in JSON format, so it is parsed for the message and the message is played to the caller with call.say(res.message).

  var body = “123456  var args = {
    'method':'POST',
    'url': 'https://SERVER_UTL',
    'header': [ { name: 'Content-Type', value: 'text/plain'} ],
    'callback': callback
  }
  if (body) {
    args.body = body
  }
  system.http(args)

  function callback(code, response, headers) {
    console.log("IVR response:" + code.toString())
    var res = JSON.parse(response)
    if (res.message) call.say(res.message)
  }

Call flow control from a server

When you want to transfer the call connected to the IVR to another extension, group, IVR or anywhere else, simply call the transfer function of the call object with the destination. For example, to transfer to another IVR 87:

call.transfer(“87”)

Similarly, as in the example above, that destination can come from the server as a response to an HTTP request.

A simple example

Let’s say we want to ask the customer to enter a customer code, send it to a server and, if found, give one prompt, followed by a transfer to the customer service department, say account 42. If the code isn't found, a different prompt will be given and followed by a transfer to a different IVR (let's say 70).

'use strict';

call.say('Welcome to company ABC. Please enter your 8 digit customer number.')

var digits = ''
call.dtmf(ondtmf)
function ondtmf(digit) {
  digits += digit
  if (digits.length == 8) {
    send(digits)
    digits = ''
  }
}

function send(digits) {
  var body = digits
  var args = {
    'method':'POST',
    'url': 'https://SERVER_URL',
    'header': [ { name: 'Content-Type', value: 'text/plain'} ],
    'callback': callback
  }
  if (body) {
    args.body = body
  }
  system.http(args)

  function callback(code, response, headers) {
    console.log("IVR response:" + code.toString())
    var res = JSON.parse(response)
    if (res.message) call.say(res.message)
    if (res.transfer) setTimeout(function(){
      call.transfer(res.destination)
    }, 5000)  
  }
}

Of course this is just an example. This can be accmplished in different ways and with proper checks and logs, etc.

The function call.ondtmf() takes a function as callback, which is called every time a digit (DTMF) is pressed with the value of the digit passed as argument. In this example, they are being concatenated into a string and finally sent to the server. In this example, the server responds with a JSON reply with a message (to play out as speech) and a destination (where to transfer the call after playing the message).

So, if the number is found it could return something like this:

{

  “message”:“Thanks Mr. Jones for the number. I will now transfer you to Customer Service.”

  “Destination”:“42”

}

If the number isn't found, it could return something like:

{

  “message”:“Sorry. The number you provided does not exist.”

  “Destination”:“70”

}

When the response is received and parsed, the message is played, then the call is transferred to the destination. The transfer is done after a timeout of 5 seconds (5000 ms) to provide some time for the message to be played out completely before the call is transferred.

if (res.message) call.say(res.message)
if (res.transfer) setTimeout(function(){
  call.transfer(res.destination)
}, 5000)

Vodia's IVR system with JavaScript control provides businesses with enhanced flexibility and power, enabling them to dynamically manage call flow, personalize prompts, and integrate real-time server responses. By leveraging HTTP requests and handling DTMF inputs, the IVR can offer customized interactions, improving overall customer service efficiency. Whether it's verifying customer information or directing calls based on server responses, Vodia’s solution enhances the IVR experience, allowing businesses to create more intelligent, responsive communication systems. For more information, contact us at sales@vodia.com or call +1 (617) 861-3490.

Latest Articles

View All

Real-Time Media Streaming in Vodia PBX: AI, Call Transcription, and Security in V69.5.6 | Webinar Recording Now Available

Vodia is excited to share the recording of our April 8, 2025 webinar on "Real-Time Media Streaming in Vodia PBX: AI, Call Transcription, and Security in V69.5.6." In this session, we explore how AI, call transcription, and security have become core features in the latest version of our PBX. We dive into the practical benefits of AI, including how it improves business communication with real-time transcription, enhances security with advanced features, and streamlines workflows through integrations like OpenAI and Microsoft Teams. Watch the recording to learn how these innovations can transform your business communications and boost efficiency.

April 16, 2025

Streamline Call Data and Recordings Directly to the Cloud!

Vodia offers advanced solutions for managing Call Data Records (CDRs) and call recordings, allowing businesses to handle data efficiently. Traditionally, CDRs were stored locally in CSV files, requiring manual transfer to remote locations, which can be time-consuming for organizations handling large volumes. Vodia simplifies this process by providing real-time streaming of CDRs using protocols like WebCDR, JSONS, TCP, and MongoDB, allowing for immediate analysis and custom report generation. Additionally, Vodia integrates with cloud storage services like AWS, DigitalOcean, Linode, and Wasabi, eliminating the need for manual synchronization and local storage. This integration enhances data security, scalability and ease of management.

April 15, 2025

The Vodia PBX Cloud Whisper AI Deployment

Vodia PBX now offers real-time call transcription through a seamless integration with Whisper AI, OpenAI’s advanced speech recognition system. With support for multiple languages, technical vocabulary, and noisy environments, Whisper delivers accurate transcriptions even in complex call scenarios. Administrators can enable transcription per tenant using an OpenAI API key, making setup simple and flexible. Once active, all calls are automatically transcribed and accessible in the user portal for easy review and record-keeping. This powerful integration brings enhanced clarity, compliance, and insight to voice communication—whether you're managing support teams, analyzing conversations, or working across language barriers.

April 9, 2025