Asterisk hack: make your Google Talk client invisible

It’s been a too-busy-to-write week, but I found some time the last few evenings to brush up my C coding (only hacking at this point, really) to make Asterisk 1.8 do something I’ve wanted from the beginning: Google Talk’s invisible mode for the Google Voice integration.

Quick background: Google wrote a variety of XMPP extensions to make Google Talk do voice and a bunch of other non-standard XMPP things. One of those things is what Google calls “shared statuses,” which also includes invisible mode–the ability to be online but set your client as invisible so that others can’t see you, but could chat with you.

You might want to use this feature if, like me, your Google Voice number is attached to your main GMail account. I don’t use the chat features but I appear online to anyone who has me in their contact list, as long as Asterisk is logged in, and that has the potential to draw unwanted instant messages (that will never get answered).

Note: I want to reinforce that this is a hack. The code is clean enough, but this is only useful for Google Talk and is only implemented as a set of Asterisk CLI commands. Furthermore, this functionality would probably never be implemented in Asterisk’s res_jabber because it’s Google-proprietary. On the other hand, if any Asterisk developers want to run with this, go for it! I don’t guarantee that this code will work for you and if your Asterisk process segfaults, stop using it.

Setup

Apply this patch against Asterisk 1.8.2.2’s (or trunk, currently) res/res_jabber.c by downloading the patch to your Asterisk source directory and running patch < res_jabber.patch . You may have to tell it to apply the patch to res/res_jabber.c.

Rebuild (or build) Asterisk. If you are rebuilding, just run make after applying the patch. You should see make build the res_jabber module. Then make install and restart Asterisk.

Usage

At the CLI, you can issue jabber set invisible on asterisk to turn on invisibility for the Jabber connection named “asterisk.” If you don’t know what your Google Talk XMPP connection is called, just issue jabber show connections and find out. You can set your connection visible again with jabber set invisible off asterisk.

Now, here’s another thing that is really hacky: Google Talk only seems to apply the visibility/invisibility change if you are toggling. Here’s what I mean: if you were invisible, and logged out, then logged back in, Google still thinks you are invisible–but you’re not! So in that case, if you jabber set invisible on ..., it doesn’t do anything, until you first set it off and then back on again. I think I know why this is happening and it has to do with res_jabber sending standard <presence> information at login rather than Google’s special shared-status presence scheme. If you want to be sure you are invisible, just start off by setting invisible off and then set it on. For me, that works every time. (I’d be grateful for someone who really knows all about this to fix it up and make it work right, the first time.)

References

I got the idea from this year-old blog posting about enabling Google Talk invisibility in Pidgin, which refers to the official documents published by Google on how it works.

12 thoughts on “Asterisk hack: make your Google Talk client invisible”

  1. Thanks! This is the final fix that makes GV+Asterisk perfect for me. I actually had someone get a little peeved at me for not responding when my GChat showed logged-in and active, because Asterisk was logged in as me.

    This patch still applies cleanly against asterisk-10.0.0-rc1, and works perfectly out of the box.

    Also: I can’t reproduce Troy’s bug. If I log into GMail, I show up as visible right away. And when I log out of GMail I disappear, even though I can still be reached by GVoice.

  2. Thanks a lot, very important patch. I wouldn’t use GV + Asterisk without it. I applied the patch to 1.8.4.4 and created the ipk (optware) for my DD-WRT. My WRT54GL v1.1/DD-WRT v24-sp2 now has Asterisk 1.8 with jabber invisible. Let me know if anyone is needs the mipsel ipk for linksys routers with this patch.

  3. After downloading Asterisk 1.8.4.2 and the patch:

    [root@asterisk18 src]# tar zxf asterisk-1.8.4.2.tar.gz
    [root@asterisk18 src]# cd asterisk-1.8.4.2
    [root@asterisk18 asterisk-1.8.4.2]# patch < /root/src/res_jabber.patch
    can’t find file to patch at input line 3
    Perhaps you should have used the -p or –strip option?
    The text leading up to this was:
    ————————–
    |— res/res_jabber.c
    |+++ res/res_jabber.c
    ————————–
    File to patch: res/res_jabber.c
    patching file res/res_jabber.c
    [root@asterisk18 asterisk-1.8.4.2]#

    Works fine. I ran it from the asterisk source directory and specified “res/res_jabber.c” when it prompted for the file to patch.

  4. Any chance you could update the patch for 1.8.4.2? I tried the one posted, but ‘3 out of 3 hunks failed’.

    Thanks.

  5. This is awesome, now my asterisk jabber is invisible. Thanks for your patch! I hope Asterisk adds it (or something like it) to their codebase.

    My only peeve is that apparently the invisibility applies to the entire jabber account instead of just the connection. I log into gmail and it wants to keep me invisible. Luckily Pidgin doesn’t support invisibility, so that will work ok regardless, but it’s kind of stupid that it tries to make everything invisible.

  6. Not exactly, but you can issue the jabber commands from the shell. For example, put at the end of your startup script:

    asterisk -rx “jabber set invisible off asterisk”
    asterisk -rx “jabber set invisible on asterisk”

    If you’re using FreePBX, just put those two commands after the place where you issue “amportal start”.

  7. Is there some way to toggle invisibility automatically when asterisk starts (so I don’t have to manually set myself to invisible when I start it)?

  8. OK, working on it. I have to go through their sign-up process and they have to approve me to submit a piece of code. I’m reluctant to submit this hack, because I believe someone else could do better with a blank slate. I just produced this for some quick-n-dirty functionality. But if submitting it will get someone thinking about adding this kind of functionality, sure.

    Your thoughts on putting code like this in chan_gtalk vs. res_jabber make sense in that chan_gtalk is clearly for Google, thus no polluting of the res_jabber module. On the other hand, setting invisibility seems like more of a “resource” function, not a function of a channel driver. Leaving the code in res_jabber and enabling it only if the discovery protocol reveals that we are talking to Google with their XMPP extensions seems like a reasonable compromise.

  9. I think that this is great and the way the chan_gtalk needs to go. I know that invisibility isn’t a part of the Jabber standard, so is there any way that this functionality can be put into the chan_gtalk to avoid the hackiness of it in res_jabber? I looked at trying to do that earlier but couldn’t figure out a clean way. I’m hoping that someone with more familiarity with the code can do something

Comments are closed.