Saturday, September 13, 2014

Soft Phone, YATE, and Google Voice via OBi202

In many of my previous posts, I described how to set up the open source telephony engine YATE to enrich caller ID data of incoming Google Voice calls. This post takes a slightly different turn, which is to implement the following:
I want to install a software phone on my computer that will dial out and receive calls via Google Voice.


Background

I have a dedicated Google Voice number as my "work" phone (it's in the same geographical area as my employer, since I work from home). When interacting with my technical colleagues we mostly use Skype or Google Hangouts with video, but there is occasional use for a telephone. I do need to place several calls since I do phone interviews with numerous candidates.

The only option I could find on Ubuntu to place and receive calls via Google Voice is to use the Google Hangouts plugin (or leave Chrome open to the gmail page). Either way, I have to leave a copy of Chrome running all the time.

Further complicating matters is that my employer uses Google Docs, and I have a separate login for "corporate" content, and switching Google IDs can confuse the hangouts plugin. I worked around this by creating a separate profile directory for Chrome dedicated to the hangouts plugin and nothing else, so I can keep one Chrome session open all the time for the hangouts plugin (signed in with my personal Google ID), and use another Chrome session for browsing and documents (signed in with my corporate ID). This works OK, but it's messy.

Then, there is my love-hate relationship with the Hangouts plugin itself. Over the last 6 months I've experienced numerous issues:

  • When someone calls the phone, the popup would say there is an incoming call, but provided nothing to click to answer it. This was improved in mid-2014.
  • After a system update, the plugin no longer recognized my wireless headset, even though it was recognized on the Google Chat page. Therefore, upon receiving a call I had to switch the sounds manually to the headset. I eventually automated that with a script, but it was certainly non-ideal. This was fixed in early September.
  • Any "crossing of streams" thoroughly confuses the plugin, whether phone related or if you're using the video chat. Most annoying is when via IM I agree with a colleague to go to Google Voice, but we don't agree who will place the call. There is mass confusion if we both try to call each other at the same time.
  • Incoming Caller ID has number but no name -- this is a limitation of Google Voice in general.
  • The plugin remembered the video chats but it didn't seem to have a way to remember phone numbers I had dialed.
  • The hangouts plugin doesn't have a DBUS interface, so I can't script a hot-key to actually answer the call.
  • The above things and much more seem to change with each system and plugin update.
Clearly, the support for phone was an afterthought Hangouts plugin, and I spent more time than I'd care to admit trying to make it all work as I like. So when I heard that Google Voice is again supported on the OBi, and I brought back my caller ID script, I started to wonder: can I find a "soft phone" for my computer that will work with Google Voice?

Indeed, there are soft phone programs for Linux (currently I'm using "SFLphone") but I could not find a single one that supports Google Voice natively. They do all support SIP, however. So I sought out to integrate the soft phone with the OBi and YATE.

My solution

My solution is to handle incoming and outgoing calls as follows:
  • Incoming calls to the Google Voice number hit the OBi and are routed to YATE for caller ID processing as usual. YATE then forwards the call to my soft phone.
  • Outgoing calls are placed via the SIP protocol to YATE from the soft phone. YATE forwards the call to the SIP service provider on the OBi, which routes the call out via Google Voice.
  • There are 2 sets of credentials created -- one to authenticate the YATE server to the OBI, and another to authenticate the soft phone to YATE.

Prerequisites

  1. You need to have your Google Voice set up on your OBi and working. This takes up one service provider (SP) slot.
  2. You need to have your SIP connection to YATE set up and running. I added the soft phone configuration to my existing configuration for the caller ID script.
  3. You need a "soft phone" program that supports SIP installed and working. Currently I'm using "SFLphone".

Configuring the OBi202

This section describes what settings to make in the OBi202. You will need to be in "expert mode" either by logging in directly to your OBi202 or by entering expert mode from the obitalk.com site.

To complete this section you need to:
  • Choose a username for YATE to use when connecting to your OBi (in examples "obisip")
  • Choose a corresponding password for the above user (in examples "obisippass")
  • Know the service provider for your Google Voice (in examples SP1)
  • Know the service provider for your YATE server (in examples SP2)

  1. Configure your Google Voice SP to forward calls to YATE. See Step #3 in the caller ID setup document.
  2. Expand User Settings >> User Defined DigitMaps. Find an undefined map (for me the first available was Map2.) Uncheck the Device Default and OBiTALK Settings boxes. Enter the label as Trusted and the DigitMap as the username for YATE in parentheses and single quotes. My settings as per examples:

    Label:      Trusted
    DigitMap:   ('obisip')
  3. When you've entered the Label and DigitMap, click Submit. The OBi reboots, so wait a minute.
  4. Expand Voice Service >> SP2 Service (the service provider for YATE) and change the following settings (uncheck Device Default and OBiTALK Settings and then put in my values):
    1. X_InboundCallRoute: Add the following string to the beginning of whatever you have in there now. Note that "sp1" represents your Google Voice SP, change "1" to something else if Google Voice is on another SP.

      {(MTrusted)>(Msp1):sp1},Your Existing Stuff Here

      So if you followed the caller ID setup instructions as per my examples, your inbound call route now looks like this:

      {(MTrusted)>(Msp1):sp1},{ph}

      or if you have multiple Google Voice numbers ringing different phones:

      {(MTrusted)>(Msp1):sp1},
      {(<11:>x.):ph},{(<12:>x.):ph2}

      NOTE: Consider copying and pasting the above - with the typeface that blogger uses, the braces -- { } -- and the parentheses -- ( ) -- look pretty similar.
    2. The X_RegisterEnable box should be unchecked.
    3. The X_Proxy box should be checked.
    4. AuthUserName should be the username you chose (e.g. obisip)
    5. AuthPassword should be the password you chose (e.g. sipuserpass)
    6. The X_EnforceRequestUserID box should be unchecked.
    7. While you are in here, note the value of X_UserAgentPort. You'll need this later. It's probably 5080 for SP1, 5081 for SP2, 5082 for SP3, or 5083 for SP4.
    8. When all settings are adjusted, click the Submit button.
    9. The OBi reboots - wait 1 minute.
  5. At this point nothing you have done should break any of your current settings. I suggest that you try placing a call out via your handset to Google Voice, and you confirm that an incoming call from Google Voice is enriched with caller ID name (if applicable) and rings your handset.
What did we just do?
  • Set it up so that when SP2 (YATE) receives a call from 'obisip' (brought in via the 'Trusted' map) it routes it to service provider 1 (Google Voice). Other calls route to your phone handset (or perhaps, via prefixes, to different handsets if you've set it up that way in conjunction with the caller ID script).
  • Set up credentials that YATE will use when logging in to your OBi (obisip/sipuserpass)
  • Configured the OBi "proxy mode" for your SIP SP (more...)
  • Learned the port number that we will have to configure YATE to connect to in the next section

Configuring Outbound Calling

For outbound calling to work correctly as per these instructions, the following must be true:
  • You need to have completed the previous section, configuring the OBi202
  • You need to know the username and password from the previous section.
  • You need to know the IP address of your OBi (it should be a static address)
  • You need to know the value of X_UserAgentPort for your YATE SP as per the previous section
  • You need to choose an "extension" number for your soft phone. I chose 1001.
  • You need to choose a password corresponding to the "extension" number. I use softpass in this example but you should change this to something more secure.
Here is how to set up outbound calling:
  1. Create a section in /etc/yate/accfile.conf for the connection to the OBi. This connection will be named obi202_sip (no need to change this). You will be using the IP address of your OBi, the X_UserAgentPort for your YATE SP, and the username and password for the OBi SIP user from the prior section. Be sure to change any bolded entries below. (For clarification, 192.168.1.142 is replaced with the IP address of your OBi and 5081 is replaced with the actual value of X_UserAgentPort.)

    [obi202_sip]
    enabled=yes
    protocol=sip
    username=obisip
    password=sipuserpass
    description=SP2 on my OBi
    registrar=192.168.1.142:5081
    outbound=192.168.1.142:5081
    interval=60
  2. Create an account for your soft phone to register with your YATE server. Do this by editing the file /etc/yate/regfile.conf and adding lines that looks like this. The value you put in the brackets are the username and the password is on the following line.

    [1001]

    password=softpass
  3. Create a rule in /etc/yate/regexroute.conf to route calls from this extension to the OBi. Place this under the entry or entries you have that route calls to your Google Voice number to the OBi. If you used an extension other than 1001 or a SIP user other than obisip, be sure to adjust the bolded entries below.

    ${caller}^1001$=sip/sip:${called};caller=obisip;line=obi202_sip
  4. Restart the YATE server.
At this point, you need to configure your soft phone. Instructions will of course vary, but the following are the common settings:
  • Protocol: SIP
  • Server: 192.168.1.1:5060        << fill in your YATE server's actual IP address
  • Username: 1001                      << fill in the extension you used in regfile.conf
  • Password: softpass                 << fill in the password corresponding to your extension
  • You shouldn't have to set up any proxies, voicemail extensions, STUN, etc. (This assumes your computer and soft phone are on the same network as the OBi device.)
Your soft phone should indicate it's registered. If you get some kind of error message, like wrong credentials or unable to connect, then you have settings wrong that you should fix before you proceed.

Now it's time to test. Use your soft phone to place a call to some non-Google Voice number. If all goes well, the call should connect, with a caller ID of the Google Voice number on the SP that you set up.

Configuring Inbound Calling

For inbound calling to work correctly as per these instructions, the following must be true:
  • You need to have completed the previous two sections (OBi202 and outbound calling)
  • You need to know the username for your extension (e.g. 1001)
  • You need to know the IP address of your computer
  • You need to know the port your SIP client is listening on (default 5060)
To set up inbound calling you merely need to add a rule to the YATE routing file, telling it that all incoming calls to your Google Voice number are routed to the extension at your computer. Note that if you previously had a rule routing calls to your Google Voice number back to the OBi, you should remove that rule.
  1. Create a rule in /etc/yate/regexroute.conf as follows.

    Replace 2125551212 with your Google Voice number.
    Replace 1001 with the extension number
    Replace 192.168.1.50 with the IP address of your computer
    Replace 5060 with the port the SIP client is listening on (5060 is the default)

    ${called}^2125551212=sip/sip:1001@192.168.1.50:5060
  2. Restart the YATE server.
Now it's time to test. Call your Google Voice number from somewhere, and see if the call "rings" your soft phone.

Conclusion

If you have successfully completed this tutorial, you now have a "soft phone" on your desktop that can place calls via Google Voice and have custom caller ID names added for incoming Google Voice calls.

References

The following documents described how to do parts of this, either for a direct soft phone connection to the OBi, or for an IP phone, or for Asterisk. I found them useful as I figured this out and adapted the instructions to YATE, and I list them in hopes you may find them useful as well.

No comments:

Post a Comment