我一直在努力学习如何为Amazon Echo制作技能。我成功地做出了一个超级简单的游戏,字面上只是回应你好。AWS Lambda'流程在完成请求之前退出'
对于第二次尝试,试图锁定我所学到的东西,我想要更冒险,并让Alexa从数组中提供随机GoT引用。一般来说,我对编码相当陌生,大多数人一直在从事网络工作。我试图通过不同的方式寻找相当长的一段时间,找不到任何有帮助的东西。
当在Lambda中测试时,我在Log Output中收到错误“在完成请求之前退出进程”,我也可以看到“Alexa没有在exports.handler上定义”,我一直对此持反对态度,真的希望有人能帮助。对不起,这个长windedness ..
下面是我的代码:
"use strict";
var alexa = require('alexa-sdk');
// QUOTES ARRAY
var quotes = [
'A mind needs books as a sword needs a whetstone, if it is to keep its edge',
'Never forget what you are, for surely the world will not',
'I wont be knitting by the fire while I have men fight for me'
];
// HANDLERS
var handlers = {
getThatQuote: function() {
var quoteIndex = Math.floor(Math.random() * quotes.length);
var randomQuote = quotes[quoteIndex];
return randomQuote;
},
LaunchRequest: function() {
this.emit(":tell", "Welcome to Game of Quotes");
},
QuoteGet: function() {
this.emit(":tell", "Here is your quote" + this.getThatQuote());
},
};
exports.handler = function (event, context) {
const alexa = Alexa.handler(event, context);
alexa.registerHandlers(handlers);
alexa.execute();
};
var alexa = require('alexa-sdk')与尝试使用Alexa SDK(通过Alexa.handler(event,context))的更高代码不兼容。使用相同的Alexa拼写。 – jarmod