lib/flint.js
function Flint(options) {
  EventEmitter.call(this);

  this.id = options.id || u.genUUID64();

  /**
   * Options Object
   *
   * @memberof Flint
   * @instance
   * @namespace options
   * @property {string} token - Spark Token.
   * @property {string} webhookUrl - URL that is used for SPark API to send callbacks.
   * @property {string} [webhookSecret] - If specified, inbound webhooks are authorized before being processed.
   * @property {string} [messageFormat=text] - Default Spark message format to use with bot.say().
   * @property {number} [maxPageItems=50] - Max results that the paginator uses.
   * @property {number} [maxConcurrent=3] - Max concurrent sessions to the Spark API
   * @property {number} [minTime=600] - Min time between consecutive request starts.
   * @property {number} [requeueMinTime=minTime*10] - Min time between consecutive request starts of requests that have been re-queued.
   * @property {number} [requeueMaxRetry=3] - Msx number of atteempts to make for failed request.
   * @property {array} [requeueCodes=[429,500,503]] - Array of http result codes that should be retried.
   * @property {number} [requestTimeout=20000] - Timeout for an individual request recieving a response.
   * @property {number} [queueSize=10000] - Size of the buffer that holds outbound requests.
   * @property {number} [requeueSize=10000] - Size of the buffer that holds outbound re-queue requests.
   * @property {string} [id=random] - The id this instance of flint uses.
   * @property {string} [webhookRequestJSONLocation=body] - The property under the Request to find the JSON contents.
   * @property {Boolean} [removeWebhooksOnStart=true] - If you wish to have the bot remove all account webhooks when starting.
   */
  this.options = options;

  this.active = false;
  this.initialized = false;
  this.storageActive = false;
  this.isBotAccount = false;
  this.isUserAccount = false;
  this.person = {};
  this.email;

  // define location in webhook request to find json values of incoming webhook.
  // note: this is typically 'request.body' but depending on express/restify configuration, it may be 'request.params'
  this.options.webhookRequestJSONLocation = this.options.webhookRequestJSONLocation || 'body';

  // define if flint remove all webhooks attached to token on start (if not defined, defaults to true)
  this.options.removeWebhooksOnStart = typeof this.options.removeWebhooksOnStart === 'boolean' ? this.options.removeWebhooksOnStart : true;

  // define default messageFormat used with bot.say (if not defined, defaults to 'text')
  if(typeof this.options.messageFormat === 'string' && _.includes(['text', 'markdown', 'html'], _.toLower(this.options.messageFormat))) {
    this.messageFormat = _.toLower(this.options.messageFormat);
  } else {
    this.messageFormat = 'text';
  }

  this.batchDelay = options.minTime * 2;
  this.auditInterval;
  this.auditDelay = 300;
  this.auditCounter = 0;
  this.logs = [];
  this.logMax = 1000;
  this.lexicon = [];
  this.bots = [];
  this.spark = {};
  this.webhook = {};

  // register internal events
  this.on('error', err => {
    if(err) {
      console.err(err.stack);
    }
  });
  this.on('start', () => {
    require('./logs')(this);
    this.initialize();
  });
}
function Flint(options) {
  EventEmitter.call(this);

  this.id = options.id || u.genUUID64();

  /**
   * Options Object
   *
   * @memberof Flint
   * @instance
   * @namespace options
   * @property {string} token - Spark Token.
   * @property {string} webhookUrl - URL that is used for SPark API to send callbacks.
   * @property {string} [webhookSecret] - If specified, inbound webhooks are authorized before being processed.
   * @property {string} [messageFormat=text] - Default Spark message format to use with bot.say().
   * @property {number} [maxPageItems=50] - Max results that the paginator uses.
   * @property {number} [maxConcurrent=3] - Max concurrent sessions to the Spark API
   * @property {number} [minTime=600] - Min time between consecutive request starts.
   * @property {number} [requeueMinTime=minTime*10] - Min time between consecutive request starts of requests that have been re-queued.
   * @property {number} [requeueMaxRetry=3] - Msx number of atteempts to make for failed request.
   * @property {array} [requeueCodes=[429,500,503]] - Array of http result codes that should be retried.
   * @property {number} [requestTimeout=20000] - Timeout for an individual request recieving a response.
   * @property {number} [queueSize=10000] - Size of the buffer that holds outbound requests.
   * @property {number} [requeueSize=10000] - Size of the buffer that holds outbound re-queue requests.
   * @property {string} [id=random] - The id this instance of flint uses.
   * @property {string} [webhookRequestJSONLocation=body] - The property under the Request to find the JSON contents.
   * @property {Boolean} [removeWebhooksOnStart=true] - If you wish to have the bot remove all account webhooks when starting.
   */
  this.options = options;

  this.active = false;
  this.initialized = false;
  this.storageActive = false;
  this.isBotAccount = false;
  this.isUserAccount = false;
  this.person = {};
  this.email;

  // define location in webhook request to find json values of incoming webhook.
  // note: this is typically 'request.body' but depending on express/restify configuration, it may be 'request.params'
  this.options.webhookRequestJSONLocation = this.options.webhookRequestJSONLocation || 'body';

  // define if flint remove all webhooks attached to token on start (if not defined, defaults to true)
  this.options.removeWebhooksOnStart = typeof this.options.removeWebhooksOnStart === 'boolean' ? this.options.removeWebhooksOnStart : true;

  // define default messageFormat used with bot.say (if not defined, defaults to 'text')
  if(typeof this.options.messageFormat === 'string' && _.includes(['text', 'markdown', 'html'], _.toLower(this.options.messageFormat))) {
    this.messageFormat = _.toLower(this.options.messageFormat);
  } else {
    this.messageFormat = 'text';
  }

  this.batchDelay = options.minTime * 2;
  this.auditInterval;
  this.auditDelay = 300;
  this.auditCounter = 0;
  this.logs = [];
  this.logMax = 1000;
  this.lexicon = [];
  this.bots = [];
  this.spark = {};
  this.webhook = {};

  // register internal events
  this.on('error', err => {
    if(err) {
      console.err(err.stack);
    }
  });
  this.on('start', () => {
    require('./logs')(this);
    this.initialize();
  });
}
function Flint ( options ) { EventEmitter . call ( this ) ; this . id = options . id || u . genUUID64 ( ) ; /**
   * Options Object
   *
   * @memberof Flint
   * @instance
   * @namespace options
   * @property {string} token - Spark Token.
   * @property {string} webhookUrl - URL that is used for SPark API to send callbacks.
   * @property {string} [webhookSecret] - If specified, inbound webhooks are authorized before being processed.
   * @property {string} [messageFormat=text] - Default Spark message format to use with bot.say().
   * @property {number} [maxPageItems=50] - Max results that the paginator uses.
   * @property {number} [maxConcurrent=3] - Max concurrent sessions to the Spark API
   * @property {number} [minTime=600] - Min time between consecutive request starts.
   * @property {number} [requeueMinTime=minTime*10] - Min time between consecutive request starts of requests that have been re-queued.
   * @property {number} [requeueMaxRetry=3] - Msx number of atteempts to make for failed request.
   * @property {array} [requeueCodes=[429,500,503]] - Array of http result codes that should be retried.
   * @property {number} [requestTimeout=20000] - Timeout for an individual request recieving a response.
   * @property {number} [queueSize=10000] - Size of the buffer that holds outbound requests.
   * @property {number} [requeueSize=10000] - Size of the buffer that holds outbound re-queue requests.
   * @property {string} [id=random] - The id this instance of flint uses.
   * @property {string} [webhookRequestJSONLocation=body] - The property under the Request to find the JSON contents.
   * @property {Boolean} [removeWebhooksOnStart=true] - If you wish to have the bot remove all account webhooks when starting.
   */ this . options = options ; this . active = false ; this . initialized = false ; this . storageActive = false ; this . isBotAccount = false ; this . isUserAccount = false ; this . person = { } ; this . email ; // define location in webhook request to find json values of incoming webhook. // note: this is typically 'request.body' but depending on express/restify configuration, it may be 'request.params' this . options . webhookRequestJSONLocation = this . options . webhookRequestJSONLocation || 'body' ; // define if flint remove all webhooks attached to token on start (if not defined, defaults to true) this . options . removeWebhooksOnStart = typeof this . options . removeWebhooksOnStart === 'boolean' ? this . options . removeWebhooksOnStart : true ; // define default messageFormat used with bot.say (if not defined, defaults to 'text') if ( typeof this . options . messageFormat === 'string' && _ . includes ( [ 'text' , 'markdown' , 'html' ] , _ . toLower ( this . options . messageFormat ) ) ) { this . messageFormat = _ . toLower ( this . options . messageFormat ) ; } else { this . messageFormat = 'text' ; } this . batchDelay = options . minTime * 2 ; this . auditInterval ; this . auditDelay = 300 ; this . auditCounter = 0 ; this . logs = [ ] ; this . logMax = 1000 ; this . lexicon = [ ] ; this . bots = [ ] ; this . spark = { } ; this . webhook = { } ; // register internal events this . on ( 'error' , err => { if ( err ) { console . err ( err . stack ) ; } } ) ; this . on ( 'start' , ( ) => { require ( './logs' ) ( this ) ; this . initialize ( ) ; } ) ; }
Creates an instance of Flint.

@constructor Flint
@param {Object} options - Configuration object containing Flint settings.
@property {string} id - Flint UUID
@property {boolean} active - Flint active state
@property {boolean} intialized - Flint fully initialized
@property {boolean} isBotAccount - Is Flint attached to Spark using a bot account?
@property {boolean} isUserAccount - Is Flint attached to Spark using a user account?
@property {object} person - Flint person object
@property {string} email - Flint email
@property {object} spark - The Spark instance used by flint

@example
var options = {
webhookUrl: 'http://myserver.com/flint',
token: 'Tm90aGluZyB0byBzZWUgaGVyZS4uLiBNb3ZlIGFsb25nLi4u'
};
var flint = new Flint(options);
Creates an instance of Flint .