Creating an Outgoing Channel

Hello Everyone,
First of all i trying out asterisk for the very first time.
i want to build a simple application where two sip peers could connect with each other via the ARI (Stasis App)
Right now i can connect to Stasis app, but then i want to create a new outgoing channel, the add it to a bridge. But i cannot work out reading the documentation, how would i create an outgoing channel, as i am unaware how the parameters would be in my code.
ari.channels.create(
{app: val, endpoint: val},
function (err, channel) {}
);
Promises:

ari.channels.create({
app: val,
endpoint: val
})
.then(function (channel) {})
.catch(function (err) {});

suppose my stasis app name is outgoing and then my goal is to call a sip peer from my extensions.conf file, how would i proceed.

Please bear with me, as this is very new to me.
looking forward to hear from you guys.

For create the app value would be the name of your Stasis application (outgoing) and endpoint would be the dial string to call your SIP device, such as SIP/test.

After creating the above channel you would need to create a bridge, add it to the bridge, and then call dial on the channel.

There is also the originate which takes the same arguments but will only enter your Stasis application when the channel is answered (it is a combined create + dial).

Hi jcolp,
After your help, I tried following the steps as below.
Created an outgoing channel.
Creating a bridge.
Then answering the inbound call.
Connecting the incoming channel with bridge.
Connecting the outgoing created channel to the bridge.
But when i try to connect my bridge with created outgoing channel, It throws me an error “Channel in invalid state”.
Any thoughts or suggestion why it throws me the error “Channel in invalid state”.

You would need to provide the console output, as well as which way you are using to dial the channel (originate or create+dial).

Hi jcolp,
I have attached a screenshot of my console output.
The steps i have followed are as below.

  1. In my stasisStart , the channel is answered first.
  2. Then i create a mixing bridge and play music on hold on it.
  3. Then i create an outgoing channel with the command —> ari.channels.originate({app:“Juggle”, variables: {“CALLERID(name)”:‘ravi’}, endpoint: “SIP/ravi”}
  4. Then add the original channel and the dialed channel channel (dialed via the originate command) to the bridge.
  5. i can hear the music on hold on both channels. but my goal is to establish a audio call connection between the two.

Am i following the right steps to establish a call connection between the two sip peers ?
Also one more thing, if the dialed channel is not answered and i try to bridge the channel, then i get an error.
many Thanks in advance and really looking forward to hearing from you.

Have you waited until the outgoing channel is answered before adding it to the bridge?
Have you stopped MOH on the bridge?

That was my doubt , do i have to first answer the outgoing channel and then add it to the bridge ?
i haven’t stopped playing the music because i wanted to make sure whatever i have done till now is in the right direction of my goal. but i will certainly try to stop the music on hold as soon both the call are bridged together.

The originate functionality will only have the channel enter your Stasis application when the channel is answered. Until that time you can not do anything with the channel except hang it up.

Thank you for helping me out. I will try to implement it. I really appreciate the help you are providing.

Hi Jcolp,
I would want my stasis application to connect to a soap server which in turn provides me some service. i wanted to know how it can be done ?
going through the documentation, i realized that client.connect(url, username, password, function (err, ari) {}), connects me to the asterisk server, but i also want the same client to be connected to the soap server.
Can you guide me in the right direction .

You would need to find a library or something to connect from within your application. The same as if you had written something not involving Asterisk at all.

Hi jcolp,
I have a situation where a sip call goes into my stasis application, i can get the details of the channel by using commands like, channel.name and channel.id.But i need to get the IP address of the Sip peer in my stasis application. i can check the Ip address in asterisk console by the command “sip show peers”, but i want the same IP in stasis. Can you help me in figuring out a way to do that.
Thanks in advance.

Hi jcolp,
i wanted to know is there a way i could to dial to real world phone numbers from my asterisk application instead of the sip peers from my sip.conf ?
Thanks in advance.

Something has to define how you call to the PSTN. You either do it in the dialplan, or in your application. If using the dialplan you can use a Local channel like Local/18005551212@outgoing which would call extension ‘18005551212’ in context outgoing and in that context could Dial() using a SIP provider or something else.

howto do it from stasis application?