Asynchronous or multi-threaded dialing?


#1

I can’t seem to find any references to how I might solve this problem, even though it seems like it ought not be that unusual.

For illustration purposes, let me construct a scenario that I’d like to achieve. This is not a REAL example, so I don’t need help finding a workaround. I need to find a way to achieve this KIND of scenario more-or-less as described.

Say I call into asterisk from my cell phone. Based on recognizing my callerid, the dial plan automatically dials into my company voicemail and checks for messages. If messages are found, it records the “you have 3 new voicemails” response. Here’s the key part: this second channel is operating asynchronously from my initial call. In the initial call, perhaps I’m checking local voicemail in asterisk while the call to my company voicemail system is happening (to use a *nix analogy, I’ve run the dial command as a background task as if I could append a & at the end). After checking my local asterisk voicemail, I make a menu selection to find out whether there’s any voicemail on my company system. Now, asterisk is already prepared to play the recording back to me.

Again, the example might be a bit contrived, but essentially the model is a familiar “multi-threaded”, “asynchronous” or “background task” model, and that’s what I want to achieve.

So far, my leading candidate is to start a separate call (representing the background task - the one that checks company voicemail in my example) via a callfile, and have both it, and my initial call, managed via AGI scripts. The AGI scripts would then open some channel of communication between them – perhaps a simple unix pipe, or maybe shared memory or a database. But this approach seems awkward, and I’m wondering if I’m missing a more natural construct in Asterisk.

Appreciate any ideas or comments.


#2

[quote=“greyhound”]Say I call into asterisk from my cell phone. Based on recognizing my callerid, the dial plan automatically dials into my company voicemail and checks for messages. If messages are found, it records the “you have 3 new voicemails” response. Here’s the key part: this second channel is operating asynchronously from my initial call. In the initial call, perhaps I’m checking local voicemail in asterisk while the call to my company voicemail system is happening (to use a *nix analogy, I’ve run the dial command as a background task as if I could append a & at the end). After checking my local asterisk voicemail, I make a menu selection to find out whether there’s any voicemail on my company system. Now, asterisk is already prepared to play the recording back to me.

Again, the example might be a bit contrived, but essentially the model is a familiar “multi-threaded”, “asynchronous” or “background task” model, and that’s what I want to achieve.

So far, my leading candidate is to start a separate call (representing the background task - the one that checks company voicemail in my example) via a callfile, and have both it, and my initial call, managed via AGI scripts. The AGI scripts would then open some channel of communication between them – perhaps a simple unix pipe, or maybe shared memory or a database. But this approach seems awkward, and I’m wondering if I’m missing a more natural construct in Asterisk.

Appreciate any ideas or comments.[/quote]

It may be best to use an AGI to make a request to a server process (ie - use FastAGI to a daemon). The server process would then use the ManagerAPI to make the second ‘background’ call while immediately returning a unique request ID to the calling extensions logic. The extensions logic would then store that in a local variable, carry on its business and then make a call with that unique request ID via the AGI to the same server process to obtain the result.

Also, instead of the hypothetical scenario, what is it that you are actually trying to acheive?


#3

I’m sorry to be mysterious. I’m researching an idea with some commercial/licensing unknowns at the moment, so I need to keep some of the details confidential.

At this time, I’m just trying to figure out whether I’m missing some obvious Asterisk capability that would make this kind of application easier.

I appreciate the suggestion about fastagi and using the manager API. That might turn out to be easier than the technique I’ve been thinking about, but it’s still fundamentally leaving the management of the background process, and communication between the foreground and background up to me. I guess that’s just the way it’s going to have to be.

cheers,
john