XMPP on Python responds to Gtalk but not to Hangouts

2.6k Views Asked by At

I was trying out a Gtalk bot using python and XMPP.

When I ping the bot using iChat application, I could receive the response back. But when I ping using Hangouts, I am not able to receive the response message. But still I could see my message at server side logs.

# -- coding: utf-8 -
import xmpp 

user="[email protected]"
password="PASSWORD"
server=('talk.google.com', 5223)

def message_handler(connect_object, message_node): 
        us = str(message_node.getFrom()).split('/')[0]
        if us == '[email protected]':
            us = us[0:4]
            print str(message_node)
            message = "Welcome to my first Gtalk Bot :) " + us
            s= str(message_node.getBody()).replace("\n", "\t")
            if s <> 'None' :
                print "MESSAGE: " + s
                connect_object.send(xmpp.Message( message_node.getFrom() ,message))

jid = xmpp.JID(user) 
connection = xmpp.Client(jid.getDomain()) 
connection.connect(server) 
result = connection.auth(jid.getNode(), password ) 

connection.RegisterHandler('message', message_handler)  
connection.sendInitPresence() 

while connection.Process(1): 
    pass

Is this something to do with gtalk moving out of XMPP support?

My Bot is still able to receive message but my Hangouts Application is not receiving response

2

There are 2 best solutions below

0
On BEST ANSWER

I was able to fix the issue.

You need to add typ = 'chat' attribute to xmpp.Message

connect_object.send(xmpp.Message( message_node.getFrom() ,message, typ='chat' ))

Now my gTalkBot reponds to my message from hangouts & ichat client.

Many thanks to this stack overflow answer

0
On

If you have extended sleekxmpp.ClientXMPP, then you can ensure messages are sent to hangouts by added mtype='chat' to send_message()

bot = MyBot([...])
bot.send_message(mto=JID,mbody=MSG,mtype='chat')