Ejemplo n.º 1
0
def handle_session_end_request():
    should_end_session = True
    return utils.build_response(
        utils.build_speechlet_response(card_title=cards.END_SESSION_TITLE,
                                       card_text=cards.END_SESSION_CONTENT,
                                       output=speech.END_SESSION, reprompt_text=None,
                                       should_end_session=should_end_session))
def search_results(intent, session):
    """
    Search GitHub for the intent's query slot
    """

    query = intent['slots']['query']['value']

    results = search_repositories(query)

    card_title = "Search Results for " + query

    if results['items']:
        top_repo = results['items'][0]
        speech_output_fmt = "I found {0} results. The top hit is {1} by {2}. "
        speech_output = speech_output_fmt.format(
            results['total_count'],
            top_repo['name'],
            top_repo['owner']['login']
        )
    else:
        speech_output = "I couldn't find any repositories matching " + query

    speechlet_response = build_speechlet_response(
        card_title,
        speech_output
    )
    return build_response(session.get('attributes', {}), speechlet_response)
Ejemplo n.º 3
0
def ensure_date_is_not_in_the_future(date):
    if not utils.is_not_in_future(date):
        speech_output = speech.SERVICE_IS_IN_THE_FUTURE
        speechlet_response = utils.build_speechlet_response(output=speech_output,
                                                            reprompt_text=None,
                                                            should_end_session=True)
        return utils.build_response(speechlet_response)
    return None
Ejemplo n.º 4
0
def handle_welcome():
    speech_output = speech.WELCOME
    should_end_session = False
    reprompt_text = None
    return utils.build_response(
        utils.build_speechlet_response(card_title=cards.WELCOME_TITLE,
                                       card_text=cards.WELCOME_CONTENT, output=speech_output,
                                       reprompt_text=reprompt_text,
                                       should_end_session=should_end_session))
def handle_session_end_request():
    """
    Say goodbye to the user.
    """
    card_title = "Session Ended"
    speech_output = "Thank you for using my python skill. Have a nice day! "

    speechlet_response = build_speechlet_response(card_title,
                                                  speech_output,
                                                  should_end_session=True)
    return build_response({}, speechlet_response)
def about_family(intent, session):
    """
    Messing with my kids
    """
    query = intent['slots']['query']['value']
    results = get_response(query)
    card_title = " About" + query

    speechlet_response - build_speechlet_response(
        card_title,
        results
    )
    return build_response(session.get('attributes',{}), speechlet_response)
Ejemplo n.º 7
0
def ensure_date_is_a_sunday(intent, future_days_go_back_year_threshold=LARGE_NUMBER_DAYS):
    try:
        date = utils.sunday_from(intent["slots"]["Date"]["value"],
                                 future_days_go_back_year_threshold)
    except RuntimeError as e:
        speech_output = e.message
        get_date_directives = [{"type": "Dialog.ElicitSlot", "slotToElicit": "Date"}]
        speechlet_response = utils.build_speechlet_response(output=speech_output,
                                                            reprompt_text=None,
                                                            should_end_session=False,
                                                            directives=get_date_directives)
        return None, utils.build_response(speechlet_response)
    return date, None
Ejemplo n.º 8
0
def ensure_service_valid(intent):
    try:
        service = intent["slots"]["Service"]["resolutions"]["resolutionsPerAuthority"][0]["values"][
            0]["value"]["id"].lower()
    except KeyError:
        speech_output = speech.PLEASE_REPEAT_SERVICE
        speechlet_response = utils.build_speechlet_response(output=speech_output,
                                                            reprompt_text=None,
                                                            should_end_session=False,
                                                            directives=[{
                                                                "type": "Dialog.ElicitSlot",
                                                                "slotToElicit": "Service"}])
        return None, utils.build_response(speechlet_response)
    return service, None
Ejemplo n.º 9
0
def handle_get_next_event():
    reprompt_text = None
    should_end_session = True
    next_event = events.get_next_event()

    if not next_event:
        return utils.build_response(utils.build_speechlet_response(
            output=speech.NO_EVENTS_FOUND,
            reprompt_text=reprompt_text,
            should_end_session=should_end_session))

    return utils.build_response(utils.build_speechlet_response(
        output=speech.get_next_event(event_name=next_event['name'],
                                     event_datetime=next_event['datetime']),
        reprompt_text=reprompt_text,
        should_end_session=should_end_session,
        card_text=cards.get_next_event_content(
            event_description=next_event['description'],
            event_location_name=next_event['location_name']),
        card_title=cards.get_next_event_title(
            event_title=next_event['name'],
            event_datetime=next_event['datetime']),
        card_small_image_url=next_event['small_image_url'],
        card_large_image_url=next_event['large_image_url']))
def get_welcome_response(session):
    """
    Welcome the user to my python skill
    """
    card_title = "Welcome"

    speech_output = "Welcome to my python skill. You can search for GitHub repositories. "

    # If the user either does not reply to the welcome message or says something
    # that is not understood, they will be prompted again with this text.
    reprompt_text = "Ask me to search GitHub for a repository. "

    session_attributes = session.get('attributes', {})

    speechlet_response = build_speechlet_response(card_title, speech_output,
                                                  reprompt_text)
    return build_response(session_attributes, speechlet_response)
