asteriskasternet

Using Asterisk AGI to make outbound calls using Originate and controlling both sides of call


I am building a very complex IVR using the Asterisk AGI. I'm using AsterNET .NET framework to integrate into FastAGI.

Most of the scripting is working fine, the issue I am having is with making outbound calls. The IVR application will work with inbound calls coming into the dialplan which sends it over to AGI to do the work. The AGI script does loads of things, database look ups, multiple tiered menus etc etc, and also then makes outdials to numbers to connect the inbound caller too. Obviously, I could just use the Dial application in AGI so something like:

Exec("Dial", "PJSIP/Number,30,r")

and indeed I can and that works fine. However, I need more control over the outbound side of the call. For instance, I need to keep the inbound ringing or playing music, while the outbound answers and I play audio to the outbound. Which again, I know I can do using Dial, however, I need to play audio to the outbound side of the call, and allow them to accept the call or reject it using DTMF, which Dial does not do. If they reject the call, the outbound ceases and goes back to the inbound script to do something else, which maybe dial a different number, or do something else like voicemail.

So, I thought about using Originate instead, and passing it back to another AGI script, so something like:

Exec("Originate", "PJSIP/Number,app,AGI,agi://IP_Address:1234/outbound_call")

which again sort of works. The inbound waits for a bit while the outbound side answers, the outbound side then does whatever is in the script, and the inbound then follows it's script - separately. So then I need to join them together, so I use Bridge of course!!! But I seemingly have no idea what the other channel is to join them both together, and I have the issue of how do I notify my inbound leg what the status of the outbound leg is, as if I don't do this as soon as the outbound leg answers my inbound leg continues its execution, whereas I need it to wait if the outbound has answered and is requesting dtmf from the destination. I guess I could poll a database perhaps, but each script would again have to be referenced somehow.

I've also tried sending over the channel of the inbound to the outbound script, like:

("Originate", "PJSIP/Number,app,AGI,agi://IP_Address:1234/outbound_call," +  + request.Channel)

but I cannot get the Channel variable to show up, as i can't get multiple arguments working for arg2 on the Originate Exec, it just sees it as arg3 which is ignored if type is app.

Maybe I am coming at this from the wrong angle, so I'd appreciate any thoughts on how to do this. I cannot just use extensions to build this as it's far too complex, and it will be receiving many simultaneous calls, all using the same script but calling different destinations etc at the same time, and it's all dynamic.

Thanks

David


Solution

  • In case anyone is interested, I did this myself by using AMI to do an Action Originate to call out to my outbound call and send to an AGI script the inbound's channel, then my AGI script controls the outbound call, and then I use Bridge to bridge the outbound call from my AGI script to inbound using the channel parameter passed, so my 2 channels are completely separate so I can do what I like with either of them before I Bridge them together. Took me days of testing, but it's done without using Local channel or rewriting app_originate.