Skip to content

Instantly share code, notes, and snippets.

@zuk
Created February 27, 2011 22:36
Show Gist options
  • Save zuk/846641 to your computer and use it in GitHub Desktop.
Save zuk/846641 to your computer and use it in GitHub Desktop.
XMPP Groupchat reverse echo using Blather
require 'rubygems'
require 'blather/client'
# CONFIGURATION
jid = 'tester@proto.encorelab.org'
password = "foofoo"
chatroom = "s3@conference.proto.encorelab.org"
setup(jid, password)
# LOGIC
when_ready do
puts "Joining room..."
pres = Blather::Stanza::Presence::Status.new
pres.to = chatroom+"/"+jid
pres.state = :chat
client.write(pres)
end
message :groupchat?, :body do |m|
if m.from == chatroom+"/"+jid
puts "got message from myself"
else
m2 = Blather::Stanza::Message.new
m2.to = "s3@conference.proto.encorelab.org"
m2.body = m.body.reverse
m2.type = "groupchat"
client.write(m2)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment