-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
28 lines (25 loc) · 805 Bytes
/
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
exports.handler = async (event) => {
const queryResult = event.body.queryResult || JSON.parse(event.body).queryResult
if(!queryResult) { return }
const result = await getHandler(queryResult.intent.displayName).handle(queryResult)
const response = {
statusCode: 200,
body: JSON.stringify(result)
}
return response
};
function getHandler(intentName) {
try {
return require(`./routes/FulfillmentWebHook/intents/${intentName.substring(0, intentName.indexOf('-') > 0 ? intentName.indexOf('-') : intentName.length).trim()}`)
} catch (error) {
console.log(error)
return {
handle: defaultHandler
}
}
}
function defaultHandler() {
return {
"fulfillmentText": "Sorry can't process your request."
}
}