-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
151 lines (139 loc) · 5.44 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
'use strict';
const Alexa = require('ask-sdk-core');
// use 'ask-sdk' if standard SDK module is installed
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText = 'Welcome to the Alexa Skills Kit, you can say hello!';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
}
};
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
const speechText = 'Hi my name is omid!';
return handlerInput.responseBuilder
.speak(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
}
};
const WhoIsIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'WhoIsIntent';
},
handle(handlerInput) {
var speechText = "";
try{
const emp = handlerInput.requestEnvelope.request.intent.slots.emp
.resolutions.resolutionsPerAuthority[0].values[0].value.id;
console.log(emp);
switch(emp){
case "4":
speechText = "Ehsaan is our talented content provider and we are totaly happy with him. you can ask him anything regards sports";
break;
case "5":
speechText = "Majid";
break;
case "6":
speechText = "Sahar is the most talented graphic designer in our company, she always forced us to update our windows wallpaper, please ask her to stop it!";
break;
case "7":
speechText = "Mrs, Nobakht is our I.O.T lab researcher. i desperedly ask her to done it as soon as possible, because there is no purpose for an I.O.T department without an I.O.T lab";
break;
case "1":
speechText = "Oomid Ostad Rahimi is head of our department. A bright and humble man. I realy enjoy to speak with him";
break;
case "2":
speechText = "Oomid Golshan, he is my father and I realy thank him for introducing my colleagues to me";
break;
case "3":
speechText = "Babak is my dear friend and also our talented business developer, be carefull about him, if you push him hard there is chance that you don't see him for a while. we call this phenomenon, Baabak short disappearance.";
break;
default:
speechText = "man, mottevvaje'e manz zooret nashodam!";
break;
}
}
catch(e){
const eName = handlerInput.requestEnvelope.request.intent.slots.emp.value;
console.log(eName);
speechText = "Are you sure that "+eName+" work in hub ?";
}
return handlerInput.responseBuilder
.speak(speechText)
.withSimpleCard('Hub Who Is', speechText)
.getResponse();
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
console.log(handlerInput);
const speechText = 'You can say hello to me!';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
}
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const speechText = 'Goodbye!';
return handlerInput.responseBuilder
.speak(speechText)
.withSimpleCard('Hello World', speechText)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
//any cleanup logic goes here
return handlerInput.responseBuilder.getResponse();
}
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`Error handled: ${error.message}`);
return handlerInput.responseBuilder
.speak('Sorry, I can\'t understand the command. Please say again.')
.reprompt('Sorry, I can\'t understand the command. Please say again.')
.getResponse();
},
};
////////////////////////////////
// Code for the handlers here //
////////////////////////////////
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(LaunchRequestHandler,
WhoIsIntentHandler,
HelloWorldIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler)
.lambda();