def plot_scores_flow(sender_id, response):
    img_id = str(uuid4())
    time_periods = response[RESULT][PARAMETERS][TIME_PERIODS]
    if time_periods.lower() == 'last month':
        if plot_scores_for_last_month(sender_id, img_id):
            __helper_plot_scores(sender_id, img_id)
        else:
            send_text_message(
                sender_id, 'You can only see your results after '
                'practicing on the platform')
    elif time_periods.lower() == 'last week':
        if plot_scores_for_last_week(sender_id, img_id):
            __helper_plot_scores(sender_id, img_id)
        else:
            send_text_message(
                sender_id, 'You can only see your results after '
                'practicing on the platform')
    else:
        if plot_scores_for_eternity(sender_id, img_id):
            __helper_plot_scores(sender_id, img_id)
        else:
            send_text_message(
                sender_id, 'You can only see your results after '
                'practicing on the platform')
    send_helper_messages(sender_id)
def scores_in_topics_flow(sender_id):
    img_id = str(uuid4())
    if scores_in_topics_plot(sender_id, img_id):
        image_path = get_file_name(img_id)
        send_image_local(sender_id, image_path)
        delete_img(img_id)
    else:
        send_text_message(
            sender_id, 'You can only see your results after '
            'practicing on the platform')
    send_helper_messages(sender_id)
def video_flow(sender_id, message_text):
    most_relevant_video = get_most_relevant_video(message_text)
    if most_relevant_video:
        video_link = 'https://www.youtube.com/watch?v={}'.format(
            most_relevant_video)
        send_text_message(sender_id, 'Here is a video on this:')
        send_open_graph_video(sender_id, video_link)
        send_helper_messages(sender_id)
    else:
        send_text_message(sender_id, 'Sorry! We could not find a video '
                          'for the topic')
示例#4
0
def handle_solver(sender_id, message_text):
    question = message_text[5:].strip()
    solution_gifs = get_solution_gifs(question)
    if solution_gifs:
        send_text_message(
            sender_id, "Here's your solution")
        for gif in solution_gifs:
            send_image(
                sender_id, gif)
    else:
        send_text_message(
            sender_id,
            "Sorry! We can't understand this question."
            "Will get back to you in a few days.")
    send_helper_messages(sender_id)
示例#5
0
def handle_question(payload, sender_id):
    question_id = payload['qid']
    if payload['id'] == payload['correct']:
        send_text_message(sender_id, "That's the right answer!")
        send_image(sender_id, random.choice(correct_gifs))
    else:
        send_text_message(sender_id, "Sorry! That's not correct.")
        send_image(sender_id, random.choice(wrong_gifs))

    if has_video(question_id):
        send_text_message(sender_id,
                          "Here's the video solution to the question")
        video_link = "{0}{1}".format(S3_LINK, video(question_id))
        send_video(sender_id, video_link)
    send_helper_messages(sender_id)
def questions_answered_flow(sender_id, response):
    time_periods = response[RESULT][PARAMETERS][TIME_PERIODS]
    if time_periods == '' or time_periods.lower() == 'today':
        time_periods = 'today'
        questions_answered = questions_answered_today(sender_id)
    elif time_periods.lower() == 'last month':
        time_periods = 'last month'
        questions_answered = questions_answered_last_month(sender_id)
    elif time_periods.lower() == 'last week':
        time_periods = 'last week'
        questions_answered = questions_answered_last_week(sender_id)
    send_text_message(
        sender_id,
        'You have answered {0} questions {1}'.format(questions_answered,
                                                     time_periods))
    send_helper_messages(sender_id)
def handle_message(message_text, sender_id, request_id, bing_search=False):
    response = APIAI.Instance().message_response(message_text, sender_id)
    intent = response[RESULT][METADATA][INTENT_NAME]
    log(response)
    if intent == DIAGNOSTIC_YES:
        diagnostic_yes_flow(sender_id, response, request_id)
    elif intent == STUDY:
        study_flow(sender_id, response, request_id)
    elif intent == GREETING:
        greeting_flow(sender_id, response)
    elif intent == DIAGNOSTIC_NO:
        diagnostic_no_flow(sender_id, response)
    elif intent == VIDEO_SEARCH:
        video_flow(sender_id, message_text)
    elif intent == TEST:
        test_start_flow(sender_id, response)
    elif intent == QUESTIONS_ANSWERED:
        questions_answered_flow(sender_id, response)
    elif intent == QUESTIONS_ANSWERED_CORRECTLY:
        questions_answered_correctly_flow(sender_id, response)
    elif intent == TOP_TOPICS:
        top_topics_flow(sender_id)
    elif intent == BOTTOM_TOPICS:
        bottom_topics_flow(sender_id)
    elif intent == PLOT_SCORES:
        plot_scores_flow(sender_id, response)
    elif intent == SCORES_IN_TOPICS:
        scores_in_topics_flow(sender_id)
    elif intent == PLOT_MENU:
        plot_menu_flow(sender_id)
    elif intent == DEFAULT:
        if not bing_search:
            corrected_sentence = BingSearcher().correct_spelling(message_text)
            handle_message(corrected_sentence,
                           sender_id,
                           request_id,
                           bing_search=True)
            return
        send_text_message(sender_id, response[RESULT][FULFILLMENT][SPEECH])
        send_helper_messages(sender_id)