Skip to content

Instantly share code, notes, and snippets.

@sjwaight
Created August 26, 2021 08:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Snippet of Python showing how you can use an Alexa Intent that includes a Slot
class ReadItemsFromDate(AbstractRequestHandler):
"""Handler for ReadItemsFromDate Intent."""
def can_handle(self, handler_input):
return ask_utils.is_intent_name("ReadItemsFromDate")(handler_input)
def handle(self, handler_input):
# Extract the date value from the slot for this intent
# In this case we are going to assume it's a valid date and not check
news_date_raw = ask_utils.get_slot_value(handler_input,"newsDate")
logging.info(f"Called Skill Handler for ReadItemsFromDate Intent with 'newsDate' Slot value of '{news_date_raw}'.")
# Default to there being no news available for this date. Date format is fine - Alexa will handle parsing on return.
speak_output = f"I couldn't find any Azure news for {news_date_raw}."
# Calculate the date window for updates
ending = datetime.strptime(news_date_raw,"%Y-%m-%d")
starting = ending + timedelta(days=-1)
updatelist = get_updates_rss(startDate=starting,endDate=ending)
if len(updatelist) > 0:
speak_output = f"Here are the top Azure news items from {news_date_raw}."
speak_output+= generate_list_respose(updatelist)
speak_output += f" That's the top Azure news from {news_date_raw}!"
return (
handler_input.response_builder
.speak(speak_output)
.ask(speak_output)
.response
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment