This may qualify as the single most complicated way to dial the phone ever created. However the end result — click on number in the Mac OS X Address Book and have it dialed for me — is quite neat.

OS X Address Book

Here’s what happens when I select the “Dial” mouseover for a telephone number: an AppleScript is called that sends an XML-RPC request to a PHP-based XML-RPC server that then, in turn, places the call by connecting, over TCP/IP, with the Asterisk Manager API, to my Asterisk PBX.

The end result is that the phone on my desk rings, I pick up, and my call is connected with the number I selected.

Here are the pieces.

The AppleScript Address Book Plug-in

Using this burger locator script as a starting point, I created an AppleScript called AddressBook2Asterisk [hint: on a Mac, simply click on that link to open the script in Script Editor] that looks like this:

using terms from application “Address Book”
  
  on action property
    return “phone”
  end action property
  
  on action title for p with e
    return “Dial”
  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
    set resultList to DialOut(“peter”, “secret”, telephone)
    return true
  end perform action
  
end using terms from

on DialOut(username, password, telephone)
  tell application 
    “http://www.serverurl.com/directory/asterisk-dial-xmlrpc.php”
    return call xmlrpc {method name:”asterisk.dial”, 
    parameters:{username, password, telephone}}
  end tell
end DialOut

The XML-RPC Server

This AppleScript calls an XML-RPC server called asterisk-dial-xmlrpc.php, written in PHP, using the Useful Inc. XML-RPC in PHP code running on my webserver.

The XML-RPC server accepts three parameters from the XML-RPC client called from AppleScript: username, password and telephone number. The username and password are the same as in /etc/asterisk/manager.conf. This affords some measure of security, as it means that without the username and password, arbitrary calls to Timbuktu can’t be made by others (note, however, that the password is sent cleartext, so you should take precautions if your client and your server aren’t local to each other and behind a firewall).

Dialing the Telephone

Assuming the username and password are correct, the PHP script then, using a snippet of code found here, connects directly with the Asterisk Manager API via TCP/IP on port 5038, and originates the call.

And that’s it: select “Dial” and the phone rings and the call connects.

Why XML-RPC?

You may wonder why I complicate things by using XML-RPC to communicate from AppleScript to Asterisk rather than simply connecting directly to the Asterisk Manager API from AppleScript. Simple answer is “I couldn’t figure out how to do that.” More subtle answer is “creating the XML-RPC server means I can dial the phone from anything in the world that can talk XML-RPC.”

I’m not a master, or even a journeyman, at AppleScript, XML-RPC or Asterisk, so I welcome commments on improving the code.

One of the perils of running your own open source PBX is that a lot of the things that you can “just assume” about running a phone system you have to remember to think about with Asterisk. For example, today I was experimenting with the Asterisk Manager API and used it to open a channel to my outside POTS line. I then got distracted, and forgot to “hang up” the channel, so the line stayed “in use” for 3 or 4 minutes until I realized the error of my ways.

BTW, the solution to the immediate problems was to connect to the Asterisk CLI, and issue the command “soft hangup Zap/1-1”.

My friend, and Zap Your PRAM speaker, Art Rhyno has been named Academic Librarian of the Year by the Ontario College and University Library Association. In Art’s field, this is like winning the Oscar for Best Director. Congratulations, Art!

Please note that in the introductory minutes to yesterday’s keynote at MacWorld, there was strong reinvented presence:

Northwest Airlines has a dramatic new visual identity. Compare this to the old look.

Daniel Burka did some high-quality investigative journalism and got the real story of the new Formosa location.

The RSS feed for the Drive Around the World just got converted to a full feed (i.e. the full text of posts, including photos, rather than frustrating excerpts). This is great, and makes it far easier to follow the expedition. Thanks!

I’ve been experimenting with VoicePulse Connect!: I’ve got a Peterborough, NH number set up to send calls, via IAX, to my Asterisk server, and I’m dialing out from the same server, again via IAX. The advantage of the incoming setup is that it allows toll-free calls from my customer in southern New Hamphire, and the advantage of the outgoing is that I can make long distance calls for 2.95 cents/minute ($US) in North America.

Quality-wise things have been mixed.

I bridged a call into my Eastlink line (also running into the Asterisk server) with an incoming VoicePulse call yesterday (using the handy Asterisk MeetMe application, which makes it very easy). The people on the other end of the VoicePulse call were on a speakerphone, and their voices were “pixelated” (for lack of a better word). There was another person, not on a speakerphone, conferenced in on their end, and his quality was much better, so I assume this is a mixture of challenges of the speakerphone (which has never been excellent) and silence detection cutting off quiet voices (people closer to the speakerphone came in much louder).

For regular handset-to-handset calls, I’ve found incoming calls on the VoicePulse number to be very clear and “telephone call-like” while outcalls, both to the U.S. and Canada, have suffered, at least today, from a lot of clicking and popping and crosstalk. Of course because of the number of steps along the way, it’s difficult to isolate the source of these problems, and I’m sure at least some of them are bandwidth related, either on my end, or somewhere along the way.

So far I’m willing to continue to experiment, as the quality is still “good enough.” It’s possible that with some configuration changes on my end, I can improve things too.

Norman Kunc, who is my sister-in-law’s sister’s mother’s husband, was on Sounds Like Canada on CBC Radio this morning talking about disability. He’s a powerful speaker, with a good message; if you have a chance to hear him speak, you should take it.

The point he made that hit me most strongly was a suggestion that we need to learn how to see the intrinsic rather than comparative value in people. In other words, judge me for what’s inherently good (or bad) about me, not by comparing me to others. If we all did more of that, I think we’d all be happier.

Kudos to the Sounds Like Canada, by the way, for putting URLs in their daily show logs.

The CBC Archives on the web, which remains a beacon of sanity inside the sometimes crazy online presence of the corporation, has an excellent feature on the Toronto and Montreal subway systems. Well worth a browse and/or listen.

About This Blog

Photo of Peter RukavinaI am . I am a writer, letterpress printer, and a curious person.

To learn more about me, read my /nowlook at my bio, listen to audio I’ve posted, read presentations and speeches I’ve written, or get in touch (peter@rukavina.net is the quickest way). 

I have been writing here since May 1999: you can explore the 25+ years of blog posts in the archive.

You can subscribe to an RSS feed of posts, an RSS feed of comments, or a podcast RSS feed that just contains audio posts. You can also receive a daily digests of posts by email.

Search