text: // 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 love = require('./love.js');
  const msg = {
      WELCOME_MSG: 'Bienvenido a la Calculadora del Amor. Por favor, dime el nombre de dos personas para poder calcularle su compatibilidad en el amor.',
      REJECTED_MSG: 'No pasa nada. Por favor dime de nuevo el nombre de dos personas.',
      HELP_MSG: 'Solo tienes que decirme el nombre de dos personas a las que quieres comprobarle su compatibilidad en el amor.',
      GOODBYE_MSG: '¡Hasta luego!',
      REFLECTOR_MSG: 'Acabas de activar {{intent}}',
      ERROR_MSG: 'Lo siento, ha habido un problema. Por favor inténtalo otra vez.'
  };
  
  const LaunchRequestHandler = {
      canHandle(handlerInput) {
          return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
      },
      handle(handlerInput) {
          const speakOutput = msg.WELCOME_MSG;
          return handlerInput.responseBuilder
              .speak(speakOutput)
              .reprompt(speakOutput)
              .getResponse();
      }
  };
  const GetLoveIntentHandler = {
      canHandle(handlerInput) {
          return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
              && Alexa.getIntentName(handlerInput.requestEnvelope) === 'GetLoveIntent';
      },
      handle(handlerInput) {
          const { requestEnvelope } = handlerInput;
          const { intent } = requestEnvelope.request;
  
          let speakOutput = msg.REJECTED_MSG;
  
          console.log("AVER: " + speakOutput);
  
          if (intent.confirmationStatus === 'CONFIRMED') {
              const fName = Alexa.getSlotValue(requestEnvelope, 'fName');
              const sName = Alexa.getSlotValue(requestEnvelope, 'sName');
  
              var percentage = love.calculatePercentage(fName, sName);
  
              speakOutput = 'El porcentaje es del ' + percentage + "% ." + love.getResults(percentage);
          }
  
          return handlerInput.responseBuilder
              .speak(speakOutput)
              .reprompt(speakOutput)
              .getResponse();
      }
  };
  const HelpIntentHandler = {
      canHandle(handlerInput) {
          return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
              && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
      },
      handle(handlerInput) {
          const speakOutput = msg.HELP_MSG;
  
          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 = msg.GOODBYE_MSG;
          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 = msg.REFLECTOR_MSG;
  
          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 = msg.ERROR_MSG;
  
          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,
          GetLoveIntentHandler,
          HelpIntentHandler,
          CancelAndStopIntentHandler,
          SessionEndedRequestHandler,
          IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
      )
      .addErrorHandlers(
          ErrorHandler,
      )
      .lambda();
  