Asterisk ARI - Pass channel to Stasis before Ringing - asterisk

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:
The Stasis app receives a second StasisStart when the caller hangs up, returning a Channel not found error.
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.
Create a Bridge.
Add the incomming channel A in this bridge.
Create a new outgoing channel B from your ari app with POST /channels/create.
Add the outgoing channel B in that bridge.
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

Related

Asterisk ringback tone recording

I made an outbound-call service application using Asterisk AMI interface.
Following is how my application works.
I generate an Originate request to internal channel using TCP/IP socket.
my dialplan accepts the request and run dial command. extension.conf file is
[from-internal]
exten => _X.,1,NoOP()
same => n,MixMonitor(${DialMonitorFile}.wav)
same => n,Dial(PJSIP/${EXTEN}#TRUNK_100-1234-5678,30)
What I want to do is record whole call process (from ringback tone sound until user hangup).
But, when dial started, only 44 byte size file is generated (maybe wav file header?) before user accepts the call. And, file increased after user accepts call.
Can someone help me how can I record ringback tone sound as well ?
Regards,
Brian
You should do Answer before MixMonitor if you want that
Please note, CDRs will be affected

Recording ChanSpy in Asterisk

One call-center needs to play music during phone calls on demand and it should be recorded.
So the auto dialing program makes a call through local channel:
[dialout]
exten => _XXXXXXXXXXX,1,Dial(SIP/${provider}/${EXTEN})
Then when answered it connects an operator:
[operators]
exten => s,1,MixMonitor(${FileName})
same = n,Dial(SIP/${EXTEN})
And then they have a button in questionary which sends to Asterisk AMI commands:
Action: Originate;
Channel: LOCAL/$num#whisper-to-participant;
Application: Playback;
Data: $song;
Async: True;
Here's "whisper-to-participant" context:
exten => _XXX,1,ChanSpy(SIP/${EXTEN},Bq)
So caller and callee both hear music and it's working fine. But I can't get this music be recorded with MixMonitor, I only hear caller and callee.
Can anyone suggest anything to make it work with MixMonitor? Maybe some completely different approach?
Solution
Instead of MixMonitor I use Monitor and it records everything even music barked to ChanSpy. This is the simplest resolution and it works.
You can put user from start to conference, record conference.
After that if you add music into conference, it will be saved
see Confbridge

Asterisk / SIP - Delaying the 200 OK till after calling card is entered

Im trying to figure out a clever way to delay the 200 ok for the sip handshake till after the "please enter your calling card code" that my voip system will be transmitting to the incoming call..
Any thoughts on this.. I must admit, I';m looking at this conceptually at this point and am a bit naive...
Thanks in advance!
You won't be able to at least if you're planning on supporting standard SIP devices.
You can send early media to a device, such as your "please enter.." audio, with a 183 Session Progress Response but I can't see that being much use as the SIP calling device won't send any DTMF tones to the server until the call has been answered which requires the 200 Ok response.
Despite that I suspect you may be looking at the wrong thing. The 200 Ok from Asterisk is for the call between the caller and the Asterisk server to get the DTMF tones and determine whether the next call leg is authorised. Only after the calling card code is accepted does the next call leg start. It sounds like your problem is that users are noticing that the billable call time includes the time they spend entering their calling card PIN. Fiddling with the 200 Ok response is not the way to fix that. Trying to get Asterisk to generate a new CDR for the second call leg would be a better approach.
For called party:
[main_content]
exten => _X.,1,Dial(SIP/${NUM}#provider,,M(dialout-macro))
[macro-dialout-macro]
exten => s,1,Noop(here you should add detect of "please enter")
exten => s,n,Noop(some other commands go)
exten => s,n,MacroExit;we are ready to connect call.
For calling party - you need ALL your provider support early media and dtmf before answer. It is posible get provider which support early media, yes. But i not know any system which support dtmf before answer,sorry.
Dialplan will be like this
exten => _x.,1,Read(variable,filename,10,n,3)
note: no answer should be BEFORE that command, should be used option n
n: to read digits even if the line is not up.
However as i say that will work only in theory.

Testing Asterisk SIP and DAHDI local calls

I am a real beginner in asterisk, so please tolerate my question :)
I tried to configure asterisk for realtime and it is working fine for local sip calls. Now, I am trying to make the following test with dahdi calls:
I connected an analog phone to an FXS channel of my Digium card and tried to call this phone (exten 124) from a sip softphone (X-lite).
I get the following error:
-- Executing [124#from-sip:1] Dial("SIP/2000-00000004", "SIP/124")
[May 31 10:24:22] WARNING[5457]: chan_sip.c:5667 create_addr: Purely numeric hostname (124), and not a peer--rejecting
my extensions.conf:
[from-sip]
switch =>Realtime
[from-pstn]
exten => 124,1,Dial(DAHDI/3)
It seems that the dial is done using from-sip context not from-pstn context as required.
Anyone to advise or correct my understanding?
Thanks million
Zak
In Asterisk realtime and not realtime you can configure where to send calls from particular extension, this should be configured in "context"(for realtime check context column), so I believe in your case it is "from-sip". This means all calls from that extension will hit this context, you can't send one call from same extension to one context and other to another, all calls will hit "from-sip" context.

channel originate, how to do call from a local channel? (call intercom and send dtmf)

My goal is to :
run a background task activated by dynamic feature while in active call, that will execute dial to another EXT and send DTMF.
It means, when a user is active call with someone, when the user press 5555, the door will be opened.
In order to open the door today, I have to manually call EXT 6(the door) and send DTMF digits: 00*
All of this has to happen automatically when the user press 5555 without interfering the active call.
I tried before to do all of this with dial, but dial blocks the call or bridges with another extension and then I lose the original call.
I figured out that I need to do this with ASYNC, means I can not use dialplan, I need to use CLI, and then originate some how.
Asterisk will need to create a local session / local channel and establish/connect to the door extension, then send DTMF and hangup
All of this – in background.
this is somthing i managed to do so far:
features_applicationmap_custom.conf
openthedoor=> 5555,caller,macro,OpenIntercomCall
then in ->
extensions_custom.conf
[macro-OpenIntercomCall]
exten => s,1,System(asterisk -rx "channel originate SIP/6 extension#yoyo")
i do not understand how do i call to SIP/6 from asterisk(using a local or random channel), and then send DTMF on answer.
the door ext is SIP/6, and 00* is the dtmf to open it.
What i am trying to do is that when a user 5555 in a call, the door will be opened.
means i want asterisk to call the intercom and send dtmf
There are no any sence do exec asterisk from inside asterisk. You can do Originate command.
Originate(tech_data,type,arg1[,arg2[,arg3[,timeout]]])
For example you can do something like this
exten => s,1,Originate(SIP/6,app,SendDTMF,ww00*)
Should be enought for your need.

Resources