NodeJSでAWSラムダ関数を使用してAlexaスキルを作成しています。NodeJSのコールバック関数をオブジェクトに変換する
"errorMessage": "Exception: TypeError: object is not a function"
まず、私のアプリは、イベントを取得します。
アプリは、私はテントを呼び出すときにエラーを投げています。それは意図だ場合は、それを呼び出します:
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()
にコールバックを渡し見ることができます。どのインテントであるかをチェックします。 function
として、コールバックを通過し、ここで示しConsole.logging:
function onIntent(intentRequest, session, callback) {
if ("ItemIntent" === intentName) {
console.log(callback); // This is a function
getOrderResponse(intent, session, callback);
しかし、getOrderResponse()
でcallback
の種類は何とかオブジェクトに変身しますか?これは私がそのエラーを取得している理由ですが、私はそれが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));
}
でなければなりません。 'callback'を最初の引数として渡すべきです、' getOrderResponse'が3つのパラメータを受け入れる必要があります。 –