Sending DTMF from a web-based dialpad in Stasis and triggering logic

I’m working on a mobile simulator with a simple web interface that includes a dialpad. The flow is:

  1. User presses digits on the web dialpad.

  2. The digits are sent to a Stasis application in Asterisk.

  3. I want two things to happen when a digit is entered:

    • The caller hears the DTMF tone corresponding to the digit.

    • The Stasis app receives an OnChannelDtmfReceived event so I can run some logic in response.

I’m wondering: is there a way to send DTMF specifically from that channel so both of these things happen?

Right now, the digits are reaching the Stasis app, but I’m not sure how to make them audible to the caller while still triggering logic in the event handler.

Any guidance, examples, or suggestions would be really appreciated!

Thanks in advance.

If you are just looking to play the audio tone to the channel, then you would use play[1] with the digits URI. If that isn’t what the core of your question is, then you’d need to clarify more.

[1] Channels - Asterisk Documentation

Thanks for the response! To clarify my exact scenario:

I have two different Stasis apps, app-1 and app-2. The flow is:

I dial a number, and the dialplan sends the call to app-1.

From app-1, I generate an outbound call. That number’s dialplan points to app-2:

exten => 1234,NoOp(Call to 1234)
same => n,Ringing()
same => n,Stasis(app-2)

App-2 is connected to a web UI with buttons for hangup, answer, dialpad, etc. When I click answer in app-2:

AsteriskConfig.asterisk.channels().answer(channelId).execute();

App-1 sees the call answered.

App-1 creates a bridge and adds both channels.

Now the challenge: I want to send DTMFs from app-2 to app-1.

I’m polling a database in app-2 to get the digit.

I want the digit to be audible to the caller and trigger OnChannelDtmfReceived in app-1.

I noticed ARI sendDTMF injects DTMF into a channel, but it doesn’t behave like real “user-entered” DTMF.

Ideally, when a user presses a key in app-2’s web UI, it should act as if the user pressed it on their phone, so app-1 receives the DTMF event normally. (While in bridge if I enter some dtmfs from linphone both app-1 and app-2 receive channelDtmf received events)

It sounds as if you are trying to use ARI like it is a channel signalling protocol. It is not. It is also not a third party call control mechanism, where you can make it act as if a phone is doing things.

Thanks, I understand. I was hoping that perhaps via HTTP requests I could send events to simulate DTMF, but it sounds like that’s not feasible with ARI.

Would you say that attempting to simulate “from-channel” DTMF in this way is inherently difficult, or is there any recommended approach to achieve something similar?

I haven’t given it thought. You’re trying to use things in a way they weren’t inherently intended.

You could send the actual DTMF audio. The tones are not hard to generate.

To implement real-time response to the buttons (tone sounds as long as the button is down, stops as soon as it is released) would likely be easiest via a WebSocket connection.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.