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.

19 thoughts on “Asterisk 11 + Google Voice: Multiple Lines

  1. thcii

    great article! for some reason, all outbound calls seem to originate from the same number and not the originating google account. can you help?

    Reply
    1. dantheman2865 Post author

      Thanks! Will you post (maybe use pastebin.com) or email your extensions.conf with some more details? How many Google Voice lines are you using in this case?

      Reply
      1. thcii

        i have two google voice accounts with a third on the way. all outbound calls seem to route through the home context using the google account listed there. pastebin -> trabbits (this number is handy to identify where you are calling from 18004444444.)

        Reply
          1. thcii

            problem solved! when i added the additional GV accounts, i failed to update/add the new context names in sip.conf. btw, i will be testing this with a raspberrypi and i will let you know how it goes. thanks again. thcii

          2. dantheman2865 Post author

            That’s what I suspected, congrats! I would love to hear how the Raspberry Pi handles the load. It should be fine, but it would be cool to make 2 or 3 phone calls outgoing and see the processor load (and note the audio quality).

  2. pschakravarthi

    Getting following error when trying to do outbound call using google

    Unable to add Google ICE candidates as ICE support not available or no candidates available

    Getting following error when incoming call from google

    Received Google transport information on session ‘SIP1300447863@10.236.195.103’ but ICE support not available

    OS : CentOS 64Bit
    Asterisk Version : 11.7.0

    No nat.. direct public IP assigned to Asterisk VM

    Reply
    1. dantheman2865 Post author

      Did you follow the original post? If so, can you post your configuration files, say to pastebin?

      Reply
      1. pschakravarth

        Yes.. I followed original post. Here Is my config details

        sip.conf
        ===========================

        [general]
        context=default
        allowoverlap=no
        bindport=5060
        bindaddr=0.0.0.0
        tcpenable=yes
        tcpbindaddr=0.0.0.0
        srvlookup=yes
        t38pt_udptl=yes
        promiscredir=yes

        [6821]
        type=friend
        nat=yes
        secret=yP239vvs#
        context=users
        qualify=yes
        host=dynamic
        ;transport=tcp
        mailbox=6821@default
        callerid=”MyHome”
        canreinvite = no

        motif.conf
        ========================
        [default](!)
        disallow=all
        allow=ulaw
        allow=h264
        ;context=google-in ; Default context that incoming sessions will land in

        [mygthome](default)
        transport=ice-udp
        connection=mygthome
        context=mygthome-in

        xmpp.conf
        =======================

        [mygthome]
        type=client
        serverhost=talk.google.com
        username=mygthome@gmail.com/Talk
        secret=mypassword
        port=5222
        usetls=yes
        priority=10
        usesasl=yes
        statusmessage=”onAsterisk**”
        timeout=100

        rtp.conf
        =======================
        [general]
        icesupport=yes
        rtpstart=10000
        rtpend=12000

        extentions.conf
        =======================
        [mygthome-in]
        exten => s,1,NoOp()
        exten => mygthome@gmail.com,n,Dial(SIP/6821,180,D(:1))
        exten => mygthome@gmail.com,n,Hangup()

        [trunk]
        exten => _92XXXXXXXXXX,1,Dial(Motif/mygthome/${EXTEN:-10}@voice.google.com)
        exten => _92XXXXXXXXXX,n,Hangup()

        Reply
          1. dantheman2865 Post author

            Unfortunately, I cannot see anything wrong with this configuration. Doubly unfortunately, Google is ending support for XMPP in Google Voice this coming May. So sorry!

  3. twinclouds

    Hi,
    I tried the .conf files and they work pretty well. The only question is how the asterisk known the incoming call is from one GV account or the other? I understand outgoing calls nut not sure about the incoming call. Hope you can explain. Thanks.

    Reply
    1. dantheman2865 Post author

      Hi twinclouds, Incoming GV calls are handled in res_xmpp.conf, which gets passed into motif.conf. In this file, you can set the context that those incoming calls dump into using the “context=” line. Glad this is working for you!

      Reply
      1. twinclouds

        Thanks. That makes sense.
        Actually, I used your approach on my Oauth2.0 enabled asterisk. Everything works fine. However, there’s no res_xmpp.conf but only xmpp.conf I don’t know if it is due to Oauth2.0.
        Thanks again for your service to the community. I always use the instructions of your first post when I set up my Asterisk11 with GV.

        Reply
        1. dantheman2865 Post author

          Thanks! I wrote these guides because I couldn’t find anything written in plain English when I was first figuring all of this out. Google ended official support for XMPP in Google Voice, but I guess they still haven’t closed the service, right?

          Reply
          1. twinclouds

            Yes. It is still alive and well. I don’t know if Google will shut it down at all. At least there haven’t been any indications or rumors lately.

Leave a Reply