// ---- Standard-Handler (Pflicht für jeden Alexa Skill) ---- const Alexa = require('ask-sdk-core'); const LaunchRequestHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest'; }, handle(handlerInput) { const speakOutput = 'Willkommen beim Hausassistent. Du kannst mich zum Beispiel fragen, wie warm es in einem Raum ist.'; 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 = 'Du kannst mich zum Beispiel fragen: wie warm ist es im Wohnzimmer.'; 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 = 'Bis bald!'; return handlerInput.responseBuilder.speak(speakOutput).getResponse(); }, }; const FallbackIntentHandler = { canHandle(handlerInput) { return ( Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest' && Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.FallbackIntent' ); }, handle(handlerInput) { const speakOutput = 'Das habe ich nicht verstanden. Du kannst mich zum Beispiel fragen, wie warm es im Wohnzimmer ist.'; return handlerInput.responseBuilder.speak(speakOutput).reprompt(speakOutput).getResponse(); }, }; const SessionEndedRequestHandler = { canHandle(handlerInput) { return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest'; }, handle(handlerInput) { return handlerInput.responseBuilder.getResponse(); }, }; const ErrorHandler = { canHandle() { return true; }, handle(handlerInput, error) { console.error(`~~~~ Error handled: ${error.stack}`); const speakOutput = 'Entschuldigung, da ist etwas schiefgelaufen. Bitte versuch es noch einmal.'; return handlerInput.responseBuilder.speak(speakOutput).reprompt(speakOutput).getResponse(); }, }; module.exports = { LaunchRequestHandler, HelpIntentHandler, CancelAndStopIntentHandler, FallbackIntentHandler, SessionEndedRequestHandler, ErrorHandler, };