/dev/random Nonsense Ensured

12Aug/116

Free Calling with Google Voice and Asterisk

asteriskgvoice

I've been playing with Asterisk and Google Voice for the better part of a year now, and just recently was finally able to get it all working the way I wanted it to. When Google started letting you make phone calls using Voice from Gmail, they opened up the ability to make phone calls over gtalk, their XMPP/Jabber based IM/Voice/Video service. When I heard that, I thought it would be a piece of cake to get Voice working with Asterisk's Jabber/Jingle channel... nope! In fact, Voice didn't start working with Asterisk until 1.8.1 which is what I was waiting to finally become stable enough to use. Then after a few more problems with Asterisk breaking support for my Cisco 7960 (SIP) which was finally fixed in 1.8.4.4. Now that you've heard my life story, here's how I got that working.

Prerequisites

  • A modern Linux box, I'm running OpenSUSE 11.4 Kernel 2.6.37.1
  • Asterisk 1.8.1.1 or newer, I'm running 1.8.4.4 (to get support for my Cisco 7960 SIP)
  • Some sort of VoIP phone connected to your Asterisk box, soft or hard

Google Voice Setup

You need to, of course, have a Google account, with Voice enabled, and Gmail calling turned on as well.  Once you have that setup, make sure that you change the Chat setting from the default of "Automatically allow people that I communicate with often to chat with me and see when I'm online" to the second option of "Only allow people that I've explicitly approved to chat with me and see when I'm online."

Asterisk Setup

On the Asterisk side, things aren't quite as easy.  You'll want to make sure you have at least the chan_gtalk and the res_jabber modules compiled and installed before proceeding or else none of this will work.  I of course needed things like chan_sip as well to work with my Cisco 7960.  In your Asterisk configuration directory (usually /etc/asterisk) you'll need these conf files to look at least like this:

/etc/asterisk/gtalk.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[general]
context=local                   ; Context to dump call into
bindaddr=10.8.2.5               ; Address to bind to
;externip=1.2.3.4               ; Set your external ip if you are behind a NAT.
;stunaddr=mystunserver.com      ; Get your external ip from a STUN server.
                                ; Note, if the STUN query is successful, this will
                                ; replace any value placed in externip;
allowguest=yes                  ; Allow calls from people not in list of peers

[guest]                         ; special account for options on guest account
disallow=all
allow=ulaw
context=local
connection=asterisk

/etc/asterisk/jabber.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[general]
debug=no                                ; Enable debugging (disabled by default).
autoprune=no                            ; Auto remove users from buddy list. Depending on your
                                        ; setup (ie, using your personal Gtalk account for a test)
                                        ; you might lose your contacts list. Default is 'no'.
autoregister=yes                        ; Auto register users from buddy list.
;collection_nodes=yes                   ; Enable support for XEP-0248 for use with
                                        ; distributed device state.  Default is 'no'.
;pubsub_autocreate=yes                  ; Whether or not the PubSub server supports/is using
                                        ; auto-create for nodes.  If it is, we have to
                                        ; explicitly pre-create nodes before publishing them.
                                        ; Default is 'no'.
;auth_policy=accept                     ; Auto accept users' subscription requests (default).
                                        ; Set to deny for auto denial.
[asterisk]
type=client                             ; Client or Component connection
serverhost=talk.google.com              ; Route to server for example, talk.google.com
;pubsub_node=pubsub.astjab.org          ; Node to use for publishing events via PubSub
username=butters08@gmail.com/Talk       ; Username with optional resource. (must be /Talk for Voice)
secret=XXXXXXXXXXXXXXXX                 ; Google Password
;priority=1                             ; Resource priority
port=5222                               ; Port to use defaults to 5222
usetls=yes                              ; Use tls or not
usesasl=yes                             ; Use sasl or not
;buddy=mogorman@astjab.org              ; Manual addition of buddy to list.
                                        ; For distributed events, these buddies are
                                        ; automatically added in the whitelist as
                                        ; 'owners' of the node(s).
;distribute_events=yes                  ; Whether or not to distribute events using
                                        ; this connection.  Default is 'no'.
status=away                             ; One of: chat, available, away, xaway, or dnd
statusmessage="I'm an Asterisk Server!" ; Have custom status message for Asterisk
timeout=100                             ; Timeout (in seconds) on the message stack, defaults to 5.
                                        ; Messages stored longer than this value will be deleted by Asterisk.
                                        ; This option applies to incoming messages only, which are intended to
                                        ; be processed by the JABBER_RECEIVE dialplan function.

/etc/asterisk/extensions.conf

