Asterisk REST - Playing Multiple files one API

I’m working on an IVR system and wondering how to play multiple audio files in sequence, based on a provided list—while also allowing termination on specific digit input.

For example, I want to play the following menu:

  • {for} {sales} {press} {1}
  • {for} {account} {press} {2}
  • {for} {tech support} {press} {3}

Ideally, I’d like to call a single API that accepts:

  • A list of media files to be played in order, and
  • A set of acceptable DTMF digits (e.g., 1, 2, 3).

While the audio is playing, if a valid digit is pressed, playback should stop immediately, and I should be able to detect which digit was pressed.

Currently, I have to:

  • Call the API separately for each menu chunk,
  • Monitor for digit input after each call, and
  • Manually stop the playback when a digit is detected.

This approach works, but it feels inefficient. I’m looking for a better way to handle this flow using a single API call, if possible.

Any ideas or suggestions?

The playback API allows specifying a comma separated list of sounds[1] so there is no need for separate API calls for each.

There is no capability in ARI to do this.

[1] Channels - Asterisk Documentation

Is there a good reason to use ARI? This is easy to do in dialplan, using Background() and WaitExten.

its works :slight_smile: Thanks.

I have some complex logic to handle.

Why? Isn’t the API good enough? Do you have some doubts?

ARI is a low level API, so, for things that are easy in the dialplan, you may need many steps.

The ExternalIVR dialplan command is supposed to offer something like this. But from my experience, its queuing doesn’t work right.

I have a working example that copes with the quirks in the ivr_dtmf_demo example script in my Seaskirt Examples repo.

There is a repository that uses the ARI and includes an example of using playback with DTMF tones: node-ari-client/examples/playback.js at master · asterisk/node-ari-client · GitHub