dist/lib/driver.js
function respondToMessages(callback, options = {}) {
    const config = Object.assign({}, settings, options);
    // return value, may be replaced by async ops
    let promise = Promise.resolve();
    // Join configured rooms if they haven't been already, unless listening to all
    // public rooms, in which case it doesn't matter
    if (!config.allPublic &&
        exports.joinedIds.length === 0 &&
        config.rooms &&
        config.rooms.length > 0) {
        promise = joinRooms(config.rooms)
            .catch((err) => {
            log_1.logger.error(`[joinRooms] Failed to join configured rooms (${config.rooms.join(', ')}): ${err.message}`);
        });
    }
    exports.lastReadTime = new Date(); // init before any message read
    reactToMessages((err, message, meta) => __awaiter(this, void 0, void 0, function* () {
        if (err) {
            log_1.logger.error(`[received] Unable to receive: ${err.message}`);
            callback(err); // bubble errors back to adapter
        }
        // Ignore bot's own messages
        if (message.u._id === exports.userId)
            return;
        // Ignore DMs unless configured not to
        const isDM = meta.roomType === 'd';
        if (isDM && !config.dm)
            return;
        // Ignore Livechat unless configured not to
        const isLC = meta.roomType === 'l';
        if (isLC && !config.livechat)
            return;
        // Ignore messages in un-joined public rooms unless configured not to
        if (!config.allPublic && !isDM && !meta.roomParticipant)
            return;
        // Set current time for comparison to incoming
        let currentReadTime = new Date(message.ts.$date);
        // Ignore edited messages if configured to
        if (!config.edited && message.editedAt)
            return;
        // Set read time as time of edit, if message is edited
        if (message.editedAt)
            currentReadTime = new Date(message.editedAt.$date);
        // Ignore messages in stream that aren't new
        if (currentReadTime <= exports.lastReadTime)
            return;
        // At this point, message has passed checks and can be responded to
        log_1.logger.info(`[received] Message ${message._id} from ${message.u.username}`);
        exports.lastReadTime = currentReadTime;
        // Processing completed, call callback to respond to message
        callback(null, message, meta);
    }));
    return promise;
}
function respondToMessages(callback, options = {}) {
    const config = Object.assign({}, settings, options);
    // return value, may be replaced by async ops
    let promise = Promise.resolve();
    // Join configured rooms if they haven't been already, unless listening to all
    // public rooms, in which case it doesn't matter
    if (!config.allPublic &&
        exports.joinedIds.length === 0 &&
        config.rooms &&
        config.rooms.length > 0) {
        promise = joinRooms(config.rooms)
            .catch((err) => {
            log_1.logger.error(`[joinRooms] Failed to join configured rooms (${config.rooms.join(', ')}): ${err.message}`);
        });
    }
    exports.lastReadTime = new Date(); // init before any message read
    reactToMessages((err, message, meta) => __awaiter(this, void 0, void 0, function* () {
        if (err) {
            log_1.logger.error(`[received] Unable to receive: ${err.message}`);
            callback(err); // bubble errors back to adapter
        }
        // Ignore bot's own messages
        if (message.u._id === exports.userId)
            return;
        // Ignore DMs unless configured not to
        const isDM = meta.roomType === 'd';
        if (isDM && !config.dm)
            return;
        // Ignore Livechat unless configured not to
        const isLC = meta.roomType === 'l';
        if (isLC && !config.livechat)
            return;
        // Ignore messages in un-joined public rooms unless configured not to
        if (!config.allPublic && !isDM && !meta.roomParticipant)
            return;
        // Set current time for comparison to incoming
        let currentReadTime = new Date(message.ts.$date);
        // Ignore edited messages if configured to
        if (!config.edited && message.editedAt)
            return;
        // Set read time as time of edit, if message is edited
        if (message.editedAt)
            currentReadTime = new Date(message.editedAt.$date);
        // Ignore messages in stream that aren't new
        if (currentReadTime <= exports.lastReadTime)
            return;
        // At this point, message has passed checks and can be responded to
        log_1.logger.info(`[received] Message ${message._id} from ${message.u.username}`);
        exports.lastReadTime = currentReadTime;
        // Processing completed, call callback to respond to message
        callback(null, message, meta);
    }));
    return promise;
}
function respondToMessages ( callback , options = { } ) { const config = Object . assign ( { } , settings , options ) ; // return value, may be replaced by async ops let promise = Promise . resolve ( ) ; // Join configured rooms if they haven't been already, unless listening to all // public rooms, in which case it doesn't matter if ( ! config . allPublic && exports . joinedIds . length === 0 && config . rooms && config . rooms . length > 0 ) { promise = joinRooms ( config . rooms ) . catch ( ( err ) => { log_1 . logger . error ( ` ${ config . rooms . join ( ', ' ) } ${ err . message } ` ) ; } ) ; } exports . lastReadTime = new Date ( ) ; // init before any message read reactToMessages ( ( err , message , meta ) => __awaiter ( this , void 0 , void 0 , function * ( ) { if ( err ) { log_1 . logger . error ( ` ${ err . message } ` ) ; callback ( err ) ; // bubble errors back to adapter } // Ignore bot's own messages if ( message . u . _id === exports . userId ) return ; // Ignore DMs unless configured not to const isDM = meta . roomType === 'd' ; if ( isDM && ! config . dm ) return ; // Ignore Livechat unless configured not to const isLC = meta . roomType === 'l' ; if ( isLC && ! config . livechat ) return ; // Ignore messages in un-joined public rooms unless configured not to if ( ! config . allPublic && ! isDM && ! meta . roomParticipant ) return ; // Set current time for comparison to incoming let currentReadTime = new Date ( message . ts . $date ) ; // Ignore edited messages if configured to if ( ! config . edited && message . editedAt ) return ; // Set read time as time of edit, if message is edited if ( message . editedAt ) currentReadTime = new Date ( message . editedAt . $date ) ; // Ignore messages in stream that aren't new if ( currentReadTime <= exports . lastReadTime ) return ; // At this point, message has passed checks and can be responded to log_1 . logger . info ( ` ${ message . _id } ${ message . u . username } ` ) ; exports . lastReadTime = currentReadTime ; // Processing completed, call callback to respond to message callback ( null , message , meta ) ; } ) ) ; return promise ; }
Proxy for `reactToMessages` with some filtering of messages based on config.

@param callback Function called after filters run on subscription events.
- Uses error-first callback pattern
- Second argument is the changed item
- Third argument is additional attributes, such as `roomType`
@param options Sets filters for different event/message types.
Proxy for reactToMessages with some filtering of messages based on config .