Example #1
0
def add_to_journal(user: User, user_input):
    # Changes data file to inside docs for access to website 
    chdir("docs")

    if not path.exists("data"):
        mkdir("data")

    user_folder = "data/{}".format(default_if_blank(user.handle, ''))

    if not path.exists(user_folder):
        mkdir(user_folder)
    
    new_file_name = user_folder + '/' + str(date.today()) + ".md"

    try:
        # f = open(new_file_name, 'x') # Doesn't exist
        # f.write("## " + str(date.today()))
        # f.write(user_input + "<br>")

        f = open(new_file_name, 'x')
        f.write(user_input)
    except: 
        f = open(new_file_name, 'a')
        f.write("\n" + user_input + "<br>")

    f.close()
Example #2
0
def __process_dialogflow_input(user: User, session: Session, user_input):
    intent_result = detect_intent_via_text(session.id, user_input)

    intent_action = default_if_blank(intent_result.action, '')

    if is_not_blank(intent_action):
        INTENT_HANDLERS.get(intent_action,
                            handle_invalid_intent)(user, intent_result,
                                                   session.id)
def __display_main_greeting(user: User, intent_result, session_id):
    response = intent_result.fulfillment_text.format(
        default_if_blank(user.name, 'Customer'))

    return send_message_with_options(user,
                                     intent_result.intent.display_name,
                                     session_id,
                                     response,
                                     *MAIN_SUGGESTIONS,
                                     row_width=1)
Example #4
0
def get_journal_entry(user: User):
    filePath = "data/{}/{}.md".format(default_if_blank(user.handle,''), str(date.today()))
    if not path.exists(filePath):
        response = "You haven't written anything today. Start writing now!"
    else:
        f = open(filePath, "r") # Modify to get correct file based on user and date 
        response = "*Today's Date:* " + str(date.today()) + '\n'
        for line in f:
            if line in FIRST_QUESTION or line in NEXT_QUESTION:
                response += "*" + f.readline().rstrip('\n') + "*" + '\n'
            elif line == BYE_MSG:
                pass
            else:
                response += line
    return response
def __confirm_order(user: User, intent_result, session_id):
    order_items = get_current_order(user, session_id)

    if len(order_items) > 0:
        response = "Here are the items in your order:\n"
        for name, count in order_items.items():
            response += "- {}x {}\n".format(
                count, default_if_blank(MENU_CODES_TO_OPTIONS[name], 'N.A.'))
        response += "\nSubmit?"

        return send_message_with_options(user,
                                         intent_result.intent.display_name,
                                         session_id, response,
                                         "Yes, submit my order!",
                                         "Nah, cancel it")
    else:
        detect_intent_via_event(session_id, 'NINJA_CAFE_MAIN_EVENT')

        response = "Oops, you don't have any items in your order. Let me know how else I can help you!"

        return send_message(user, intent_result.intent.display_name,
                            session_id, response)
Example #6
0
def __current_orders_key(user: User, session_id):
    return "orders_{}_{}".format(default_if_blank(user.id, ''), session_id)
Example #7
0
def __session_key(user: User):
    return "session_{}".format(default_if_blank(user.id, ''))
Example #8
0
def get_orders_url(user: User):
    return "https://api-dev.ninjavan.co/global/ninjacafe/orders/{}".format(
        default_if_blank(user.id, ''))
def __display_default_response(user: User, intent_result, session_id):
    response = default_if_blank(intent_result.fulfillment_text,
                                DEFAULT_ERROR_MESSAGE)

    return send_message(user, intent_result.intent.display_name, session_id,
                        response)