def recently_solved_action(event): """ Handles the user's reply to the inquiry about a recently solved ticket. :param event: JSON containing information about the interaction. """ recipient_id = event['sender']['id'] payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.RECENTLY_SOLVED_TICKET) if payload == Payloads.ADD_TO_TICKET.value: redis_store.set(recipient_id, SessionStates.ADDING_COMMENT_TO_TICKET.value) facebook_requests.post_image(recipient_id, constants.OWLY_LISTENING_GIF) facebook_requests.post_text(recipient_id, constants.ADD_COMMENT_TO_TICKET) elif payload == Payloads.NEW.value: ZendeskTicket.query.filter_by( user_id=recipient_id, status=ZendeskStatus.SOLVED.value).delete() db.session().commit() support_action(event) elif payload == Payloads.LEARNING.value: ZendeskTicket.query.filter_by( user_id=recipient_id, status=ZendeskStatus.SOLVED.value).delete() db.session().commit() facebook_requests.post_image(recipient_id, constants.OWLY_YES_GIF) facebook_requests.post_text(recipient_id, constants.REMEMBER_YOU_CAN_ASK) social_networks_action(event)
def article_links_action(event): """ Handles the postback when the user selects a learning objective from a social network, and we need to display links. :param event: JSON containing information about the interaction. """ recipient_id = event['sender']['id'] objective_payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.ARTICLE_LINKS) # Handle possible auxiliary options of switching networks or ending session if objective_payload == Payloads.SWITCH.value: switch_networks_action(event) return elif objective_payload == Payloads.DONE.value: done_action(event) return # Retrieve and send the list of article links objective = LearningObjective.query.filter_by(id=objective_payload).first() text = constants.HERES_SOME_INFO_ON % (objective.display_text, objective.network.display_text) facebook_requests.post_text(recipient_id, text) db.session().add(UserObjective(recipient_id, objective.id)) db.session().commit() send_article_links_helper(recipient_id, objective.network, objective)
def failed_interpret_action(event): """ Handles the postback from when the NLP algorithm can't interpret a user's message. :param event: JSON containing information about the interaction. """ from hootbot.actions.facebook.facebook_actions_dict import facebook_actions_dict payload = Payloads( trim_payload(full_str=event['postback']['payload'], payload=Payloads.FAILED_INTERPRET)) # 'payload' will be either SOCIAL, SUPPORT or DONE, so dispatch to corresponding actions facebook_actions_dict[payload](event)
def social_or_support_action(event): """ Handles the postback from when the user answers whether they want to learn or want support. :param event: JSON containing information about the interaction. """ from hootbot.actions.facebook.facebook_actions_dict import facebook_actions_dict payload = Payloads( trim_payload(full_str=event['postback']['payload'], payload=Payloads.SOCIAL_OR_SUPPORT)) # 'payload' will be either SOCIAL or SUPPORT, so dispatch to corresponding actions facebook_actions_dict[payload](event)
def learning_objectives_action(event): """ Handles the postback when the user selects a social network. :param event: JSON containing information about the interaction. """ recipient_id = event['sender']['id'] text = "Would you like to learn about:" network_payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.LEARNING) network = SocialNetwork.query.filter_by(id=network_payload).first() send_objectives_helper(recipient_id, text, network)
def reply_to_stop_tips_action(event): """ Handles the user saying whether or not they want to stop tips. :param event: JSON containing information about the interaction. """ recipient_id = event['sender']['id'] payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.WIT_STOP_TIPS) if payload == Payloads.YES.value: ScheduledMessage.query.filter_by(facebook_id=recipient_id).delete() db.session().commit() facebook_requests.post_text(recipient_id, constants.IF_YOU_CHANGE_YOUR_MIND) elif payload == Payloads.NO.value: facebook_requests.post_text(recipient_id, constants.GREAT_STAY_TUNED)
def restart_scheduled_messages_action(event): """ Handles the postback from when the user claims they want to restart their scheduled messages. :param event: JSON containing information about the interaction. """ recipient_id = event['sender']['id'] payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.RESTART_SCHEDULED_MESSAGES) if payload == Payloads.YES.value: message = ScheduledMessage.query.filter_by( facebook_id=recipient_id).first() message.next_day_to_send = 1 db.session().commit() facebook_requests.post_text(recipient_id, constants.SCHEDULED_TIPS_RESET) social_networks_action(event)
def support_or_learn_action(event): """ Handles the postback from when the user confirms they want support after Wit assumed they did. :param event: JSON containing information about the interaction. """ payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.WIT_SUPPORT_OR_LEARN) if payload == Payloads.SUPPORT.value: facebook_actions.support_action(event) elif payload == Payloads.HELP.value: facebook_requests.post_text(event['sender']['id'], constants.HELP_CENTER_HAS_GREAT_INFO) facebook_requests.post_generic_template( event['sender']['id'], "Help Desk Articles", "https://hootsuite.com/uploads/images/stock/Help_Desk_Articles.jpg", "https://hootsuite.com/help") else: facebook_actions.social_networks_action(event)
def article_links_action(event): """ At this point, the user has selected a network and objective, so we display article links :param event: JSON containing information about the interaction. """ recipient_id = event['sender']['id'] full_payload = trim_payload(full_str=event["postback"]["payload"], payload=Payloads.WIT_ARTICLE_LINKS) split_str = full_payload.split("_") network = SocialNetwork.query.filter_by(id=split_str[0]).first() objective = LearningObjective.query.filter_by(network=network).filter_by( display_text=split_str[1]).first() text = constants.HERES_SOME_INFO_ON % (objective.display_text, network.display_text) facebook_requests.post_text(recipient_id, text) db.session().add(UserObjective(recipient_id, objective.id)) db.session().commit() facebook_actions.send_article_links_helper(recipient_id, network, objective)
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)