def get_welcome_response(session):
    """
    Welcome the user to my python skill
    """
    card_title = "Welcome"

    speech_output = "What would you like me to do? "

    # If the user either does not reply to the welcome message or says something
    # that is not understood, they will be prompted again with this text.
    reprompt_text = "I'm still waiting for your instructions."

    session_attributes = session.get('attributes', {})

    speechlet_response = build_speechlet_response(
        card_title,
        speech_output,
        reprompt_text
    )
    return build_response(session_attributes, speechlet_response)
Ejemplo n.º 12
0
def handle_play_sermon(intent):
    maybe_response = ensure_date_and_service_slots_filled(intent)
    if maybe_response:
        return maybe_response

    date, maybe_response = ensure_date_is_a_sunday(
        intent,
        future_days_go_back_year_threshold=config.FUTURE_DAYS_GO_BACK_YEAR_THRESHOLD_SERMONS)
    if maybe_response:
        return maybe_response

    service, maybe_response = ensure_service_valid(intent)
    if maybe_response:
        return maybe_response

    maybe_response = ensure_date_is_not_in_the_future(date)
    if maybe_response:
        return maybe_response

    sermon = sermons.get_sermon(date, service)

    if not sermon:
        return utils.build_response(utils.build_speechlet_response(
            output=speech.SERMON_NOT_AVAILABLE, reprompt_text=None, should_end_session=True))

    reprompt_text = None
    should_end_session = True
    return utils.build_response(
        utils.build_audio_player_play_response(
            output_speech=speech.SERMON_PREAMBLE.format(sermon_title=sermon["title"],
                                                        speaker=sermon["speaker"]),
            reprompt_text=reprompt_text, audio_stream_url=sermon["audio_url"],
            should_end_session=should_end_session,
            card_content=cards.GET_SERMON_CONTENT.format(passage=sermon["passage"],
                                                         series_name=sermon["series_name"],
                                                         speaker=sermon["speaker"]),
            card_title=cards.GET_SERMON_TITLE.format(sermon_title=sermon["title"])))
Ejemplo n.º 13
0
def handle_irrelevant_audio_intent():
    speech_output = speech.IRRELEVANT_AUDIO_INTENT
    return utils.build_response(
        utils.build_speechlet_response(output=speech_output,
                                       reprompt_text=None,
                                       should_end_session=True))
def handle_irrelevant_audio_intent() -> AlexaResponse:
    return utils.build_speechlet_response(speech.IRRELEVANT_AUDIO_INTENT, True)
Ejemplo n.º 15
0
def handle_get_passage(intent):
    maybe_response = ensure_date_and_service_slots_filled(intent)
    if maybe_response:
        return maybe_response

    date, maybe_response = ensure_date_is_a_sunday(
        intent,
        future_days_go_back_year_threshold=config.FUTURE_DAYS_GO_BACK_YEAR_THRESHOLD_PASSAGES)
    if maybe_response:
        return maybe_response

    service, maybe_response = ensure_service_valid(intent)
    if maybe_response:
        return maybe_response

    reading_data = passages.get_passage(date, service)
    if not reading_data:
        speechlet_response = utils.build_speechlet_response(output=speech.NO_BIBLE_PASSAGE,
                                                            reprompt_text=None,
                                                            should_end_session=True)
        return utils.build_response(speechlet_response)

    book = reading_data["book"]
    start_chapter = str(reading_data["start"]["chapter"])
    start_verse = str(reading_data["start"]["verse"])
    end_chapter = str(reading_data["end"]["chapter"])
    end_verse = str(reading_data["end"]["verse"])
    humanised_passage = utils.humanise_passage(book, start_chapter, start_verse, end_chapter,
                                               end_verse)
    passage_text = bible.get_bible_text(book, start_chapter, start_verse, end_chapter, end_verse)

    get_read_passage_directives = [{"type": "Dialog.ElicitSlot", "slotToElicit": "ReadPassage"}]

    if "value" not in intent["slots"]["ReadPassage"]:
        should_end_session = False

        speechlet_response = utils.build_speechlet_response(
            card_title=cards.get_passage_title(date, service),
            card_text=cards.GET_PASSAGE_CONTENT.format(
                passage_text=passage_text, passage=humanised_passage,
                bible_translation=config.BIBLE_TRANSLATION
            ),
            output=speech.BIBLE_PASSAGE_RESPONSE.format(bible_passage=humanised_passage),
            reprompt_text=None, should_end_session=should_end_session,
            directives=get_read_passage_directives)

        return utils.build_response(speechlet_response)

    try:
        to_read_passage = intent["slots"]["ReadPassage"]["resolutions"]["resolutionsPerAuthority"][
                              0]["values"][0]["value"]["id"] == "YES"
    except KeyError:
        speech_output = speech.PLEASE_REPEAT_GENERAL
        speechlet_response = utils.build_speechlet_response(output=speech_output,
                                                            reprompt_text=None,
                                                            should_end_session=False,
                                                            directives=get_read_passage_directives)
        return utils.build_response(speechlet_response)

    speech_output = (
        speech.READ_RESPONSE.format(
            passage_text=bible.remove_square_bracketed_verse_numbers(passage_text))
        if to_read_passage
        else speech.DO_NOT_READ_RESPONSE
    )

    speechlet_response = utils.build_speechlet_response(output=speech_output, reprompt_text=None,
                                                        should_end_session=True)
    return utils.build_response(speechlet_response)