Link: Using FreeSWITCH to add Google Voice to Asterisk

 

Important
This is an edited version of a post that originally appeared on a blog called The Michigan Telephone Blog, which was written by a friend before he decided to stop blogging. It is reposted with his permission. Comments dated before the year 2013 were originally posted to his blog.

EDIT (2018): This article is extremely out-of-date and in no way useful today, and will probably be removed from this site at some point in the future. You might find this article more useful: How to use Google Voice with FreePBX and Asterisk without using XMPP or buying new hardware.

For those of you using Asterisk, Bill over at the PSU VoIP blog has come up with a way to interface Asterisk with Google Voice, by co-installing FreeSWITCH (which also supports Google Voice).  Turns out that Asterisk and FreeSWITCH can co-exist on the same server, though you do have to change the configuration a bit so they don’t compete for the same ports.  Anyway, Bill has come up with a how-to on adding Google Voice integration to current versions of Asterisk, so if that interests you, head on over and have a look:

Using FreeSWITCH to add Google Voice to Asterisk

The bonus is that once you get FreeSWITCH installed you can play around with it and look at some of its other features, if you are so inclined. Of course, the Asterisk folks could backport the Google Voice support to previous versions and make it unnecessary to do things like this, but I’m not holding my breath.

EDIT (January 26, 2012): The Google Voice channel drivers in Asterisk 1.8 have become unreliable enough (in my personal opinion, anyway) that I just used the technique shown in this article, and I must say that it works a LOT better than Asterisk 1.8’s Google Voice support.  I also added some comments to that article (probably too many!) that among other things show how I got it working for multiple Google Voice accounts.  So I would now recommend using this method to bridge Asterisk to Google Voice in preference to using Asterisk 1.8’s native channel drivers (unless you are very short on memory and/or storage space) — it just works, and calls connect faster.  Read the article AND the comments under it first, so you’ll know what to expect, and do be aware that it takes a relatively LONG time to compile and install FreeSWITCH (compared to Asterisk).  At points during the installation it may look like it’s stuck in an endless loop, but it really isn’t. Just go away and take a walk outside or something, and come back in a while and it should be done.

