Beaglebone node-xmpp bot example

Here is source for a simple bot that is implemented in node-.js using
the node-xmpp library. This bot is designed to interact with the
Nimbits cloud data service.

It basically looks for changes to nimbits data and handles the
resulting xmpp notifications.

The handler is pretty simple -- it just parses the json content and
prints result in the system console. The long-term idea is to get a
clean 2-way xmpp based bot that can send and receive data to a variety
of cloud services, do m2m stuff, be driven using an XMPP based hmi
etc.

forgive the ratty formatting and any javascript newbishness

/**
* Nim Bot - simple node-xmpp bot to handle nimbits IM data
**/
var sys = require('sys');
var xmpp = require('/home/root/node_modules/node-xmpp');

// --- set up credentials
var jid = 'PezBeagle@gmail.com'; // your bot's google id here
var password = 'notmypassword'; // your bot's gmail password here

// --- Create an XMPP client instance
var cl = new xmpp.Client({ jid: jid, password: password });

// --- Create a handler for the xmpp client "online" event
// Basically, this handler, as written, will make
// us show up on google chat as "available"
cl.on('online',
  function() {
    cl.send(new xmpp.Element('presence', { }).
      c('show').t('chat').up().
      c('status').t('nimbits node-xmpp i/o bot')
    );
  }
);

// --- create a handler for the xmpp client "stanza" event
// this handler basically handles all incoming messages
cl.on('stanza',
  function(stanza) {
    if (stanza.is('message') &&
      // Important: never reply to errors!
      stanza.attrs.type !== 'error') {
        // --- extract sender info
        // and <body> ... </body> from message
        var sender;
        var body;
        sender = stanza.attrs.from;
        body = '' + stanza.children[0]; // this coerces
stanza.children[0] to string

        // --- echo info about sender
        sys.puts("from:" + sender);

        // --- See if this is from nimbits.com
        // If it isn't, we just ignore it
        // the address is nimbits1 AT appspot.com/bot
        if(sender == 'nimbits1@appspot.com/bot'){

          // --- Echo the json "blob"
          sys.puts(stanza.children[0].children[0]) ;

          // --- eval the json
          var nimbitsInfo;
          var nimbitsData;
          nimbitsInfo = eval('(' + stanza.children[0].children[0] + ')');
          nimbitsData = eval('(' + nimbitsInfo.value + ')');
          sys.puts(nimbitsInfo.name + '=' + nimbitsData.d);
        }
      }

      }
  );

// --- make error handler
cl.on('error',
      function(e) {
          sys.puts(e);
      });

It would be great to incorporate some basic services into bonescript.
I'd like to keep the API simple like what you'd find for the Arduino.
That is, something easy to understand. Of course, the idea of event
listeners needs to be added, but it should be kept simple and
incremental. Examples need to be easy to follow. Patches to
bonescript are quite welcome. Using an MIT license.

Hmm -- let me think about how i can encapsulate it with that in
mind.

The Arduino/Wiring event stuff is pretty well done, iirc, so I guess
I'll peek at that and see if I can takes some inspiration from it for
an beaglebone XMPP bot library.