Example #1
0
bot.onConnect(function(){
	console.info('> Joining channel...');
	bot.join(opts.channel);
	bot.onMessage(delegate);
	bot.message(opts.channel, 'I\'m ready! ' + Object.keys(bot.plugins).sort().join(', '));
	console.info('> Ready!');
});
Example #2
0
            memory.get("SELECT * FROM Debug ORDER BY time DESC LIMIT 1", function(err, row)
            {
                var tm = Config.customerID + Util.chooseRandom(Config.admins) + "@" + Config.chatServer;
                var ts = Math.round(new Date().getTime() / 1000);

                NedBot = new wobot.Bot(
                {
                    debug    : Config.debugXMPP,
                    jid      : Config.userID + '@' + Config.chatServer + '/bot',
                    password : Config.password,
                    name     : Config.name
                });

                if( (ts - row["time"]) >= Config.imBrokenMsgFreq * 60 )
                {
                    var counter = row["attempts"] + 1;

                    NedBot.connect();
                    NedBot.onConnect(function()
                    {
                        this.message(tm, Config.imBrokenMessage);
                        Util.consoleLog(Config.imBrokenMessage);
                    });

                    memory.run("INSERT INTO Debug(user, attempts, time) VALUES (?, ?, ?)", [tm, counter, ts]);
                    NedBot.disconnect();
                }
            });
Example #3
0
function bootstrap(identifier, plugin) {
	try {
		var module = require(plugin);
		if (!module.load) { module.load = noop; }
		bot.loadPlugin(identifier, module);
	} catch (e) {
		error('   > skipped: ', e);
	}
}
Example #4
0
conn.login(runtimeOptions.salesforceUsername, runtimeOptions.salesforcePassword, function(err, userInfo) {
  if (err) { return console.error(err); }
  console.log(' -=- > Connected to Salesforce');

  var b = new wobot.Bot({
    jid: runtimeOptions.hipchatUser + "/bot",
    password: runtimeOptions.hipchatPassword
  });

  b.connect();

  b.onConnect(function() {
    var self = this;
    console.log(' -=- > Connected to HipChat');
    runtimeOptions.hipchatRoomsToJoin.forEach(function(room) {
      console.log(' -=- > Joining default room ' + room);
      self.join(room);
    });
  });

  b.onInvite(function(roomJid, fromJid, reason) {
    var self = this;
    console.log(' -=- > Invited to and joining ' + roomJid + ' by ' + fromJid + ': ' + reason);
    self.join(roomJid);
  });

  b.onMessage(function(channel, from, message) {
    var self = this;
    var alreadyProcessed = [];
    var matches = message.match(runtimeOptions.hipchatUsername);
    var lowerMessage = message.toLowerCase();
    var oppSoql;
    if (!matches) {
      return;
    }

    console.log(' -=- > Responding to message ' + message + ' [from ' + from + ']');
    if (lowerMessage.indexOf("help") > -1) {
      var help = "@me directly with phrases like 'case #0000', 'new opportunities this week', 'closed opportunities', or just 'opportunity'";
      self.message(channel, help);
    }
    // Opportunity, opportunities
    else {
      if (lowerMessage.indexOf("pportunit") > -1) {
        console.log(' -=- > Looking up Opportunities');
        var days = '1';
        var timeLabel = 'day';
        var typeLabel;

        if (lowerMessage.indexOf('week') > -1) {
          days = '7';
          timeLabel = 'week';
        }
        if (lowerMessage.indexOf("new opportunit") > -1) {
          typeLabel = 'New';
          oppSoql = "SELECT Name, Amount, LeadSource, Probability, StageName, CreatedDate FROM Opportunity WHERE Type='New' AND CreatedDate = Last_N_Days:" + days + " ORDER BY CreatedDate DESC";
        }
        else if (lowerMessage.indexOf("closed opportunit") > -1) {
          typeLabel = 'Won';
          oppSoql = "SELECT Name, Amount, LeadSource, Probability, StageName, CreatedDate FROM Opportunity WHERE StageName ='Closed Won' AND CreatedDate = Last_N_Days:" + days + " ORDER BY CreatedDate DESC";
        }
        else {
          typeLabel = 'All';
          oppSoql = "SELECT Name, Amount, LeadSource, Probability, StageName, CreatedDate FROM Opportunity WHERE CreatedDate = Last_N_Days:" + days + " ORDER BY CreatedDate DESC";
        }
        conn.query(oppSoql, function(err, result) {
          if (err) { return console.error(err); }
          console.log(' -=- > Found ' + result.totalSize);
          var response = typeLabel + ' opportunities in the last ' + timeLabel + ': ' + result.totalSize + '\n';
          result.records.forEach(function(opp) {
            response = response + '* “' + opp.Name + '” ($' + opp.Amount + '), in ' + opp.StageName + ' from ' + opp.LeadSource + '\n';
          });
          self.message(channel, response);
        });
      }

      var caseMentions = message.match(CASE_MENTION);
      if (caseMentions !== null) {
        var caseNumber = caseMentions[1];
        if (alreadyProcessed.indexOf(caseNumber) < 0 && runtimeOptions.hipchatIgnoredUsers.indexOf(from) < 0) {
          console.log(' -=- > Looking up Case #' + caseNumber);
          alreadyProcessed.push(caseNumber);

          var caseSoql = "SELECT Id, Subject, Status, Contact.Name, Owner.Name, Type FROM Case WHERE CaseNumber='" + caseNumber + "'";
          conn.query(caseSoql, function(err, result) {
            // FIXME: Handle { [INVALID_SESSION_ID: Session expired or invalid] name: 'INVALID_SESSION_ID', errorCode: 'INVALID_SESSION_ID' }
            if (err) { return console.error(err); }
            console.log(' -=- > Found ' + result.totalSize);
            var sfCase = result.records[0];
            var clarification = runtimeOptions.salesforceUrl + sfCase.Id + ': “' + sfCase.Subject + '” (' + sfCase.Type + ') from ' + sfCase.Contact.Name + ' assigned to ' + sfCase.Owner.Name  + ' and marked as ' + sfCase.Status;
            self.message(channel, clarification);
          });
        }
      }
    }
  });
});
Example #5
0
    }
});


