message: [Sockets] Use callbacks to handle websocket errors
diff: @@ -134,21 +134,27 @@ function SocketBot(configuration) {
  bot.send = function(message, cb) {
  if (bot.connected || !bot.ws) {
  - try {
  if (bot.ws) {
  - bot.ws.send(JSON.stringify(message));
  + bot.ws.send(JSON.stringify(message), function(err) {
  + if (cb) {
  + return cb(err, message);
  + }
  + });
  } else {
  + try {
  bot.http_response.json(message);
  + if (cb) {
  + cb(null, message);
  }
  } catch (err) {
  + if (cb) {
  + return cb(err, message);
  + } else {
  console.error('ERROR SENDING', err);
  - if (cb) return cb(err, message);
  }
  - if (cb) cb(null, message);
  -
  + }
  + }
  } else {
  -
  - // console.log('not connected. wait to resend');
  setTimeout(function() {
  bot.send(message, cb);
  }, 3000);
  @@ -158,8 +164,12 @@ function SocketBot(configuration) {
  bot.startTyping = function() {
  if (bot.connected) {
  bot.ws.send(JSON.stringify({
  - type: 'typing',
  - }));
  + type: 'typing'
  + }), function(err) {
  + if (err) {
  + console.error('startTyping failed: ' + err.message);
  + }
  + });
  }
  };
  @@ -248,22 +258,14 @@ function SocketBot(configuration) {
  cb();
  };
  return bot;
  -
  -
  });
  -
  controller.handleWebhookPayload = function(req, res) {
  -
  var payload = req.body;
  controller.ingest(controller.spawn({}), payload, res);
  -
  - }
  -
  -
  + };
  return controller;
  -
  }
  module.exports = SocketBot;
  