Now obviously not all of this is required, this is just how I have my dial plan setup. To receive incoming calls from Voice you must have a exten => s,1,Answer() though as Voice doesn't say where it's coming from.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[general]
static=yes
writeprotect=yes
autofallthough=yes
clearglobalvars=no
priorityjumping=no

[local]
exten => s,1,Answer()
exten => s,n,Set(crazygooglecid=${CALLERID(name)}) ; Get rid of crazy Google incoming CID
exten => s,n,Set(stripcrazysuffix=${CUT(crazygooglecid,@,1)})
exten => s,n,Set(CALLERID(name)="${CURL(http://cnam.bulkCNAM.com/?id=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&did=${CALLERID(num)})}") ; Set Caller ID from bulkCNAM
exten => s,n,Wait(2)
exten => s,n,Dial(SIP/102&SIP/103,20,D(:1)) ; This sends the 1 after you answer, otherwise it'll fall back on Google Voice-mail
                                            ; It also dials my SIP phones (7960 and Android 2.3 Phone)

; Internal Calling
exten => _1XX,1,Dial(SIP/${EXTEN})
; External Calling
exten => _1XXXXXXXXXX,1,Dial(gtalk/asterisk/+${EXTEN}@voice.google.com)
exten => _XXXXXXXXXX,1,Dial(gtalk/asterisk/+1${EXTEN}@voice.google.com)

Final Thoughts

I know this isn't the most in depth guide on getting Asterisk working on your machine, but there are enough guides out there for that. Hope my article helped you get Voice working with Asterisk, happy calling!

References

Comments (6) Trackbacks (0)
  1. Hey, man! This is really cool. :-D Someone mentioned that this was your semester project for Operating Systems? I could do a writeup on the project I did with Alex Thelen. We “hacked” the Jedi Force Trainer, but more on that later.

    What is XMPP/Jabber? Did Google’s use of X/J make working w Asterisk easier? Harder? Neutral?

    • It was kind of my semester project for OS, last fall before Google let you connect over XMPP and Asterisk supported it, I had a very hacky way to do it. Basically I had to connect to a service that Google bought at the beginning of Voice called Gizmo5, which I could connect to via SIP and it was the only VoIP service that Google supported at the time. It kind of worked but the only way to make outgoing calls was to use the Voice webpage which was annoying.

      Google’s use of XMPP definitely made connecting to them a lot easier than it used to be, but it would have been even easier if they had implemented native SIP support, but that would have been too easy ;)

  2. Can you upload your 7960 configs as well?

    • I’d be happy to, I plan on doing a write up for connecting a 7960 to Asterisk over SIP, but knowing me, that won’t be for a while ;) Here it is:
      /etc/astersik/sip.conf

      [general]
      bindport=5060
      bindaddr=10.8.2.5
      disallow=all
      allow=ulaw
      allow=gsm
      allow=alaw
      allow=h261
      canreinvite=no
      context=local
      srvlookup=yes

      ; Linksys PAP2 Port 1
      ;[100]
      ;type=peer
      ;username=100
      ;secret=XXXXXXX
      ;host=dynamic
      ;disallow=all
      ;allow=ulaw
      ;qualify=yes
      ;context=outgoing
      ;nat=yes
      ;tos=reliability
      ;srvlookup=yes

      ; Linksys PAP2 Port 2
      ;[101]
      ;type=friend
      ;username=101
      ;secret=XXXXXXX
      ;host=dynamic
      ;disallow=all
      ;allow=ulaw
      ;qualify=yes
      ;context=outgoing
      ;nat=yes

      ; Travis' Cisco 7960
      [102]
      type=friend
      host=dynamic
      username=102
      secret=XXXXXXX
      context=local
      allow=all
      qualify=yes
      nat=no
      canreinvite=no
      callerid=Travis Thompson <102>

      ; Android phone
      [103]
      type=friend
      host=dynamic
      username=103
      secret=XXXXXXXX
      context=local
      allow=all
      qualify=yes
      nat=yes
      canreinvite=no
      callerid=Travis Thompson <103>
  3. Instead of using (what I assume is my) BulkCNAM.com service on line 12 of your extensions.conf, why not use the following free and very nearly as good service:

    exten => s,n,Set(CALLERID(name)=”${CURL(http://freecnam.org/dip?q=${CALLERID(num)})}”) ; Set Caller ID from freeCNAM project


Leave a comment

(required)

No trackbacks yet.

  • Twitter
  • Buzz
  • Tumblr
  • Facebook
  • LinkedIn
  • Digg
  • Picasa
  • Flickr
  • Panoramio
  • YouTube
  • Last.fm