Я хочу сохранить разговор lex в динамоде через функцию лямбда, но я не могу сохранить данные в динамоде. Есть следующий шаг для создания разговорного бота lex. 1. создать чат-бота с намерением 2. создать лямбда-функцию для лямбда-ответа в облаке
var dbhandler = require("./dbhandler");
exports.handler = async (event,context,callback) => {
console.log(JSON.stringify(event))
var intent = event.currentIntent.name;
dbhandler.putchatbotDetails(intent,function(err,data){
if(err){
context.fail(err);
}else{
var response = {
"sessionAttributes": {
"name": event.currentIntent.slots.name,
"phone": event.currentIntent.slots.phone,
"test": event.currentIntent.slots.test,
"email": event.currentIntent.slots.email,
"location": event.currentIntent.slots.location,
"college": event.currentIntent.slots.college,
"year": event.currentIntent.slots.year,
"time": event.currentIntent.slots.time,
},
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": data.Item.Data
},
}
};
callback(null,response);
}
});
};
создать файл dbhandler для хранения лексической речи в динамодабе
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
* the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
var AWS = require("aws-sdk");
AWS.config.update({
region: "us-east-1"
});
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "chatbotdata";
var putchatbotDetails = (intent ,callback)=>{
var params = {
TableName: table,
Key:{
"intent" : "current"
}
};
docClient.put(params, function(err, data) {
callback(err,data);
});
};
module.exports ={
putchatbotDetails
};