question

newuser-2eef1a59-d220-426b-a16b-5337be0a1d2f avatar image

Skill won't close the session after fulfilling a request?

Here is my index.js

// This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2).

// Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,

// session persistence, api calls, and more.

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


const LaunchRequestHandler = {

canHandle(handlerInput) {

return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';

},

handle(handlerInput) {

const speakOutput = 'Welcome, this is an interactive Alan Turing skill. You can start a conversation or ask for help.';

return handlerInput.responseBuilder

.speak(speakOutput)

.reprompt(speakOutput)

.getResponse();

}

};

const theimitationgameIntentHandler = {

canHandle(handlerInput) {

return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'

&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'theimitationgameIntent';

},

handle(handlerInput) {

const speakOutput = 'Would you like to ask another question?';

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 = 'To start a conversation, you can ask questions like can machines think, what is your legacy, or what is the imitation game?';


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, thank you for playing The Imitation Game!';

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,

theimitationgameIntentHandler,

HelpIntentHandler,

CancelAndStopIntentHandler,

SessionEndedRequestHandler,

IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers

)

.addErrorHandlers(

ErrorHandler,

)

.lambda();



Here is my package.json


{

"name": "the-imitation-game",

"version": "1.1.0",

"description": "alexa utility for quickly building skills",

"main": "index.js",

"scripts": {

"test": "echo \"Error: no test specified\" && exit 1"

},

"author": "Amazon Alexa",

"license": "ISC",

"dependencies": {

"ask-sdk-core": "^2.6.0",

"ask-sdk-model": "^1.18.0",

"aws-sdk": "^2.326.0"

}

}

skillcertificationdeveloper account
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers