-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello_world.py
183 lines (149 loc) · 6.92 KB
/
hello_world.py
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
from ask_sdk_core.skill_builder import SkillBuilder
sb = SkillBuilder()
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_request_type, is_intent_name
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_model import Response
from ask_sdk_model.ui import SimpleCard
from ask_sdk_core.dispatch_components import AbstractExceptionHandler
import time
from sinchsms import SinchSMS
API_Key = "2bc51576-0921-480f-94e6-ff5cb9bf83a7"
APP_secret = "eVr2fKmQSUKwcP4l3sPKPg=="
client = SinchSMS(API_Key, APP_secret)
mylocation = "Location not set!"
numbers = []
names = []
def make_message(message, name):
return str('Hey ' + name + '!! Help needed at ' + mylocation + '\nDescription : ' + message)
def send_sms(generic_message, numbers, names):
i = 0
for number in numbers:
message = make_message(generic_message, names[i])
i = i + 1
response = client.send_message(number, message)
#send_sms(numbers)
class LaunchRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("LaunchRequest")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Welcome to the Alexa Help, you can ask me for any help!"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
class HelpMeIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("HelpMeIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "sms sent"
slots = handler_input.request_envelope.request.intent.slots
help_request = slots.get("help_request_slot").value
send_sms(help_request, numbers, names)
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
class SetLocationIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("SetLocationIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Location set successfully"
slots = handler_input.request_envelope.request.intent.slots
global mylocation
mylocation = str(slots.get("location").value)
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
class ClearAllIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("ClearAllIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Successfully cleared all numbers"
global numbers
global names
numbers = []
names = []
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
class AddNumberIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("AddNumberIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Successfully added number"
speech_text_retake = "Please tell a valid number!"
slots = handler_input.request_envelope.request.intent.slots
new_number = slots.get("NUMBER").value
name = slots.get("NAME").value
#flag = False
if (len(str(new_number)) != 10):
speech_text = speech_text_retake
else:
numbers.append("+91"+str(new_number))
names.append(name)
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text)).set_should_end_session(
False)
return handler_input.response_builder.response
class HelpIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("AMAZON.HelpIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "You can say hello to me!"
handler_input.response_builder.speak(speech_text).ask(speech_text).set_card(
SimpleCard("Hello World", speech_text))
return handler_input.response_builder.response
class CancelAndStopIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_intent_name("AMAZON.CancelIntent")(handler_input) or is_intent_name("AMAZON.StopIntent")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
speech_text = "Goodbye!"
handler_input.response_builder.speak(speech_text).set_card(
SimpleCard("Hello World", speech_text))
return handler_input.response_builder.response
class SessionEndedRequestHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return is_request_type("SessionEndedRequest")(handler_input)
def handle(self, handler_input):
# type: (HandlerInput) -> Response
# any cleanup logic goes here
return handler_input.response_builder.response
class AllExceptionHandler(AbstractExceptionHandler):
def can_handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> bool
return True
def handle(self, handler_input, exception):
# type: (HandlerInput, Exception) -> Response
# Log the exception in CloudWatch Logs
print(exception)
speech = "Sorry, I didn't get it. Can you please say it again!!"
handler_input.response_builder.speak(speech).ask(speech)
return handler_input.response_builder.response
sb.add_request_handler(LaunchRequestHandler())
sb.add_request_handler(HelpMeIntentHandler())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(CancelAndStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(AddNumberIntentHandler())
sb.add_request_handler(ClearAllIntentHandler())
sb.add_request_handler(SetLocationIntentHandler())
sb.add_exception_handler(AllExceptionHandler())
handler = sb.lambda_handler()