mirror of
https://github.com/r-ca/kidshift-skills.git
synced 2024-10-26 01:24:03 +00:00
156 lines
6.4 KiB
JavaScript
156 lines
6.4 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const Alexa = __importStar(require("ask-sdk-core"));
|
|
const AWS = __importStar(require("aws-sdk"));
|
|
const DynamoDBPersistantAttributesAdapter = __importStar(require("ask-sdk-dynamodb-persistence-adapter"));
|
|
const LaunchRequestHandler = {
|
|
canHandle(handlerInput) {
|
|
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
|
|
},
|
|
handle(handlerInput) {
|
|
const speakOutput = 'Welcome, you can say Hello or Help. Which would you like to try?';
|
|
return handlerInput.responseBuilder
|
|
.speak(speakOutput)
|
|
.reprompt(speakOutput)
|
|
.getResponse();
|
|
}
|
|
};
|
|
const HelloWorldIntentHandler = {
|
|
canHandle(handlerInput) {
|
|
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
|
|
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'HelloWorldIntent';
|
|
},
|
|
async handle(handlerInput) {
|
|
const speakOutput = 'Hello World!';
|
|
return handlerInput.responseBuilder
|
|
.speak(speakOutput)
|
|
.getResponse();
|
|
}
|
|
};
|
|
const KidShiftAuthIntentHandler = {
|
|
canHandle(handlerInput) {
|
|
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
|
|
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'KidShiftAuthIntent';
|
|
},
|
|
handle(handlerInput) {
|
|
// if (Alexa.getSlot(handlerInput.requestEnvelope, 'loginCode').value === undefined) {
|
|
// return handlerInput.responseBuilder
|
|
// .speak('Please provide a valid login code')
|
|
// .reprompt('Please provide a valid login code')
|
|
// .getResponse();
|
|
// }
|
|
// return handlerInput.responseBuilder
|
|
// .speak('your auth code is ' + Alexa.getSlotValue(handlerInput.requestEnvelope, 'loginCode'))
|
|
// .getResponse();
|
|
return handlerInput.responseBuilder
|
|
.speak('hoge')
|
|
.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 FallbackIntentHandler = {
|
|
canHandle(handlerInput) {
|
|
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
|
|
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.FallbackIntent';
|
|
},
|
|
handle(handlerInput) {
|
|
const speakOutput = 'Sorry, I don\'t know about that. Please try again.';
|
|
return handlerInput.responseBuilder
|
|
.speak(speakOutput)
|
|
.reprompt(speakOutput)
|
|
.getResponse();
|
|
}
|
|
};
|
|
const SessionEndedRequestHandler = {
|
|
canHandle(handlerInput) {
|
|
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
|
|
},
|
|
handle(handlerInput) {
|
|
console.log(`~~~~ Session ended: ${JSON.stringify(handlerInput.requestEnvelope)}`);
|
|
return handlerInput.responseBuilder.getResponse();
|
|
}
|
|
};
|
|
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)
|
|
.getResponse();
|
|
}
|
|
};
|
|
const ErrorHandler = {
|
|
canHandle() {
|
|
return true;
|
|
},
|
|
handle(handlerInput, error) {
|
|
const speakOutput = 'Sorry, I had trouble doing what you asked. Please try again.';
|
|
console.log(`~~~~ Error handled: ${JSON.stringify(error)}`);
|
|
return handlerInput.responseBuilder
|
|
.speak(speakOutput)
|
|
.reprompt(speakOutput)
|
|
.getResponse();
|
|
}
|
|
};
|
|
exports.handler = Alexa.SkillBuilders.custom()
|
|
.addRequestHandlers(LaunchRequestHandler, HelloWorldIntentHandler, HelpIntentHandler, CancelAndStopIntentHandler, FallbackIntentHandler, SessionEndedRequestHandler, IntentReflectorHandler, KidShiftAuthIntentHandler)
|
|
.addErrorHandlers(ErrorHandler)
|
|
.withPersistenceAdapter(new DynamoDBPersistantAttributesAdapter.DynamoDbPersistenceAdapter({
|
|
tableName: process.env.DYNAMODB_PERSISTENCE_TABLE_NAME || 'ask-sdk-table',
|
|
createTable: false,
|
|
dynamoDBClient: new AWS.DynamoDB({ apiVersion: 'latest', region: process.env.DYNAMODB_PERSISTENCE_REGION })
|
|
}))
|
|
.withCustomUserAgent('sample/hello-world/v1.2')
|
|
.lambda();
|
|
//# sourceMappingURL=index.js.map
|