예제 #1
0
def daily_tips_action(event):
    recipient_id = event['sender']['id']

    options = [(Payloads.YES.value, "Great! Hook me up!"),
               (Payloads.NO.value, "I'm already a pro!")]
    facebook_requests.post_button_list(recipient_id,
                                       constants.TIP_EACH_MORNING,
                                       Payloads.NEW, options)
예제 #2
0
def social_networks_action(event):
    """
    Handles the postback from when the user answers that they want to learn more about social.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    options = [(x.id, x.display_text) for x in SocialNetwork.query.all()]
    facebook_requests.post_button_list(recipient_id, constants.WHAT_NETWORK,
                                       Payloads.LEARNING, options)
예제 #3
0
def stop_tips_action(event):
    """
    Handles the postback from when the user says they want to stop the daily tips.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    options = [(Payloads.YES.value, "Yes"), (Payloads.NO.value, "No")]
    facebook_requests.post_button_list(recipient_id,
                                       constants.ARE_YOU_SURE_STOP_TIPS,
                                       Payloads.WIT_STOP_TIPS, options)
예제 #4
0
def assumed_support_request_action(event):
    """
    Handles the postback from Wit when it's been assumed the user needs support.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    options = [(Payloads.SUPPORT.value, "Message Support"),
               (Payloads.HELP.value, "Help Articles"),
               (Payloads.SOCIAL.value, "Keep learning!")]
    facebook_requests.post_button_list(recipient_id,
                                       constants.YOU_MIGHT_NEED_SUPPORT,
                                       Payloads.WIT_SUPPORT_OR_LEARN, options)
예제 #5
0
def handle_failed_interpretation(event):
    """
    Handles the case when the NLP algorithm failed to interpret the user's message
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    options = [(Payloads.SOCIAL.value, "Teach me!"),
               (Payloads.SUPPORT.value, "Speak to Support"),
               (Payloads.DONE.value, "Done for today")]
    facebook_requests.post_image(recipient_id, constants.THINKING_OWLY_GIF)
    facebook_requests.post_button_list(recipient_id, constants.BEYOND_ME,
                                       Payloads.FAILED_INTERPRET, options)
예제 #6
0
def networks_for_objective_action(fb_id, objective):
    """
    Sends a list of networks to the user for a given learning objective.
    :param fb_id: Facebook user ID
    :param objective: The display_text of the desired learning objective
    """
    text = constants.I_CAN_TEACH_ABOUT_OBJECTIVE % objective
    networks = SocialNetwork.query.all()
    objective_text = LearningObjective.query.filter_by(
        display_text=objective).first().display_text
    options = [("%s_%s" % (x.id, objective_text), x.display_text)
               for x in networks]
    facebook_requests.post_button_list(fb_id, text, Payloads.WIT_ARTICLE_LINKS,
                                       options)
예제 #7
0
def recent_ticket_question_action(event):
    """
    Handles the situation where the user has had their ticket 'solved' but not yet 'closed'.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    options = [(Payloads.ADD_TO_TICKET.value, "Add Details"),
               (Payloads.NEW.value, "New Issue"),
               (Payloads.LEARNING.value, "Start Learning!")]
    facebook_requests.post_button_list(recipient_id, constants.RECENTLY_SOLVED,
                                       Payloads.RECENTLY_SOLVED_TICKET,
                                       options)
    redis_store.set(recipient_id,
                    SessionStates.REPLYING_TO_RECENT_TICKET_QUESTION.value)
예제 #8
0
def get_started_action(event):
    """
    Handles the postback from when a user taps on 'Get Started'.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    facebook_requests.post_text(recipient_id, constants.HI_THERE_IM_OWLY)
    facebook_requests.post_image(recipient_id, constants.OWLY_WAVING_GIF)

    options = [(Payloads.ASK_TIPS.value, "Teach me!"),
               (Payloads.SUPPORT.value, "Support please!")]
    facebook_requests.post_button_list(recipient_id,
                                       constants.WANT_TO_LEARN_OR_SUPPORT,
                                       Payloads.SOCIAL_OR_SUPPORT, options)
예제 #9
0
def short_intro_action(event):
    """
    Assume user has already seen the intro options about scheduled messages, and skip that part.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    facebook_requests.post_text(recipient_id, constants.HI_THERE_IM_OWLY)
    facebook_requests.post_image(recipient_id, constants.OWLY_WAVING_GIF)

    options = [(Payloads.SOCIAL.value, "Teach me!"),
               (Payloads.SUPPORT.value, "Support please!")]
    facebook_requests.post_image(recipient_id,
                                 constants.WAVING_QUESTION_MARKS_GIF)
    facebook_requests.post_button_list(recipient_id,
                                       constants.WANT_TO_LEARN_OR_SUPPORT,
                                       Payloads.SOCIAL_OR_SUPPORT, options)
예제 #10
0
def send_objectives_helper(recipient_id, text, network):
    """
    Helper method used to send learning objectives to the user.
    :param recipient_id: ID of the Facebook user
    :param text: Text to be sent along with the options
    :param network: SocialNetwork object that the options should be retrieved for
    """
    objectives = get_unselected_objectives(network, recipient_id)
    if not objectives:
        # No more learning objectives to show in this scenario, so update the text
        text = constants.ANYTHING_ELSE_TODAY
    objective_options = [(x.id, x.display_text) for x in objectives]
    options = objective_options + [(Payloads.SWITCH.value, "Switch Networks"),
                                   (Payloads.DONE.value, "I'm done!")]
    facebook_requests.post_button_list(recipient_id, text,
                                       Payloads.ARTICLE_LINKS, options)
예제 #11
0
def new_to_hootsuite_action(event):
    """
    Handles the postback from when the user answers whether or not they want daily tips.
    :param event: JSON containing information about the interaction.
    """
    recipient_id = event['sender']['id']
    payload = trim_payload(full_str=event["postback"]["payload"],
                           payload=Payloads.NEW)

    if payload == Payloads.YES.value:

        scheduled_message, existed = ScheduledMessage.get_or_create(
            search_key={"facebook_id": recipient_id},
            facebook_id=recipient_id,
            topic="daily_social_tips")

        if existed:
            text = constants.CURRENTLY_RECEIVING_TIPS_ON_DAY % scheduled_message.next_day_to_send
            options = [(Payloads.YES.value, "Yes please!"),
                       (Payloads.NO.value, "No thanks!")]
            facebook_requests.post_button_list(
                recipient_id, text, Payloads.RESTART_SCHEDULED_MESSAGES,
                options)
            return
        else:
            facebook_requests.post_text(recipient_id,
                                        constants.EXPECT_TIP_EACH_WEEKDAY)
    else:
        facebook_requests.post_text(recipient_id,
                                    constants.STEP_FURTHER_GET_CERTIFIED)
        facebook_requests.post_generic_template(
            recipient_id, "Hootsuite Pro Certification",
            "https://hootsuite.com/uploads/images/stock/Chatbot-Daily-Icons-Hoot-Pro.png",
            "https://education.hootsuite.com/enroll/20308?coupon=H00tB0tPlatform"
        )
    social_networks_action(event)