0

我有两个意图:

意图类型

这是现在的聊天机器人:

这是现在的聊天机器人

在此之后,将确认他是否要投资股票。如果他说是,那么必须在他不输入任何内容的情况下启动另一个意图。

我如何实现这一目标?

这是我的 Lambda 函数:

// --------------- Intents -----------------------
var type;
/**
 * Called when the user specifies an intent for this skill.
 */
function dispatch(intentRequest, callback) {
    // console.log(JSON.stringify(intentRequest, null, 2));
    console.log(`dispatch userId=${intentRequest.userId}, intent=${intentRequest.currentIntent.name}`);

    const name = intentRequest.currentIntent.name;

    // Dispatch to your skill's intent handlers
    if (name === 'FinancialType') {
        return getFinancialType(intentRequest,callback);
    }
    throw new Error(`Intent with name ${name} not supported`);
}

// --------------- Main handler -----------------------

function loggingCallback(response, originalCallback) {
    // console.log(JSON.stringify(response, null, 2));
    originalCallback(null, response);
}

// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.
exports.handler = (event, context, callback) => {
    try {
        // By default, treat the user request as coming from the America/New_York time zone.
        process.env.TZ = 'America/New_York';
        console.log(`event.bot.name=${event.bot.name}`);

        /**
         * Uncomment this if statement and populate with your Lex bot name and / or version as
         * a sanity check to prevent invoking this Lambda function from an undesired Lex bot or
         * bot version.
         */
        /*
        if (event.bot.name !== 'MakeAppointment') {
             callback('Invalid Bot Name');
        }
        */
        dispatch(event, (response) => loggingCallback(response, callback));
    } catch (err) {
        callback(err);
    }
};

function close(fulfillmentState, message) {
    return {
        dialogAction: {
            type: 'Close',
            fulfillmentState,
            message,
        },
    };
}


function elicitSlot(intentName, slots, slotToElicit, message) {
    return {
        dialogAction: {
            type: 'ElicitSlot',
            intentName,
            slots,
            slotToElicit,
            message,
        },
    };
}

function buildValidationResult(isValid, violatedSlot, messageContent) {
    return {
        isValid,
        violatedSlot,
        message: { contentType: 'PlainText', content: messageContent },
    };
}

function getFinancialType(intentRequest,callback){
    var age = intentRequest.currentIntent.slots.age;
    var amount = intentRequest.currentIntent.slots.amount;
    const source = intentRequest.invocationSource;

    if(amount >= 10000){
        type = 'Equity';
    }

    callback(close('Fulfilled',{contentType: 'PlainText',
    content: `You have choosen to invest ` + amount + ' in ' + type }));   

}
4

1 回答 1

0

在 AWS 控制台中有一个选项可让 Lex 包含一条确认消息。您可以在那里要求用户确认。

文档:http ://docs.aws.amazon.com/lex/latest/dg/howitworks-manage-prompts.html#msg-prompts-context-for-msgs

于 2017-07-25T22:25:34.953 回答