c# asternet cancel outgoing-call

254 Views Asked by At

I'm using Asternet for my manager-program so employees can call a customer with just a click. But I'm trying to find how to cancel or disconnect a call to a customer. When I click on the call-button, the extension calls. When I pick up the phone, it starts to dial to the customer and a window appears to show the employee the progress. But I added a button so the employee can cancel the call. But I can't find any event or function to stop calling the customer.

manager = new ManagerConnection(host, port, username, password);
                manager.DialBegin += Manager_DialBegin;
                manager.DialEnd += Manager_DialEnd;
                manager.Hangup += Manager_Hangup;
                manager.PingInterval = 0;
                try
                {
                    manager.Login();
                    OriginateAction oc = new OriginateAction();
                    oc.Context = "from-internal";
                    oc.Priority = "1";
                    oc.Channel = "SIP/100";
                    oc.CallerId = "100";
                    oc.Exten = lblPhoneNumber.Text;
                    oc.Timeout = 30000;
                    oc.Async = true;
                    manager.SendAction(oc, null);
                }
                catch (ManagerException ex)
                {
                    var sendMail = Task.Run(async () => await Email.SendMail(Properties.Settings.Default.SmtpEmailLogAddress, "", "", "Error connecting to Asterisk",
                                                                            "Could not connect to the Asterisk-server for employee: " + Functions.GetEmployeeByID(Manager.Employee_ID),
                                                                            true, "", System.Net.Mail.MailPriority.Normal));
                }

Thanks!

1

There are 1 best solutions below

0
On

Ah, After searching and searching I have found it. In your button_click event add:

HangupAction hangup = new HangupAction(yourCallId);
manager.SendAction(hangup, 10000);
//Or var result = manager.SendAction(hangup, 10000).IsSuccess();
//Note that your manager must be private within your class