Having Fun with
 Jabber Bots
 Victor Hugo Germano
Why Jabber Bots?
What kinda a crazy am I?
It’s Fun!
http://www.flickr.com/photos/sleepallday/3311794264/
Maybe a glimpse of the future?
                 http://www.flickr.com/photos/dancoulter/21042744/
Dynamic web
Is not enough!
Tired of Ctrl+R and F5




                 http://www.flickr.com/photos/disaster_area/3454110496/
We want websites like this!
But during the game...



      Real time streamming... for sure!
FLASH
Would FLASH be the answer?
No!
At least is what most companies are saying
“Big” Problem
How to create a chat room? Or a chess game?
Because

     Latency Matters
Specially when developing and application
client




server



Traditional Polling
         Often Problematic
?
Any other options?
Extensive Messaging and
   Presence Protocol




   Event-Driven

   XML oriented
Stanzas

  Presence
<presence from="victorhg@im.net/home">
  <status>at #pyconIreland o/</status>
</presence>
Stanzas

Message
<message to="mary@im.net/work"
     from="victorhg@im.net/home"
     type="chat" >
    <body>How u doing? ;) </body>
</message>
Stanzas

  IQ (Info Query)
<iq type="get" id="an_id"
     from="victorhg@im.net/casa"
     to="im.net">
    <query xmlns="jabber:iq:roster"/>
</iq>
client




server



         Long Polling
Jabber.org
But XML sucks!
xmppPy is your friend!
xmppPy
conn = xmpp.Client(‘gmail.com’)

conn.connect([server, port])

conn.auth(user, pwd)

conn.send(Message(
       "email@gmail.com","hello!"))

conn.disconnect()
First Example
Using GTalkBot



http://github.com/victorhg/botnet/blob/master/botnet/gtalkbot.py
mybot.py
from gtalkbot import GTalkBot, botcommand

class MyBot(GTalkBot):
  def __init__(self):
   super(MyBot,self).__init__('USER_ID','PWD')

 @botcommand
 def hello(self, mess, args):
  return “Hello World!”

MyBot().run_client()

http://github.com/victorhg/botnet/blob/master/botnet/gtalkbot.py
$> python mybot.py
How about a real bot?
Enough with the hello_world
Demo
Add a contact on your GTalk account



pycon.bot@gmail.com
Having fun!
Show me the code!
How can
you use it?

              http://www.flickr.com/photos/flysi/183272970/
Real Time Web?
Powered by XMPP
BOSH
Bidirectional-streams Over Synchronous HTTP
Strophe.js
When XMPP hits the web


    http://code.stanziq.com/strophe/
Strophe.js
// Connecting
var conn = new Strophe.Connection(URL)
conn.connect( jid, password, callback );

// Creating stanzas
var stanza = new Strophe.Builder(
     “message”,
   { “to”: “john@jabber.org”, type:”chat” }
);
Who uses XMPP on the web?
References
http://xmpp.org/

http://xmpppy.sourceforge.net/

http://thpinfo.com/2007/python-jabberbot/

http://xmpppy-guide.berlios.de/

http://code.stanziq.com/strophe/
Real Time Web with XMPP @ InfoQ
Thank you!

   twitter.com/victorhg
google.com/profiles/victorhg


                  Use it! Share it!
                    Remix it!

Having fun with jabber bots