SOLVED Good Dialer for Mac OS X

edisoninfo

Guru
Joined
Nov 19, 2007
Messages
505
Reaction score
4
Any good dialers out there for the Mac? Not necessarily concerned about the incoming pop-ups, just would like a way to click a number in the Apple address book and dial. I am playing with CallControl now and it is so-so, but wondered if anyone else had a favorite.


EDIT:
I am only interested in native apps. I'm not a fan of web apps, sync'ing address books, etc. Way way too much hassle. I want to auto-launch an app, it sits quietly waiting for my command, I click the mouse, it dials.....
 

ppmax

Guru
Joined
Oct 18, 2007
Messages
79
Reaction score
5
I set up a pretty cool integration between AddressBook and Asterisk and will post a how-to when I get back from work tonight.
 

ppmax

Guru
Joined
Oct 18, 2007
Messages
79
Reaction score
5
First up, if you're using a softphone and want to dial using that application I suggest downloading Telephone which comes with an Address Book plugin:
http://code.google.com/p/telephone/

I prefer to use a real phone when talking at home, and have a regular phone hooked up to the LinkSys SPA2102 ATA. To dial from Address Book with a real phone, Address Book needs to send a command to a php page on your PBX's webserver, which then dials the number passed from Address Book, and then dials your home extension.

I grabbed a few bits of scripts from the net; some of this code seems to be based on a few things Ward published a while back here http://nerdvittles.com/index.php?p=168. I also found some AppleScript here http://www.jaredwatkins.com.

With these as a base I ended up with two files that you'll need to put in two locations. Before telling you where to copy them, here is the code for both--You'll probably need to make a change here or there.

AppleScript scpt file
Be sure to enter a password for the line "set passwd to..."; it can be anything you want;
Be sure to enter the IP address of your PBX for the line "set command to..."; this assumes your PBX is on your local network but may work remotely as well;
Code:
using terms from application "Address Book"
	
	on action property
		return "phone"
	end action property
	
	on action title for p with e
		return "Dial with Asterisk"
	end action title
	
	on should enable action for p with e
		if value of e is missing value then
			return false
		else
			return true
		end if
	end should enable action
	
	on perform action for p with e
		set telephone to value of e
		-- The insecure option is for using self signed ssl cert
		-- You should probably change the password  =]
		set passwd to "[your password here]"
		set urlencoded to urlencode(telephone) of me
		set command to "curl \"http://ip.address.of.your.pbx/asterisk-dial.php?key=" & passwd & "&telephone=" & urlencoded & "\""
		
		do shell script command
		return true
	end perform action
	
end using terms from

on urlencode(theText)
	set theTextEnc to ""
	repeat with eachChar in characters of theText
		set useChar to eachChar
		set eachCharNum to ASCII number of eachChar
		if eachCharNum = 32 then
			set useChar to "+"
		else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57) and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
			set firstDig to round (eachCharNum / 16) rounding down
			set secondDig to eachCharNum mod 16
			if firstDig > 9 then
				set aNum to firstDig + 55
				set firstDig to ASCII character aNum
			end if
			if secondDig > 9 then
				set aNum to secondDig + 55
				set secondDig to ASCII character aNum
			end if
			set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
			set useChar to numHex
		end if
		set theTextEnc to theTextEnc & useChar as string
	end repeat
	return theTextEnc
end urlencode

Here's the code from the asterisk-dial.php file;
You'll need to enter the password you entered in the applescript above; see the line "$GETREQUEST_KEY...";
Also be sure to set the extension number you want to ring at the line "ASTERISK_EXTEN..."; I set this to the extension of my main "normal" phone connected via the SPA2102;
Code:
<?php
error_reporting(E_ERROR);

$USERNAME         = "admin";		// Value from /etc/asterisk/manager.conf
$PASSWORD         = "amp111";		// Value from /etc/asterisk/manager.conf
$ASTERISK_HOST    = "127.0.0.1";	// The IP address of your local Asterisk server
$ASTERISK_PORT    = 5038;		// Value from /etc/asterisk/manager.conf
$ASTERISK_CONTEXT = "from-internal";		// The context, from /etc/asterisk/extensions.conf, to dial out.
$ASTERISK_EXTEN   = "SIP/100";	// The local extension you want to ring before dialing out
$GETREQUEST_KEY   = "[password from scpt file]";      // Set this to match the password in the applescript

// Bigtime security check
if ($_REQUEST["key"] != $GETREQUEST_KEY)
{
    $fp = fopen("/tmp/dialedcalls.log","a");                                          
    fwrite($fp,strftime("%Y-%m-%d %H:%M:%S") . " $_SERVER[REMOTE_ADDR] $_REQUEST[telephone] KEY_CHECK_FAILED\n");
    fclose($fp);
    die;    
}


