Talk to GTalk from Python

April 27th, 2009 by Ahmed S. Farghal Leave a reply »

Some friend of mine asked me today if I can help him to communicate with google talk from python as he wants to send notifications about some network usage over the chat service. In fact, that was pretty interesting and it just inspired me with tons and zillions of ideas that you can do with that, things like getting security alters, usage logs, any simply feedback that you want to receive while being online and without being irritated with the fact that you have to refresh what you are monitoring every while.

It’s not a hard trick at all, but looks like all of the scripts on the internet are written wrong! and he have been trying to use all of them with no luck, so I helped him as I have some good experience with python-xmpp (xmpppy) module in python.

The idea is that we want to send a message to a Google Apps. User and use another account on the same domain to chat and here comes the trick about it and of course this script is released under the BSD License so you can do whatever you want to do with it :)

import xmpp

client = xmpp.Client('ahmedsoliman.com')
client.connect(server=('<a href="http://talk.google.com/" target="_blank">talk.google.com</a>', 5222))
client.auth(user='myUser', password='myPassword', resource='myResource', sasl=0)

client.send( xmpp.Message('anotherUser@ahmedsoliman.com', 'Hello World'))

Of course you can download the python-xmpp package manually or if you are using fedora, simply use the magical yum install python-xmpp

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • StumbleUpon
  • DZone
  • PDF
  • Reddit
  • RSS
  • Twitter
Advertisement

4 comments

  1. KAM says:

    Yeah python is really cool in it’s support for jabber clients and the applications of it is unlimited

    Creating bots for google is really interesting and it’s really very attractive specially because you’re using a very reliable and super fast backend server to deliver your messages .

    You can actually create intelligent clients that can react to a human been … like asking questions and accordingly give an answer and in case of failure route the call to a real technical support … ya3ni creativity in IM systems specially its applications in control systems is absolutely unlimited ..

  2. Ahmed Kamal says:

    That friend who asked would be me :)
    As usual Soliman is my local development guru, thanks man

  3. Mohamed Atia says:

    Python supports XMPP by default !!?
    ooh, the guy works in Google :D

  4. KAM says:

    It doesn’t support it by default ya atia .. it’s a module

    Actually python has only three modules that support XMPP ( client side mainly )

    1- jabber
    2- pyxmpp
    3- xmpppy

    and xmpppy is the most stable but it’s really annoying specially when it comes to coding guidelines … it looks like they don’t have any :)

Leave a Reply