Monthly Archives: July 2013

Asterisk 11 + Google Voice: Multiple Lines

Introduction: Coexistence

My neighbor and I share an internet connection; we are very good friends and this affords us the opportunity to barter and share quite a few things. In order to help him slim his monthly costs, I’ve offered to set up the same service for him that I have: free “land-line” phone service through Google Voice. This requires some clever design in order to allow us both to route calls the way we want to.¬†In this post, I will detail the configuration for supporting multiple Google Voice accounts through one Asterisk server.

Background: Configuration, Continued

This post assumes a configuration based on my previous post: Asterisk 11 + Google Voice. In that post, I start from scratch installing an Asterisk 11 service on Ubuntu.

Walkthrough:

Making this configuration work is all about context. Asterisk Contexts allow certain phones to call each other, but more importantly, define where incoming calls go.

The configuration is simple: There is one context for all of the simple extensions (my neighbor and I call each other directly, not over the PSTN) and a separate context for each Google Voice number. Each specific context includes 10-digit rules for dialing traditional phone numbers, a trap to catch incoming calls (with no extension specified), and the main context.

Now, for the actual config files.

res_xmpp.conf remains as before, only add an entry for each additional Google Voice account you wish to employ:

[me-xmpp]
type=client
serverhost=talk.google.com
...
statusmessage=Asterisk Phone
timeout=5

[neighbor-xmpp]
type=client
serverhost=talk.google.com
...
statusmessage=Asterisk Phone
timeout=5

In motif.conf, add one entry for each GV account therefore bridging the Google account to the Asterisk context:

[me-motif]
context=me-context
disallow=all
allow=ulaw
connection=me-xmpp

[neighbor-motif]
context=neighbor-context
disallow=all
allow=ulaw
connection=neighbor-xmpp

Assuming you have already set up phones in SIP, the only thing left is to specify your contexts in extensions.conf:

[home-context]
exten => 200,1,Dial(SIP/200,60) // My SIP phone
exten => 201,1,Dial(SIP/201,60) // My neighbor's SIP phone
exten => 202,1,Dial(SIP/202,60) // Second phone in my house

[mine-context]
exten => s,1,NoOp() // Catch calls coming into my context without an extension
 same => n,Wait(1)
 same => n,Set(crazygooglecid=${CALLERID(name)})
 same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
 same => n,Set(CALLERID(all)=${stripcrazysuffix})
 same => n,Dial(SIP/200,20,D(:1)) // Send them to my phone

// Catch calls going out of this context and use my Motif account
exten => _+1NXXNXXXXXX,1,Dial(Motif/mine-motif/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,1,Dial(Motif/mine-motif/${EXTEN}@voice.google.com,,r)
exten => _NXXNXXXXXX,1,Dial(Motif/mine-motif/${EXTEN}@voice.google.com,,r)

include => home-context // Adds all standard SIP phones (above) to the context

[neighbor-context]
exten => s,1,NoOp() // Catch calls coming into my neighbor's context without an extension
 same => n,Wait(1)
 same => n,Set(crazygooglecid=${CALLERID(name)})
 same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
 same => n,Set(CALLERID(all)=${stripcrazysuffix})
 same => n,Dial(SIP/201,20,D(:1)) // Send them to my neighbor's phone

// Catch calls going out of this context and use my neighbor's Motif account
exten => _+1NXXNXXXXXX,1,Dial(Motif/neighbor-motif/${EXTEN}@voice.google.com,,r)
exten => _1NXXNXXXXXX,1,Dial(Motif/neighbor-motif/${EXTEN}@voice.google.com,,r)
exten => _NXXNXXXXXX,1,Dial(Motif/neighbor-motif/${EXTEN}@voice.google.com,,r)

include => home-context // Allows my neighbor to call either of my phones

Conclusion

As I’ve said before, Asterisk is incredibly powerful. There is so much you can do with it if you even start to understand it! As before, please leave any feedback in the comments below; I would love to know how it’s working for any of you.