我正在创建一个计数器,用于计算alexa技能调用CFFI请求的时间。我通过读取和更新处理CFFI的句柄内的s3中的文件来执行此操作。仅CFFI可以正常工作。带有读取文件代码的CFFI可以正常工作。带有写入文件代码的CFFI会写入文件,但返回空调用响应。
我尝试了异步等待承诺。我增加了分配给函数的内存。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="aux-class green">DIV 1</div>
<div class="aux-class green">DIV 2</div>
<button id="click">Click Me</button>
我希望调用响应中的代码中显示json输出,但是我得到null。
预期产量
canHandle(handlerInput) {
return (handlerInput.requestEnvelope.request.type === 'CanFulfillIntentRequest'
&& (
handlerInput.requestEnvelope.request.intent.name === 'ProductIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'WhichToothpasteIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'WhiteTeethIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'ToothbrushIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'BrushingTimeIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'BrushingWayIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'DentistVisitIntent' ||
handlerInput.requestEnvelope.request.intent.name === 'ElectricToothbrushIntent'
));
},
async handle(handlerInput) {
var s3 = new AWS.S3();
var params = { Bucket: "toothpaste-counter", Key: "calls.json" };
var datum;
var datum2={
"name": "CFFI5",
"calls": 5
};
///*JSON.parse(
await s3.getObject(params, function (err, data) {
if (!err)
datum = JSON.parse(data.Body.toString());
else
datum = err;
//context.succeed();
}).promise();
datum.calls++;
var params2 = { Bucket: "toothpaste-counter", Key: "calls.json", Body: Buffer.from(JSON.stringify(datum)) };
await s3.putObject(params2, function (err, data) {
if (!err)
datum = JSON.parse(data.Body.toString());
else
datum = err;
//context.succeed();
}).promise();
return handlerInput.responseBuilder
.withCanFulfillIntent(
{
"canFulfill": "YES",
"slots":{
"voiceExpert": {
"canUnderstand": "YES",
"canFulfill": "YES"
}
}
})
.getResponse();
},
};
我得到的输出
"body": {
"version": "1.0",
"response": {
"canFulfillIntent": {
"canFulfill": "YES",
"slots": {
"voiceExpert": {
"canUnderstand": "YES",
"canFulfill": "YES"
}
}
}
},
"userAgent": "ask-node/2.5.2 Node/v8.10.0",
"sessionAttributes": {}
}
},