Вопрос

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.

Это было полезно?

Решение

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 ^_^ !

Другие советы

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()
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top