function questionHandler(uuid, msg, callback) {
    let tokens = null;
    let isCommand = false;

    for (let cmd of botCommands) {
        if ((tokens = msg.match(cmd.regex)) !== null) {
            tokens[tokens.length - 1] = cmd.answer.replace(/{\s*query\s*}/i, tokens[tokens.length - 1].trim());
            if (!cmd.use_backend) {
                callback({
                        text: tokens[tokens.length - 1].trim(),
                        intent: 'cmd',
                        action: 'cmd',
                        command: true,
                    });
                return true;
            }
            isCommand = true;
            break;
        }
    }

    tokens = tokens || msg.match(config.REGEX);
    if (tokens == null) {
        return false;
    }

    const message = tokens[tokens.length - 1].trim();
    const timestamp = Date.now();
    const throttle = questionThrottle.users[uuid];
    if (throttle && timestamp - throttle < questionThrottle.limit) {
        return false;
    }

    if (msg.search(/^[!\/]/) !== -1 && message.length < 2) {
        updateCommands(false);
        callback({
                text: `Есть вопрос? Напиши в чате ${(msg.match(/^![^\s]+/i) || ['!bot'])[0]} ТВОЙ_ВОПРОС`,
                intent: 'cmd',
                action: 'cmd',
                command: isCommand,
            });
        return true;
    }

    if (message.length < 2) {
        return false;
    }

    questionThrottle.users[uuid] = timestamp;

    dialogClient
        .detectIntent({
            session: dialogClient.sessionPath(config.DIALOGFLOW_PROJECT, uuid),
            queryInput: {
                text: {
                    text: message.substr(0, 255),
                    languageCode: 'ru-RU',
                }
            }
        })
        .then(function (responses) {
            const result = responses[0].queryResult;
            let msg = {
                    text: result.fulfillmentText,
                    action: result.action,
                    intent: result.intent.displayName,
                    command: isCommand,
                };

            if (result.fulfillmentMessages && result.fulfillmentMessages.length > 0) {
                msg.text = result.fulfillmentMessages[result.fulfillmentMessages.length - 1].text.text[0];
            }

            if (msg.intent.search('clip') !== -1) {
                msg.text = getLastSongText(msg.text);
            }

            callback(msg);
        })
        .catch(function (err) {
            console.error('[DialogError]', err);
        });
    return true;
}
/**
 * Handle message and get intent from dialogflow
 *
 * @param uuid     object   Unique id for this dialog
 * @param message  string   Message text
 * @param callback function Callback for sending response, function (msg) { ... }
 */
