Created
July 28, 2018 04:55
-
-
Save okn3/8a88a329e931ec35790627c788100dcf to your computer and use it in GitHub Desktop.
alexa_template.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Alexa = require('ask-sdk-core'); | |
| // 立ち上げ時に呼ばれる | |
| const LaunchRequestHandler = { | |
| canHandle(handlerInput) { | |
| return handlerInput.requestEnvelope.request.type === 'LaunchRequest'; | |
| }, | |
| handle(handlerInput) { | |
| const speechText = 'ようこそ、アレクサスキルキットへ。こんにちは、と言ってみてください。'; | |
| return handlerInput.responseBuilder | |
| .speak(speechText) | |
| .reprompt(speechText) | |
| .withSimpleCard('Hello World', speechText) | |
| .getResponse(); | |
| } | |
| }; | |
| // skill起動時に呼ばれる | |
| const <****>IntentHandler = { | |
| canHandle(handlerInput) { | |
| return handlerInput.requestEnvelope.request.type === 'IntentRequest' | |
| && handlerInput.requestEnvelope.request.intent.name === '<****>Intent'; | |
| }, | |
| handle(handlerInput) { | |
| const speechText = 'こんにちはゴミの日のスキルです'; | |
| return handlerInput.responseBuilder | |
| .speak(speechText) | |
| .getResponse(); | |
| } | |
| }; | |
| // ヘルプ時に呼ばれる | |
| const HelpIntentHandler = { | |
| canHandle(handlerInput) { | |
| return handlerInput.requestEnvelope.request.type === 'IntentRequest' | |
| && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent'; | |
| }, | |
| handle(handlerInput) { | |
| const speechText = 'こんにちは。と言ってみてください。'; | |
| return handlerInput.responseBuilder | |
| .speak(speechText) | |
| .reprompt(speechText) | |
| .getResponse(); | |
| } | |
| }; | |
| // ストップ時に呼ばれる | |
| const CancelAndStopIntentHandler = { | |
| canHandle(handlerInput) { | |
| return handlerInput.requestEnvelope.request.type === 'IntentRequest' | |
| && (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent' | |
| || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent'); | |
| }, | |
| handle(handlerInput) { | |
| const speechText = 'さようなら'; | |
| return handlerInput.responseBuilder | |
| .speak(speechText) | |
| .getResponse(); | |
| } | |
| }; | |
| // 終了時に呼ばれる | |
| const SessionEndedRequestHandler = { | |
| canHandle(handlerInput) { | |
| return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest'; | |
| }, | |
| handle(handlerInput) { | |
| //クリーンアップロジックをここに追加しますe | |
| return handlerInput.responseBuilder.getResponse(); | |
| } | |
| }; | |
| //エラー時に呼ぼれる | |
| const ErrorHandler = { | |
| canHandle () { | |
| return true | |
| }, | |
| handle (handlerInput, error) { | |
| console.log(`Error handled: ${error.message}`) | |
| const message = "すみません、なんだかうまく行かないようです。もう一度お試しください。"; | |
| return handlerInput.responseBuilder | |
| .speak(message) | |
| .getResponse() | |
| } | |
| } | |
| exports.handler = Alexa.SkillBuilders.custom() | |
| .addRequestHandlers(LaunchRequestHandler, | |
| <****>IntentHandler, | |
| HelpIntentHandler, | |
| CancelAndStopIntentHandler, | |
| SessionEndedRequestHandler) | |
| .addErrorHandlers(ErrorHandler) | |
| .lambda(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment