首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Amazon Lex意图

Amazon Lex意图
EN

Stack Overflow用户
提问于 2017-07-22 15:27:39
回答 1查看 882关注 0票数 0

我有两个意图:

这是现在的聊天机器人:

在此之后,将会确认他是否想要投资于股权。如果他说是,那么必须在他没有键入任何内容的情况下开始另一个意图。

我该如何实现这一点?

下面是我的Lambda函数:

代码语言:javascript
复制
// --------------- 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 }));   

}
EN

回答 1

Stack Overflow用户

发布于 2017-07-26 06:25:35

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45251920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档