-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
323 lines (305 loc) · 14.2 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// This sample demonstrates handling intents from an Alexa skill using the Alexa Skills Kit SDK (v2).
// Please visit https://alexa.design/cookbook for additional examples on implementing slots, dialog management,
// session persistence, api calls, and more.
const Alexa = require('ask-sdk-core');
const LaunchRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'Hello Welcome to the seven wonders. you can know about 7 wonders of the world. How can I help you?';
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
const IntroIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'IntroIntent';
},
handle(handlerInput) {
const data = require('./data/intro.json');
const template = require('./templates/intro.json');
const speakOutput = 'we have seven wonders in the world. It was a campaign started in 2000 to choose Wonders of the World from a selection of 200 existing monuments. The popularity poll was led by Canadian-Swiss Bernard Weber and organized by the New7Wonders Foundation based in Zurich, Switzerland, with winners announced on 7 July 2007 in Lisbon.';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('Wonders Of the World', speakOutput)
.getResponse();
}
};
const TajMahalIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'TajMahalIntent';
},
handle(handlerInput) {
const data = require('./data/TajMahal.json');
const template = require('./templates/TajMahal.json');
const speakOutput = 'The Taj Mahal is an ivory-white marble mausoleum on the south bank of the Yamuna river in the Indian city of Agra. In 2007, it was declared a winner of the New7Wonders of the World (2000–2007) initiative.';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('TAJ MAHAL', speakOutput)
.getResponse();
}
};
const ColosseumIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'ColosseumIntent';
},
handle(handlerInput) {
const data = require('./data/Colosseum.json');
const template = require('./templates/Colosseum.json');
const speakOutput = 'The Colosseum or Coliseum, also known as the Flavian Amphitheatre, is an oval amphitheatre in the centre of the city of Rome, Italy. Built of concrete and sand, it is the largest amphitheatre ever built. The Colosseum is situated just east of the Roman Forum.';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('COLOSSEUM', speakOutput)
.getResponse();
}
};
const PetraIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'PetraIntent';
},
handle(handlerInput) {
const data = require('./data/Petra.json');
const template = require('./templates/Petra.json');
const speakOutput = 'Petra, originally known to the Nabataeans as Raqmu, is a historical and archaeological city in southern Jordan. The city is famous for its rock-cut architecture and water conduit system. Another name for Petra is the Rose City due to the color of the stone out of which it is carved.';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('PETRA', speakOutput)
.getResponse();
}
};
const MachuPicchuIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'MachuPicchuIntent';
},
handle(handlerInput) {
const data = require('./data/MachuPicchu.json');
const template = require('./templates/MachuPicchu.json');
const speakOutput = 'Machu Picchu, is a 15th-century Inca citadel situated on a mountain ridge 2,430 metres (7,970 ft) above sea level. It is located in the Cusco Region, Urubamba Province, Machupicchu District in Peru, above the Sacred Valley, which is 80 kilometres (50 mi) northwest of Cuzco and through which the Urubamba River flows.';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('MACHU PICCHU', speakOutput)
.getResponse();
}
};
const ChristtheRedeemerIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'ChristtheRedeemerIntent';
},
handle(handlerInput) {
const data = require('./data/ChristtheRedeemer.json');
const template = require('./templates/ChristtheRedeemer.json');
const speakOutput = 'Christ the Redeemer, is an Art Deco statue of Jesus Christ in Rio de Janeiro, Brazil, created by Polish-French sculptor Paul Landowski and built by the Brazilian engineer Heitor da Silva Costa, in collaboration with the French engineer Albert Caquot. ';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('Christ the Redeemer', speakOutput)
.getResponse();
}
};
const ElCastilloIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'ElCastilloIntent';
},
handle(handlerInput) {
const data = require('./data/ElCastillo.json');
const template = require('./templates/ElCastillo.json');
const speakOutput = 'El Castillo, also known as the Temple of Kukulcan, is a Mesoamerican step-pyramid that dominates the center of the Chichen Itza archaeological site in the Mexican state of Yucatán. ';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('El Castillo', speakOutput)
.getResponse();
}
};
const GreatWallofChinaIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GreatWallofChinaIntent';
},
handle(handlerInput) {
const data = require('./data/GreatWallofChina.json');
const template = require('./templates/GreatWallofChina.json');
const speakOutput = 'The Great Wall of China is a series of fortifications made of stone, brick, tamped earth, wood, and other materials, generally built along an east-to-west line across the historical northern borders of China to protect the Chinese states and empires against the raids and invasions of the various nomadic groups of the Eurasian Steppe.';
if (supportsAPL(handlerInput)) {
handlerInput.responseBuilder
.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
version: '1.0',
document: template,
datasources: data
})
}
return handlerInput.responseBuilder
.speak(speakOutput)
.withSimpleCard('The Great Wall of China', speakOutput)
.getResponse();
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speakOutput = 'Here you will get to know about the seven wonders of the world. You can say the name of any of the 7 wonders of the world. For example you can say, great wall of china';
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 SessionEndedRequestHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'SessionEndedRequest';
},
handle(handlerInput) {
// Any cleanup logic goes here.
return handlerInput.responseBuilder.getResponse();
}
};
// The intent reflector is used for interaction model testing and debugging.
// It will simply repeat the intent the user said. You can create custom handlers
// for your intents by defining them above, then also adding them to the request
// handler chain below.
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)
//.reprompt('add a reprompt if you want to keep the session open for the user to respond')
.getResponse();
}
};
// Generic error handling to capture any syntax or routing errors. If you receive an error
// stating the request handler chain is not found, you have not implemented a handler for
// the intent being invoked or included it in the skill builder below.
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`~~~~ Error handled: ${error.stack}`);
const speakOutput = `Sorry, I had trouble doing what you asked. Please try again.`;
return handlerInput.responseBuilder
.speak(speakOutput)
.reprompt(speakOutput)
.getResponse();
}
};
function supportsAPL(handlerInput) {
const supportedInterfaces =
handlerInput.requestEnvelope.context.System.device.supportedInterfaces;
const aplInterface = supportedInterfaces['Alexa.Presentation.APL'];
return aplInterface != null && aplInterface != undefined;
}
// The SkillBuilder acts as the entry point for your skill, routing all request and response
// payloads to the handlers above. Make sure any new handlers or interceptors you've
// defined are included below. The order matters - they're processed top to bottom.
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
IntroIntentHandler,
TajMahalIntentHandler,
ColosseumIntentHandler,
PetraIntentHandler,
MachuPicchuIntentHandler,
ChristtheRedeemerIntentHandler,
ElCastilloIntentHandler,
GreatWallofChinaIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler, // make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
)
.addErrorHandlers(
ErrorHandler,
)
.lambda();