title: Asterisk: connect one channel to another with AMI
body: <p>I've got Asterisk 11.4.0, a remote cloud server and a Node.js server as middleware. When any account tries to make a call, I need information from remote server which external line to use (or even not make this call at all!). Those data can't be calculated directly in Asterisk. Only after cloud's response the call must be proceeded. My action queue looks like this:</p>
  
  <p>Capture the call initiation from Asterisk with AMI on middle server;</p>
  
  <p>Send info to cloud for analysis;</p>
  
  <p>Proceed a call with passed in response external line using AMI (or not proceed at all);</p>
  
  <p>The problem is, I don't know how to make it. I think, when one tries to make a call, I can use WaitExten in dialplan option and capture Newchannel event with middle server, sending all information to cloud. When it responses, I can originate the call, using existing waiting line.</p>
  
  <p>Can you tell me, how can I attach channel to Originate operation, when i pass it as "channel" parameter, Asterisk do not connect this line with called exten.</p>