本文介绍了Amazon Lex Bot-回复你好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开始学习Amazon lex,并仔细阅读了它们的文档和示例Bot.

I have started learning Amazon lex, gone through their Documentation and Example Bots.

我面临的问题是,所有的漫游器都是Q& A类型,如果我必须让漫游器回复Hello,那么正确的方法或方法是什么?

Problem i am facing is that all the bots are Q&A types, if i have to make the bot reply to Hello, what should be the correct way or how to do it?

根据我的理解:

用户可以提出许多其他直接问题,我是否必须回答所有具有lambda函数意图的问题?我正在使用Java脚本.

There can be many other direct question that user can ask, do i have to reply all the question for an intent with lambda function? I am using java script.

我被困住了,建议任何方法吗?

I am stuck, suggest any method ?

编辑1 :

这是我一直在寻找的,仍然有任何建议会有所帮助.

This is what i was looking for, still any suggestion will be helpful.

推荐答案

要在Lambda函数中实现从 JavaScript(Node.js)返回格式化的响应:

To implement returning a formatted response from JavaScript (Node.js) in a Lambda Function:

首先创建一些方便的功能,以构建正确的Lex响应格式.

First create some handy functions for building proper Lex response formats.

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

您可以在 AWS-Lex-Convo-Bot-Example index.js

然后只需调用该函数并将其传递给它所需的内容,就像这样:

Then just call that function and pass it what it needs, like this:

var message = {
    'contentType': 'PlainText', 
    'content': 'Hi! How can I help you?'
}

var responseMsg = close( sessionAttributes, 'Fulfilled', message );

(将您的消息写在'content'内,如果使用SSML标签,请将'contentType'更改为'SSML')

(write your message inside 'content', if using SSML tags, change 'contentType' to 'SSML')

然后将responseMsg传递到exports.handlercallback.

将所有内容放在一起,您将得到:

Put it all together and you get:

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

exports.handler = (event, context, callback) => {
    console.log( "EVENT= "+JSON.stringify(event) );

    const intentName = event.currentIntent.name;
    var sessionAttributes = event.sessionAttributes;

    var responseMsg = "";

    if (intentName == "HelloIntent") { // change 'HelloIntent' to your intent's name
        var message = {
            'contentType': 'PlainText', 
            'content': 'Hi! How can I help you?'
        }

        responseMsg = close( sessionAttributes, 'Fulfilled', message );
    }
    // else if (intentName == "Intent2") { 
    //      build another response for this intent
    // }
    else {
        console.log( "ERROR unhandled intent named= "+intentName );
        responseMsg = close( sessionAttributes, 'Fulfilled', {"contentType":"PlainText", "content":"Sorry, I can't help with that yet."});
    }

    console.log( "RESPONSE= "+JSON.stringify(responseMsg) );
    callback(null, responseMsg);
}

这篇关于Amazon Lex Bot-回复你好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 12:48