Phong Tình
Phong Tình

Reputation: 21

Asterisk catch a Incoming call and transfer it to a specific exten

I have been building a Window Form desktop application using C# that interfaces with Asterisk using Asterisk.NET. My first problem is catch a Incoming call and transfer it to specific exten. The first my idea is using OriginateAction, when a call come, I use Dial event and catch it and use OriginateAction to call to a specific exten.

RedirectAction originateAction = new RedirectAction();

originateAction.Channel = e.Channel;
originateAction.Context = "default";
originateAction.Exten = "203";
originateAction.Priority = 1;

ManagerResponse originateResponse = manager.SendAction(originateAction);
Console.WriteLine(originateResponse);

But it not work like my wish. The second my idea is using RedirectAction:

RedirectAction originateAction = new RedirectAction();

originateAction.Channel = e.Channel;
originateAction.Context = "default";
originateAction.Exten = "203";
originateAction.Priority = 1;

ManagerResponse originateResponse = manager.SendAction(originateAction);
Console.WriteLine(originateResponse);

And it not work.

I have find on many websites but the documents is very little.

How can I solve this issue?

Thanks!

Upvotes: 0

Views: 2798

Answers (1)

QuickDanger
QuickDanger

Reputation: 1112

I would suggest using some kind of dynamic dialplan instead of "catching" calls reactively. Why not use an AGI script?

Essentially, your application tells a database or other central system what to do when calls matching certain criteria come in. Then Asterisk runs the script you setup when calls reach a certain context (such as all incoming calls), and then the script routes the call dynamically based on the inputs given by your application.

Since you seem to like .NET, here's a .NET AGI project to help you get started: AsterNET. It looks like the library you mentioned, Asterisk.NET, is also capable of Fast CGI (what AGI uses), but the last release was in 2009, whereas AsterNet is active as recently as 3 months ago.

I personally use phpAGI to do all kinds of neat ACD and call routing stuff in our call center.

For more info on AGI, see the official docs.

Edit: I should probably also explain some basic call flow terminology (from the docs):

  • Originate: Generates an outgoing call to a Extension/Context/Priority or Application/Data. Example: User clicks a button, Originate a call to their desk phone, when they answer that call, it executes dialplan, or a dialplan application.
  • Redirect: Redirect (transfer) a call. Example: Agent and Customer are talking, but Manager wants to take over the call. Use Redirect to "take" the call from Agent and ring the Manager.
  • Dial: (in dialplan only, not AMI) Dial the technology/channel specified. Note that you can only Originate from your .NET application, not Dial.

Can you show your event handler code? It looks like that library would say something like manager.NewChannel += new ManagerEventHandler(new_channel);

Upvotes: 1

Related Questions