-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.js
54 lines (47 loc) · 1.14 KB
/
handler.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
'use strict'
const assert = require('assert')
const answer = (title, message) => {
return {
"version": "1.0",
"response": {
"outputSpeech": {
"type": "PlainText",
"text": message
},
"card": {
"content": message,
"title": title,
"type": "Simple"
},
"shouldEndSession": true
},
"sessionAttributes": {}
}
}
module.exports.answer = (event, context, callback) => {
try {
assert(event.session)
assert(event.session.application)
assert(event.request)
assert(event.request.intent)
assert(event.request.intent.name.toLowerCase() === 'answer')
assert(event.request.intent.slots.item.value)
} catch (e) {
callback(null, answer(
"Invalid request",
"Sorry, but I cannot handle your request"
))
}
var item = event.request.intent.slots.item.value
if (item * 1 === 42) {
callback(null, answer(
"42",
"42 is the answer to the Ultimate Question of Life, the Universe, and Everything!"
))
} else {
callback(null, answer(
"Asked for " + item,
"I don't know anything about " + item
))
}
}