[Nexus 4 General] jhax01:
In the battle to get this working for myself, I happened to learn a few things proving that you can, in fact, teach an old dog new tricks...lol. I'm going to add my *.conf here with a bit of explanation that may help others understand what's going on with each of the files. I certainly didn't understand at first, but as I researched my issues a little deeper, the light bulb slowly started to come on.

I'll start with "motif.conf"...the sole purpose here is to let Asterisk know that we are intending to utilize Google as a conduit for communication and that calls will originate or terminate in the context defined in motif.conf. We also make sure that Asterisk knows to only use the ulaw protocol as that is the only way Google Voice knows how to communicate.

motif.conf

[google]
context=incoming-motif
disallow=all
allow=ulaw
connection=google

Next is xmpp.conf - This is where we define the resource that is available to Asterisk to accomplish the connection to the google account. As errorcod3 stated - make sure you put in the correct gmail info.... Also note that we are generically defining a connection type below and coupling this with the context of "incoming-motif" above gives us a mechanism for making and receiving calls. Essentially, the "how" that Asterisk will apply to make or receive a call. Additionally, make sure you set the priority high if you are using a google account that make be logged into Gtalk somewhere else. If it is set to 1 under those circumstances, the call will never make it to Asterisk.

xmpp.conf

[general]
[google]
type=client
serverhost=talk.google.com
username=YOUREMAIL@GMAIL.COM
secret=GMAILPASSWORD
priority=100
port=5222
usetls=yes
usesasl=yes
status=available
statusmessage="VOIP"
timeout=5

Now we can define our soft phone or SIP client. This is our connection into Asterisk just as motif/xmpp are Asterisk's connection to google chat.

sip.conf

[general]
allow=all
allowguest=no
nat=force_rport,comedia
tcpbindaddr=0.0.0.0
tcpenable=yes

externhost=EXTERNALIP
localnet=IFCONFIG/SUBNETMASK

[USERNAME]
type=peer
secret=PASSWORDYOUGENERATE
host=dynamic
context=local
transport=udp,tcp

Here's where I differ from errorcod3's methodology a bit. In the general section, I'm telling Asterisk that it's ok to accept any compression protocols for the SIP => Asterisk portion of the connection with "allow=all". The only drawback to this is that if the compression type is not supported or compiled with Asterisk, then it will attempt to pass through the protocol rather than transcode it. Gtalk itself supports several types, but Google Voice, on the other hand, only supports ulaw. So if it passes through something unsupported there will be no audio. The upside is that it allows you to switch protocols on the fly easily. *allowguest=no* - this one is important if your server is in the open (i.e. - EC2). Leaving it out, or setting the parameter to *yes* will allow anyone to use your PBX to dial out unconditionally as long as they know the IP. The next lines allow TCP as a protocol and set nat to yes, essentially. Everything after USERNAME defines your actual soft phone connection and lets Asterisk know that when you initiate a call, it should use the context *local* to route it.

Lastly, we have extensions.conf. This is where we set our dial plan for Asterisk or the "conditions" that tell it to do what and when.

extensions.conf

[general]
autofallthrough=yes

; If an unauthenticated request some how gets through, send them to free 411.
[default]
exten => 411,1,Answer()
same => n,Dial(Motif/google/1800...@voice.google.com)

[local]
exten => _1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)
exten => _+1XXXXXXXXXX,1,Dial(Motif/google/${EXTEN}@voice.google.com,,r)

[incoming-motif]
exten => s,1,NoOp()
same => n,Set(crazygooglecid=${CALLERID(name)})
same => n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
same => n,Set(CALLERID(all)=${stripcrazysuffix})
same => n,Dial(SIP/USERNAME,20,D(:1))

Ok, line by line, this is what we are doing here.

autofallthrough - we set this to yes so that if Asterisk runs out of things to do with an active connection or has problems, it will send a busy signal, or hang up, or whatever. Otherwise, it will just sit there will an open connection and wait for another extension to be dialed.

[default] - This is what Asterisk will do if it receives a dial request from an un-authenticated guest. We already have it set to not allow guests, but just in case, if something gets through somehow, we are going to send them to free 411. It will effectively ignore any dial requests that are not made from the SIP client we define in sip.conf.

[local] - think of this context as our outbound calls or the connection from your soft phone to the world. When you dial out, sip.conf points your request at the context of *local*, then under local Asterisk matches a formatting case to the appropriate extension. Then in the case of the above, Asterisk places the call through the "Motif" technology via the "google" account we defined in xmpp.conf.

[incoming-motif] - This context handles our inbound calls from google voice by first stripping out everything but the phone number on the inbound transmission. Then, in the last line, it dials the soft phone defined in sip.conf to complete the connection.

The above conf files will provide an audio only connection. I'm also currently working on adding TLS authentication for the SIP client instead of sending the user name and password in the clear and if the OP is in agreement, I will add the directions. (your authentication into google voice is already sent encrypted) Hope I didn't overstep my bounds... Just trying to help clarify what is going on for folks like myself who didn't have a clue at first. :D

---------- Post added at 10:49 PM ---------- Previous post was at 10:44 PM ----------

Oh, I see... As near as I can tell, reliability is more a function of your SIP client and it's ability to keep connected with the server. I haven't had any issues...so far anyway. :)

Call quality-wise, I added g729 to my setup and am pretty happy with it so far.

---------- Post added at 10:55 PM ---------- Previous post was at 10:49 PM ----------

Yep, you definitely can.... A couple other interesting things I came across are sending blocked calls to a privacy manager that requires them to input their number before it will complete the call & blacklists, etc.... Asterisk has a ridiculous amount of options....