Click here to Skip to main content
12,951,034 members (57,873 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 3 Jun 2013

SmartPresence for Google Talk

, 3 Jun 2013 CPOL
SmartPresence for Google Talk

Editorial Note

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.


Plantronics Spokes comes out of the box with a feature that we call Smart Presence, which enables automatic presence updates based on the contextual information from the headsets. For example, if you have Skype and your headset is connected to your machine and to your cell phone, once you get a mobile call, your Skype status will change to Busy, and will revert back to Available once the call is done.

In this article I'll show you the code I wrote during a recent Hackathon in Miami on how to do the same for Google Talk.

Here are some basics that you'll need:

  • Spokes (we'll be using the REST API, so either Spokes or the SDK) 
  • an account with Google and either Google Talk or Gmail running
  • some background information on XMPP (used by Google Talk) and some of the Google extensions
  • in my case here, I'm using an XMPP library for Python

The first 2 are easy, go to and Google Accounts if you need them.

XMPP info can be found here: and the extensions here:

By default, if you update the presence in an XMPP client (such as Pidgin, for example), it will not propagate across to all clients logged in the same account. This is where the Google extension comes into play: Shared Status Messages - Google Talk for Developers — Google Developers

Let's get busy...

Here's the XMPP/Google Talk implementation:

import xmpp
Simple implementation of the Shared Status Messages - Google extension to XMPP Presence
class GoogleTalk:
    def __init__(self,user,password):
        self.user = user
    def set_available(self):
        self.client.send(xmpp.protocol.Iq('set','google:shared-status', payload=[xmpp.Node('show',payload=['']), xmpp.Node('status',payload=[''])]))
    def set_busy(self):
        self.client.send(xmpp.protocol.Iq('set','google:shared-status', payload=[xmpp.Node('show',payload=['dnd']), xmpp.Node('status',payload=['Busy'])]))
    def set_away(self):
        self.client.send(xmpp.protocol.Iq('set','google:shared-status', payload=[xmpp.Node('show',payload=['away'])]))
    def set_in_a_call(self):
        self.client.send(xmpp.protocol.Iq('set','google:shared-status', payload=[xmpp.Node('show',payload=['dnd']), xmpp.Node('status',payload=['In a call'])]))
    def set_in_a_mobile_call(self):
        self.client.send(xmpp.protocol.Iq('set','google:shared-status', payload=[xmpp.Node('show',payload=['dnd']), xmpp.Node('status',payload=['In a mobile call'])]))

This code alone allows a user to change his/her presence in Google Talk and GMail by simply doing something like:

gt = GoogleTalk(, user.password)

Where and user.password contain the real user and password for authenticating with Google.

The next part now is to get the Spokes and device side of things working. Using the code from my previous post on REST and Python, and expanding it a little to also handle call notifications:

class Spokes:
    def get_call_service_events(self):
        self.CallServicesEventsURL = '/Spokes/CallServices/Events'
        self.conn.request('GET', self.CallServicesEventsURL);
        r = self.conn.getresponse()
        #Call states as define in the Spokes SDK
        call_states=['Unknown', 'AcceptCall', 'TerminateCall',  'HoldCall',  'Resumecall', 'Flash', 'CallInProgress',
            'CallRinging', 'CallEnded', 'TransferToHeadSet','TransferToSpeaker', 'MuteON', 'MuteOFF', 'MobileCallRinging',
            'MobileCallInProgress', 'MobileCallEnded', 'Don', 'Doff','CallIdle', 'Play',  'Pause',  'Stop',  'DTMFKey', 'RejectCall']
        if r.status == 200:
            response =
            response = json.loads(response)
            if response['Err']==None and len(response['Result'])>0:
                for c in response['Result']:
            return call_state_events

And the 'main' module would look like:

gt = GoogleTalk(, user.password)
s = Spokes()
dl = s.get_device_list()
if len(dl)>0:
    d = dl[0]
    print "Connected to: ", d.ProductName
    if d.attached:
        while True:
            evts = d.get_events()
            if evts:
                for ev in evts:
                    if 'Don' == ev['Event_Name']:
                    elif 'Doff' == ev['Event_Name']:
                cms = s.get_call_manager_state()
                print "Number of active calls: ", len(cms)
                print "Calls: "
                for call in cms: print call
                csevts = s.get_call_service_events()
                print csevts
                if csevts:
                    for csev in csevts:
                        if 'CallInProgress' == csev:
                        if 'MobileCallInProgress' == csev:
                        if 'CallEnded' == csev or 'MobileCallEnded' == csev:
    print "No devices found"

The application will loop until it is terminated and while it is running, if you get a call in your cell, skype or any other softphone integrated with Spokes, your presence in Google Talk will also be in sync with that in the other soft phones.

The presence will also be updated depending the wearing state of the headset, and it'll show as 'Away' if the headset is not being worn, and as 'Available' of the headset is being worn (main code lines 17-20).

I hope this sparks some other ideas and gives you some information on how Spokes, REST and XMPP can work together.

This article was written by Ricardo de Andrade. Ricardo is a Systems Architect and Evangelist at Plantronics helping the developer community, clients and partners with the Spokes SDK and building solutions around current and future offerings. Ricardo has an extensive background in software and cloud distributed architectures, and in specific telecommunications. Ricardo previously worked for Microsoft where he helped clients and partners to develop cloud based speech recognition applications and integrate their web services into the Microsoft Tellme services.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United States United States
Today’s smart devices and applications have untapped potential in the realm of context-aware computing. Plantronics is making it possible for its audio devices to deliver contextual information to a range of applications through Plantronics headsets. The Plantronics Spokes SDK allows developers to create a range of business applications that will have the power to change the way we communicate and collaborate.

Please check out our DevZone for more info on the Spokes SDK:

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 3 Jun 2013
Article Copyright 2013 by Plantronics
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid