Esempio n. 1
0
def ask_category(fulfillment):
    params = util.lookup_context(
        fulfillment, 'buying_drink_dialog_context').get('parameters')

    drinks = {
        '咖啡': ['美式', '拿鐵', '卡布奇諾'],
        '茶': ['紅茶', '綠茶', '烏龍茶'],
        '果汁': ['芒果汁', '檸檬汁', '芭樂汁']
    }

    drink_cate = params.get('drink_category')
    hot_cold = params.get('hot_cold')
    drink_item = params.get('drink_item')

    response_str = '我們有'
    if not drink_item == '':
        if drink_item in sum([x for x in drinks.values()], []):
            return util.simple_response(response_str +
                                        drink_item['drink_item'])
        else:
            return util.simple_response('抱歉!我們沒有' + drink_item['drink_item'])
    else:
        if not drink_cate == '':
            return util.simple_response(response_str +
                                        ','.join(drinks.get(drink_cate)))
        else:
            return util.simple_response(response_str +
                                        ','.join(list(drinks.keys())))

    return util.simple_response('')
Esempio n. 2
0
def check_equip_in_use(fulfillment):
    try:
        date_pattern = '%Y-%m-%dT%H%M%S%z'
        params = fulfillment.get('queryResult').get('parameters')
        meeting_room = params.get('meeting_room')
        date = datetime.strptime(
            params.get('date').replace(':', ''), date_pattern)
        start_time = datetime.strptime(
            params.get('time-period').get('startTime').replace(':', ''),
            date_pattern)
        end_time = datetime.strptime(
            params.get('time-period').get('endTime').replace(':', ''),
            date_pattern)
        target_rooms = [
            x['id'] for x in meeting_rooms.values()
            if x['name'].find(meeting_room) >= 0
        ]
        meeting_room_id = next(iter(target_rooms), None)

        if is_equip_in_use(meeting_room_id, date, start_time, end_time):
            return util.simple_response(text_content=meeting_room + u'已經被人預約')
        else:
            return util.simple_response(text_content=meeting_room +
                                        u'尚未被預約,請問幫您預約嗎?')

    except Exception as e:
        # traceback.print_exc()
        return util.simple_response(text_content=str(e))
Esempio n. 3
0
def list_rented_equips(fulfillment):
    rented_list = get_rented_equips()
    if len(rented_list) == 0:
        return util.simple_response(text_content=u'您目前沒有預約任何的設備')
    else:
        str_rented_list = u'您預約的設備如下:\n'
        str_rented_list += ', \n'.join([
            x[2] + ' ' + x[3] + ' ' + x[1] + '(預約代號: ' + x[0] + ')'
            for x in rented_list
        ])
        return util.simple_response(text_content=str_rented_list)
Esempio n. 4
0
def looking_for_pic(fulfillment):
    # print(fulfillment)
    sys_code = fulfillment.get('queryResult').get('parameters').get('sys_code')

    # 取得系統pic
    strsql = '''
            select *
        from (select c.user_name_e,c.user_name_c, b.user_email
                from sec1117 a, sec1118 b,sec1102 c
                where a.user_code = b.user_code
                and a.user_code=c.user_code
                and a.pic_type = 'B'
                and a.system_code = :sys_code
                order by a.pic_seq)
        where rownum <= 3
    '''
    with util.get_db_conn() as conn:
        res = conn.execute(strsql, sys_code=sys_code)
        res = res.fetchall()

    if len(res) == 0:
        strRes = '無法取得指定系統負責人,請重新輸入'
        return util.clear_response(fulfillment, strRes)
    else:
        strRes = sys_code + '負責人是: '
        for row in res:
            strRes += row[1] + '(' + row[2] + '), '
        strRes += ' 請問是否幫您將問題轉給系統負責人?'
        return util.simple_response(text_content=strRes)
Esempio n. 5
0
def ordering(fulfillment):
    params = fulfillment.get('queryResult').get('parameters')
    deliver_method = params.get('deliver_method', '')
    drink_item = params.get('drink_item.original', '')
    ice_level = params.get('ice_level', '')
    sugar_level = params.get('sugar_level', '')
    number = params.get('number', '')

    if deliver_method == '外送':
        jsonRep = {
            'followupEventInput': {
                'name': 'events_deliver_info',
                'languageCode': 'zh-TW',
                'parameters': {}
            }
        }
    else:
        jsonRep = {
            'followupEventInput': {
                'name': 'events_order_confirm',
                'languageCode': 'zh-TW',
                'parameters': {}
            }
        }
    return util.simple_response(fulfillmentObj=jsonRep)
Esempio n. 6
0
def list_rs(fulfillment):
    office_code = fulfillment.get('queryResult').get('parameters').get(
        'office_code')

    strsql = '''
    select a.rs_url,
       a.is_internet,
       decode(b.is_active, 0, 'Active', 'InActive') as status
  from was5005 a, was5011 b
 where a.office_code = :office_code
   and a.rs_id = b.rs_id
    '''

    with util.get_db_conn() as conn:
        res = conn.execute(strsql, office_code=office_code)
        res = res.fetchall()

    if len(res) == 0:
        strRes = '無法取得Office: ' + office_code + 'Report Server資訊,請重新查詢!'
        return util.clear_response(fulfillment, strRes)
    else:
        strRes = 'Office: ' + office_code + " Report Server資訊如下:\n" + ', '.join(
            row[0] for row in res)

    return util.simple_response(text_content=strRes)
