Initiate trunk to trunk through API

asterisk

I know it's possible to use the Originate action through the manager API to initiate a call between an external channel and an internal SIP extension. How would one initiate a call between two external channels?

By having this functionality one can help reduce the cost of calls from cellular or off-site phone systems by using a VoIP solution to bridge the call.

Best Answer

The secret of understanding the Originate action is to grasp that it's connecting a device to a context/extension/priority combination in the dialplan.

Typically, you'll see something like this:

Action: Originate
Channel: SIP/Alice
Context: testing
Exten: 200
Priority: 1

This would call Alice's SIP phone, and when she answers, connect her to extension 200 in the [testing] context.

Now, to connect two external numbers, all you need is an extension in your dialplan that knows how to dial an external number. Assuming we set up something like this:

[external]

exten => _NXXNXXXXXX,1,Dial(SIP/some_provider/${EXTEN})

then we could send calls to the [external] context in order to have them dial out to the outside. (I used North American numbering and a SIP trunk to connect to the outside world... your dialplan will obviously be a bit different, but I hope you get the idea.)

Once you have that in place, you can do this via AMI:

Action: Originate
Channel: SIP/some_provider/8005551212
Context: external
Exten: 8885554321
Priority: 1

This will call out to 8005551212, and when that line is answered, start dialing 8885554321.