Having fun with jabber bots
-
Upload
victor-hugo-germano -
Category
Technology
-
view
8.267 -
download
5
description
Transcript of Having fun with jabber bots
Having Fun with Jabber Bots
Victor Hugo Germano
Why Jabber Bots?What kinda a crazy am I?
It’s Fun!
http
://w
ww
.flic
kr.c
om/p
hoto
s/sl
eepa
llday
/331
1794
264/
http://www.flickr.com/photos/dancoulter/21042744/
Maybe a glimpse of the future?
Dynamic webIs 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” ProblemHow to create a chat room? Or a chess game?
Latency MattersBecause
Specially when developing and application
client
server
Traditional PollingOften Problematic
?Any other options?
Extensive Messaging and Presence Protocol
Event-Driven
XML oriented
Stanzas
<presence from="[email protected]/home"> <status>at #pyconIreland \o/</status></presence>
Presence
Stanzas
Message<message to="[email protected]/work" from="[email protected]/home" type="chat" > <body>How u doing? ;) </body></message>
Stanzas
IQ (Info Query)<iq type="get" id="an_id" from="[email protected]/casa" to="im.net"> <query xmlns="jabber:iq:roster"/></iq>
client
server
Long Polling
Jabber.org
But XML sucks!xmppPy is your friend!
xmppPyconn = xmpp.Client(‘gmail.com’)
conn.connect([server, port])
conn.auth(user, pwd)
conn.send(Message("[email protected]","hello!"))
conn.disconnect()
First ExampleUsing GTalkBot
http://github.com/victorhg/botnet/blob/master/botnet/gtalkbot.py
mybot.py
http://github.com/victorhg/botnet/blob/master/botnet/gtalkbot.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()
$> python mybot.py
How about a real bot?Enough with the hello_world
DemoAdd a contact on your GTalk account
Having fun!Show me the code!
How can you use it?
http://www.flickr.com/photos/flysi/183272970/
Real Time Web?Powered by XMPP
BOSHBidirectional-streams Over Synchronous HTTP
Strophe.jsWhen 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”: “[email protected]”, type:”chat” }
);
Who uses XMPP on the web?
References
http://xmpppy.sourceforge.net/
http://xmpp.org/
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/victorhggoogle.com/profiles/victorhg
Use it! Share it!Remix it!