-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
137 lines (121 loc) · 5.13 KB
/
index.js
File metadata and controls
137 lines (121 loc) · 5.13 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = '';
const Recipes = require('./recipes.js');
const Show = require('./show.js');
const toTitleCase = require('to-title-case');
const BODY_TEMPLATE_3 = 'bodyTemplate3';
const LIST_TEMPLATE_1 = 'listTemplate1';
const languageStrings = {
'en': {
translation: {
SKILL_NAME: 'Recipe Helper',
WELCOME_MESSAGE: 'Welcome to %s. You can ask a question like, what is the recipe for %s? ... Now, what can I help you with?',
WELCOME_REPROMPT: 'If you need help, just say help me',
WELCOME_CARD_TITLE: '%s - Welcome!',
LIST_RECIPES_CARD: '%s - Recipes',
RECIPE_DIRECTIONS_CARD: '%s - Directions for %s',
RECIPE_INGREDIENTS_CARD: '%s - Ingredients for %s',
RECIPE_DESCRIPTION_CARD: '%s - %s',
DISPLAY_CARD_TITLE: '%s - Recipe for %s',
HELP_MESSAGE: '',
},
},
}
const handlers = {
'LaunchRequest': function() {
Recipes.getAllRecipeData(recipes => {
Recipes.getRandomRecipe(recipes, recipe => {
this.attributes.speechOutput = this.t('WELCOME_MESSAGE', this.t('SKILL_NAME'), recipe.title);
this.attributes.repromptSpeech = this.t('WELCOME_REPROMPT');
this.response.speak(this.attributes.speechOutput).listen(this.attributes.repromptSpeech);
this.response.cardRenderer(this.t('WELCOME_CARD_TITLE', this.t('SKILL_NAME')));
this.emit(':responseReady');
});
});
},
'ListRecipes': function() {
if (Show.supportsDisplay.call(this)) {
Recipes.getAllRecipeData(recipes => {
Show.renderTemplate.call(this, LIST_TEMPLATE_1, recipes);
});
} else {
Recipes.getAllRecipeData(recipes => {
var speechOutput = Recipes.listRecipes(recipes);
this.attributes.speechOutput = speechOutput;
this.response.speak(speechOutput);
this.response.cardRenderer(this.t('LIST_RECIPES_CARD', this.t('SKILL_NAME')));
this.emit(':responseReady');
});
}
},
'GetRecipeDetails': function() {
var spokenRecipeName = Recipes.getSpokenRecipe(this.event.request.intent.slots.recipe);
if (Show.supportsDisplay.call(this)) {
Recipes.getAllRecipeData(recipes => {
Recipes.matchRecipe(spokenRecipeName, recipes, recipe => {
Show.renderTemplate.call(this, BODY_TEMPLATE_3, recipe);
});
});
} else {
console.log('Need to implement!');
}
},
'GetRecipeDirections': function() {
var spokenRecipeName = Recipes.getSpokenRecipe(this.event.request.intent.slots.recipe);
Recipes.getAllRecipeData(recipes => {
Recipes.matchRecipe(spokenRecipeName, recipes, recipe => {
this.attributes.speechOutput = recipe.directions;
this.response.speak(recipe.directions);
this.response.cardRenderer(this.t('RECIPE_DIRECTIONS_CARD', this.t('SKILL_NAME'), toTitleCase(recipe.title)));
this.emit(':responseReady');
});
});
},
'GetRecipeIngredients': function() {
var spokenRecipeName = Recipes.getSpokenRecipe(this.event.request.intent.slots.recipe);
Recipes.getAllRecipeData(recipes => {
Recipes.matchRecipe(spokenRecipeName, recipes, recipe => {
var ingredients = Recipes.parseIngredients(recipe.ingredients);
this.attributes.speechOutput = ingredients;
this.response.speak(ingredients);
this.response.cardRenderer(this.t('RECIPE_INGREDIENTS_CARD', this.t('SKILL_NAME'), toTitleCase(recipe.title)));
this.emit(':responseReady');
});
});
},
'GetRecipeDescription': function() {
var spokenRecipeName = Recipes.getSpokenRecipe(this.event.request.intent.slots.recipe);
Recipes.getAllRecipeData(recipes => {
Recipes.matchRecipe(spokenRecipeName, recipes, recipe => {
this.attributes.speechOutput = recipe.caption;
this.response.speak(recipe.caption);
this.response.cardRenderer(this.t('RECIPE_DESCRIPTION_CARD', this.t('SKILL_NAME'), toTitleCase(recipe.title)));
this.emit(':responseReady');
});
});
},
'GetRecipeIngredientsForDifferentServings': function() {
var recipeName = getSpokenRecipe(this.event.request.intent.slots.recipe);
var servings = this.event.requests.intent.slots.servings;
},
'AMAZON.HelpIntent': function() {
},
'AMAZON.RepeatIntent': function() {
},
'AMAZON.StopIntent': function() {
},
'AMAZON.CancelIntent': function() {
},
'SessionEndedRequest': function() {
},
'Unhandled': function() {
},
};
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.appId = APP_ID;
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
}