Alexa.getRequestType не является функцией в навыках AWS lambda alexa - PullRequest
0 голосов
/ 22 октября 2019

Я очень новичок в Alexa Skills и только что завершил соединение модели взаимодействия с навыком Alexa и функции Lambda в AWS.

Я установил простую программу node.js на консоли разработчика AWS lambda, и яЯ тестирую его на консоли AWS, используя функцию тестирования. Но я не могу понять, почему это дает мне ошибку. Кроме того, я создал этот проект из примера репо - serverlessrepo-alexa-skil-alexaskillskitnodejsfact

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();

Похоже, что Alexa.getRequestType не определен. Что-то мне не хватает в этом процессе?

Спасибо!

1 Ответ

0 голосов
/ 23 октября 2019

Я посмотрел код, и кажется, что вы включаете пакет ask-sdk вместо ask-sdk-core.

Также убедитесь, что вы используете последние версии обоих пакетов. Вот файл package.json из репозитория Sample Hello World. Вы можете использовать кодовую базу здесь , а также

Кроме того, я использовал пакет Serverless для навыка факта NodeJS, и он не использует Alexa.getRequestType(handlerInput.requestEnvelope), а вместо этого обрабатывает запрос какhandlerInput.requestEnvelope.request.type. Можете ли вы подтвердить, какой серверный ресурс вы использовали?

...