30 July 2005

Calling Features With Asterisk


In the past couple of days I’ve added a few useful calling features to the Asterisk installation we use for handling the calls to our household. These calling features would cost another $10-15 per month from the local RBOC if we wanted them normally. We’d just as soon not get nickeled and dimed for these though since they can be done for free.

There are snippets below to help the aspiring Asterisk user add these call features to their own system.

Caller-ID based Blacklisting

This feature takes incoming calls from specific folks that call a little too much and sends them somewhere that won’t make our phone ring. If the friendly, well-meaning vampires at the local blood bank are calling you twice every day, this is for you.

macro-stdexten

[incoming]
exten => s,1,Macro(stdexten,1234,SIP/MyInternalLine)


Now, in the macro-stdexten we tell it to check the blacklist. Key lines for this function are s,1 and s,102. The other lines are relevant to things I’ll cover later.


[macro-stdexten]
exten=s,1,LookupBlacklist ; If CID blacklisted, goto 102
exten=s,2,DBget(temp=CFIM/${ARG1}) ; Get CFIM (Call Forward IMmediate) key, if there isn't one, goto 103
exten=s,3,Dial(Local/${temp}@local/n) ; Unconditional forward
exten=s,4,DBput(lastcaller/${ARG1}=${CALLERIDNUM}) ; Note the last caller
exten=s,5,Dial(${ARG2},20) ; Call the extension with a 20 sec timeout
exten=s,6,DBget(temp=CFBS/${ARG1}) ; Get CFBS (Call Forward BuSy) key, if there isn't one, goto 107
exten=s,7,Dial(Local/${temp}@local/n) ; Forward on busy or unavailable
; Blacklisted CallerID
exten=s,102,Goto(blacklisted,s,1)
; No CFIM key
exten=s,103,Goto(s,4)
; No CFBS key = goto voicemail
exten=s,107,Answer
exten=s,108,Wait(1)
exten=s,109,Voicemail(u${ARG1})


So now people that have their phone numbers in the blacklist will get sent to blacklist s,1. We’d best define that…


[blacklisted]
exten=s,1,Answer
exten=s,2,Wait(1)
exten=s,3,Playback(nbdy-avail-to-take-call)
exten=s,4,Playback(carried-away-by-monkeys)
exten=s,5,Playback(lots-o-monkeys)
exten=s,6,Hangup


Now, I think the monkeys make the whole calling experience a lot more fun for the caller. If you want them to hear something more dignified you could always go for Playback(not-taking-your-call).

You can add and remove numbers from the blacklist by using the Asterisk console and database put blacklist 2025551212 1 and database del blacklist 2025551212. But it would probably be better if you could configure this from your phone so…


[blacklist-add]
exten=s,1,Playback(enter-num-blacklist)
exten=s,2,DigitTimeout(5)
exten=s,3,ResponseTimeout(30)
exten=_X.,1,DBput(blacklist/${EXTEN}=1)
exten=_X.,2,SayDigits(${EXTEN})
exten=_X.,3,Playback(num-was-successfully)
exten=_X.,4,Playback(added)
exten=_X.,5,Hangup

[blacklist-remove]
exten=s,1,Playback(enter-num-rmv-blklist)
exten=s,2,DigitTimeout(5)
exten=s,3,ResponseTimeout(30)
exten=_X.,1,DBput(blacklist/${EXTEN}=1)
exten=_X.,2,SayDigits(${EXTEN})
exten=_X.,3,Playback(num-was-successfully)
exten=_X.,4,Playback(removed)
exten=_X.,5,Hangup


If you are following the calling feature codes that are used in the United States, users should be able to do blacklist-add with *60 and blacklist-remove with *80.

Call Forwarding

Most of the logic for call forwarding is in the macro-stdexten above. If the call forwarding is configured, we send the call to that number. If you just have one PSTN line like we do, you’ll have to be able to route those forward calls over a VoIP provider, since the PSTN line may already be used up by the incoming call.

