Skip to main content

Create a Voice Application

A Programmable Voice Application is a server that takes control of the flow in a call. A Voice Application can use any combination of the following verbs:

  • Answer - Accepts an incoming call
  • Hangup - Closes the call
  • Play - Takes an URL or file and streams the sound back to the calling party
  • Say - Takes a text, synthesizes the text into audio, and streams back the result
  • Gather - Waits for DTMF or speech events and returns back the result
  • SGather - Returns a stream for future DTMF and speech results
  • Dial - Passes the call to an Agent or a Number at the PSTN
  • Record - It records the voice of the calling party and saves the audio on the Storage sub-system
  • Mute - It tells the channel to stop sending media, effectively muting the channel
  • Unmute - It tells the channel to allow media flow

Perform the following steps to create a Voice Application:

1. Open a new terminal
2. Create a new folder
3. Initiate a node application
4. Create the file index.js, add the application's content, save the file
5. Install the voice module
6. Run the application

First, create an empty NodeJS project with:

mkdir voiceapp
cd voiceapp
npm init # and follow the wizard

Then, with your favorite IDE create a file index.js with the following content:

const { VoiceServer } = require("@fonoster/voice");

const serverConfig = {
pathToFiles: `${process.cwd()}/sounds`,

new VoiceServer(serverConfig).listen(
async (req, res) => {
await res.answer();
await res.hangup();

Next, install the Voice module with:

npm install @fonoster/voice

Finally, launch the Voice Application with:

node index.js

Your output will look like this:

$ node index.js 
info: initializing voice server
info: starting voice server @, port=3000, path=/voiceapp

Your app will live at ⚠️ Be sure to leave the server up!

Using Ngrok to publish your Voice Application

Now that we have the Voice Application up and running, you need to make it available on the Internet. The fastest way to enable public access is by using Ngrok. For example, with Ngrok, you can publish a web server with a single command.

1. Open a new terminal
2. Start Ngrok with the application's protocol/port

Remember to keep your application running

Run Ngrok, in your console, with the following command:

ngrok http 3000

Now you can use Ngrok's URL as the webhook on any of your Fonoster Numbers.