NodeJS で AWS Lambda 関数を使用して Alexa スキルを作成しています。
Intent を呼び出すと、アプリがエラーをスローします。
"errorMessage": "Exception: TypeError: object is not a function"
まず、アプリがイベントを取得します。Intent の場合は、次を呼び出します。
exports.handler = function (event, context) {
try {
...
else if (event.request.type === "IntentRequest") {
onIntent(
event.request,
event.session,
function intent_callback(sessionAttributes, speechletResponse) {
context.succeed(buildResponse(sessionAttributes, speechletResponse));
}
);
上記が にコールバックを渡していることがわかりますonIntent()
。それがどのインテントかをチェックします。ここの Console.logging は、渡されたコールバックを次のように示しますfunction
。
function onIntent(intentRequest, session, callback) {
if ("ItemIntent" === intentName) {
console.log(callback); // This is a function
getOrderResponse(intent, session, callback);
しかし、 in の型がcallback
どういうgetOrderResponse()
わけかオブジェクトに変わるのでしょうか? これがエラーが発生する理由ですが、ここではタイプではないことがわかりませんfunction
。なぜオブジェクトなのですか?
function getOrderResponse(callback) {
console.log('getOrderResponse', callback); // type = Object: { name: 'ItemIntent', slots: { Item: { name: 'Item' } } }
var card_title = config.data().CARD_TITLE;
var sessionAttributes = {},
speechOutput = 'So you want quick order',
shouldEndSession = false,
repromptText = 'Hello';
sessionAttributes = {
'speechOutput': repromptText,
'repromptText': repromptText,
'questions': 'some questions'
};
callback(sessionAttributes, buildSpeechletResponse(card_title, speechOutput, repromptText, shouldEndSession));
}