Starting an Application during a call

is there a way to start an Application except putting it in the dial plan?
I’d like to remote control my Asterisk server and if a specific event happens during the telephone call, I’d like to start an Application.
Thanks in advance!

YES. You have to write script which are listen to AMI events and if specific events are appear then you execute something

Or, if the event is a DTMF sequence, you can use features.conf.

thanks for the replys. If I undersand AMI correctly it listens for any channel events. Is there a way to start an Application if the event is not comming from the channel, so triggering an application from outside?

At this point, knowing your real goals would be useful.

However note that “applications” in the Asterisk sense have to be run on channels, and require a thread to do this. Only one thread can own a channel at a time, and in a normal call, that thread is the thread belonging to the incoming leg.

My goal is to remote control the Asterisk server and if I send event 123 form my PC to the server it should start application 456 e.g. record on the current channel

Current channel has no meaning outside of an already executing application or dialplan.

The only way of starting an application on a channel, other than through the dialplan or DTMF features, is to redirect the channel to a piece of dialplan that executes that application. That will result in the channel no longer being under control of the original dialplan, and, if it was in a bridge, it will removed from the bridge. In the case of a simple bridge, the other party in the bridge will receive a hangup event.

This last problem can be partly mitigated by the ability to simultaneously redirect two channels,

Note though that some manipulations on channels do not require an application to be run. You can certainly pause and resume monitoring without running an application. You may even be able to start it, but I would need to check that.

Unfortunately I also have to be able to whisper into the channel so monitor is not an option. I thought the best option would be to write an application but after starting it in the dialplan I can’t control it anymore, or am I wrong?
I just thought would ChanSpy() be a solution? The problem is I don’t really understand what chanspy can do. I thought I have my “normal” channel which is spyed and if I need to record something or whisper into the channel I could do that as Spy.So basically change the ChanSpy application a little so that it react to events and if a specific event happen it should e.g. whisper on channel. Or is there another way to “control” a channel.

I think you are in developer territory and need the developer mailing list or IRC channel.

However, you are still going to get better help if you specify your goals in concrete terms rather than in terms of your current thinking on the solution to them.

Ok, my problem is that I want to answer a call. Then I’d like to send some pcm files in form of an ast_frame on the channel using ast_write(chan, ast_frame). After that I just want to have a normal voice call, but if I invoke a method ((sendPCM(pcm)) from my PC it should again start sending the pcm file. Furthermore I want to have a method (getPCM()) that reads frome the channel with ast_read(chan) and sends the received data to my PC. If the call is dropped I’d like to get a responce to my PC in form of an event (callisdropped). This is basically what I’d like to develop. I hope that helps to understand my intention.

You can’t fundamentally do two things at once, that is you can’t start an app - or invoke ast_write/ast_read on a channel if it is doing something else. ChanSpy on the channel when used with a Local channel can be used to overcome this - as you then have ownership and control over the Local channel. This can allow you to spy and whisper on another channel. How you would get that audio to your PC is up to you… but triggering the ChanSpy/Local part can be done using AMI with an Originate and some dialplan.

Sounds good thanks, may I ask what do you mean with “AMI with an Originate and some dialplan”?

AMI can be used to initiate the call to spy/whisper on the channel and direct the Local channel to the dialplan. People use this for injecting some sound files into calls, for example.

Ok thank you, I’ll give it a try. Just one more thing, is ChanSpy corrupting the transfered data in any way? Or is it exactly the same as I would get without ChanSpy?

That depends on the option given to it. It can spy on either the audio from the channel, or both the audio to/from it which results in a mixed stream.

Ok thanks alot! As I don’t care what the “User” at my end says, I can configure it to only spy on the incoming audio.

While thiniking of how to implement the funktionality, another question raised. Is it possible to hang up while an application is executed with AMI? Also this is more complicated than hoped^^ Do you have any instructions or guidance for using AMI/developing AMI scripts?
Maybe I drop my requirements and strip the case of interfering the call. Is there an interface to remote control an application, so that I start my application at the beginning of the call invoke getPCM() and sendPCM(pcm) from my PC, end the application and have normal call without interfering again?

AMI provides a mechanism for hanging up a channel. I don’t have any example or handy code to show what you want. If you write an Asterisk application in C you would need to implement it how ChanSpy already works, and then the rest is up to you - how to get the audio around, how to control it, etc.