Hi everyone.
I’m trying to use ARI event to forward call from one extension to anothe essentialy bypassing the diaplan.
In the code used below event is fired twice but it throws an exception with message 412 Precondition Failed
Anyone know how could I call an extension and answer a call using AsterNET library?
Thanks.
try
{
Console.WriteLine($"Channel {e.Channel.Id} entered Stasis.");
Console.WriteLine($"Channel state: {e.Channel.State}.");
if (e.Channel.State != "Up")
{
_client.Channels.Answer(e.Channel.Id);
}
var bridge = await _client.Bridges.CreateAsync(type: "mixing");
_client.Bridges.AddChannel(bridge.Id, e.Channel.Id);
var context = "from-internal-custom";
var endPoint = $"Local/{100}@{context}"; // The extension you want to dial
// var endPoint = "PJSIP/100"; // The extension you want to dial
var extension = "101";
var timeout = 30; // Timeout in seconds for dialing the extension
var newChannel = _client.Channels.Create(
endpoint: endPoint,
app: _app,
channelId: $"forward-{Guid.NewGuid()}");
Console.WriteLine($"New channel Id: {newChannel.Id}.");
Console.WriteLine($"New channel state: {newChannel.State}.");
if (newChannel.State != "Up")
{
_client.Channels.Answer(newChannel.Id);
}
_client.Bridges.AddChannel(bridge.Id, newChannel.Id);
}
catch (Exception exception)
{
Console.WriteLine(exception);
}