asterisk play music while waiting for DTMF - asterisk

i am setting up a DISA in asterisk .
what i would like to do is play a music to the caller while asterisk is receiving the DTMF.
the DTMF would stop playing when it receives DTMF for "#"
i have tried using background() and playback() command , but they do not serve the purpose!
any ideas?
khan

You can try using phpagi. There is a function called fastpass_get_data, where you can get dtmf input while playing a sound.
http://phpagi.sourceforge.net/phpagi22/api-docs/phpAGI/AGI.html#fastpass_get_data

I'm assuming just using the builtin DISA application doesn't meet your needs. If it does, just use that.
There are different ways to program asterisk. You can use normal dialplan, ael dialplan, AGI, AMI, even write your own modules in C.
You can do more things in dialplan, but often using a real language through AGI results in more readable code.
Using the dialplan applications StartMusicOnHold, StopMusicOnHold, and either Read or WaitExten, you should be able to do what you want. Run asterisk -rx 'core show application StartMusicOnHold', etc, to read about each of those.
You basically want to run StartMusicOnHold, then gather digits using Read or WaitExten until you're done (perhaps collecting them into a channel variable), then run StopMusicOnHold.

Related

Do I need a dialplan?

I'm getting started with Asterisk and I have to develop an app that will only be used to call people (an alarm system).
I'm using Java and Asterisk-Java, and I read that on their GitHub:
Did you know you can originate directly into AGI? This is really powerful and eliminates the need for dialplan when doing AGI.
So, if I get it properly, that means I can do without a dialplan.
Though, I can't get Asterisk-Java to work properly, but I don't know it is because I have no dial plan or for some other reason.
Thanks
Yes, you need dialplan for anything except outgoing calling(initiated from asterisk side).
If you using only Originate and not need hangup handlers, caller id etc etc you can go without dialplan.
But in most cases it will be really tricky and usless.

Asterisk IP-PBX: API to set up and tear down a call between two extensions

I have a working system that controls a Cisco CUCM IP-PBX to set up and tear down a call between two parties A and B; it makes use of Java's JTAPI to:
make A call B
make B answer (pick up)
(wait for a few seconds)
make either A or B drop the call
Now I want to do the same with an Asterisk PBX (version 13.17.0). From what I have gathered, Asterisks JTAPI implementation doesn't work for recent Asterisks; the latest version that I can find, dates from 2006 and it seems to try and send AMI commands to which Asterisk replies something along the lines of "no such command" - I'm guessing the AMI syntax has changed over the years.
What I'm using now is a library called asterisk-java and more specifically, its AMI support. I'm sending an OriginateAction and the net effect is that:
Asterisk calls A
I have to pick up A's phone manually
A calls B
I have to pick up B's phone manually
finally a call is established between A and B
So instead of a fully automated process like in the Cisco case, I have to do manual work and I can't seem to find an API to just set up a call between A and B and having it drop after a couple of seconds.
Questions: is the AMI the correct API for my use case or is there a better alternative? And what API calls do I have to make to establish and drop a call?
Thanks,
Jan
Does this answered question help with establishing a call without picking up:
Originate a call with Asterisk - without the originating extension ringing
To have a channel drop a call, using AMI, you can use 'BridgeKick' to boot a channel, or 'BridgeDestroy' to cause each channel to 'BridgeLeave':
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+ManagerAction_BridgeKick

Asterisk AMI Atxfer on explicitely bridged channels

