-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlex-validation.js
107 lines (85 loc) · 3.29 KB
/
lex-validation.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
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
let cuisines = ['chinese', 'italian', 'japanese','mexican', 'tradamerican'];
let nextslot = "cuisine";
let response = {
"dialogAction": {
"type": "Delegate",
"slots": event.currentIntent.slots,
}
};
if (event.invocationSource === "DialogCodeHook") {
if (event.currentIntent.slots.location === null || event.currentIntent.slots.cuisine === null) {
console.log(response);
callback(null, response);
}
if (!cuisines.includes(event.currentIntent.slots.cuisine)) {
callback(null, {
"dialogAction": {
"type": "ElicitSlot",
"message": {
"contentType": "PlainText",
"content": "Please choose between 'chinese', 'italian', 'japanese','mexican', 'tradamerican'"
},
"intentName": event.currentIntent.name,
"slots": event.currentIntent.slots,
"slotToElicit" : "cuisine"
}
});
}
if (event.currentIntent.slots.people === null) {
callback(null, response);
}
if (event.currentIntent.slots.people <= 0 || event.currentIntent.slots.people >= 20) {
callback(null, {
"dialogAction": {
"type": "ElicitSlot",
"message": {
"contentType": "PlainText",
"content": "Please choose between 1 and 20"
},
"intentName": event.currentIntent.name,
"slots": event.currentIntent.slots,
"slotToElicit" : "people"
}
});
}
if (event.currentIntent.slots.time === null) {
callback(null, response);
}
if (event.currentIntent.slots.number === null) {
callback(null, response);
}
callback(null, response);
}
if (event.invocationSource === "FulfillmentCodeHook") {
AWS.config.update({region: 'us-east-1'});
// Create an SQS service object
var sqs = new AWS.SQS({apiVersion: '2012-11-05'});
var params = {
DelaySeconds: 1,
MessageBody: JSON.stringify(event.currentIntent.slots),
QueueUrl: "https://sqs.us-east-1.amazonaws.com/231323952634/custQ"
};
sqs.sendMessage(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.MessageId);
}
});
response = {
"dialogAction": {
"type": "Close",
"fulfillmentState": "Fulfilled",
"message": {
"contentType": "PlainText",
"content": "Got it. Watch out for that text message"
}
}
};
//console.log(event.currentIntent.slots);
callback(null, response);
}
return response;
};