lib/index.js
function slackAPI(args, err_cb) {
    err_cb = err_cb || function () {};
    var self = this;
    var authtoken = args.token;

    this.slackData = {};
    this.token = '';
    this.logging = true;
    this.autoReconnect = true;
    this.i = 0;

    if (typeof args !== 'object') {
        this.logging = true;

        this.out('error', errors.object_arg_required);
        throw new Error(errors.object_arg_required);
    }

    if (typeof args.logging !== 'boolean') {
        this.logging = true;
        this.out('error', errors.boolean_arg_required);
    } else {
        this.logging = args.logging;
    }

    if (!authtoken || typeof authtoken !== 'string' || !authtoken.match(/^([a-z]*)\-([0-9]*)\-([0-9a-zA-Z]*)/)) {
        this.logging = true;

        this.out('error', errors.invalid_token);
        throw new Error(errors.invalid_token);
    }

    if (typeof args.autoReconnect !== 'boolean') {
        this.autoReconnect = false;
    } else {
        this.autoReconnect = args.autoReconnect;
    }

    this.token = authtoken;

    self.reqAPI('rtm.start', {}, function (data) {
        if (!data.ok) return err_cb(data.error);

        self.slackData.self = data.self;
        self.slackData.team = data.team;
        self.slackData.channels = data.channels;
        self.slackData.groups = data.groups;
        self.slackData.users = data.users;
        self.slackData.ims = data.ims;

        self.connectSlack(data.url, function (err, data) {
            if (!err) {
                self.emit(events[data.type], data);
            } else {
                self.emit('error', data);
            }
        });
    });

    eventEmitter.call(this);
}
function slackAPI(args, err_cb) {
    err_cb = err_cb || function () {};
    var self = this;
    var authtoken = args.token;

    this.slackData = {};
    this.token = '';
    this.logging = true;
    this.autoReconnect = true;
    this.i = 0;

    if (typeof args !== 'object') {
        this.logging = true;

        this.out('error', errors.object_arg_required);
        throw new Error(errors.object_arg_required);
    }

    if (typeof args.logging !== 'boolean') {
        this.logging = true;
        this.out('error', errors.boolean_arg_required);
    } else {
        this.logging = args.logging;
    }

    if (!authtoken || typeof authtoken !== 'string' || !authtoken.match(/^([a-z]*)\-([0-9]*)\-([0-9a-zA-Z]*)/)) {
        this.logging = true;

        this.out('error', errors.invalid_token);
        throw new Error(errors.invalid_token);
    }

    if (typeof args.autoReconnect !== 'boolean') {
        this.autoReconnect = false;
    } else {
        this.autoReconnect = args.autoReconnect;
    }

    this.token = authtoken;

    self.reqAPI('rtm.start', {}, function (data) {
        if (!data.ok) return err_cb(data.error);

        self.slackData.self = data.self;
        self.slackData.team = data.team;
        self.slackData.channels = data.channels;
        self.slackData.groups = data.groups;
        self.slackData.users = data.users;
        self.slackData.ims = data.ims;

        self.connectSlack(data.url, function (err, data) {
            if (!err) {
                self.emit(events[data.type], data);
            } else {
                self.emit('error', data);
            }
        });
    });

    eventEmitter.call(this);
}
function slackAPI ( args , err_cb ) { err_cb = err_cb || function ( ) { } ; var self = this ; var authtoken = args . token ; this . slackData = { } ; this . token = '' ; this . logging = true ; this . autoReconnect = true ; this . i = 0 ; if ( typeof args !== 'object' ) { this . logging = true ; this . out ( 'error' , errors . object_arg_required ) ; throw new Error ( errors . object_arg_required ) ; } if ( typeof args . logging !== 'boolean' ) { this . logging = true ; this . out ( 'error' , errors . boolean_arg_required ) ; } else { this . logging = args . logging ; } if ( ! authtoken || typeof authtoken !== 'string' || ! authtoken . match ( / ^([a-z]*)\-([0-9]*)\-([0-9a-zA-Z]*) / ) ) { this . logging = true ; this . out ( 'error' , errors . invalid_token ) ; throw new Error ( errors . invalid_token ) ; } if ( typeof args . autoReconnect !== 'boolean' ) { this . autoReconnect = false ; } else { this . autoReconnect = args . autoReconnect ; } this . token = authtoken ; self . reqAPI ( 'rtm.start' , { } , function ( data ) { if ( ! data . ok ) return err_cb ( data . error ) ; self . slackData . self = data . self ; self . slackData . team = data . team ; self . slackData . channels = data . channels ; self . slackData . groups = data . groups ; self . slackData . users = data . users ; self . slackData . ims = data . ims ; self . connectSlack ( data . url , function ( err , data ) { if ( ! err ) { self . emit ( events [ data . type ] , data ) ; } else { self . emit ( 'error' , data ) ; } } ) ; } ) ; eventEmitter . call ( this ) ; }
Spawn the API
@param  object   args   Arguments to start the bot with for example the auth token.
@param  function err_cb Callback if boot failed
@example new slackAPI({'token': 'xo-abcdeftokenhere', 'logging': true, autoReconnect: true})
Spawn the API