Exemple #1
0
def task_new_project(payload, event):
    """User selected new project from main menu options."""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    if sender_id not in crafter.keys():
        crafter[sender_id] = {}
    crafter[sender_id]['current_route'] = 'new_project'
    page.send(sender_id, "Got it. What would you like to call this project?")
Exemple #2
0
def select_project_callback(payload, event):
    """User selects a project from quick reply list to update."""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    if sender_id not in crafter.keys():
        crafter[sender_id] = {}
    project_id = int(payload.split('_')[-1])
    crafter[sender_id]['project_id'] = project_id
    page.send(sender_id, "I love it. Upload your newest project photo.")
Exemple #3
0
def callback_clicked_fabric_stock(payload, event):
    """User selects fabric button"""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    if sender_id not in crafter.keys():
        crafter[sender_id] = {}
    crafter[sender_id]['stock_type'] = payload.split('_')[0].lower()
    page.send(
        sender_id,
        "Awesome, upload your {} photo and I'll take it from there.".format(
            crafter[sender_id]['stock_type']))
Exemple #4
0
def handle_message(event):
    """Handles all message types recieved by the bot and routes accordingly."""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    print message_text
    if sender_id not in crafter.keys():
        crafter[sender_id] = {}

    if message_text and "craftybot" in message_text.lower(
    ):  #Lines 19 - 31 Handle all message dealing with text
        handle_start_route(sender_id=sender_id)

    elif message_text == 'New Project' or message_text == 'Add Stock' or message_text == 'Update Status' or message_text == 'Note' or message_text == 'No Notes':
        pass
    elif crafter[sender_id].get(
            'current_route'
    ) == 'new_project' and not crafter[sender_id].get('project_id'):
        handle_project_name(sender_id=sender_id, message_text=message_text)

    elif crafter[sender_id].get(
            'current_route') == 'new_project' and crafter[sender_id].get(
                'fabric_id') and not crafter[sender_id].get('due_date'):
        handle_due_date(sender_id, message_text)

    elif crafter[sender_id].get('current_route') == 'new_project' and crafter[
            sender_id].get('due_date'):
        handle_project_notes(sender_id=sender_id, message_text=message_text)

    elif message_attachments:  #Handles all message that are none text base, mostly attachmets
        image_url = message_attachments[0].get('payload', {}).get('url')
        if crafter[sender_id].get(
                'current_route') == 'new_project' and crafter[sender_id].get(
                    'project_id') and not crafter[sender_id].get('fabric_id'):
            stock_type = 'pattern'
            if crafter[sender_id].get('pattern_id'):
                stock_type = 'fabric'
            handle_stock_image(sender_id=sender_id,
                               image_url=image_url,
                               stock_type=stock_type)

        elif crafter[sender_id].get('current_route') == 'add_stock':
            stock_type = crafter[sender_id].get('stock_type')
            handle_stock_image(sender_id=sender_id,
                               image_url=image_url,
                               stock_type=stock_type)

        elif crafter[sender_id].get(
                'current_route') == 'update_status' and crafter[sender_id].get(
                    'project_id'):
            handle_status_image(sender_id=sender_id, image_url=image_url)
Exemple #5
0
def task_new_stock(payload, event):
    """User selected to add to stock from main menu options."""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    if sender_id not in crafter.keys():
        crafter[sender_id] = {}
    crafter[sender_id]['current_route'] = 'add_stock'
    stock_type = [
        QuickReply(title="Fabric", payload="FABRIC_STOCK"),
        QuickReply(title="Pattern", payload="PATTERN_STOCK")
    ]
    page.send(sender_id,
              "Great! What do you want to add?",
              quick_replies=stock_type)
Exemple #6
0
def callback_clicked_no_note(payload, event):
    """User selects no note button"""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    page.send(
        sender_id,
        Template.Buttons(
            "Your project has been saved. If you would like to get back to main menu type 'craftybot' again.",
            [{
                'type': 'web_url',
                'title': 'Open Projects Home',
                'value': server_host + '/user/{}/projects'.format(sender_id)
            }]))
    crafter[sender_id] = dict()
Exemple #7
0
def task_update_status(payload, event):
    """User selected update status from main menu options."""
    from lib.utilities import extract_data, work_inprogress
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    if sender_id not in crafter.keys():
        crafter[sender_id] = {}
    crafter[sender_id]['current_route'] = 'update_status'

    in_progress = work_inprogress(sender_id=sender_id)
    quick_replies = list()
    for name, project_id, due_at in in_progress:
        quick_replies.append(
            QuickReply(title=name, payload="project_{}".format(project_id)))

    page.send(sender_id,
              "Great. Which project do you want to update?",
              quick_replies=quick_replies)
Exemple #8
0
def callback_clicked_note(payload, event):
    """User selects note button"""
    from lib.utilities import extract_data
    sender_id, message, message_text, message_attachments, quick_reply, = extract_data(
        event)
    page.send(sender_id, "What do you want me to note about this project")