2017-10-12 47 views
0

我一直在努力學習如何爲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(); 
}; 
+0

var alexa = require('alexa-sdk')與嘗試使用Alexa SDK(通過Alexa.handler(event,context))的更高代碼不兼容。使用相同的Alexa拼寫。 – jarmod

回答

2

變化

var alexa = require('alexa-sdk');

var Alexa = require('alexa-sdk');

而且這種變化之前,正在覆蓋低層ase alexa變量。我會建議使用你的javascript代碼的linter,因爲這會在使用前遇到像使用未定義變量的問題。

+0

老實說,非常感謝你,我真的應該抓住那個,你有我的不朽的感激!也感謝頂部! –

+0

np!很高興它解決了 – jontro

相關問題