我最近开始开发 alexa 技能(使用 SMAPI 和 ASK SDK)并在后端 Firebase 上使用 nodejs。我将我的代码部署在 Cloud Functions 上,并将我的函数 uri 放在技能清单文件中的端点上。启动技能时遇到问题。
`const AlexaASK = require('ask-sdk-core');
const LaunchRequestHandler = {
canHandle(handlerInput) {
return AlexaASK.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = "launch request message";
const repromptOutput = "reprompt message";
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(repromptOutput)
.getResponse();
},
};
const ExitHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === `IntentRequest` && (
request.intent.name === 'AMAZON.StopIntent' ||
request.intent.name === 'AMAZON.PauseIntent' ||
request.intent.name === 'AMAZON.CancelIntent'
);
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak(exitSkillMessage)
.getResponse();
},
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
//console.log(`Session ended with reason: ${JSON.stringify(handlerInput.requestEnvelope)}`);
return handlerInput.responseBuilder.getResponse();
},
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak("error")
.reprompt("error hanlder")
.getResponse();
},
};
exports.alexaskill = functions.https.onRequest((req, response) => {
const skillBuilder = AlexaASK.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
ExitHandler,
SessionEndedRequestHandler
)
.addErrorHandlers(ErrorHandler)
.create();
response.send()
});`