2

I want to write an application, which will:

  • recieve and send email messages ( I know, I can do it with ActionMailer using RoR )
  • chat with my Google+ friends
  • change my GoogleTalk (gmail) status

So, when I open my gmail interface, I see list with my contacts on the left side of page. I can open chat with people from this list, I can change status and name (near my little google+ avatar).

When I write status or name, I meen special message 'Bogdan' on this picture

Is exists some Google API for changing google-talk status (special message)? Can I do it using some RubyOnRails gems? Thanks.

bmalets
  • 3,207
  • 7
  • 35
  • 64

2 Answers2

2

So, this pretty lines of ruby code ( using xmpp4r gem ), change your google_talk status and send chat_message to your friend. Thank you, @Arkan!

require 'xmpp4r'

# init jabber client
client_jid = Jabber::JID.new( 'your_email@gmail.com' )
client     = Jabber::Client.new( client_jid )
client.connect 'talk.google.com'
client.auth 'your_gmail_password'

# change google_talk status
client.send( Jabber::Presence.new.set_show( :chat ).set_status( 'Your New GoogleTalk status' ) )

# send chat_message to friend
friend  = Jabber::JID.new("your_friend_email@gmail.com")    
message = Jabber::Message::new(friend, "it's chat message").set_type(:normal).set_id('1')
client.send(message)

I love ruby ^_^ !

bmalets
  • 3,207
  • 7
  • 35
  • 64
  • 1
    You can see your updated GoogleTalk status only from another google account!!! Otherwise you'll automatically change status to previous state, configured through your web-interface. – bmalets Jun 24 '13 at 11:56
  • 1
    If you want to work with your gmail contacts, please synchronize your google devices before test your code. Otherwise, you may have two contacts with one email. For example 'James Alan Hetfield' in your gmail contacts, but 'James Hetfield' in your phone. At first time Google will think that it's two different people ;) – bmalets Jun 24 '13 at 17:54
0

Xmpp Implementation of Gtalk. To change status This might help you.


import xmpp

import dns

class Gtalk():

def __init__(self,bot_id,bot_pwd): 
    self.bot_id = bot_id
    self.bot_pwd = bot_pwd
def connect(self):                           
    self.jid = xmpp.protocol.JID(self.bot_id)
    self.presnc = xmpp.protocol.Presence()
    self.conn = xmpp.Client(self.jid.getDomain(),debug=[])
    if self.conn.connect():
        print 'connected..'
        self.auth()
    else:
        print 'err to connect'
def auth(self): 
    if self.conn.auth(self.jid.getNode(),self.bot_pwd):
        self.conn.sendInitPresence()
        print 'Authenticated..'
    else:
        print 'err to authenticate'
def setStatus(self,value):
    self.conn.send(xmpp.protocol.Presence(status=value))
def invisible(self,username):
    self.conn.send(xmpp.protocol.Presence(username,typ='unavailable'))
def visible(slef,username):
    self.conn.send(xmpp.protocol.Presence(username,typ=None))
def disconnect(self):
    self.conn.disconnect()
Devarsh Shah
  • 189
  • 1
  • 8
  • Sorry, but what is this language? Give me please some links to documentation and examples. Is some XMPP adapters for ruby? – bmalets Jun 24 '13 at 09:25
  • @bmalets, it's python. Check out this. Might help you: https://gist.github.com/jpr5/941931 – Arkan Jun 24 '13 at 09:34