Skip to content

Commit

Permalink
Feat: SelectIntent Handler
Browse files Browse the repository at this point in the history
This adds the select intent handler, will allow users to add custom selections to the responses, these selections will be passed AS-IS as the event_response.
  • Loading branch information
keatontaylor committed May 9, 2020
1 parent 5ac9fd2 commit 8e16d0a
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## VERSION 0.3
## VERSION 0.4

import logging
import urllib3
Expand Down Expand Up @@ -174,6 +174,32 @@ def handle(self, handler_input):
.response
)

class SelectIntentHandler(AbstractRequestHandler):
"""Handler for Select Intent."""
def can_handle(self, handler_input):
# type: (HandlerInput) -> bool
return ask_utils.is_intent_name("Select")(handler_input)

def handle(self, handler_input):
# type: (HandlerInput) -> Response
selection = ask_utils.get_slot_value(
handler_input=handler_input, slot_name="Selections")

global home_assistant_object
if home_assistant_object == None:
home_assistant_object = HomeAssistant(handler_input)
home_assistant_object.get_ha_state()


home_assistant_object.post_ha_event(selection)
speak_output = "You selected " + selection
return (
handler_input.response_builder
.speak(speak_output)
# .ask("add a reprompt if you want to keep the session open for the user to respond")
.response
)

class HelpIntentHandler(AbstractRequestHandler):
"""Handler for Help Intent."""

Expand Down Expand Up @@ -292,6 +318,7 @@ def handle(self, handler_input, exception):
sb.add_request_handler(YesIntentHanlder())
sb.add_request_handler(NoIntentHanlder())
sb.add_request_handler(HelpIntentHandler())
sb.add_request_handler(SelectIntentHandler())
sb.add_request_handler(CancelOrStopIntentHandler())
sb.add_request_handler(SessionEndedRequestHandler())
sb.add_request_handler(IntentReflectorHandler()) # make sure IntentReflectorHandler is last so it doesn't override your custom intent handlers
Expand Down

0 comments on commit 8e16d0a

Please sign in to comment.