Dial();

function Dial() {
    global $USERNAME,$PASSWORD;
    global $ASTERISK_HOST,$ASTERISK_PORT;
    global $ASTERISK_CONTEXT,$ASTERISK_EXTEN;

    $telephone = $_REQUEST["telephone"];
    $telephone = str_replace("-","",$telephone);
    $telephone = str_replace(" ","",$telephone);
    $telephone = str_replace(")","",$telephone);                                                                        
    $telephone = str_replace("(","",$telephone);                                                                 
        
    $socket = fsockopen($ASTERISK_HOST,$ASTERISK_PORT, $errno, $errstr, $timeout);
			
    fputs($socket, "Action: Login\r\n");
    fputs($socket, "UserName: $USERNAME\r\n");
    fputs($socket, "Secret: $PASSWORD\r\n\r\n");
			
    // Then we originate a call.  The effect of this (at least in my world, is to
    // ring my phone(s) ($ASTERISK_EXTEN) and then once I pick up, to
    // dial the number I passed ($telephone).

    fputs($socket, "Action: Originate\r\n");
    fputs($socket, "Channel: $ASTERISK_EXTEN\r\n");
    fputs($socket, "Context: $ASTERISK_CONTEXT\r\n");
    fputs($socket, "Exten: $telephone\r\n");
    fputs($socket, "Priority: 1\r\n");
    fputs($socket, "Callerid: Address Book\r\n");
    fputs($socket, "Action: Logoff\r\n\r\n");
			
    // Get the first line returned by the Asterisk Manager

    $wrets=fgets($socket,128);
			
    // Asterisk Manager will return 'Asterisk Call Manager/1.0' when we
    // connect to it.  This could be a smarter routine here -- we could
    // see if we actually authenticated and placed the call, etc.  For
    // now, we simply return an error if we didn't manage to connect
    // to the Manager at all.
			
    if ($wrets <> "Asterisk Call Manager/1.0")
    {
        echo "OK\n";
    }
    else
    {
        echo "Did not work!\n";
    }		

    // I like to keep a log of the calls I've made this way.
    
    $fp = fopen("/tmp/dialedcalls.log","a");
    fwrite($fp,strftime("%Y-%m-%d %H:%M:%S") . " $_SERVER[REMOTE_ADDR] $telephone\n");
    fclose($fp);

}

?>

Once you're done editing the files, save them locally and then copy them to the locations listed below.
* On OS X put the applescript file here:
~/Library/Address Book Plug-Ins/Asterisk Dial.scpt
FYI: The ~ tilde means your home/user folder; the absolute path would be:
/Users/[your username]/Library/Address Book Plug-Ins/Asterisk Dial.scpt

* On your PBX put the php file here:
/var/www/html/asterisk-dial.php
If you need to edit this file just do this:
cd /var/www/html/
sudo chmod u+w asterisk-dial.php //if it's not already, make the file writable
sudo nano -w asterisk-dial.php //edit the file with nano

After copying the php file to your PBX, chown the file to asterisk:asterisk and then chmod to 444. Chown will make asterisk own the file; chmod will make the file read only by all users.

The sum total of all this is that you can open address book, click the gray field name of a phone number, then choose "Dial with Asterisk" which will send a http request to the php page on your PBX...which then dials the number you chose...and then calls your home phone when the dialed number is connecting.

This worked so well I set it up on the wife's MacBook ;)

PP
 

jpe

Member
Joined
Nov 14, 2007
Messages
149
Reaction score
0
ha hah hah a... i was just posting a link to telephone and was going to ask about your addressbook integration. When I look I saw you posted and answered questions...
 

edisoninfo

Guru
Joined
Nov 19, 2007
Messages
505
Reaction score
4
Thanks ppmax!!! This is pretty much what the program CallControl does but this is free! One problem, the 'Dial with Asterisk' command shows up on the menu when I click the grey box by the phone number in the addressbook. But nothing happens. I watched the piaf cli and nothing, nothing in the httpd log files either. I missed something
 

ppmax

Guru
Joined
Oct 18, 2007
Messages
79
Reaction score
5
One problem, the 'Dial with Asterisk' command shows up on the menu when I click the grey box by the phone number in the addressbook. But nothing happens.

Im sorry it doesnt work--maybe I missed something ;)

Here are a couple things to check:
* On your PBX, open the file /tmp/dialedcalls.log
Can you post any messages found in that file?
* Out of curiosity, what did you enter for the var named $ASTERISK_EXTEN? This has to be set to an extension that is reachable/answerable for the callback when the number from AB is dialed.

