-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
137 lines (127 loc) · 6.56 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* eslint-disable func-names */
/* eslint quote-props: ["error", "consistent"]*/
/**
* This sample demonstrates a sample skill built with Amazon Alexa Skills nodejs
* skill development kit.
* This sample supports multiple languages (en-US, en-GB, de-GB).
* The Intent Schema, Custom Slot and Sample Utterances for this skill, as well
* as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-howto
**/
'use strict';
const Alexa = require('alexa-sdk');
const recipes = require('./recipes');
const APP_ID = undefined;
const handlers = {
'NewSession': function () {
this.attributes.speechOutput = this.t('WELCOME_MESSAGE', this.t('SKILL_NAME'));
// 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.
this.attributes.repromptSpeech = this.t('WELCOME_REPROMT');
this.emit(':ask', this.attributes.speechOutput, this.attributes.repromptSpeech);
},
'RecipeIntent': function () {
const itemSlot = this.event.request.intent.slots.Item;
let itemName;
if (itemSlot && itemSlot.value) {
itemName = itemSlot.value.toLowerCase();
}
const cardTitle = this.t('DISPLAY_CARD_TITLE', this.t('SKILL_NAME'), itemName);
const myRecipes = this.t('RECIPES');
const recipe = myRecipes[itemName];
if (recipe) {
this.attributes.speechOutput = recipe;
this.attributes.repromptSpeech = this.t('RECIPE_REPEAT_MESSAGE');
this.emit(':askWithCard', recipe, this.attributes.repromptSpeech, cardTitle, recipe);
} else {
let speechOutput = this.t('RECIPE_NOT_FOUND_MESSAGE');
const repromptSpeech = this.t('RECIPE_NOT_FOUND_REPROMPT');
if (itemName) {
speechOutput += this.t('RECIPE_NOT_FOUND_WITH_ITEM_NAME', itemName);
} else {
speechOutput += this.t('RECIPE_NOT_FOUND_WITHOUT_ITEM_NAME');
}
speechOutput += repromptSpeech;
this.attributes.speechOutput = speechOutput;
this.attributes.repromptSpeech = repromptSpeech;
this.emit(':ask', speechOutput, repromptSpeech);
}
},
'AMAZON.HelpIntent': function () {
this.attributes.speechOutput = this.t('HELP_MESSAGE');
this.attributes.repromptSpeech = this.t('HELP_REPROMT');
this.emit(':ask', this.attributes.speechOutput, this.attributes.repromptSpeech);
},
'AMAZON.RepeatIntent': function () {
this.emit(':ask', this.attributes.speechOutput, this.attributes.repromptSpeech);
},
'AMAZON.StopIntent': function () {
this.emit('SessionEndedRequest');
},
'AMAZON.CancelIntent': function () {
this.emit('SessionEndedRequest');
},
'SessionEndedRequest': function () {
this.emit(':tell', this.t('STOP_MESSAGE'));
},
};
const languageStrings = {
'en-GB': {
translation: {
RECIPES: recipes.RECIPE_EN_GB,
SKILL_NAME: 'British Warcraft Helper',
WELCOME_MESSAGE: "Welcome to %s. You can ask a question like, what\'s the recipe for a pumpkin pie? ... Now, what can I help you with.",
WELCOME_REPROMT: 'For instructions on what you can say, please say help me.',
DISPLAY_CARD_TITLE: '%s - Recipe for %s.',
HELP_MESSAGE: "You can ask questions such as, what\'s the recipe, or, you can say exit...Now, what can I help you with?",
HELP_REPROMT: "You can say things like, what\'s the recipe, or you can say exit...Now, what can I help you with?",
STOP_MESSAGE: 'Goodbye!',
RECIPE_REPEAT_MESSAGE: 'Try saying repeat.',
RECIPE_NOT_FOUND_MESSAGE: "I\'m sorry, I currently do not know ",
RECIPE_NOT_FOUND_WITH_ITEM_NAME: 'the recipe for %s. ',
RECIPE_NOT_FOUND_WITHOUT_ITEM_NAME: 'that recipe. ',
RECIPE_NOT_FOUND_REPROMPT: 'What else can I help with?',
},
},
'en-US': {
translation: {
RECIPES: recipes.RECIPE_EN_US,
SKILL_NAME: 'American Minecraft Helper',
WELCOME_MESSAGE: "Welcome to %s. You can ask a question like, what\'s the recipe for a chest? ... Now, what can I help you with.",
WELCOME_REPROMT: 'For instructions on what you can say, please say help me.',
DISPLAY_CARD_TITLE: '%s - Recipe for %s.',
HELP_MESSAGE: "You can ask questions such as, what\'s the recipe, or, you can say exit...Now, what can I help you with?",
HELP_REPROMT: "You can say things like, what\'s the recipe, or you can say exit...Now, what can I help you with?",
STOP_MESSAGE: 'Goodbye!',
RECIPE_REPEAT_MESSAGE: 'Try saying repeat.',
RECIPE_NOT_FOUND_MESSAGE: "I\'m sorry, I currently do not know ",
RECIPE_NOT_FOUND_WITH_ITEM_NAME: 'the recipe for %s. ',
RECIPE_NOT_FOUND_WITHOUT_ITEM_NAME: 'that recipe. ',
RECIPE_NOT_FOUND_REPROMPT: 'What else can I help with?',
},
},
'de-DE': {
translation: {
RECIPES: recipes.RECIPE_DE_DE,
SKILL_NAME: 'Assistent für Minecraft in Deutsch',
WELCOME_MESSAGE: 'Willkommen bei %s. Du kannst beispielsweise die Frage stellen: Welche Rezepte gibt es für eine Truhe? ... Nun, womit kann ich dir helfen?',
WELCOME_REPROMT: 'Wenn du wissen möchtest, was du sagen kannst, sag einfach „Hilf mir“.',
DISPLAY_CARD_TITLE: '%s - Rezept für %s.',
HELP_MESSAGE: 'Du kannst beispielsweise Fragen stellen wie „Wie geht das Rezept für“ oder du kannst „Beenden“ sagen ... Wie kann ich dir helfen?',
HELP_REPROMT: 'Du kannst beispielsweise Sachen sagen wie „Wie geht das Rezept für“ oder du kannst „Beenden“ sagen ... Wie kann ich dir helfen?',
STOP_MESSAGE: 'Auf Wiedersehen!',
RECIPE_REPEAT_MESSAGE: 'Sage einfach „Wiederholen“.',
RECIPE_NOT_FOUND_MESSAGE: 'Tut mir leid, ich kenne derzeit ',
RECIPE_NOT_FOUND_WITH_ITEM_NAME: 'das Rezept für %s nicht. ',
RECIPE_NOT_FOUND_WITHOUT_ITEM_NAME: 'dieses Rezept nicht. ',
RECIPE_NOT_FOUND_REPROMPT: 'Womit kann ich dir sonst helfen?',
},
},
};
exports.handler = (event, context) => {
const alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
// To enable string internationalization (i18n) features, set a resources object.
alexa.resources = languageStrings;
alexa.registerHandlers(handlers);
alexa.execute();
};