0

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));
}
4

1 に答える 1

2

コールバックは 3 番目のパラメーターである必要があります。

getOrderResponse(intent, session, callback);送信する最初のパラメーターはintentオブジェクトです。

function getOrderResponse(callback) {

する必要があります

function getOrderResponse(intent, session, callback) {

于 2016-04-11T22:49:59.690 に答える