How to bridge after G(incoming_calls,ANSWERED,1)g

Im trying to make following:
Dial -> If failed call agi
-> if success call agi and bridge the connections

The connections getting bridged if not using G() howto do?

exten => DIAL,1,NoOp(Dial)
exten => DIAL,n,Dial(SIP/${TerminationProvider}/${CallTo},60,G(incoming_calls,ANSWERED,1)g)
exten => DIAL,n,Agi(agi:// … ailed=true)
exten => DIAL,n,Hangup()

exten => ANSWERED,1,Goto(ANSWERED1,1)
exten => ANSWERED,n,Goto(ANSWERED2,1)

exten => ANSWERED1,1,Answer()
exten => ANSWERED1,n,Agi(agi:// … _channel=${OriginatingChannel})
exten => ANSWERED1,n,Wait(2000)

exten => ANSWERED2,1,Bridge(${OriginatingChannel})

I’m fairly sure the Answer serves no useful purpose. Answer rarely does serve any useful purpose.

The dialplan code with the Bridge will get run in parallel with the AGI and cause it to get masqueraded out, before it completes - it may still have effective side effects.

We had to use G and Bridge, but you may find that the subroutine, etc., options of Dial will work in your case. This wasn’t for this application.

I haven’t got the code with me, but I’m fairly sure that we had to look up some channel variable with DIAL in its name to find the name of the channel to which to bridge.

I would consider this an Asterisk Support, not an Asterisk General topic.