I’m still old school enough to think that voice conversations still matter. So I call people, and they call me. When I’m out and about I like to know who has called me back at my office (no I don’t want my cell to ring EVERY TIME someone calls my home number, my cosinity number or my home office number). That way I can see who it is and give them a ring right back if it was really something we needed to discus.
I’ve had a number of solutions in place for this over the last 2 years or so. From IM messages to SMS messages. The problem with IM is the lack of great notification on mobile devices. The problem with SMS is paying 2-5 cents each.
This led me to think – maybe using Twitter and @ messages or DM’s was a better answer.
Before I give you the code let me first explain how this works. If you are not comfortable with Asterisk, Asterisk AGI, and customizing extensions.conf you should probably stop here.
Essentially I’ve created an AGI script in PHP which decides – by evaluating the assigned account from extensions.conf – what message to send and to whom.
Step One is adding the following 2 lines to extensions.conf where you process your incoming calls:
exten => XXXXX,1,Set(CDR(accountcode)=AccountName)
exten => XXXXX,2,AGI,send-twitter-msg.php
XXXXX is your current extension and AccountName is the account we will use in just a moment to figure out who to message and what to say.
Step Two is to create the following script in /var/lib/asterisk/agi-bin/ (call the script send-twitter-msg.php):
Download the script here. – Putting the whole script in the blog doesn’t work very well. There are instructions in the script.
UPDATE 09/16/2009: If the above download doesn’t work for you you can download the file zipped here.
All that is left is to reload extensions on the Asterisk CLI and make a test call. Everything should work.
One thing to test right away is that the AGI script is executable by root. There are two steps to make sure it is. First, check to make sure the correct path to php is in the first line of the script – try “whereis php” or “whereis php5”. Then update the first line as needed.Second, make sure the script is executable – as root try “chmod 700 /var/lib/asterisk/agi-bin/send-twitter-msg.php”
Have fun… if you have any questions drop a comment below and l’ll get back to you.