lib/slackutil.js
/**
     * @brief This function checks if the given user is valid with respect to
     *        the current team and channel.
     *
     * @param userName name of the user to be validated
     * @param channel id of the channel for which the user has to be validated
     * @param callback function invoked when validation is complete:
     *                 function cb(error, userId)
     *
     * @return none
     */
@brief This function checks if the given user is valid with respect to
the current team and channel.

@param userName name of the user to be validated
@param channel id of the channel for which the user has to be validated
@param callback function invoked when validation is complete:
function cb(error, userId)

@return none
@brief This function checks if the given user is valid with respect to the current team and channel . @param userName name of the user to be validated @param channel id of the channel for which the user has to be validated @param callback function invoked when validation is complete : function cb ( error userId ) @return none
function isValidUser(userName, channel, callback) {
        webClient.users.list(function (userListError, userListInfo) {
            if (userListError !== undefined && userListError !== null) {
                return callback(userListError);
            }
            if (
                userListInfo === undefined
                    || userListInfo === null
                    || userListInfo.ok !== true
            ) {
                return callback(
                    new Error("Error processing token auth request:")
                );
            }
            if (userListInfo.members === undefined) {
                return callback();
            }
            let foundUser = false;
            userListInfo.members.every(function (member) {
                if (member.name === userName) {
                    foundUser = true;
                    webClient.channels.info(
                        channel,
                        function (channelInfoError, channelInfo) {
                            if (channelInfoError !== undefined
                                    && channelInfoError !== null) {
                                return callback(channelInfoError);
                            }
                            if (channelInfo === undefined
                                    || channelInfo === null) {
                                return callback(
                                    new Error("Error processing channels.info")
                                );
                            }
                            if (channelInfo.ok !== true) {
                                return callback(
                                    new Error(channelInfo)
                                );
                            }
                            if (
                                channelInfo.channel === undefined
                                    || channelInfo.channel === null
                                    || channelInfo.channel.members
                                    === undefined
                                    || channelInfo.channel.members
                                    === null
                            ) {
                                return callback();
                            }
                            let members = channelInfo.channel.members;
                            if (members.indexOf(member.id) >= 0) {
                                return callback(undefined, member.id);
                            }
                            return callback();
                        }
                    );
                    return false;
                }
                return true;
            });
            if (foundUser === false) {
                return callback();
            }
        });
    }
function isValidUser ( userName , channel , callback ) { webClient . users . list ( function ( userListError , userListInfo ) { if ( userListError !== undefined && userListError !== null ) { return callback ( userListError ) ; } if ( userListInfo === undefined || userListInfo === null || userListInfo . ok !== true ) { return callback ( new Error ( "Error processing token auth request:" ) ) ; } if ( userListInfo . members === undefined ) { return callback ( ) ; } let foundUser = false ; userListInfo . members . every ( function ( member ) { if ( member . name === userName ) { foundUser = true ; webClient . channels . info ( channel , function ( channelInfoError , channelInfo ) { if ( channelInfoError !== undefined && channelInfoError !== null ) { return callback ( channelInfoError ) ; } if ( channelInfo === undefined || channelInfo === null ) { return callback ( new Error ( "Error processing channels.info" ) ) ; } if ( channelInfo . ok !== true ) { return callback ( new Error ( channelInfo ) ) ; } if ( channelInfo . channel === undefined || channelInfo . channel === null || channelInfo . channel . members === undefined || channelInfo . channel . members === null ) { return callback ( ) ; } let members = channelInfo . channel . members ; if ( members . indexOf ( member . id ) >= 0 ) { return callback ( undefined , member . id ) ; } return callback ( ) ; } ) ; return false ; } return true ; } ) ; if ( foundUser === false ) { return callback ( ) ; } } ) ; }
@brief This function checks if the given user is valid with respect to
        the current team and channel.
@brief This function checks if the given user is valid with respect to the current team and channel .
// Get list of users in the current team. // users.list API error. // users.list response object unavailable. // No members in the current team. // Find the user to be validated in the list using the user name. // User found in the user list. // Get list of users in the current channel. // channels.info API error. // channel info response unavailable. // No members in the current channel. /* User id of user to be validated is in
                                 * the channel's list of users.
                                 */ // User is invalid.