def handler(user_id: str, project: str) -> Response:
    """ Handler of TEAM_06_ADD_PROJECT intent,
        TEAM_06_ADD_PROJECT intent is activated when user says '[Aa]m (?P<project>.*)'
        returns question for task

    :return:        Response
    """

    # Check project_id
    clockify_api_key = get_clockify_api_key(user_id)
    clockify = get_clockify(clockify_api_key)
    clockify_id = clockify['user_id']
    workspace_id = clockify['active_workspace_id']
    projects = get_projects(clockify_api_key, workspace_id)

    # Help the ASR
    if project == 'Hecker Tom' or project == 'hekatron' or project == 'Hecker Ton' or project == 'Hecker':
        project = 'Hackathon'

    # Create new Project
    try:
        project_id = projects[project]
    except KeyError:
        add_project(clockify_api_key, workspace_id, project_name=project)

    if set_project(user_id, project):
        msg = _('ASK_TASK')
    else:
        msg = _('ASK_PORJECT')
    response = ask(msg)
    return response
def handler(user_id: str) -> Response:
    """ Handler of TEAM_06_OPEN_TIME_TRACKING intent,
        TEAM_06_OPEN_TIME_TRACKING intent is activated when user says 'zeiterfassung stoppen'
        welcomes user

    :return:        Response
    """

    user_info = get_user(user_id)

    if user_info:
        update_user(user_info)
    else:
        create_user(user_id)

    clockify_api_key = get_clockify_api_key(user_id)

    if clockify_api_key is None or clockify_api_key == '':
        user_token = get_user_token(user_id)

        if user_token is None or user_token == '':
            user_token = get_random_string(4)
            set_user_token(user_id, user_token)

        msg = _('WELCOME_NEW_USER')

        response = tell(msg)

        response.card = Card(
            type_="GENERIC_DEFAULT",
            title="Time Tracker: Hinterlege deinen Clockify Account",
            text="User Token: {token}".format(token=user_token),
            action=get_auth_url(token=user_token),
            action_text="Klick hier, um einen Account zu hinterlegen.")
    else:
        clockify = get_clockify(clockify_api_key)
        clockify_id = clockify['user_id']
        workspace_id = clockify['active_workspace_id']
        time_entries = get_time_entries(clockify_api_key=clockify_api_key,
                                        workspace_id=workspace_id,
                                        user_id=clockify_id)
        running_timer = check_running_timer(time_entries)
        # Get time tracking status
        if running_timer:
            msg = _('WELCOME_RETURNING_USER')
            msg = msg + " " + _('WELCOME_STOP_SELECTION')
        else:
            msg = _('WELCOME_SELECTION')

        response = ask(msg)

    return response
def handler(user_id: str) -> Response:
    """ Handler of TEAM_06_STOP_TIME_TRACKING intent,
        TEAM_06_STOP_TIME_TRACKING intent is activated when user says 'zeiterfassung stoppen'
        stops running timer 

    :return:        Response
    """
    clockify_api_key = get_clockify_api_key(user_id)
    clockify = get_clockify(clockify_api_key)
    clockify_id = clockify['user_id']
    workspace_id = clockify['active_workspace_id']
    time_entries = get_time_entries(clockify_api_key, workspace_id,
                                    clockify_id)
    project_ids = get_project_ids(clockify_api_key, workspace_id)

    # Get time tracking status
    running_timer = check_running_timer(time_entries)

    if running_timer:
        # Stop time tracking
        now = datetime.utcnow()
        now_str = now.isoformat()
        now_str = now_str.split('.')[0] + ".000Z"
        time_entrie = stop_time_entrie(clockify_api_key,
                                       workspace_id,
                                       user_id=clockify_id,
                                       end_datetime=now_str)

        project = project_ids[time_entrie['projectId']]
        duration = parse_duration(time_entrie['timeInterval']['duration'])
        task = time_entrie['description']

        set_project(user_id, '')
        set_task(user_id, '')

        msg = _('STOP_COMFIRMATION',
                project=project,
                task=task,
                duration=duration)
    else:
        msg = _('STOP_ERROR')

    response = tell(msg)
    return response
def handler(user_id: str, task: str) -> Response:
    """ Handler of TEAM_06_ADD_TASK intent,
        TEAM_06_ADD_TASK intent is activated when user says '(ich möchte|ich werde) (die|den|das)(?P<task>.*)'
        returns confirmation start timer

    :return:        Response
    """

    set_task(user_id, task)

    # Get project from db
    project = get_project(user_id)
    clockify_api_key = get_clockify_api_key(user_id)
    clockify = get_clockify(clockify_api_key)
    clockify_id = clockify['user_id']
    workspace_id = clockify['active_workspace_id']
    projects = get_projects(clockify_api_key, workspace_id)
    project_id = projects[project]

    if project is None:
        msg = _('ASK_PROJECT')
        response = ask(msg)
    elif task is None:
        msg = _('ASK_TASK')
        response = ask(msg)
    else:
        # Start time tracking
        now = datetime.utcnow()
        now_str = now.isoformat()
        now_str = now_str.split('.')[0] + ".000Z"

        add_time_entrie(clockify_api_key,
                        workspace_id,
                        project_id,
                        task,
                        now_str,
                        end_datetime=None)

        msg = _('START_COMFIRMATION')
        response = tell(msg)

    return response
def handler(user_id: str) -> Response:
    """ Handler of TEAM_06_SHOW_TIME_TRACKING intent,
        TEAM_06_SHOW_TIME_TRACKING intent is activated when user says 'Stunden'
        returns booked working hours

    :return:        Response
    """

    user_info = get_user(user_id)
   
    if user_info:
        update_user(user_info)
    else: 
        create_user(user_id)
    
    clockify_api_key = get_clockify_api_key(user_id) 

    if clockify_api_key is None or clockify_api_key == '':
        user_token = get_user_token(user_id)
        
        if user_token is None or user_token == '':
            user_token = get_random_string(4)
            set_user_token(user_id, user_token)

        msg = _('WELCOME_NEW_USER')

        response = tell(msg)

        response.card = Card(
            type_="GENERIC_DEFAULT",
            title="Time Tracker: Hinterlege deinen Clockify Account",
            text="User Token: {token}".format(token=user_token),
            action=get_auth_url(token=user_token),
            action_text="Klick hier, um einen Account zu hinterlegen."
        )
    else:

        try:
            clockify = get_clockify(clockify_api_key)
            clockify_id = clockify['user_id']
            workspace_id = clockify['active_workspace_id']
            project_ids = get_project_ids(clockify_api_key, workspace_id)
            time_entries = get_time_entries(clockify_api_key, workspace_id, clockify_id)

            time_entrie = time_entries[0]
            if time_entrie['timeInterval']['duration'] is None:
                time_entrie = time_entries[1]

            if time_entrie:
                project = project_ids[time_entrie['projectId']]
                duration = parse_duration(time_entrie['timeInterval']['duration'])
                task = time_entrie['description']
                msg = _("SHOW_TIME", project=project, duration=duration, task=task)
                response = tell(msg)
                response.card = Card(
                    type_="GENERIC_DEFAULT",
                    title="Time Tracker: Clockify Link",
                    text="Hier ist der Link zu deinen gebuchten Stunden:",
                    action=get_clockify_url(),
                    action_text="Öffnen"
                )
            else: 
                msg = _("SHOW_ERROR")
                response = tell(msg)
        except:
            msg = _("SHOW_ERROR")
            response = tell(msg)
    return response