The main thing is simply to let people configure the call forwarding using a prompt system similar to the one we just used for the blacklist configuration. There are again standard calling feature codes for unconditional call forwarding in the United States. Activating call forwarding is *72 and deactivating is *73.


[callfwd-add]
exten=s,1,Playback(please-enter-the)
exten=s,2,Playback(call-forwarding)
exten=s,3,Playback(telephone-number)
exten=s,4,DigitTimeout(5)
exten=s,5,ResponseTimeout(30)
exten=_X.,1,DBput(CFIM/${CALLERID}=${EXTEN})
exten=_X.,2,Playback(call-forwarding)
exten=_X.,3,Playback(has-been-set-to)
exten=_X.,4,SayDigits(${EXTEN})
exten=_X.,5,Hangup

[callfwd-remove]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,DBdel(CFIM/${CALLERIDNUM})
exten => s,4,Playback(call-fwd-cancelled)
exten => s,5,Hangup


Last Call Return

So again, part of what lets this work is in macro-stdexten s,4 above where the last call to each extension is recorded into the database for posterity. Then we can offer last call return when people dial *69 with the following snippet:


[app-lastcallreturn]
exten => s,1,Answer
exten => s,2,Wait(1)
exten => s,3,Playback(last-num-to-call)
exten => s,4,DBget(number=lastcaller/${CALLERIDNUM}) ; goto 105 if no lastcaller
exten => s,5,GotoIf($"${number}" = ""?105,1) ; also if it's blank (caller id blocked)
exten => s,6,SayDigits(${number})
exten => s,7,Wait,1
exten => s,8,Playback(to-call-num-press)
exten => s,9,Playback(digits/1)
exten => 1,1,Goto(longdistance,1${number},1)
exten => s,105,Playback(unidentified-no-callback)
exten => s,106,Hangup


Summary

Most of this was adapted from examples at www.voip-info.org where there is a nice wiki with Asterisk information. I made an effort to clean up some of the examples they had and try to use the more standard vertical service codes. Hopefully this is useful to folks.


25 July 2005

Trēo 650 Overview


After 2 years of service, Verizon was kind enough to give me $100 off a new phone which I used to get a Trēo 650. It is a lot like the old Palm III I used to use back in the day to stay organized in school.

The Bluetooth syncing was a bit of a hassle to get set up. The “Transport Monitor” application on my Mac kept throwing up a dialog that said “Your request could not be completed. (16)” As it turns out you have to go into Bluetooth in the System Preferences and turn on “Bluetooth-PDA-Sync” in the “Sharing” tab. It ships turned off generally.

The free GraffitiAnywhere program let’s me get back to using Graffiti on screen for some of my writing which can sometimes be easier than thumbing the tiny keyboard on the device.

I’ve hidden away the “WirelessSync” tool that Verizon bundles, since some people suggest that it breaks the ability to sync normally. The Versamail install that comes on the CD-ROM but not on the device is vastly superior to the Mail program that is on the device. I have to guess that Verizon hides it on the CD to try and keep users from sending pictures via email rather than paying 25¢ an image to send them via SMS/MMS.

Working with some of the other contributors to Typo the free and open-source Vagablog Palm/Treo program. Just set it for “Blogger.com” mode and the Title and Category fields will do the right things.

I did manage to lock my Trēo up while playing around with the Adobe PDF for Palm translator. Somehow it managed to make an input PDF file double the size of the original and it filled up the device memory. This led to endless rebooting sadness. A hard reset of the device resolved matters after I got it limped far enough to delete the offending file.


21 July 2005

Switched to Typo


I’ve switched from using the PostgreSQL port of WordPress to using Typo for managing the weblog part of the site. This also means that I won’t be working on WordPress-pg any more since there isn’t a lot of motivation for me without having my own site on it.

