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(). 它检查它是哪个 Intent。此处的 Console.logging 将传递的回调显示为function

function onIntent(intentRequest, session, callback) {

    if ("ItemIntent" === intentName) {
        console.log(callback); // This is a function

        getOrderResponse(intent, session, callback);

然而,callbackin的类型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

回调必须是第三个参数。

getOrderResponse(intent, session, callback);您发送的第一个参数是intent对象。

function getOrderResponse(callback) {

应该

function getOrderResponse(intent, session, callback) {

于 2016-04-11T22:49:59.690 回答