I'm trying to complete software which does all call logic via AMI on it's own using Asterisk only as interface to VOIP, SIP/GSM. Almost everything works great, but...:
Here is my scenario:
- incoming call is forwarded to announcement and then to MOH forever
- my app decides which extensions to dial (7777) using AMI Action: Originate
- once somebody picks up on extension, his/her channel (SIP/306-xxxxx for example) is bridged with waiting call's channel using AMI Action: Bridge
Until this point everything is working fine, both connected parties can hear each other, recording on demand works. All is fine.
Now I'm trying to make assisted transfer to another extension (Atxfer) using AMI on one of the bridged channels. And it doesn't work. I got couple of ami events about DTMF's on a channel (audio is muted while they are played). Every DTMF digit couses quick Bridge:unlink and Bridge:link event on AMI.
I tried to change dtmfmode, upgrade from asterisk 1.8 to 11 (asterisk now) and it always was the same.
While having this problems with Atxfer blind transfer on those channels works (using AMI Action: Redirect).
full log shows nothing something like this:
[2013-11-11 20:24:57] DEBUG[9457]: features.c:3740 feature_interpret: Feature interpret: chan=SIP/306-00000017, peer=SIP/GTS-00000016, code=*2, sense=1, features=0, dynamic=apprecord#apprecord
I recommend you read some asterisk book for beginner like ORelly's "Asterisk the future of telephony".
In you case correct solution is use asterisk Dial command for first channel instead of second call creation.
It is not clear how you do transfer using AMI. If you want do it via ami(which is VERY bad way), you have do something like following
On transfer request(digit) unbridge channels. Better put it in AsyncAGI after that.
Collect digits where to transfer using Read command
Transfer to new destination
If fail bridge again
NOTE: You resulting application will be really buggy and not scalable. AMI interface is not designed to do such things and work very bad when you have alot of actions and channels running on same box. So you have test your app under hi concurrent load to ensure it work(or more likly not work).

Record and playback simultaneously - Asterisk

I am trying to build an application where I am required to record and playback simultaneously. The application needs to go live on an asterisk telephony server. My problem is:
A user calls the asterisk server and starts to speak.
The voice packets being sent by the user are recorded in a wav file on the system.
A copy of the voice packets are sent as feedback simultaneously.
I have taken a look at ChanSpy, but it will not work if one is using Record.
My questions:
1. If a user calls an asterisk server, does that channel become a simplex or half-duplex channel?
2. Are there any commands etc. that allow us to do the above?
3. If not, does that mean I need to go into C programming for asterisk (agi-bin)?
P.S: Please let me know in case more information is needed.
Why not try MixMonitor? That allows you to record the call, and doesn't interfere with ChanSpy usage. ChanSpy IS the best way to do this, by the way.
You are wanting to feed to voice channel from the caller back to the same caller correct?
Have you tried the Echo command?

Asterisk Dialplan (extensions.conf) Applications

i am developing an application that shall allow users to access their mail boxes using their phones.
I developped an IVR menu of which users will make use to retrieve their mails. More specifically I write an AGI in perl to retrieve the mails. The issue is that the AGI execution takes quite a long time.To this end, I need to make my users hear some music played back in the background while the agi being executed. That is, i need to make the "AGI" and "MusicOnHold" applications in my dialplan execute simultaneously. Any clue how I can achieve this?
This may not be the answer you expected, but if you plan to create a proper application for doing stuff over the phone, have a look at other solutions apart from asterisk. Both yate and (as far as I know - never tried this one for anything serious) freeswitch implement a more asynchronous interface where you can connect an incoming call to whatever sound source you want without losing control over it. They may be a much better choice for advanced applications.
Asterisk is cool for simple logic, but if you need some processing in the background and leaving the call in some state for an undefined time, it becomes quite hard to manage.
You can issue SET MUSIC ON from you AGI applications, process your calculations, then issue SET MUSIC OFF.
If you want the music to be interruptable, issue this:
CONTROL STREAM FILE <filename> "0123456789*#" "0" "" "" ""
The second parameter is the list of digits able to interrupt the music.
It's better not to mix AGI and dialplan commands.
AGI is capable of everything dialplan is capable of, but AGI is implemented in a full fledged programming language and therefore gives you more control over the execution logic.
Is the complete execution taking a long time or just starting up the app? If the whole execution takes too long then you can do what Quassnoi says, start the music as soon as the AGI program starts.
If startup time is the problem, then you might need to implement something with FastAGI, so that your app is always running and listening for connections over a socket. The performance is much much better in an environment with a lot of AGI calls.

Resources