Created
August 26, 2021 08:28
-
-
Save sjwaight/6621e89df0b2f9a557cefe37e41fee07 to your computer and use it in GitHub Desktop.
Snippet of Python showing how you can use an Alexa Intent that includes a Slot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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