for(var i=0; i<Config.roomsToJoin.length; i++) 
{
    Config.roomsToJoin[i] = Config.customerID + Config.roomsToJoin[i] + '@' + Config.confServer;
}

var wobot = require('wobot');
var main  = "index.js";

NedBot = new wobot.Bot(
{
    debug    : Config.debugXMPP,
    jid      : Config.userID + '@' + Config.chatServer + '/bot',
    password : Config.password,
    name     : Config.name
});


NedBot.loadPlugin("main", require('./plugins/' + main));
NedBot.connect();


NedBot.onConnect(function() 
{
    Util.consoleLog('Connected');
    self = this;

    if(Config.joinAllRooms)
Example #6
0
function respond(e, msg) {
	if (e) { error('Plugin Error', e.substr ? e : JSON.stringify(e)); }
	if (msg) { bot.message(opts.channel, msg); }
}
Example #7
0
function error(condition, text) {
	text = condition + ': ' + text;
	console.error(text);
	bot.message(opts.channel, text);
}
Example #8
0
function connect(callback) {
	console.info('> Connecting to server...');
	callback(null, bot.connect());
}
Example #9
0
bubo_bot.send_message = function(channel, message){
  b.message(channel, message);
}
Example #10
0
        bot_modules[modname] = require(path+"/"+fname);
      }
    });
}
var DIR = path_module.join(__dirname, 'plugins');
LoadModules(DIR);

var PRIV_DIR = path_module.join(__dirname, 'private_plugins');
LoadModules(PRIV_DIR);

exports.module_holder = bot_modules;

// Start the bot!
var b = new wobot.Bot({
    debug: runtimeOptions.debug,
    jid: runtimeOptions.hipchatUser + "/bot",
    password: runtimeOptions.hipchatPassword
});

// Connect the bot!
b.connect();

b.onConnect(function() {
  var self = this;
  console.log(' -=- > Connect');
  // Join the rooms configured 
  runtimeOptions.hipchatRoomsToJoin.forEach(function(room) {
    console.log(' -=- > Joining default room ' + room);
    self.join(room);
  });
});