这是我们为处理答案所做的,存储在 DynamoDB 中:
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
exports.handler = async (event) => {
// TODO implement
console.log(JSON.stringify(event));
var pinpointResponse = JSON.parse(event.Records[0].Sns.Message);
var phoneNumber = pinpointResponse.originationNumber.substring(2);
var message = pinpointResponse.messageBody;
console.log("phoneNumber", phoneNumber);
console.log("message", message);
//Insert into DynamoDB
var InsertParams = {
TableName : "ChatHistory",
Item : {
"phoneNumber" : phoneNumber + "",
"Answer" : message
}
};
var AWSNew = require('aws-sdk');
AWSNew.config.update({region: 'us-east-2'});
var docClient = new AWSNew.DynamoDB.DocumentClient();
await docClient.put(InsertParams).promise();
const response = {
statusCode: 200,
body: JSON.stringify('SUCCESS'),
};
return response;
};