20 thoughts on “Link: Using FreeSWITCH to add Google Voice to Asterisk

    1. Well, when I wrote this, there was no up-to-date release version of Asterisk that would handle this. But that has now changed (as of this morning)!

      Unfortunately, in the Asterisk/FreePBX world, newer versions of software have a nasty tendency to “break” existing systems. The Asterisk folks in particular don’t seem to see any need in maintaining backwards compatibility with previous major versions. If you use a program like FreePBX, you don’t just want to drop a new major release of Asterisk onto your system because it’s pretty likely that bad things will happen. More than likely you’re going to wind up reinstalling from scratch, and a lot of folks may not be prepared to bite that bullet just yet.

      Besides, it’s a good excuse to play with FreeSWITCH, whose developers seem to give a lot more thought to what users want and need. But if anyone is brave enough to try upgrading Asterisk on their system (particularly if you also run FreePBX, and are going from Asterisk 1.4 or 1.6 to 1.8), I would love to hear how much of a hassle you actually encountered.

  1. Telephone systems guy: My Asterisk work is for my home phone system, which has a user base of two. But I try to run it in a professional, production state, because we rely on the phone system (yes, even with cell phones).

    On the other hand, I am a tinkerer, and want to try new features. I could try those new features on other hardware if I had any, or could ruin the “production” status of my pbx, or just believe that 1.8.0 is totally production-ready for my environment and hope for the best. OR… I could do something off to the side with my limited resources that can easily be reverted and not screw anything up. I chose the latter, but of course as 1.8.x gets some deployment and tons of community testing and full support from FreePBX, which is the front-end I prefer, I’ll strongly consider moving there and enjoying the new features available.

  2. The blue.box software (which configures FreeSWITCH and Asterisk) now includes an XMPP module. It was designed to work with FreeSWITCH + Google Voice though it will work with any XMPP service.

    You can now configure GTalk inbound & outbound calls strictly via the GUI – no XML coding. It only works with FreeSWITCH for now, we’ll add Asterisk support when someone shows us how or we get the time to tinker and figure it out ourselves.

    Feel free to try it out, and thanks to Jon and Rocco of the 2600hz team for this contribution. Bug reports and feature improvements welcome.

    – Darren Schreiber
    2600hz Project

  3. If you only need GV dialout, I have compiled a mini how to do that on Asterisk without FreePBX. It can be done in 20 minutes and no compilation is needed. I don’t know it can be even simpler than that.
    The how to is for Dockstar, a small ARM based device, but I think it can be used for linux on PC as well.
    The post is on http://forums.plugpbx.org/index.php?topic=152.0.

    1. Twinclouds: Thanks for the link. One thing we’re trying to get away from is the need to use Sipgate, or any other provider that forces the call to go through the PSTN. That’s why we’re looking at methods that directly interface with Google Voice. You might want to think about redoing what you have done, but using either the new release version of Asterisk 1.8 or FreeSWITCH (if either of those will run on the Dockstar), and see if you can eliminate the need to use Sipgate (or any other DID provider).

  4. o.k. Thanks for pointing out. I didn’t realize you don’t need Sipgate with FreeSwitch. It is certainly more desirable than use Sipgate. I will take a look of using either FreeSwitch and Asterisk 1.8. Are both of them using the Google Voice DID? Google said they are only sure it will be free until the end of the year.

    1. My understanding is that both FreeSWITCH and Asterisk 1.8 directly connect with Google Voice using Gtalk, but since we are only running Asterisk 1.4 at this time I can’t say much more than that. The main reason I suggested you try the newer versions is because it looks like your installation is fairly recent anyway, which probably means you don’t have to or three years worth of custom tweaks and add-ons that you’d have to try to reinstall if you started over. The longer you have run an Asterisk system the less you want to mess with it (especially once it runs the way you want it to), so if you’re going to do an upgrade it’s probably better to do it at the outset.

  5. I have the config in place without all the additional configs that were suggested. I am having a issue where the call gets disconnected after about 5 seconds of talking. Have any of you had this issue, and if not, do you know what could be causing it?

    Is there a way to get your scrubbed config of the .xml file. Find it really odd that it just disconnects as about 10 seconds.

    1. Greg, I will try posting my freeswitch.xml, but can’t guarantee WordPress won’t mess it up. This contains two sample accounts (client profiles) with the account info scrubbed (I actually have more than that). It’s mostly Bill’s original configuration but with a few tweaks as described in my comments on his site. Remember to makes sure that none of the ports used can be accessed from the wide open Internet (make sure they are blocked in your firewall).

      <?xml version="1.0"?>
      <document type="freeswitch/xml">
      
        <include>
          <!-- this is a good place to pre-define globals if you want -->
          <X-PRE-PROCESS cmd="set" data="global_codec_prefs=G7221@32000h,G7221@16000h,G722,PCMU,PCMA,GSM"/>
        </include>
      
        <section name="configuration" description="Various Configuration">
      
          <configuration name="modules.conf" description="Modules">
            <modules>
              <load module="mod_event_socket"/>
              <load module="mod_console"/>
              <load module="mod_logfile"/>
              <load module="mod_sofia"/>
              <load module="mod_dingaling"/>
              <load module="mod_commands"/>
              <load module="mod_dptools"/>
              <load module="mod_dialplan_xml"/>
            </modules>
          </configuration>
      
          <configuration name="console.conf" description="Console Logger">
            <mappings>
              <map name="all" value="console,debug,info,notice,warning,err,crit,alert"/>
            </mappings>
            <settings>
              <param name="colorize" value="true"/>
              <param name="loglevel" value="info"/>
            </settings>
          </configuration>
      
          <configuration name="switch.conf" description="Core Configuration">
            <cli-keybindings>
              <key name="1" value="help"/>
              <key name="2" value="status"/>
              <key name="3" value="show channels"/>
              <key name="4" value="show calls"/>
              <key name="5" value="sofia status"/>
              <key name="6" value="dingaling status"/>
              <key name="7" value="reloadxml"/>
            </cli-keybindings>
      
            <settings>
              <param name="colorize-console" value="true"/>
              <param name="max-sessions" value="1000"/>
              <param name="sessions-per-second" value="30"/>
              <param name="loglevel" value="debug"/>
              <param name="dump-cores" value="yes"/>
              <param name="rtp-enable-zrtp" value="false"/>
            </settings>
          </configuration>
      
          <configuration name="logfile.conf" description="File Logging">
            <settings>
              <param name="rotate-on-hup" value="true"/>
            </settings>
            <profiles>
              <profile name="default">
                <settings>
                  <param name="rollover" value="10485760"/>
                </settings>
                <mappings>
                  <map name="all" value="debug,info,notice,warning,err,crit,alert"/>
                </mappings>
              </profile>
            </profiles>
          </configuration>
      
          <configuration name="event_socket.conf" description="Event socket">
            <settings>
              <param name="nat-map" value="false"/>
              <param name="listen-ip" value="127.0.0.1"/>
              <param name="listen-port" value="8021"/>
              <param name="password" value="ClueCon"/>
            </settings>
          </configuration>
      
          <configuration name="sofia.conf" description="sofia Endpoint">
            <global_settings>
              <param name="log-level" value="0"/>
              <param name="debug-presence" value="0"/>
            </global_settings>
      
            <profiles>
              <profile name="freeswitch-sip">
                <gateways>
                  <gateway name="asterisk-local">
                    <param name="username" value="freeswitch"/>
                    <param name="password" value="0"/>
                    <param name="proxy" value="127.0.0.1:5060"/>
                    <param name="register" value="false"/>
                    <param name="retry-seconds" value="30"/>
                    <param name="caller-id-in-from" value="true"/>
                  </gateway>
                </gateways>
      
                <domains>
                  <domain name="all" alias="true" parse="false"/>
                </domains>
      
                <settings>
                  <param name="debug" value="0"/>
                  <param name="sip-trace" value="no"/>
                  <param name="log-auth-failures" value="false"/>
                  <param name="forward-unsolicited-mwi-notify" value="false"/>
                  <param name="context" value="asterisk"/>
                  <param name="rfc2833-pt" value="101"/>
                  <param name="sip-port" value="5050"/>
                  <param name="dialplan" value="XML"/>
                  <param name="dtmf-type" value="info"/>
                  <param name="inbound-codec-prefs" value="$${global_codec_prefs}"/>
                  <param name="outbound-codec-prefs" value="$${global_codec_prefs}"/>
                  <param name="use-rtp-timer" value="true"/>
                  <param name="rtp-timer-name" value="soft"/>
                  <param name="vad" value="none"/>
                  <param name="rtp-ip" value="127.0.0.1"/>
                  <param name="sip-ip" value="127.0.0.1"/>
                  <param name="inbound-codec-negotiation" value="generous"/>
                  <param name="tls" value="false"/>
                  <param name="nonce-ttl" value="60"/>
                  <!--<param name="disable-transcoding" value="true"/>-->
                  <param name="auth-calls" value="false"/>
                  <param name="auth-all-packets" value="false"/>
      
                  <param name="ext-rtp-ip" value="127.0.0.1"/>
                  <param name="ext-sip-ip" value="127.0.0.1"/>
      
                  <param name="rtp-timeout-sec" value="300"/>
                  <param name="rtp-hold-timeout-sec" value="1800"/>
      
                  <param name="challenge-realm" value="auto_from"/>
                </settings>
              </profile>
            </profiles>
          </configuration>
      
          <configuration name="dingaling.conf" description="XMPP Jingle Endpoint">
            <settings>
              <param name="debug" value="0"/>
              <param name="codec-prefs" value="PCMU"/>
            </settings>
      
            <profile type="client">
              <param name="name" value="gtalk-9995559999"/>
              <param name="login" value="account1@gmail.com/freeswitch"/>
              <param name="password" value="password1"/>
              <param name="dialplan" value="XML"/>
              <param name="context" value="gtalk"/>
              <param name="message" value="This is FreeSWITCH"/>
              <param name="auto-reply" value="This is an automated system for audio calls only. Please do not chat."/>
              <param name="rtp-ip" value="auto"/>
              <param name="candidate-acl" value="wan.auto"/>
              <param name="local-network-acl" value="localnet.auto"/>
              <param name="ext-rtp-ip" value="stun:stun.freeswitch.org"/>
              <param name="auto-login" value="true"/>
              <param name="sasl" value="plain"/>
              <param name="server" value="talk.google.com"/>
              <param name="tls" value="true"/>
              <!-- disable to trade async for more calls -->
              <param name="use-rtp-timer" value="false"/>
              <!-- default extension (if one cannot be determined) -->
              <param name="exten" value="9995559999"/>
            </profile>
      
            <profile type="client">
              <param name="name" value="gtalk-2345556789"/>
              <param name="login" value="account2@gmail.com/freeswitch"/>
              <param name="password" value="password2"/>
              <param name="dialplan" value="XML"/>
              <param name="context" value="gtalk"/>
              <param name="message" value="This is FreeSWITCH"/>
              <param name="auto-reply" value="This is an automated system for audio calls only. Please do not chat."/>
              <param name="rtp-ip" value="auto"/>
              <param name="candidate-acl" value="wan.auto"/>
              <param name="local-network-acl" value="localnet.auto"/>
              <param name="ext-rtp-ip" value="stun:stun.freeswitch.org"/>
              <param name="auto-login" value="true"/>
              <param name="sasl" value="plain"/>
              <param name="server" value="talk.google.com"/>
              <param name="tls" value="true"/>
              <!-- disable to trade async for more calls -->
              <param name="use-rtp-timer" value="false"/>
              <!-- default extension (if one cannot be determined) -->
              <param name="exten" value="2345556789"/>
            </profile>
      
          </configuration>
      
          <configuration name="post_load_modules.conf" description="Post-load modules" />
        </section>
      
        <section name="dialplan" description="Regex/XML Dialplan">
          <context name="asterisk">
            <extension name="asterisk-outbound">
              <condition field="destination_number" expression="^(.*)$">
                <action application="ring_ready" />
                <action application="set" data="hangup_after_bridge=true"/>
                <action application="set" data="bridge_generate_comfort_noise=true"/>
                <action application="set" data="execute_on_answer=start_dtmf_generate"/>
                <action application="bridge" data="dingaling/gtalk-${sip_from_user_stripped}/+$1@voice.google.com"/>
              </condition>
            </extension>
          </context>
      
          <context name="gtalk">
            <extension name="gtalk-in">
              <condition field="destination_number" expression="^(.*)$">
                <action application="set" data="hangup_after_bridge=true"/>
                <action application="set" data="effective_caller_id_name=${caller_id_number}"/>
                <action application="set" data="execute_on_answer=send_dtmf 1"/>
                <action application="set" data="bridge_generate_comfort_noise=true"/>
                <action application="sleep" data="1000" />
                <action application="answer" />
                <action application="ring_ready" />
                <action application="set" data="ringback=%(2000, 4000, 440.0, 480.0)" />
                <action application="bridge" data="sofia/gateway/asterisk-local/$1" />
              </condition>
            </extension>
          </context>
        </section>
      
      </document>
      
    1. Yeah, that’s one thing I hate about WordPress, it tries to second guess what you want to do. Why does it have <code> tags if it won’t recognize the text within as code and leave it alone?

  6. Well i can tell it works, but still have that odd disconnect after about 7 seconds of a call connecting. Everytime. What version of asterisk/freepbx are you using if I may ask? very odd to me. I am using 1.7.5.6 with asterisk 1.8.6. i do have a firewall infront of my network, i am not seeing any outbound denies come it to block connectivity. I dont know if its because i setup this server to use the gtalk plugin of freepbx in the past or not. Thanks for your help. I assume i need a fresh install of PIAF without any configs on it at all.

    1. Greg, FreePBX 2.8.1 and Asterisk 1.8.9.1. Make sure you remove any Google Voice configurations in FreePBX, or you can avoid loading Asterisk’s Google Voice drivers altogether (which will make your system more stable). See this thread:

      http://pbxinaflash.com/forum/showthread.php?t=12323

      After reading that I edited etc/asterisk/modules.conf to include these lines

      noload => res_jabber.so
      noload => chan_gtalk.so

      And then restarted Asterisk. That should keep you from having any conflict with Asterisk and FreeSWITCH both trying to access the same Google Voice accounts.

      I’m not going to say anything at the moment about the firewall but remember that you can temporarily stop iptables by doing service iptables stop from the Linux command prompt, then quickly trying a test call to see if it makes any difference. To restart iptables do service iptables start and then once it’s started, if you use fail2ban do service fail2ban restart to get fail2ban working again (or you can just reboot to be safe). I’d be really surprised if the firewall is the problem, but then you’re having a rather weird issue so I wouldn’t rule anything out.

  7. Thanks again for your help, still no luck getting this to work. I have the hangup issue after 7 seconds. Havent found anything on the interweb for it. I will keep messing with it, but looks like PIAF and FreePBX it is for me ;(.

    thanks again.

  8. NOTICE: All comments above this one were imported from the original Michigan Telephone Blog and may or may not be relevant to the edited article above.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Featured Article:

Recent Posts

Recent Comments

Archives

Categories

Meta

GiottoPress by Enrique Chavez

%d bloggers like this: