TAPI Click-To-Dial possible?

I am sure someone will find this useful… Here is the C# .Net version of this script.

I added the Event: off to the login so that I do not get unneeded events since we have a very busy phone system. We average about 2000+ calls a day through our asterisk server.

using System;
using System.Text;
using System.Net.Sockets;
using System.Net;
namespace SynergyProviders
{
    public class PhoneDialer
    {

        private string serverAddr = "192.168.0.233";
        private string mgtUser = "";
        private string mgtPass = "";

        public PhoneDialer(string serverAddress, string mgtUsername, string mgtPassword)
        {
            serverAddr = serverAddress;
            mgtUser = mgtUsername;
            mgtPass = mgtPassword;
        }

        public void DialPhone(int usersExtension, string numberToDial)
        {
            try
            {
                
                using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP))
                {
                    var svrAddress = IPAddress.Parse(serverAddr);
                    var svrEndPoint = new IPEndPoint(svrAddress, 5038);
                    socket.Connect(svrEndPoint);

                    var byteData = new byte[128];
                    var byteResp = new byte[1024];
                    var cmdString = "Action: Login\r\n";
                    cmdString += string.Format("Username: {0}\r\n", mgtUser);
                    cmdString += string.Format("Secret: {0}\r\n", mgtPass);
                    cmdString += "Event: off\r\n\r\n";

                    socket.Send(Encoding.ASCII.GetBytes(cmdString));
                    socket.Receive(byteData);

                    cmdString = "Action: Originate\r\n";
                    cmdString += string.Format("Channel: SIP/{0}\r\n", usersExtension);
                    cmdString += string.Format("Exten: {0}\r\n", numberToDial);
                    cmdString += ("Variable: _SIPADDHEADER55=Alert-Info: Ring Answer\r\n");
                    cmdString += "Context: from-internal\r\n";
                    cmdString += string.Format("CallerId: \"Synergy Dialer\" <{0}>\r\n", usersExtension);
                    cmdString += "Priority: 1\r\n";
                    cmdString += "Async: yes\r\n\r\n";

                    socket.Send(Encoding.ASCII.GetBytes(cmdString));
                    socket.Receive(byteData);

                    socket.Close();
                }
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Unable to dial number: {0}", e.Message) );
            }

        }
    }
}

I use it in in my page by by putting it in a linkbutton. The code in the event is as follows.

var dialer = new SynergyProviders.PhoneDialer(szServerIp, szUsername, szPassword);
dialer.DialPhone(Convert.ToInt32(WebProfile.Current.PhoneInfo.PhoneExt), szNumberToDial);

have fun…

John

Hi all,

I have had this succesfully installed however when I right click and select dial, it dials to the phone no problem.

Is there a way to create a pop that will display for a couple of seconds to confirm the call is being transferred succesfully?

Thanks…

Thanks perholmes! This PHP page is exactly what we needed to dial from our web based medical records program. I am currently using it with Elastix 2.3 without any issues. The only thing I had to do was modify the script to leave the page when it was finished. Otherwise, when you use it as a right click option in Internet Explorer, it would not let me dial the same number twice. It appeared to be a caching issue. I fixed this by disabling caching in the page, and adding a redirect…

I created another page for the re-direct called “q.php” with the code:

<html> 
<head> 
<title>Done...</title> 
</head> 
<body style="background: blue; color: yellow; font: 12pt bold sans-serif;">
Done
</body> 
</html>

Then I added lines to the p.php to disable caching and redirect to the new page:

<html> 
<head> 
<title>Dialing...</title> 
</head> 
<body style="background: blue; color: yellow; font: 12pt bold sans-serif;"> 
<pre> 
<meta http-equiv="pragma" content="no-cache" />
<body style="background: blue; color: yellow; font: 12pt bold sans-serif;"> 
<pre> 
<? 

if (( !empty( $_REQUEST['n'] ) ) && ( !empty( $_REQUEST['x'] ) ) ) 
{ 
       $num = $_REQUEST['n']; 
       $ext = $_REQUEST['x']; 
       $pre = $_REQUEST['p'];

       $num = preg_replace( "/\D/", "", $num ); 
       $num = $pre . $num;

       if ( ! empty( $num ) ) 
       { 
               echo "Dialing $num\r\n"; 

               $timeout = 10; 
               $asterisk_ip = "127.0.0.1"; 

               $socket = fsockopen($asterisk_ip,"5038", $errno, $errstr, $timeout); 
               fputs($socket, "Action: Login\r\n"); 
               fputs($socket, "UserName: admin\r\n"); 
               fputs($socket, "Secret: password\r\n\r\n"); 

               $wrets=fgets($socket,128); 

               echo $wrets; 

               fputs($socket, "Action: Originate\r\n" ); 
               fputs($socket, "Channel: SIP/$ext\r\n" ); 
               fputs($socket, "Exten: $num\r\n" ); 
             //  fputs($socket, "Variable: _SIPADDHEADER55=Call-Info: answer-after=0\r\n" );
               fputs($socket, "Context: from-internal\r\n" );
	       fputs($socket, "CallerId: Dialing <$num>\r\n"); 
               fputs($socket, "Priority: 1\r\n" ); 
               fputs($socket, "Async: yes\r\n\r\n" ); 

               $wrets=fgets($socket,128); 
               echo $wrets; 
			   
	       //Added to redirect to q.php
	       header("Location: http://phone/ClickToCall/q.php/");
			   
      } 
       else 
       { 
               echo "Unable to determine number from (" . $_REQUEST['n'] . ")\r\n"; 
       } 
} 
else 
{?> 
Please enter a number to dial. 
<?} 

?> 
</pre> 
</body> 
</html> 

Note: I only use this for right clicking in IE. If you want to use with Firefox or Safari you may have to add those lines back in from the original…

hi, wondering if the above is still the best option? I am looking into Weaver Snap too (http://www.weavver.com/products/snap/)

I didnt luck with Noojee click. It doesn’t want to install, keeps getting hung up during install. So, unfortunately it just says “Installed locally”.

I’ve tried both versions of Nojee click - Firefox and Chrome. Both of them had issues - the Chrome version kept popping up notifications, and the Firefox version would fail to dial occasionally.

I grew my own solution with a php script and WGET, and it responds to callto: links in IE.