Switching to Typo represents a number of changes:


  • it natively supports more than one database

  • it is written in Ruby rather than PHP

  • it has code that is much better organized

  • it has neat AJAX features and is much easier to add those features to

  • it has unit tests

  • the contributing community seems to better understand best practices

I’ve already made some small contributions (#151, #174, #178) to Typo that have been well received and are working on this site right now. Using Ruby on Rails together with svk makes it much easier to do development for this project and testing on any workstation I’m at. Futzing around with the settings for PHP and Apache was always a big hassle for doing simple development testing.

The direction I wanted WordPress to go was to be fully database-agnostic for the article, comment and other data. This is not achievable given the direction the project is heading. Database interoperability was simply not of any interest to the maintainers and the growing plugin community just increased it’s dependence on a particular database. The project lead’s ethical lapse and the fanboy-style responses by the user community to it reinforced my doubts about my involvement when the work on the code was getting more awkward because of the changes being made.

At the end of the day, working on WordPress was slow, awkward and unrewarding. There was no hope whatsoever that the work would ever be merged. Inferior tools were viewed as vastly superior and the usage and misusage of those tools was beyond question to key members of that community. I care about the quality of the tools I use and so I’ve moved on.

Development on Typo is moving along at quite a clip right now. New features are ridiculously easy to add, even if you care enough to do it The Right Way. I’ll need to get more up to speed with Ruby at some point. But some friends have been pestering me about that for a while now.

I’m not totally sold on Ruby and Rails yet, but they are certainly cleaner to work on than PHP. Some parts of the site may look a little different than they did before and the URLs may be a little different, but nothing is too broken now except the CSS for the Gallery. Let me know if something else is amiss.


01 July 2005

Coast Pictures Online


Our pictures from the Oregon Coast are now in the photo gallery. There are lots of pictures of the beach at Pacific City where we stayed and the view from our patio where I did a good bit of reading.

Picture of waves

It was another great time at the shore. A much needed break to relax and stop by our favorite haunts on the coast. The Grateful Bread Bakery provided tasty breakfast and lunch. The Pelican Pub & Brewery has a good red ale as a spring (and apparently early-summer) seasonal, the Doryman’s Dark is good too. I will admit however to not being too picky a beer snob, so no comments about bouquet and finish.

Further south we stopped by Ainslee’s Salt Water Taffy store in Depoe Bay and Mo’s. Later in the trip, caught by a desire for some italian food we set out for a restaurant Lincoln City which frustratingly closed at 7 or 8pm. After asking some locals for advice on what to do next, we made it down to the Italian Riviera Restaurant and Piano Bar in between Lincoln City and Depoe Bay for some wonderful pasta and good live jazz to boot, definitely a great find.

Getting out to relax is wonderful, and we were treated to some nice sunsets (see the new title graphic above) to boot. Overall, we highly recommend the experience provided you remember to put on your sunblock.


Finished Reading


Cryptonomicon was an interesting read. It is quite a long read, but a couple of recent trips I took gave me an opportunity to finish it off. Stephenson’s style of weaving 2, sometimes 3, fairly orthogonal storylines with shared character names took some bit of adjustment to get used to reading. It also meant that I couldn’t really read it late in the evening when I was feeling tired, as my brain just couldn’t follow along any more. The story itself was good and reasonably topical for those that fiddle with things like Tor and PGP/GPG. I’m a bit skeptical of the kid gloves that the governments in the story seem to have toward what the end of the story, but that’s why it’s fiction.

It would be hard to call the story science fiction, given that the technology described was well-established when the book was written.

This last week I picked up a copy of the decidedly-nonfiction Beyond Fear by Bruce Schneier. I’ve made some progress on it and will write more when I finish it. My impression at the moment, about half way through, is that it is a bit ponderous and self-contradictory in places. But then when it comes to describing a need for a more realistic evaluation of threats, I’m the choir and don’t need much preaching to agree.