jsierles / uppercut forked from tyler/uppercut

A simple DSL for creating Jabber agents

This URL has Read+Write access

name age message
file LICENSE Mon Aug 04 22:44:45 -0700 2008 Initial. [tyler]
file README.textile Loading commit data...
file Rakefile
directory bin/
directory examples/
directory lib/
directory specs/
file uppercut.gemspec
README.textile

Uppercut

Overview

Uppercut is a little DSL for writing agents and notifiers which you interact with via your Jabber client.

Making an Agent

You could put together a very simple agent as follows:

  
    class BasicAgent < Uppercut::Agent
      command 'date' do |c|
        m.send `date`
      end
  
      command /^cat (.*)/ do |c,rest|
        m.send File.read(rest)
      end
  
      command 'report' do |c|
        m.send 'Hostname: ' + `hostname`
        m.send 'Running as: ' + ENV['USER']
      end
    end
  

With the above code, we’ve created an Agent template of sorts. It responds to three commands: {date cat report}.
The block which is passed to “command” should always have at least one paramater. The first parameter will
always be an Uppercut::Conversation object, which can be used to respond to the user who sent the input. When passing
a regular expression as the first parameter to “command”, all of the captures which the pattern match generates
will also be passed to the block. This can be seen in the “cat” example above. There is one capture and it is
passed in as rest.

Then to actually put the Agent to work…

  
    BasicAgent.new('user@server/resource','password').listen
  

This creates a new BasicAgent instance and sends it listen to make it start accepting messages.
Note that by default when an agent is listening, it ignores all errors. (In the future, I’ll have it log them.)

Making a Notifier

  
    class BasicNotifier < Uppercut::Notifier
      notifier :error do |m,data|
        m.to 'tbmcmullen@gmail.com'
        m.send "Something in your app blew up: #{data}"
      end
    end
  

So, we make a new Notifier class and call a notifier block within it. This makes a notifier with the name :error, which sends a message to tbmcmullen@gmail.com when it fires.

  
    notifier = BasicNotifier.new('user@server/resource','password').connect
    
    notifier.notify :error, 'Sprocket Error!'
  

The purpose of a Notifier is just to make a multi-purpose event-driven notification system. You could use it notify yourself of errors in your Rails app, or ping you when a new comment arrives on your blog, or … I dunno, something else.

I am very aware of how limited this system is at the moment. I have some big plans for Notifier, so just hang tight while I hack them out…

Todo

Security

If you intend to use this on an open Jabber network (read: Google Talk) take some precautions. Agent#new takes an optional list of JIDs that the agent will respond to.

  
    BasicAgent.new('user@server/res', 'pw', :roster => ['you@server'])
  

The agent created with the above statement will not respond to messages or subscription requests from anyone other than ‘you@server’.

Features

Uppercut is currently very thin on features, as it’s in its infancy. Here’s a brief list of where I’m
currently intending to take the project:

  • send files to and receive files from agents
  • improving the way one writes executables (using the Daemons library is best for the moment)
  • auto-updating of agents
  • I swear I’m going to find a use for MUC
  • allow agents to establish communications on their own, rather than being reactionary (think RSS updates)
  • … other stuff that sounds fun to code up …