问题描述
使用AWS Lex
来创建ChatBot并使用AWS Lambda
中的Node.js
.
Working on AWS Lex
for creating a ChatBot and using the Node.js
in AWS Lambda
.
Lambda函数:
var aws = require('aws-sdk');
var ses = new aws.SES({region: 'us-east-1'});
exports.handler = function(event, context, callback) {
var eParams = {
Destination: {
ToAddresses: [event.currentIntent.slots.Email]
},
Message: {
Body: {
Text: {
Data: "Hi, How are you?"
}
},
Subject: {
Data: "Title"
}
},
Source: "abc@gmail.com"
};
var email = ses.sendEmail(eParams, function(err, data){
if(err)
else {
context.succeed(event);
}
});
};
如何在成功执行后如何从Lambda获得对Lex的正确响应(电子邮件服务正常工作).我已经尝试过context.done();
,但是没有成功.
How to get a proper response from Lambda to Lex after successful execution (Email Service works properly). I have tried context.done();
but it did not worked out.
尝试在 AWS LEX文档中添加以下响应测试仍然得到相同的错误响应.
Edit 1:Tried adding below response test from AWS Documentation for LEX still getting the same error response.
exports.handler = (event, context, callback) => {
callback(null, {
"dialogAction": {
"type": "ConfirmIntent",
"message": {
"contentType": "PlainText or SSML",
"content": "message to convey to the user, i.e. Are you sure you want a large pizza?"
}
}
});
推荐答案
如 lambda-input-response-format docs 此处 fulfillmentState
属性是响应中必需的.
As mentioned in the lambda-input-response-format docs here fulfillmentState
property is required in the response.
另一件事是您必须在响应中为contentType
传递PlainText
或SSML
.就您而言,它只是PlainText
.
Other thing is you have to pass either PlainText
OR SSML
for the contentType
in the response. In your case its just PlainText
.
exports.handler = (event, context, callback) => {
callback(null, {
"dialogAction": {
"type": "ConfirmIntent",
"fulfillmentState": "Fulfilled", // <-- Required
"message": {
"contentType": "PlainText",
"content": "message to convey to the user, i.e. Are you sure you want a large pizza?"
}
}
});
上面的代码应该可以解决您的问题.
The above code should solve your problem.
但是,如果您在网络标签中看到要求,您将收到HTTP错误424,其中显示 DependencyFailedException 表示 "Amazon Lex没有足够的权限来调用Lambda函数" 极具误导性.
However if you see the req-res in the network tab you would receive HTTP Error 424 which says DependencyFailedException which says "Amazon Lex does not have sufficient permissions to call a Lambda function" very misleading.
这篇关于AWS lambda函数-'发生错误:收到来自Lambda的错误响应:已处理'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!