It sounds as if the asterisk-dial.php script isnt getting called...which could be related to mismatched passwords in the applescript and php file (the password is used as a token on the query string passed to the php script.

Anther thought: have you changed the default admin/amp111 password found in /etc/asterisk/manager.conf?

Post back--we'll sort it out.

PP
 

edisoninfo

Guru
Joined
Nov 19, 2007
Messages
505
Reaction score
4
Im sorry it doesnt work--maybe I missed something ;)

Here are a couple things to check:
* On your PBX, open the file /tmp/dialedcalls.log
Can you post any messages found in that file?
There is no file like this

* Out of curiosity, what did you enter for the var named $ASTERISK_EXTEN? This has to be set to an extension that is reachable/answerable for the callback when the number from AB is dialed.
I changed the SIP/100 to SIP/20 which is my extension

It sounds as if the asterisk-dial.php script isnt getting called...which could be related to mismatched passwords in the applescript and php file (the password is used as a token on the query string passed to the php script.

Anther thought: have you changed the default admin/amp111 password found in /etc/asterisk/manager.conf?
I left the brackets in the password and just changed what was between them. Should I remove the brackets also?

I verified the username/password match what is in manager.conf


Post back--we'll sort it out.

PP

This is my very first encounter with Apple Scripts so I probably have something wrong. I first cut/pasted your code into TextEdit but it would not allow me to save it with that extension. I then realized I had to launch AppleScript Editor and paste the code in there which then allowed me to put the proper file/extension in the proper folder. So, I think I have that part right. When I click the Run command in AS shouldn't some sort of error show up in the Results window? Nothing happens.
 

edisoninfo

Guru
Joined
Nov 19, 2007
Messages
505
Reaction score
4
Solved

OK. Forget everything on the last post. It was the brackets in the password field. I removed them and it works great now!!!

Thanks again!!
 

jpe

Member
Joined
Nov 14, 2007
Messages
149
Reaction score
0
Just put this in, set it to an auto answer extension and it works like a charm! :biggrin5::D:hurray:
Thanks.
 

ppmax

Guru
Joined
Oct 18, 2007
Messages
79
Reaction score
5
Excellent--glad you got it to work!

I should have noted that the brackets had to go--and that previously I had tried a password that contained special characters which did not work. I may rewrite part of the script to allow for special chars beyond alpha/num.

Best
PP
 

jpe

Member
Joined
Nov 14, 2007
Messages
149
Reaction score
0
I had no issues installing. Went right in, worked first try. I have already installed it on 3 different macs here. Made a set of files for each, named accordingly and BAM...

I have been using Geotek's phone book that uses the Asterisk phone database. This setup is much sweeter.

Long ago, I used Mezzo's dialer set up, but it broke with some mac updates.
 

Bill Jackson

New Member
Joined
Nov 3, 2015
Messages
2
Reaction score
0
Excellent post, I just made this work (after a bit of effort) on Mac OS X Yosemite and Asterisk 11 on my Raspberry Pi

A couple of things for someone else trying to make this work:

1: when you enter the script above use the Apple script editor. If you use anything else it won't work and register. (this at least on Yosemite) When I used the script editor all was fine. Something to do with how the script editor sets up the file headers.

2: on my Mac I call a lot of international numbers and it's synced with my phone that often has an international SIM in it when I travel. Thus all of my entries in my address book have a + in them for country code. This + was coming across to the php from the address book. For whatever reason my asterisk configuration didn't like this and was rejecting the phone number. It took a while to figure this out by writing a lot more stuff to the dialed numbers file. I made a slight edit to the php code above where it takes out the spaces, "()" and "-" to also take out the + and it started working.

Since I'm using Google Voice as my provider it won't allow me to dial international numbers anyway so this was not an issue. It might be if you have a service provider that gives you international calling so you'll have to figure out how to make asterisk accept the +.

Anyway, thanks for the work, it now works perfectly. Now all I need to do is switch to a multi-line phone so that one is for "dialing" and the other has auto-answer on it so that this works without touching the phone.
 

Bill Jackson

New Member
Joined
Nov 3, 2015
Messages
2
Reaction score
0
Oh, I did make one small change in the php code. I set the caller ID on the call to the number being dialed instead of a generic text string "Address book" That's a bit more useful for me.

I was trying to pass a called number on the URL that fires the php but I can't figure out how to tell the address book to give me the name of the person along with the number. Maybe some day I'll get more time to figure that out.
 

Members online

Forum statistics

Threads
25,816
Messages
167,785
Members
19,246
Latest member
rahee
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top