Sunday, November 14, 2010

Caller ID with Google Voice and Asterisk 1.8

Previously it was possible to do a lookup of your contact's name against the numbers in your GMail/Google Voice contact list and apply that to your CallerID via John Baab's method outlined on his blog.

I've since then discovered that since updating to Asterisk 1.8 with native Google Voice this no longer functions.  This is because the format of the CallerID string that is sent from incoming calls is now different.

The entire string is sent in the "Name" field of the caller ID.
For Voice Calls, this is what it looks like:
+18475551212@voice.google.com/srvres-MTAuMTIuMTM4LjI2OjD4NdM=
For calls coming in from Talk or GMail, this is what it looks like:
user@gmail.com/gmail.424BF12F

Fortunately, this entire field can be processed using built in asterisk functions to extract the data we need, restoring the functionality of John Baab's script.

Here's all the steps that i've taken to add Caller ID support:

1) Install python, python-expat, python-openssl
opkg install python python-expat python-openssl

2) Fetch John Baab's script and place it somewhere useful.
wget http://www.baablogic.net/googlecontacts.py


3) Download gdata-python from http://code.google.com/p/gdata-python-client/
wget http://gdata-python-client.googlecode.com/files/gdata-2.0.12.tar.gz


4) Manually install it.  The setup.py script doesn't work on OpenWRT, so this method can be used:

tar xzzf gdata-2.0.12.tar.gz
cp -r gdata-2.0.12/src/* /usr/lib/python2.6/site-packages/
rm -rf gdata-2.0.12*

5) Modify John's script to include your gmail login information.  Run it once manually to populate your database
./google-contacts.py

6) Modify your [google-in] context to process the number properly and do a database lookup:

[google-in]
exten => superm1@gmail.com, 1, NoOp(Callerid  ${CALLERID(name)})
exten => superm1@gmail.com, n, Set(CALLERID(num)=${SHIFT(CALLERID(name),@)})
exten => superm1@gmail.com, n, Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => superm1@gmail.com, n, Dial(SIP/101, 180, D(:1))

7) (optionally) Add this to your crontab so that it will sync new numbers on a regular basis.  John's script will actually redo the database on every run, so it will also get updates then for every removal too.
crontab -e

This will only take effect for calls routed in through google voice or talk because we only modify the google-in context.  If there is no data available, the name field will just remain empty and the number will be shown on Caller ID instead.


7 comments:

  1. i am not sure why i am getting
    [2010-11-14 22:30:13] ERROR[12197]: pbx.c:3564 ast_func_write: Function MASTER_CHANNEL not registered
    [2010-11-14 22:30:14] ERROR[12197]: pbx.c:3564 ast_func_write: Function MASTER_CHANNEL not registered
    [2010-11-14 22:30:52] ERROR[12197]: pbx.c:3564 ast_func_write: Function MASTER_CHANNEL not registered
    [2010-11-14 22:30:52] ERROR[12197]: pbx.c:3564 ast_func_write: Function MASTER_CHANNEL not registered


    any help would be appreciated

    thanks

    ReplyDelete
  2. Salim:

    I've noticed the same thing in my logs too. It appears to be benign however perpelxing.

    ReplyDelete
  3. thank you sir for taking out the time to respond...

    ReplyDelete
  4. I wonder if it would be worth the effort to package python-gdata for OpenWRT so it won't be necessary to manually install it each time...

    ReplyDelete
  5. Craig,
    By all means, go for it! :)

    ReplyDelete
  6. This is excellent information that I have used on two Asterisk 1.8 installations, one running on Ubuntu, and the other running on DD-WRT. Just a couple of caveats that I found when getting it set up on DD-WRT: copy files to cp -r gdata-2.0.12/src/* /opt/lib/python2.6/site-packages/
    and edit googlecontacts.py to make the first line be #!/opt/bin/python.

    Those changes are required because DD-WRT does not allow changing any of the main files and directories, only things that you mount, like /opt or /mnt. Thanks again for this great bit of information!

    ReplyDelete
  7. Buy Google Voice Accounts
    1~Google Voice Accounts Lasting Guaranteed
    2~100% Recovery Guaranty
    3~Verified Accounts and Active Profiles
    4~Customer Support Every Time and Every Day
    5~High Quality Service
    6~Very Fast Delivery
    7~Very Cheap Prices
    8~100% Money Back Guaranteed
    9~Work Instant Start
    10~Always Used Old and Real Looking Profile
    11~Always Used 60% Male and 40% Female Accounts
    12~Mostly Bio and Photos of the USA Profile
    13~100% Online Credibility

    Do you think our Google Voice accounts fake? no, 100% real accounts? Because we are not like other providers. We give 100% non-drop and permanent accounts. I have been working in this section for a long time so that you can trust my skills.

    For talk more about getting & Buy Google Voice Accounts or any service contract with us
    Email: buysmmusa@gmail.com

    Skype: buysmmusa

    Telegram: @buysmmusa

    WhatsApp: +1 (307) 763-5001

    ReplyDelete