Esempio n. 7
0
def get_rs_info(fulfillment):
    office_code = fulfillment.get('queryResult').get('parameters').get(
        'office_code')
    rs_code = fulfillment.get('queryResult').get('parameters').get('rs_code')
    rs_url = rs_code.upper() + '.WANHAI.COM:80%'
    strsql = '''select a.office_code,a.rs_url,a.is_internet,decode(b.is_active,0,'Active','InActive') as status from was5005 a,was5011 b 
    where a.rs_id=b.rs_id and upper(a.rs_url) like :rs_url and office_code like :office_code
    '''
    if office_code:
        office_code += '%'
    else:
        office_code = '%'

    with util.get_db_conn() as conn:
        res = conn.execute(strsql, rs_url=rs_url, office_code=office_code)
        res = res.fetchall()

    if len(res) == 0:
        strRes = '無法取得' + rs_code + '資訊,請重新查詢!'
        return util.clear_response(fulfillment, strRes)
    else:
        strRes = rs_code + '資訊如下:\n'
        for row in res:
            strRes += row[1] + '(office: ' + row[0] + ', isInternet: ' + row[
                2] + ', Status: ' + row[3] + ') '
        return util.simple_response(text_content=strRes)
Esempio n. 8
0
def ordering_summary(fulfillment):
    context = util.lookup_context(fulfillment,
                                  'buying_drink_ordering-followup')
    params = context.get('parameters')
    strResp = '您的訂購資訊如下:\n飲料: ' + params['hot_cold'] + params[
        'drink_item.original'] + '\n數量: ' + str(
            params['number']) + '\n甜度冰塊: ' + params['ice_level'] + '' + params[
                'sugar_level'] + '\n\n請問是否訂購?'
    return util.simple_response(strResp)
Esempio n. 9
0
def ordering_delivery_info(fulfillment):
    print(fulfillment)
    return util.simple_response(
        fulfillmentObj={
            'followupEventInput': {
                'name': 'events_order_confirm',
                'languageCode': 'zh-TW',
                'parameters': {}
            }
        })
Esempio n. 10
0
def index():
    jsonObj = request.get_json()
    try:
        handleName = jsonObj.get('queryResult').get('intent')['displayName']
        print('Handler:', handleName)

        return eval(handleName + '(jsonObj)')
    except Exception as e:
        print(str(e))
        return util.simple_response(fulfillmentObj=util.reset_all_contexts(
            fulfillmentObj=jsonObj))
Esempio n. 11
0
def booking_equip(fulfillment):
    try:
        date_pattern = '%Y-%m-%dT%H%M%S%z'
        params = fulfillment.get('queryResult').get('parameters')
        meeting_room = params.get('meeting_room')
        date = datetime.strptime(
            params.get('date').replace(':', ''), date_pattern)
        start_time = datetime.strptime(
            params.get('time-period').get('startTime').replace(':', ''),
            date_pattern)
        end_time = datetime.strptime(
            params.get('time-period').get('endTime').replace(':', ''),
            date_pattern)

        str_res = '您要預約: ' + meeting_room + ',時間: ' + date.strftime(
            '%Y-%m-%d') + ' ' + start_time.strftime(
                '%H:%M:%S') + '~' + end_time.strftime('%H:%M:%S') + ' 請問是否確定?'
        return util.simple_response(text_content=str_res)
    except:
        # traceback.print_exc()
        return util.simple_response(text_content=str(e))
Esempio n. 12
0
def confirm_forward(fulfillment):
    return util.simple_response(
        fulfillmentObj={
            'followupEventInput': {
                'name':
                'events_forward_issue',
                'languageCode':
                'zh-TW',
                'parameters':
                util.lookup_context(fulfillment,
                                    'system_piclooking_for_pic-followup').get(
                                        'parameters')
            }
        })
Esempio n. 13
0
def check_equip_in_use_confirm_booking(fulfillment):
    return util.simple_response(
        fulfillmentObj={
            'followupEventInput': {
                'name':
                'event_booking_equip',
                'languageCode':
                'zh-TW',
                'parameters':
                util.lookup_context(
                    fulfillment, 'whl_familycheck_equip_in_use-followup').get(
                        'parameters')
            }
        })
Esempio n. 14
0
def switch_on_off(fulfillment):
    office_code = fulfillment.get('queryResult').get('parameters').get(
        'office_code')
    switch_action = fulfillment.get('queryResult').get('parameters').get(
        'switch_action')
    rs_code = fulfillment.get('queryResult').get('parameters').get('rs_code')
    rs_url = rs_code.upper() + '.WANHAI.COM:80'
    action_code = '0' if switch_action == 'on' else '1'

    strsql = '''update was5011 set is_active=:action_code where rs_id in (select rs_id from was5005 where office_code=:office_code and upper(rs_url)=:rs_url)'''

    with util.get_db_conn() as conn:
        res = conn.execute(strsql,
                           action_code=action_code,
                           office_code=office_code,
                           rs_url=rs_url)
    print(res)
    strRes = rs_code + '已' + ('開啟' if switch_action == 'on' else '關閉')
    return util.simple_response(text_content=strRes)
Esempio n. 15
0
def list_all_meeting_rooms(fulfillment):
    global meeting_rooms
    str_meeting_rooms = ', \n'.join(
        [x['name'] for x in meeting_rooms.values()])
    return util.simple_response(text_content=str_meeting_rooms)