Stupid Atom Tricks: XMPP Bot

Continuing my habit of writing x-to-Atom gateways, here’s a little Jabber bot that will post messages you send it to an Atom Publishing Protocol Collection.

It requires atom-tools and the xmpp4r library.

require "atom/collection"
require "xmpp4r"

$coll_user = "bct"
$coll_pass = "atom-password"
$coll_url = "http://necronomicorp.com/testatom?app"

$bot_jid = "test@atompub.necronomicorp.com"
$bot_pass = "xmpp-password"

http = Atom::HTTP.new
http.user = $coll_user
http.pass = $coll_pass

coll = Atom::Collection.new $coll_url, http

cl = Jabber::Client.new($bot_jid)
cl.connect
cl.auth($bot_pass)

cl.add_message_callback do |msg|
  e = Atom::Entry.new  
  e.content = msg.body

  res = coll.post! e

  if res.code == "201"
    cl.send(Jabber::Message.new(msg.from, "success!"))
  else
    cl.send(Jabber::Message.new(msg.from, "#{res.code} #{res.message}"))
  end
end

Thread.stop

Try it out; send a message to test@atompub.necronomicorp.com. It should appear in my test collection.

(The real version is a server component which handles several collections on different JIDs.)

write a reply

this editor supports Markdown.