对不起,我的英语。我需要一种alexa技能,可以读取txt文件的内容。我认为最好的解决方案是将文件保存在S3上,但是我找不到任何有关如何访问文件并让Alexa读取文件的指南。 我现在正在尝试各种方式,这是我的代码。
const ReadStoryIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'CaptureNameIntent';
},
async handle(handlerInput) {
let speakOut;
let option = {
"Bucket" : "storytellingbucket",
"Key" : "data/testo.txt"
}
await toGetS3(option).
then((response)=>{
console.log(response),
console.log(response.Body.toString()),
speakOut = response
}).catch ((err) => {
console.log(err)
speakOut='there is an error'
})
return handlerInput.responseBuilder
.speak(speakOut)
.getResponse();
}
}
和功能
const toGetS3 = function (options) {
return new Promise((resolve, reject) => {
s3.getObject(options, function (err, data) {
//handle error
if (err) {
reject("Error", err);
}
//success
if (data) {
resolve(data.Body.toString())
}
})
}) }
该代码不起作用。我好几天都找不到解决办法了。
答案 0 :(得分:0)
如果您使用的是Alexa托管技能,则只需将故事放入代码结构中,为此创建文件夹/文件,并使用fs进行读取。
或者您可以创建另一个js文件,该文件导出故事文本并将其导入您的主文件/意图处理程序