Aws lambda Alexa.getRequestType不是AWS lambda Alexa skills中的函数

Aws lambda Alexa.getRequestType不是AWS lambda Alexa skills中的函数,aws-lambda,alexa-skills-kit,Aws Lambda,Alexa Skills Kit,我对Alexa Skills非常陌生,刚刚完成了Alexa skill交互模型和AWS上Lambda函数的连接 我在AWS lambda开发者控制台上设置了一个简单的node.js程序,并正在AWS控制台上使用其测试功能对其进行测试。但我不明白为什么这会给我一个错误。另外,我从示例repo-serverlessrepo-alexa-skil-alexaskillskitnodejsfact创建了这个项目 看起来没有定义Alexa.getRequestType。在这个过程中我有什么遗漏吗 谢谢 我

我对Alexa Skills非常陌生,刚刚完成了Alexa skill交互模型和AWS上Lambda函数的连接

我在AWS lambda开发者控制台上设置了一个简单的node.js程序,并正在AWS控制台上使用其测试功能对其进行测试。但我不明白为什么这会给我一个错误。另外,我从示例repo-serverlessrepo-alexa-skil-alexaskillskitnodejsfact创建了这个项目

看起来没有定义Alexa.getRequestType。在这个过程中我有什么遗漏吗


谢谢

我查看了代码,似乎您包含了
ask-sdk
包,而不是
ask-sdk-core

还要确保您使用的是这两个软件包的最新版本。下面是来自Hello World存储库的示例。您也可以使用


除此之外,我在NodeJS事实技能中使用了无服务器包,它没有使用
Alexa.getRequestType(handlerInput.requestEnvelope)
,而是像
handlerInput.requestEnvelope.request.type
那样处理请求。您能确认您使用的是哪种无服务器资源吗?

谢谢您指出无服务器软件包问题。就这样!我从Alexa开发者控制台复制了我的node.js代码,结果发现这个包在这里不起作用。
Response:
{
  "version": "1.0",
  "response": {
    "outputSpeech": {
      "type": "SSML",
      "ssml": "<speak>Sorry, I had trouble doing what you asked. Please try again.</speak>"
    },
    "reprompt": {
      "outputSpeech": {
        "type": "SSML",
        "ssml": "<speak>Sorry, I had trouble doing what you asked. Please try again.</speak>"
      }
    },
    "shouldEndSession": false
  },
  "userAgent": "ask-node/2.0.0 Node/v8.10.0",
  "sessionAttributes": {}
}

Request ID:
"18b2bd6c-a4c1-4934-bcc8-a78fa2bb3ab1"

Function Logs:
START RequestId: 18b2bd6c-a4c1-4934-bcc8-a78fa2bb3ab1 Version: $LATEST
2019-10-22T20:44:11.141Z    18b2bd6c-a4c1-4934-bcc8-a78fa2bb3ab1    ~~~~ Error handled: TypeError: Alexa.getRequestType is not a function
    at Object.canHandle (/var/task/index.js:8:22)
    at DefaultRequestMapper.<anonymous> (/var/task/node_modules/ask-sdk-core/lib/dispatcher/request/mapper/DefaultRequestMapper.js:74:61)
    at step (/var/task/node_modules/ask-sdk-core/lib/dispatcher/request/mapper/DefaultRequestMapper.js:44:23)
    at Object.next (/var/task/node_modules/ask-sdk-core/lib/dispatcher/request/mapper/DefaultRequestMapper.js:25:53)
    at /var/task/node_modules/ask-sdk-core/lib/dispatcher/request/mapper/DefaultRequestMapper.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (/var/task/node_modules/ask-sdk-core/lib/dispatcher/request/mapper/DefaultRequestMapper.js:15:12)
    at DefaultRequestMapper.getRequestHandlerChain (/var/task/node_modules/ask-sdk-core/lib/dispatcher/request/mapper/DefaultRequestMapper.js:63:16)
    at DefaultRequestDispatcher.<anonymous> (/var/task/node_modules/ask-sdk-core/lib/dispatcher/DefaultRequestDispatcher.js:104:60)
    at step (/var/task/node_modules/ask-sdk-core/lib/dispatcher/DefaultRequestDispatcher.js:44:23)
END RequestId: 18b2bd6c-a4c1-4934-bcc8-a78fa2bb3ab1
REPORT RequestId: 18b2bd6c-a4c1-4934-bcc8-a78fa2bb3ab1  Duration: 376.64 ms Billed Duration: 400 ms Memory Size: 128 MB Max Memory Used: 73 MB  Init Duration: 209.77 ms
/* eslint-disable  no-console */

const Alexa = require('ask-sdk');

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    handle(handlerInput) {
        const speakOutput = 'Hello! Welcome to Happy Expresso. Which Expresso type are you in the mood for?';
        const repromptText = 'I like Latte. What do you prefer?';    
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(repromptText)
            .getResponse();
    }
};

const CaptureCoffeeIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'CaptureCoffeeIntent';
    },
    handle(handlerInput) {
        const coffee = handlerInput.requestEnvelope.request.intent.slots.coffee.value;

        const speakOutput = `Thanks, I'll find a cafe nearby that has the best ${coffee}!`;
        return handlerInput.responseBuilder
            .speak(speakOutput)
            //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
            .getResponse();
    }
};
const HelpIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
    },
    handle(handlerInput) {
        const speakOutput = 'You can say hello to me! How can I help?';

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};
const CancelAndStopIntentHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
            && (Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.CancelIntent'
                || Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.StopIntent');
    },
    handle(handlerInput) {
        const speakOutput = 'Goodbye!';
        return handlerInput.responseBuilder
            .speak(speakOutput)
            .getResponse();
    }
};
const SessionEndedRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
    },
    handle(handlerInput) {
        // Any cleanup logic goes here.
        return handlerInput.responseBuilder.getResponse();
    }
};

// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
const IntentReflectorHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest';
    },
    handle(handlerInput) {
        const intentName = Alexa.getIntentName(handlerInput.requestEnvelope);
        const speakOutput = `You just triggered ${intentName}`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            //.reprompt('add a reprompt if you want to keep the session open for the user to respond')
            .getResponse();
    }
};

// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
    canHandle() {
        return true;
    },
    handle(handlerInput, error) {
        console.log(`~~~~ Error handled: ${error.stack}`);
        const speakOutput = `Sorry, I had trouble doing what you asked. Please try again.`;

        return handlerInput.responseBuilder
            .speak(speakOutput)
            .reprompt(speakOutput)
            .getResponse();
    }
};

// The SkillBuilder acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
    .addRequestHandlers(
        LaunchRequestHandler,
        CaptureCoffeeIntentHandler,
        HelpIntentHandler,
        CancelAndStopIntentHandler,
        SessionEndedRequestHandler,
        IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
    )
    .addErrorHandlers(
        ErrorHandler,
    )
    .lambda();