简体   繁体   中英

Asterisk ARI - Pass channel to Stasis before Ringing

My goal

Pass an incoming call directly to Stasis and allow the app to decide whether to play a ringing or busy tone to the caller.

The problem

With my ARI app, if I omit the same => n,Ringing line from my dialplan, the Stasis app returns an error if the caller hangs up. I can have a call hang without any early media, until I pass a channel.play() command, via the ARI.

This solution has 2 issues:

  1. The Stasis app receives a second StasisStart when the caller hangs up, returning a Channel not found error.
  2. There is no command for channel.busy

Does anyone have any suggestions?

My only option that I can currently see is to ensure that all users have voicemail and a busy tone is never played. Not everyone wants / likes voicemail and it is not ethical to answer the call and play a busy tone, without the caller knowing that their call is connected.

Update

Using the following dialplan, I can get this to work in the desired way (plays busy to a user if they're not available), but with an error:

extensions.conf

[public]
exten => _.,1,NoOp()
same  =>    n,Stasis(myStasisApp, ${SIP_HEADER(to)})
same  =>    n,Busy(10)
same  =>    n,Hangup()

myApp.js

// The user is available
channel.ring();

// The user is busy
channel.continueInDialplan();

Error

Another StasisStart is sent when the caller hangs up, followed by:

Unhandled rejection Error: {
  "message": "Channel not found"
}

We faced the same problem and lost precious time finding out the reason so I'm sharing the solution here and maybe it will help.


extensions.conf

[public]
exten => _.,1,NoOp()
same  =>    n,Stasis(myStasisApp)
same  =>    n,Hangup()

When Asterisk receive a call, it will start the stasis app.

  1. Create a Bridge.
  2. Add the incomming channel A in this bridge.
  3. Create a new outgoing channel B from your ari app with POST /channels/create .
  4. Add the outgoing channel B in that bridge.
  5. Dial from channel B the destination, where both of the channels are in the same bridge with POST /channels/{channelId}/dial

Now, you will be able to see a new ARI Dial events with Ringing and Answer.

For the Hangup, you will receive Channels end events with Hangup Cause Code not a text like 17 for busy

Asterisk Hangup Cause Mappings

It's simpler to originate a channel (Asterisk version 13) instead of create and dial (Asterisk version 14) but you will not have the early media or a full control on that channel because it's created by Asterisk and not the ARI app so this channel will start sending event back to ARI when the call start and not before.

Asterisk 14 ARI: Create, Bridge, Dial.

ARI and Channels: Manipulating Channel State

This thread helped us a lot:

Re: ARI: add channel to bridge immediatelly after originate action

.

.

.

Have fun ! and Hope this will help.
/ohammami

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM