-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
116 lines (100 loc) · 4.64 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
/**
* This sample shows how to create a Lambda function for handling Alexa Skill requests that:
*
* - Custom slot type: demonstrates using custom slot types to handle a finite set of known values
*
* Examples:
* One-shot model:
* User: "Alexa, ask Minecraft Helper how to make paper."
* Alexa: "(reads back recipe for paper)"
*/
'use strict';
var AlexaSkill = require('./AlexaSkill'),
recipes = require('./recipes');
var APP_ID = 'amzn1.echo-sdk-ams.app.605ca609-9609-42a3-ace2-65d6628ef29e'; //replace with 'amzn1.echo-sdk-ams.app.[your-unique-value-here]';
/**
* MinecraftHelper is a child of AlexaSkill.
* To read more about inheritance in JavaScript, see the link below.
*
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript#Inheritance
*/
var MinecraftHelper = function () {
AlexaSkill.call(this, APP_ID);
};
// Extend AlexaSkill
MinecraftHelper.prototype = Object.create(AlexaSkill.prototype);
MinecraftHelper.prototype.constructor = MinecraftHelper;
MinecraftHelper.prototype.eventHandlers.onLaunch = function (launchRequest, session, response) {
var speechText = "Welcome to How To Destiny. You can ask a question like, how do I get to the lighthouse? ... Now, what can I help you with.";
// If the user either does not reply to the welcome message or says something that is not
// understood, they will be prompted again with this text.
var repromptText = "For instructions on what you can say, please say help me.";
response.ask(speechText, repromptText);
};
MinecraftHelper.prototype.intentHandlers = {
"RecipeIntent": function (intent, session, response) {
var itemSlot = intent.slots.Item,
itemName;
if (itemSlot && itemSlot.value){
itemName = itemSlot.value.toLowerCase();
}
var cardTitle = "Recipe for " + itemName,
recipe = recipes[itemName],
speechOutput,
repromptOutput;
if (recipe) {
speechOutput = {
speech: recipe,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
response.tellWithCard(speechOutput, cardTitle, recipe);
} else {
var speech;
if (itemName) {
speech = "I'm sorry, I currently do not know the recipe for " + itemName + ". What else can I help with?";
} else {
speech = "I'm sorry, I currently do not know that recipe. What else can I help with?";
}
speechOutput = {
speech: speech,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
repromptOutput = {
speech: "What else can I help with?",
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
response.ask(speechOutput, repromptOutput);
}
},
"AMAZON.StopIntent": function (intent, session, response) {
var speechOutput = "Thanks for learning How To Destiny. Let us help you how to next time.";
response.tell(speechOutput);
},
"AMAZON.CancelIntent": function (intent, session, response) {
var speechOutput = "Thanks for learning How To Destiny. Let us help you how to next time.";
response.tell(speechOutput);
},
"AMAZON.HelpIntent": function (intent, session, response) {
var speechText = "You can ask questions about destiny such as, where can I find some spinmetal? or, you can say exit... Now, what can I help you with?";
var repromptText = "You can say things like, where can I find some spinmetal?, or you can say exit... Now, what can I help you with?";
var speechOutput = {
speech: speechText,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
var repromptOutput = {
speech: repromptText,
type: AlexaSkill.speechOutputType.PLAIN_TEXT
};
response.ask(speechOutput, repromptOutput);
}
};
exports.handler = function (event, context) {
var minecraftHelper = new MinecraftHelper();
minecraftHelper.execute(event, context);
};