Handle message and get intent from dialogflow
@param uuid     object   Unique id for this dialog
@param message  string   Message text
@param callback function Callback for sending response, function (msg) { ...
Handle message and get intent from dialogflow @param uuid object Unique id for this dialog @param message string Message text @param callback function Callback for sending response function ( msg ) { ...
function questionHandler(uuid, msg, callback) {
    let tokens = null;
    let isCommand = false;
    for (let cmd of botCommands) {
        if ((tokens = msg.match(cmd.regex)) !== null) {
            tokens[tokens.length - 1] = cmd.answer.replace(/{\s*query\s*}/i, tokens[tokens.length - 1].trim());
            if (!cmd.use_backend) {
                callback({
                        text: tokens[tokens.length - 1].trim(),
                        intent: 'cmd',
                        action: 'cmd',
                        command: true,
                    });
                return true;
            }
            isCommand = true;
            break;
        }
    }
    tokens = tokens || msg.match(config.REGEX);
    if (tokens == null) {
        return false;
    }
    const message = tokens[tokens.length - 1].trim();
    const timestamp = Date.now();
    const throttle = questionThrottle.users[uuid];
    if (throttle && timestamp - throttle < questionThrottle.limit) {
        return false;
    }
    if (msg.search(/^[!\/]/) !== -1 && message.length < 2) {
        updateCommands(false);
        callback({
                text: `Есть вопрос? Напиши в чате ${(msg.match(/^![^\s]+/i) || ['!bot'])[0]} ТВОЙ_ВОПРОС`,
                intent: 'cmd',
                action: 'cmd',
                command: isCommand,
            });
        return true;
    }
    if (message.length < 2) {
        return false;
    }
    questionThrottle.users[uuid] = timestamp;
    dialogClient
        .detectIntent({
            session: dialogClient.sessionPath(config.DIALOGFLOW_PROJECT, uuid),
            queryInput: {
                text: {
                    text: message.substr(0, 255),
                    languageCode: 'ru-RU',
                }
            }
        })
        .then(function (responses) {
            const result = responses[0].queryResult;
            let msg = {
                    text: result.fulfillmentText,
                    action: result.action,
                    intent: result.intent.displayName,
                    command: isCommand,
                };
            if (result.fulfillmentMessages && result.fulfillmentMessages.length > 0) {
                msg.text = result.fulfillmentMessages[result.fulfillmentMessages.length - 1].text.text[0];
            }
            if (msg.intent.search('clip') !== -1) {
                msg.text = getLastSongText(msg.text);
            }
            callback(msg);
        })
        .catch(function (err) {
            console.error('[DialogError]', err);
        });
    return true;
}
function questionHandler ( uuid , msg , callback ) { let tokens = null ; let isCommand = false ; for ( let cmd of botCommands ) { if ( ( tokens = msg . match ( cmd . regex ) ) !== null ) { tokens [ tokens . length - 1 ] = cmd . answer . replace ( / {\s*query\s*} / i , tokens [ tokens . length - 1 ] . trim ( ) ) ; if ( ! cmd . use_backend ) { callback ( { text : tokens [ tokens . length - 1 ] . trim ( ) , intent : 'cmd' , action : 'cmd' , command : true , } ) ; return true ; } isCommand = true ; break ; } } tokens = tokens || msg . match ( config . REGEX ) ; if ( tokens == null ) { return false ; } const message = tokens [ tokens . length - 1 ] . trim ( ) ; const timestamp = Date . now ( ) ; const throttle = questionThrottle . users [ uuid ] ; if ( throttle && timestamp - throttle < questionThrottle . limit ) { return false ; } if ( msg . search ( / ^[!\/] / ) !== - 1 && message . length < 2 ) { updateCommands ( false ) ; callback ( { text : ` +/ i ) | |  ['!b o t '])[0]}  Т В О _В П РОС`, intent : 'cmd' , action : 'cmd' , command : isCommand , } ) ; return true ; } if ( message . length < 2 ) { return false ; } questionThrottle . users [ uuid ] = timestamp ; dialogClient . detectIntent ( { session : dialogClient . sessionPath ( config . DIALOGFLOW_PROJECT , uuid ) , queryInput : { text : { text : message . substr ( 0 , 255 ) , languageCode : 'ru-RU' , } } } ) . then ( function ( responses ) { const result = responses [ 0 ] . queryResult ; let msg = { text : result . fulfillmentText , action : result . action , intent : result . intent . displayName , command : isCommand , } ; if ( result . fulfillmentMessages && result . fulfillmentMessages . length > 0 ) { msg . text = result . fulfillmentMessages [ result . fulfillmentMessages . length - 1 ] . text . text [ 0 ] ; } if ( msg . intent . search ( 'clip' ) !== - 1 ) { msg . text = getLastSongText ( msg . text ) ; } callback ( msg ) ; } ) . catch ( function ( err ) { console . error ( '[DialogError]' , err ) ; } ) ; return true ; }
Handle message and get intent from dialogflow
 @param uuid     object   Unique id for this dialog
 @param message  string   Message text
 @param callback function Callback for sending response, function (msg) { ... }
Handle message and get intent from dialogflow @param uuid object Unique id for this dialog @param message string Message text @param callback function Callback for sending response function ( msg ) { ... }