Showing
13 changed files
with
6133 additions
and
0 deletions
No preview for this file type
dogibogi/.DS_Store
0 → 100644
No preview for this file type
dogibogi/OpenbuilderSkills/__init__.py
0 → 100644
File mode changed
dogibogi/OpenbuilderSkills/command.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | +import random | ||
| 8 | + | ||
| 9 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 10 | +from Functions.getInstance import * | ||
| 11 | +from Functions.checkFunction import * | ||
| 12 | +from Functions.updateDatabase import * | ||
| 13 | +from Functions.messageTypes import * | ||
| 14 | + | ||
| 15 | +import tones | ||
| 16 | + | ||
| 17 | +def get_comeHere_message(): | ||
| 18 | + payload = request.get_json() | ||
| 19 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 20 | + # 유저 발화(utterance) 불러오기 | ||
| 21 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 22 | + # accountId 불러오기 | ||
| 23 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 24 | + # petId 불러오기 | ||
| 25 | + petId = getPetId(kakaoUserKey) | ||
| 26 | + # petName 불러오기 | ||
| 27 | + petName = getPetName(petId) | ||
| 28 | + # relation 불러오기 | ||
| 29 | + relation = getRelation(kakaoUserKey, petId) | ||
| 30 | + # font 불러오기 | ||
| 31 | + font = getFont(kakaoUserKey, petId) | ||
| 32 | + # 현재 시간 불러오기 | ||
| 33 | + now = datetime.datetime.now() | ||
| 34 | + | ||
| 35 | + # 펫 이미지 리스트 불러오기 | ||
| 36 | + category = '' | ||
| 37 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 38 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 39 | + | ||
| 40 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 41 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 42 | + contextList = [] | ||
| 43 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 44 | + try: | ||
| 45 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 46 | + except: | ||
| 47 | + repeatCount = 1 | ||
| 48 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 49 | + qrList = [] | ||
| 50 | + qrList = addRandomHintQR(qrList, petName) | ||
| 51 | + qrList = qrList + basicButtonWindow(petName) | ||
| 52 | + outputList = tones.getMessageOutputList(font, 'comeHere', imageUrl, 0, petName, relation) | ||
| 53 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 54 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 55 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/eventMessage.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +import datetime | ||
| 5 | +import random | ||
| 6 | + | ||
| 7 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 8 | +from Functions.getInstance import * | ||
| 9 | +from Functions.checkFunction import * | ||
| 10 | +from Functions.updateDatabase import * | ||
| 11 | +from Functions.messageTypes import * | ||
| 12 | +from Functions import pyjosa | ||
| 13 | +import tones | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +# TODO 경우의 수를 나눠서 어떤 경우에는 시간에 따라, 보통 상황, 날씨에 따라, 특정 상황에 따라 메시지 선택 | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +# 인식되어 메시지를 보내는 경우 | ||
| 20 | +def get_detection_message(accountId): | ||
| 21 | + kakaoUserKey = getKakaoUserKeyUsingAccountId(accountId) | ||
| 22 | + petId = getPetIdUsingAccountId(accountId) | ||
| 23 | + | ||
| 24 | + font = getFont(kakaoUserKey,petId) | ||
| 25 | + relation = getRelation(kakaoUserKey,petId) | ||
| 26 | + petName = getPetName(petId) | ||
| 27 | + | ||
| 28 | + now = datetime.datetime.now() | ||
| 29 | + # 상황에 따른 단독 메시지 가져오기 | ||
| 30 | + if isMorning(now): | ||
| 31 | + message = tones.getSingleMessage(font, 'morning_detected', petName, relation) | ||
| 32 | + elif isAfternoon(now): | ||
| 33 | + message = tones.getSingleMessage(font, 'afternoon_detected', petName, relation) | ||
| 34 | + elif isEvening(now): | ||
| 35 | + message = tones.getSingleMessage(font, 'evening_detected', petName, relation) | ||
| 36 | + else: | ||
| 37 | + message = '' | ||
| 38 | + | ||
| 39 | + msg = pyjosa.replace_josa(message) | ||
| 40 | + return msg | ||
| 41 | + | ||
| 42 | +# 날씨 기반의 선톡을 보내는 경우 | ||
| 43 | +def get_weather_message(accountId): | ||
| 44 | + kakao_user_key = getKakaoUserKeyUsingAccountId(accountId) | ||
| 45 | + pet_id = getPetIdUsingAccountId(accountId) | ||
| 46 | + | ||
| 47 | + font = getFont(kakao_user_key, pet_id) | ||
| 48 | + relation = getRelation(kakao_user_key, pet_id) | ||
| 49 | + pet_name = getPetName(pet_id) | ||
| 50 | + | ||
| 51 | + now = datetime.datetime.now() | ||
| 52 | + | ||
| 53 | + morning_weather = get_today_weather()['morningWeather'] | ||
| 54 | + afternoon_weather = get_today_weather()['afternoonWeather'] | ||
| 55 | + if morning_weather == '맑음' and afternoon_weather == '맑음': # 오전 오후 모두 맑은날인 경우 | ||
| 56 | + message = tones.getSingleMessage(font, 'sunny_day_weather', pet_name, relation) | ||
| 57 | + elif '비' not in morning_weather and '비' not in afternoon_weather: # 오전오후 모두 비가오지 않는 날인 경우 | ||
| 58 | + message = tones.getSingleMessage(font, 'not_rainy_day_weather', pet_name, relation) | ||
| 59 | + elif '비' not in morning_weather and '비' in afternoon_weather: # 오전은 아닌데 오후에 비가오는 날인 경우 | ||
| 60 | + message = tones.getSingleMessage(font, 'rainy_afternoon_weather', pet_name, relation) | ||
| 61 | + else: | ||
| 62 | + message = '' | ||
| 63 | + msg = pyjosa.replace_josa(message) | ||
| 64 | + return msg |
dogibogi/OpenbuilderSkills/help.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | +import random | ||
| 8 | + | ||
| 9 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 10 | +from Functions.getInstance import * | ||
| 11 | +from Functions.checkFunction import * | ||
| 12 | +from Functions.updateDatabase import * | ||
| 13 | +from Functions.messageTypes import * | ||
| 14 | +from Config import intentBlockId | ||
| 15 | + | ||
| 16 | +# 도움말 시작 | ||
| 17 | +def get_startHelp_message(): | ||
| 18 | + contextList = [] | ||
| 19 | + outputList = [] | ||
| 20 | + qrList = [] | ||
| 21 | + | ||
| 22 | + payload = request.get_json() | ||
| 23 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 24 | + outputList.append(simpleText('[시스템] 무엇이 궁금하신가요?')) | ||
| 25 | + | ||
| 26 | + # help button window | ||
| 27 | + qrList = helpButtonWindow() | ||
| 28 | + | ||
| 29 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 30 | + addMessageLogs('bot', kakaoUserKey, '[도움말]메인', datetime.datetime.now(), 'none') | ||
| 31 | + | ||
| 32 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 33 | + | ||
| 34 | +def get_quitHelp_message(): | ||
| 35 | + contextList = [] | ||
| 36 | + outputList = [] | ||
| 37 | + qrList = [] | ||
| 38 | + | ||
| 39 | + payload = request.get_json() | ||
| 40 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 41 | + petId = getPetId(kakaoUserKey) | ||
| 42 | + petName = getPetName(petId) | ||
| 43 | + outputList.append(simpleText('[시스템] 언제든지 다시 질문해주세요')) | ||
| 44 | + | ||
| 45 | + # 챗봇 노란버튼 | ||
| 46 | + qrList = basicButtonWindow(petName) | ||
| 47 | + | ||
| 48 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 49 | + addMessageLogs('bot', kakaoUserKey, '[도움말]종료', datetime.datetime.now(), 'none') | ||
| 50 | + | ||
| 51 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 52 | + | ||
| 53 | +def get_serviceIntroduction_message(): | ||
| 54 | + contextList = [] | ||
| 55 | + outputList = [] | ||
| 56 | + qrList = [] | ||
| 57 | + | ||
| 58 | + payload = request.get_json() | ||
| 59 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 60 | + petId = getPetId(kakaoUserKey) | ||
| 61 | + petName = getPetName(petId) | ||
| 62 | + | ||
| 63 | + card_list = serviceIntroductionCardList(petName) | ||
| 64 | + outputList.append(cardArray(card_list)) | ||
| 65 | + outputList.append(simpleText('도기보기와 함께라면 밖에서도 우리집 ' + petName + '와 채팅할 수 있어요😊')) | ||
| 66 | + outputList.append(simpleText(petName + '와 카톡할 준비 되셨나요?')) | ||
| 67 | + | ||
| 68 | + # help button window | ||
| 69 | + qrList = helpButtonWindow() | ||
| 70 | + | ||
| 71 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 72 | + addMessageLogs('bot', kakaoUserKey, '[도움말]서비스 소개', datetime.datetime.now(), 'none') | ||
| 73 | + | ||
| 74 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 75 | + | ||
| 76 | + | ||
| 77 | +# QR코드 스캔 도움말 | ||
| 78 | +def get_helpQrScan_message(): | ||
| 79 | + contextList = [] | ||
| 80 | + outputList = [] | ||
| 81 | + qrList = [] | ||
| 82 | + | ||
| 83 | + payload = request.get_json() | ||
| 84 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 85 | + outputList.append(simpleText('[시스템] 카메라 초점을 맞춰서 스캔해보시겠어요?')) | ||
| 86 | + outputList.append(simpleText('그래도 스캔이 잘 되지 않는다면 연락주세요\n\n📧: petpeotalk@gmail.com')) | ||
| 87 | + | ||
| 88 | + qrList.append(blockQuickReply('돌아가기↩️', '돌아가기↩️', intentBlockId.help)) | ||
| 89 | + | ||
| 90 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 91 | + addMessageLogs('bot', kakaoUserKey, '[도움말]QR코드스캔', datetime.datetime.now(), 'none') | ||
| 92 | + | ||
| 93 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 94 | + | ||
| 95 | +# 사진추가 도움말 | ||
| 96 | +def get_helpAddImage_message(): | ||
| 97 | + contextList = [] | ||
| 98 | + outputList = [] | ||
| 99 | + qrList = [] | ||
| 100 | + | ||
| 101 | + payload = request.get_json() | ||
| 102 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 103 | + petId = getPetId(kakaoUserKey) | ||
| 104 | + petName = getPetName(petId) | ||
| 105 | + | ||
| 106 | + outputList.append(simpleText('물론이에요!')) | ||
| 107 | + outputList.append(simpleText('귀여운 ' + petName + '사진은 언제든지 추가 가능합니다😍')) | ||
| 108 | + | ||
| 109 | + qrList.append(blockQuickReply('사진추가하기📸', '사진추가하기📸️', '5d4251ca8192ac0001b8d96e')) | ||
| 110 | + qrList.append(blockQuickReply('돌아가기↩️', '돌아가기↩️', intentBlockId.help)) | ||
| 111 | + | ||
| 112 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 113 | + addMessageLogs('bot', kakaoUserKey, '[도움말]사진추가', datetime.datetime.now(), 'none') | ||
| 114 | + | ||
| 115 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 116 | + | ||
| 117 | + | ||
| 118 | +# 사용인원 도움말 | ||
| 119 | +def get_helpCapacity_message(): | ||
| 120 | + contextList = [] | ||
| 121 | + outputList = [] | ||
| 122 | + qrList = [] | ||
| 123 | + | ||
| 124 | + payload = request.get_json() | ||
| 125 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 126 | + outputList.append(simpleText('아쉽게도 아직은 공기계 한 대당 한 명만 이용하실 수 있습니다')) | ||
| 127 | + outputList.append(simpleText('머지않아 온가족이 도기보기와 함께할 수 있어요!\n' | ||
| 128 | + '기대해주실거죠?☺')) | ||
| 129 | + | ||
| 130 | + qrList.append(blockQuickReply('돌아가기↩️', '돌아가기↩️', intentBlockId.help)) | ||
| 131 | + | ||
| 132 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 133 | + addMessageLogs('bot', kakaoUserKey, '[도움말]사용인원', datetime.datetime.now(), 'none') | ||
| 134 | + | ||
| 135 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
dogibogi/OpenbuilderSkills/minigame.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | + | ||
| 6 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 7 | +from Functions.getInstance import * | ||
| 8 | +from Functions.checkFunction import * | ||
| 9 | +from Functions.updateDatabase import * | ||
| 10 | +from Functions.messageTypes import * | ||
| 11 | +import tones | ||
| 12 | + | ||
| 13 | +game_369_clap = '짝👏!' | ||
| 14 | +game_369_one = '일!' | ||
| 15 | +game_369_two = '이!' | ||
| 16 | +game_369_three = '삼!' | ||
| 17 | +game_369_four = '사!' | ||
| 18 | +game_369_five = '오!' | ||
| 19 | +game_369_six = '육!' | ||
| 20 | +game_369_seven = '칠!' | ||
| 21 | +game_369_eight = '팔!' | ||
| 22 | +game_369_nine = '구!' | ||
| 23 | +game_369_ten = '십!!' | ||
| 24 | + | ||
| 25 | +def get_start_rsp_game_message(): | ||
| 26 | + payload = request.get_json() | ||
| 27 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 28 | + | ||
| 29 | + # 유저 발화(utterance) 불러오기 | ||
| 30 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 31 | + # accountId 불러오기 | ||
| 32 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 33 | + # petId 불러오기 | ||
| 34 | + petId = getPetId(kakaoUserKey) | ||
| 35 | + # petName 불러오기 | ||
| 36 | + petName = getPetName(petId) | ||
| 37 | + # relation 불러오기 | ||
| 38 | + relation = getRelation(kakaoUserKey, petId) | ||
| 39 | + # font 불러오기 | ||
| 40 | + font = getFont(kakaoUserKey, petId) | ||
| 41 | + # 현재 시간 불러오기 | ||
| 42 | + now = datetime.datetime.now() | ||
| 43 | + | ||
| 44 | + # 펫 이미지 리스트 불러오기 | ||
| 45 | + category = '' | ||
| 46 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 47 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 48 | + | ||
| 49 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 50 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'start_rsp_game') | ||
| 51 | + contextList = [] | ||
| 52 | + | ||
| 53 | + outputList = tones.getMessageOutputList(font, 'start_rsp_game', imageUrl, 90, petName, relation) | ||
| 54 | + | ||
| 55 | + qrList = [] | ||
| 56 | + qrList.append(blockQuickReply('가위✌', '가위✌', '5e411eb592690d0001fcc7c3')) | ||
| 57 | + qrList.append(blockQuickReply('바위✊', '바위✊', '5e411eb592690d0001fcc7c3')) | ||
| 58 | + qrList.append(blockQuickReply('보✋', '보✋', '5e411eb592690d0001fcc7c3')) | ||
| 59 | + | ||
| 60 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 61 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 62 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 63 | + | ||
| 64 | + | ||
| 65 | +def get_process_rsp_game_message(): | ||
| 66 | + payload = request.get_json() | ||
| 67 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 68 | + | ||
| 69 | + # 유저 발화(utterance) 불러오기 | ||
| 70 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 71 | + # accountId 불러오기 | ||
| 72 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 73 | + # petId 불러오기 | ||
| 74 | + petId = getPetId(kakaoUserKey) | ||
| 75 | + # petName 불러오기 | ||
| 76 | + petName = getPetName(petId) | ||
| 77 | + # relation 불러오기 | ||
| 78 | + relation = getRelation(kakaoUserKey, petId) | ||
| 79 | + # font 불러오기 | ||
| 80 | + font = getFont(kakaoUserKey, petId) | ||
| 81 | + # 현재 시간 불러오기 | ||
| 82 | + now = datetime.datetime.now() | ||
| 83 | + | ||
| 84 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 85 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 86 | + | ||
| 87 | + outputList = [] | ||
| 88 | + contextList = [] | ||
| 89 | + qrList = [] | ||
| 90 | + | ||
| 91 | + rv = random.randrange(0,20) | ||
| 92 | + if utterance == '가위✌': | ||
| 93 | + if 0 <= rv < 18: | ||
| 94 | + # 상대 보자기: 승리 | ||
| 95 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 96 | + outputList.append(simpleText('보!!')) | ||
| 97 | + outputList = outputList + tones.getMessageOutputList(font, 'win_rsp_game_s', imageUrl, 90, petName, relation) | ||
| 98 | + qrList.append(blockQuickReply('이겼다😆!', '이겼다😆!', '5e411ec292690d0001fcc7c5')) | ||
| 99 | + contextList.append(contextValue('rsp', 1, {'result': 'win'})) | ||
| 100 | + elif rv == 18: | ||
| 101 | + # 상대 바위: 패배 | ||
| 102 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 103 | + outputList.append(simpleText('바위!!')) | ||
| 104 | + outputList = outputList + tones.getMessageOutputList(font, 'lose_rsp_game', imageUrl, 90, petName, relation) | ||
| 105 | + qrList = qrList + basicButtonWindow(petName) | ||
| 106 | + elif rv == 19: | ||
| 107 | + # 상대 가위: 재시작 | ||
| 108 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 109 | + outputList.append(simpleText('가위!!')) | ||
| 110 | + outputList = outputList + tones.getMessageOutputList(font, 'restart_rsp_game', imageUrl, 90, petName, relation) | ||
| 111 | + qrList.append(blockQuickReply('가위✌', '가위✌', '5e411eb592690d0001fcc7c3')) | ||
| 112 | + qrList.append(blockQuickReply('바위✊', '바위✊', '5e411eb592690d0001fcc7c3')) | ||
| 113 | + qrList.append(blockQuickReply('보✋', '보✋', '5e411eb592690d0001fcc7c3')) | ||
| 114 | + elif utterance == '바위✊': | ||
| 115 | + # 상대 보: 무조건 패배 | ||
| 116 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 117 | + outputList.append(simpleText('보!!')) | ||
| 118 | + outputList = outputList + tones.getMessageOutputList(font, 'lose_rsp_game', imageUrl, 90, petName, relation) | ||
| 119 | + qrList = qrList + basicButtonWindow(petName) | ||
| 120 | + elif utterance == '보✋': | ||
| 121 | + if 0 <= rv < 16: | ||
| 122 | + # 상대 보자기: 재시작 | ||
| 123 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 124 | + outputList.append(simpleText('보!!')) | ||
| 125 | + outputList = outputList + tones.getMessageOutputList(font, 'restart_rsp_game', imageUrl, 90, petName, relation) | ||
| 126 | + qrList.append(blockQuickReply('가위✌', '가위✌', '5e411eb592690d0001fcc7c3')) | ||
| 127 | + qrList.append(blockQuickReply('바위✊', '바위✊', '5e411eb592690d0001fcc7c3')) | ||
| 128 | + qrList.append(blockQuickReply('보✋', '보✋', '5e411eb592690d0001fcc7c3')) | ||
| 129 | + elif 16 <= rv < 18: | ||
| 130 | + # 상대 바위: 승리 | ||
| 131 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 132 | + outputList.append(simpleText('바위!!')) | ||
| 133 | + outputList = outputList + tones.getMessageOutputList(font, 'win_rsp_game_p', imageUrl, 90, petName, relation) | ||
| 134 | + qrList.append(blockQuickReply('이겼다😆!', '이겼다😆!', '5e411ec292690d0001fcc7c5')) | ||
| 135 | + contextList.append(contextValue('rsp', 1, {'result': 'win'})) | ||
| 136 | + elif 18 <= rv < 20: | ||
| 137 | + # 상대 가위: 패배 | ||
| 138 | + imageUrl = getObjectByRandom(get_game_image_urls('rsp', 'paw')) | ||
| 139 | + outputList.append(simpleText('가위!!')) | ||
| 140 | + outputList = outputList + tones.getMessageOutputList(font, 'lose_rsp_game', imageUrl, 90, petName, relation) | ||
| 141 | + qrList = qrList + basicButtonWindow(petName) | ||
| 142 | + | ||
| 143 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 144 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'process_rsp_game') | ||
| 145 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 146 | + | ||
| 147 | +# 게임에 대한 보상 제공 | ||
| 148 | +def get_finish_rsp_game_message(): | ||
| 149 | + payload = request.get_json() | ||
| 150 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 151 | + | ||
| 152 | + # 유저 발화(utterance) 불러오기 | ||
| 153 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 154 | + # accountId 불러오기 | ||
| 155 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 156 | + # petId 불러오기 | ||
| 157 | + petId = getPetId(kakaoUserKey) | ||
| 158 | + # petName 불러오기 | ||
| 159 | + petName = getPetName(petId) | ||
| 160 | + # relation 불러오기 | ||
| 161 | + relation = getRelation(kakaoUserKey, petId) | ||
| 162 | + # font 불러오기 | ||
| 163 | + font = getFont(kakaoUserKey, petId) | ||
| 164 | + # 현재 시간 불러오기 | ||
| 165 | + now = datetime.datetime.now() | ||
| 166 | + | ||
| 167 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 168 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 169 | + | ||
| 170 | + contextList = [] | ||
| 171 | + qrList = [] | ||
| 172 | + outputList = [] | ||
| 173 | + | ||
| 174 | + outputList = tones.getMessageOutputList(font, 'reward_rsp_game', '', 0, petName, relation) | ||
| 175 | + qrList = qrList + basicButtonWindow(petName) | ||
| 176 | + | ||
| 177 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 178 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'finish_rsp_game') | ||
| 179 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 180 | + | ||
| 181 | +def get_start_369_game_message(): | ||
| 182 | + payload = request.get_json() | ||
| 183 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 184 | + | ||
| 185 | + # 유저 발화(utterance) 불러오기 | ||
| 186 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 187 | + # accountId 불러오기 | ||
| 188 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 189 | + # petId 불러오기 | ||
| 190 | + petId = getPetId(kakaoUserKey) | ||
| 191 | + # petName 불러오기 | ||
| 192 | + petName = getPetName(petId) | ||
| 193 | + # relation 불러오기 | ||
| 194 | + relation = getRelation(kakaoUserKey, petId) | ||
| 195 | + # font 불러오기 | ||
| 196 | + font = getFont(kakaoUserKey, petId) | ||
| 197 | + # 현재 시간 불러오기 | ||
| 198 | + now = datetime.datetime.now() | ||
| 199 | + | ||
| 200 | + # 펫 이미지 리스트 불러오기 | ||
| 201 | + category = '' | ||
| 202 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 203 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 204 | + | ||
| 205 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 206 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 207 | + contextList = [] | ||
| 208 | + | ||
| 209 | + outputList = tones.getMessageOutputList(font, 'start_369_game', imageUrl, 90, petName, relation) | ||
| 210 | + | ||
| 211 | + qrList = [] | ||
| 212 | + contextList.append(contextValue('369', 1, {'result': '1'})) | ||
| 213 | + qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4')) | ||
| 214 | + qrList.append(blockQuickReply('이!', '이!', '5e44e054ffa7480001f94ab4')) | ||
| 215 | + qrList.append(blockQuickReply('삼!', '삼!', '5e44e054ffa7480001f94ab4')) | ||
| 216 | + | ||
| 217 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 218 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'start_369_game') | ||
| 219 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 220 | + | ||
| 221 | +def get_process_369_game_message(): | ||
| 222 | + payload = request.get_json() | ||
| 223 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 224 | + | ||
| 225 | + # 유저 발화(utterance) 불러오기 | ||
| 226 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 227 | + # accountId 불러오기 | ||
| 228 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 229 | + # petId 불러오기 | ||
| 230 | + petId = getPetId(kakaoUserKey) | ||
| 231 | + # petName 불러오기 | ||
| 232 | + petName = getPetName(petId) | ||
| 233 | + # relation 불러오기 | ||
| 234 | + relation = getRelation(kakaoUserKey, petId) | ||
| 235 | + # font 불러오기 | ||
| 236 | + font = getFont(kakaoUserKey, petId) | ||
| 237 | + # 현재 시간 불러오기 | ||
| 238 | + now = datetime.datetime.now() | ||
| 239 | + | ||
| 240 | + outputList = [] | ||
| 241 | + qrList = [] | ||
| 242 | + contextList = [] | ||
| 243 | + rv = random.randrange(0, 10) | ||
| 244 | + | ||
| 245 | + if checkContextParamValue(payload, '369', 'result', '1'): | ||
| 246 | + if utterance == '이!': | ||
| 247 | + # 박수쳐서 계속 감: 90% | ||
| 248 | + if 0 <= rv < 9: | ||
| 249 | + imageUrl = getObjectByRandom(getPetImageUrls(kakaoUserKey, '')) | ||
| 250 | + outputList.append(simpleImage(imageUrl)) | ||
| 251 | + outputList.append(simpleText('짝👏!')) | ||
| 252 | + qrList.append(blockQuickReply('사!', '사!', '5e44e054ffa7480001f94ab4')) | ||
| 253 | + qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4')) | ||
| 254 | + qrList.append(blockQuickReply('오!', '오!', '5e44e054ffa7480001f94ab4')) | ||
| 255 | + contextList.append(contextValue('369', 1, {'result': '3'})) | ||
| 256 | + # 까먹어서 사용자 승리: 10% | ||
| 257 | + elif rv == 9: | ||
| 258 | + outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation) | ||
| 259 | + qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6')) | ||
| 260 | + contextList.append(contextValue('369', 1, {'result': '2'})) | ||
| 261 | + # 사용자 패배 | ||
| 262 | + elif utterance == '짝👏!' or utterance == '삼!': | ||
| 263 | + outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation) | ||
| 264 | + qrList = qrList + basicButtonWindow(petName) | ||
| 265 | + | ||
| 266 | + elif checkContextParamValue(payload, '369', 'result', '3'): | ||
| 267 | + if utterance == '사!': | ||
| 268 | + # 계속 감: 60% | ||
| 269 | + if 0 <= rv < 6: | ||
| 270 | + outputList.append(simpleText('오!')) | ||
| 271 | + qrList.append(blockQuickReply('칠!', '칠!', '5e44e054ffa7480001f94ab4')) | ||
| 272 | + qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4')) | ||
| 273 | + qrList.append(blockQuickReply('육!', '육!', '5e44e054ffa7480001f94ab4')) | ||
| 274 | + contextList.append(contextValue('369', 1, {'result': '5'})) | ||
| 275 | + # 까먹어서 사용자 승리: 40% | ||
| 276 | + elif 6 <= rv < 10: | ||
| 277 | + outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation) | ||
| 278 | + qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6')) | ||
| 279 | + contextList.append(contextValue('369', 1, {'result': '4'})) | ||
| 280 | + # 사용자 패배 | ||
| 281 | + elif utterance == '짝👏!' or utterance == '오!': | ||
| 282 | + outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation) | ||
| 283 | + qrList = qrList + basicButtonWindow(petName) | ||
| 284 | + | ||
| 285 | + elif checkContextParamValue(payload, '369', 'result', '5'): | ||
| 286 | + if utterance == '짝👏!': | ||
| 287 | + # 계속 감: 30% | ||
| 288 | + if 0 <= rv < 3: | ||
| 289 | + outputList.append(simpleText('칠!')) | ||
| 290 | + qrList.append(blockQuickReply('구!', '구!', '5e44e054ffa7480001f94ab4')) | ||
| 291 | + qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4')) | ||
| 292 | + qrList.append(blockQuickReply('팔!', '팔!', '5e44e054ffa7480001f94ab4')) | ||
| 293 | + contextList.append(contextValue('369', 1, {'result': '7'})) | ||
| 294 | + # 박수 잘못쳐서 사용자 승리: 30% | ||
| 295 | + elif 3 <= rv < 6: | ||
| 296 | + outputList = tones.getMessageOutputList(font, 'finish_369_game_mistake', '', 0, petName, relation) | ||
| 297 | + qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6')) | ||
| 298 | + contextList.append(contextValue('369', 1, {'result': '6'})) | ||
| 299 | + # 까먹어서 사용자 승리: 40% | ||
| 300 | + elif 6 <= rv < 10: | ||
| 301 | + outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation) | ||
| 302 | + qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6')) | ||
| 303 | + contextList.append(contextValue('369', 1, {'result': '6'})) | ||
| 304 | + # 사용자 패배 | ||
| 305 | + elif utterance == '칠!' or utterance == '육!': | ||
| 306 | + outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation) | ||
| 307 | + qrList = qrList + basicButtonWindow(petName) | ||
| 308 | + | ||
| 309 | + elif checkContextParamValue(payload, '369', 'result', '7'): | ||
| 310 | + if utterance == '팔!': | ||
| 311 | + # 계속 감: 20% | ||
| 312 | + if 0 <= rv < 2: | ||
| 313 | + imageUrl = getObjectByRandom(getPetImageUrls(kakaoUserKey, '')) | ||
| 314 | + outputList.append(simpleImage(imageUrl)) | ||
| 315 | + outputList.append(simpleText('짝👏!')) | ||
| 316 | + qrList.append(blockQuickReply('십!!', '십!!', '5e44e054ffa7480001f94ab4')) | ||
| 317 | + qrList.append(blockQuickReply('십일!', '십일!', '5e44e054ffa7480001f94ab4')) | ||
| 318 | + qrList.append(blockQuickReply('짝👏!', '짝👏!', '5e44e054ffa7480001f94ab4')) | ||
| 319 | + contextList.append(contextValue('369', 1, {'result': '9'})) | ||
| 320 | + # 까먹어서 사용자 승리: 80% | ||
| 321 | + elif 2 <= rv < 10: | ||
| 322 | + outputList = tones.getMessageOutputList(font, 'finish_369_game_forgot', '', 0, petName, relation) | ||
| 323 | + qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6')) | ||
| 324 | + contextList.append(contextValue('369', 1, {'result': '8'})) | ||
| 325 | + # 사용자 패배 | ||
| 326 | + elif utterance == '짝👏!' or utterance == '팔!': | ||
| 327 | + outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation) | ||
| 328 | + qrList = qrList + basicButtonWindow(petName) | ||
| 329 | + | ||
| 330 | + elif checkContextParamValue(payload, '369', 'result', '9'): | ||
| 331 | + if utterance == '십!!': | ||
| 332 | + imageUrl = getObjectByRandom(getPetImageUrls(kakaoUserKey, '')) | ||
| 333 | + outputList = tones.getMessageOutputList(font, 'win_369_game', imageUrl, 90, petName, relation) | ||
| 334 | + qrList.append(blockQuickReply('😂', '😂', '5e44e0a5ffa7480001f94ab6')) | ||
| 335 | + contextList.append(contextValue('369', 1, {'result': '10'})) | ||
| 336 | + # 사용자 패배 | ||
| 337 | + elif utterance == '십일!' or '짝👏!': | ||
| 338 | + outputList = tones.getMessageOutputList(font, 'lose_369_game', '', 0, petName, relation) | ||
| 339 | + qrList = qrList + basicButtonWindow(petName) | ||
| 340 | + | ||
| 341 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 342 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'process_369_game') | ||
| 343 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 344 | + | ||
| 345 | +# 게임에 대한 보상 제공 | ||
| 346 | +def get_finish_369_game_message(): | ||
| 347 | + payload = request.get_json() | ||
| 348 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 349 | + | ||
| 350 | + # 유저 발화(utterance) 불러오기 | ||
| 351 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 352 | + # accountId 불러오기 | ||
| 353 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 354 | + # petId 불러오기 | ||
| 355 | + petId = getPetId(kakaoUserKey) | ||
| 356 | + # petName 불러오기 | ||
| 357 | + petName = getPetName(petId) | ||
| 358 | + # relation 불러오기 | ||
| 359 | + relation = getRelation(kakaoUserKey, petId) | ||
| 360 | + # font 불러오기 | ||
| 361 | + font = getFont(kakaoUserKey, petId) | ||
| 362 | + # 현재 시간 불러오기 | ||
| 363 | + now = datetime.datetime.now() | ||
| 364 | + | ||
| 365 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 366 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 367 | + | ||
| 368 | + contextList = [] | ||
| 369 | + qrList = [] | ||
| 370 | + outputList = [] | ||
| 371 | + | ||
| 372 | + outputList = tones.getMessageOutputList(font, 'reward_369_game', '', 0, petName, relation) | ||
| 373 | + qrList = qrList + basicButtonWindow(petName) | ||
| 374 | + | ||
| 375 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 376 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'finish_369_game') | ||
| 377 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 378 | + | ||
| 379 | +# 넌센스 퀴즈 시작 | ||
| 380 | +def get_start_nonsense_quiz_message(): | ||
| 381 | + contextList = [] | ||
| 382 | + qrList = [] | ||
| 383 | + payload = request.get_json() | ||
| 384 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 385 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 386 | + petId = getPetId(kakaoUserKey) | ||
| 387 | + petName = getPetName(petId) | ||
| 388 | + relation = getRelation(kakaoUserKey, petId) | ||
| 389 | + font = getFont(kakaoUserKey, petId) | ||
| 390 | + | ||
| 391 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 392 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 393 | + | ||
| 394 | + category = '' | ||
| 395 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 396 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 397 | + # 한 퀴즈는 4개의 대사로 구성되어 있기 때문에 4로 나눠서 퀴즈의 갯수를 구함 | ||
| 398 | + quizCount = int(tones.getCountUsingIntent('cute', 'nonsense_quiz') / 4) | ||
| 399 | + randomQuizNumber = str(random.randrange(1, quizCount + 1)) | ||
| 400 | + outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + randomQuizNumber + '_Q', imageUrl, 90, petName, relation) | ||
| 401 | + answerList = tones.getKeywordListUsingIntent('cute', 'nonsense_quiz_' + randomQuizNumber + '_keyword') | ||
| 402 | + contextList.append(contextValue('utterance', 1, {'nonsense_quiz': 'start', 'nonsense_quiz_number': randomQuizNumber, 'nq_answer_list': answerList})) | ||
| 403 | + | ||
| 404 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 405 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'start_nonsense_quiz') | ||
| 406 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 407 | + | ||
| 408 | +# 넌센스퀴즈 결과 확인 | ||
| 409 | +def get_process_nonsense_quiz_message(): | ||
| 410 | + payload = request.get_json() | ||
| 411 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 412 | + | ||
| 413 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 414 | + petId = getPetId(kakaoUserKey) | ||
| 415 | + petName = getPetName(petId) | ||
| 416 | + relation = getRelation(kakaoUserKey, petId) | ||
| 417 | + font = getFont(kakaoUserKey, petId) | ||
| 418 | + now = datetime.datetime.now() | ||
| 419 | + | ||
| 420 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 421 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 422 | + | ||
| 423 | + contextList = [] | ||
| 424 | + qrList = [] | ||
| 425 | + outputList = [] | ||
| 426 | + | ||
| 427 | + quizNumber = getContextParamValue(payload, 'utterance', 'nonsense_quiz_number') | ||
| 428 | + answers = getContextParamValue(payload, 'utterance', 'nq_answer_list') | ||
| 429 | + answers = answers.replace('[', '') | ||
| 430 | + answers = answers.replace(']', '') | ||
| 431 | + answers = answers.replace("\"", "") | ||
| 432 | + answerList = answers.split(',') | ||
| 433 | + | ||
| 434 | + correct = False | ||
| 435 | + for answer in answerList: | ||
| 436 | + if answer in utterance: | ||
| 437 | + correct = True | ||
| 438 | + if correct: | ||
| 439 | + contextList.append(contextValue('utterance', 1, {'nonsense_quiz': 'correct', 'nonsense_quiz_number': quizNumber})) | ||
| 440 | + outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_O', '', 0, petName, relation) | ||
| 441 | + else: | ||
| 442 | + contextList.append(contextValue('utterance', 1, {'nonsense_quiz': 'incorrect', 'nonsense_quiz_number': quizNumber})) | ||
| 443 | + outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_X', '', 0, petName, relation) | ||
| 444 | + qrList = qrList + basicButtonWindow(petName) | ||
| 445 | + | ||
| 446 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 447 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'process_nonsense_quiz') | ||
| 448 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 449 | + | ||
| 450 | +#TODO 넌센스퀴즈 결과에 대한 보상 제공(아직 미구현) | ||
| 451 | +def get_finish_nonsense_quiz_message(): | ||
| 452 | + contextList = [] | ||
| 453 | + qrList = [] | ||
| 454 | + outputList = [] | ||
| 455 | + | ||
| 456 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 457 | + | ||
| 458 | +def get_start_word_relay_message(): | ||
| 459 | + payload = request.get_json() | ||
| 460 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 461 | + | ||
| 462 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 463 | + petId = getPetId(kakaoUserKey) | ||
| 464 | + petName = getPetName(petId) | ||
| 465 | + relation = getRelation(kakaoUserKey, petId) | ||
| 466 | + font = getFont(kakaoUserKey, petId) | ||
| 467 | + | ||
| 468 | + # 펫 이미지 리스트 불러오기 | ||
| 469 | + category = '' | ||
| 470 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 471 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 472 | + | ||
| 473 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 474 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 475 | + | ||
| 476 | + contextList = [] | ||
| 477 | + qrList = [] | ||
| 478 | + | ||
| 479 | + outputList = tones.getMessageOutputList(font, 'start_word_relay', imageUrl, 0, petName, relation) | ||
| 480 | + # 끝말잇기 대본에서 db 가져오기 | ||
| 481 | + words = tones.getKeywordListUsingIntent('cute', 'word_relay_db')[0][0] | ||
| 482 | + keywordList = wordRelayDBList(words, petName, relation) | ||
| 483 | + # 랜덤하게 하나 고르기 | ||
| 484 | + keyword = random.choice(keywordList) | ||
| 485 | + outputList.append(simpleText(keyword+'!!')) | ||
| 486 | + | ||
| 487 | + contextList.append(contextValue('utterance', 1, {'wr_keyword': keyword, 'word_relay': 'process', 'wr_repeat_count': 0})) | ||
| 488 | + | ||
| 489 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 490 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'start_word_relay') | ||
| 491 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 492 | + | ||
| 493 | +def get_process_word_relay_message(): | ||
| 494 | + contextList = [] | ||
| 495 | + qrList = [] | ||
| 496 | + payload = request.get_json() | ||
| 497 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 498 | + | ||
| 499 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 500 | + petId = getPetId(kakaoUserKey) | ||
| 501 | + petName = getPetName(petId) | ||
| 502 | + relation = getRelation(kakaoUserKey, petId) | ||
| 503 | + font = getFont(kakaoUserKey, petId) | ||
| 504 | + | ||
| 505 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 506 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 507 | + | ||
| 508 | + # 펫 이미지 리스트 불러오기 | ||
| 509 | + category = '' | ||
| 510 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 511 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 512 | + | ||
| 513 | + # 끝말잇기 대본에서 db 가져오기 | ||
| 514 | + words = tones.getKeywordListUsingIntent('cute', 'word_relay_db')[0][0] | ||
| 515 | + keywordList = wordRelayDBList(words, petName, relation) | ||
| 516 | + | ||
| 517 | + outputList = [] | ||
| 518 | + # 끝말잇기 반복한 횟수 | ||
| 519 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'wr_repeat_count')) + 1 | ||
| 520 | + # 5번 반복했으면 종료 | ||
| 521 | + if repeatCount == 5: | ||
| 522 | + outputList = tones.getMessageOutputList(font, 'perfect_win_word_relay', imageUrl, 30, petName, relation) | ||
| 523 | + qrList.append(blockQuickReply('이겼다!', '이겼다!', '5e5cbe0d7b777800010f7d95')) | ||
| 524 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'win', 'wr_repeat_count': repeatCount})) | ||
| 525 | + # 글자수가 한개인 경우 사용자 패배 | ||
| 526 | + elif len(list(utterance)) == 1: | ||
| 527 | + outputList.append(simpleText(utterance + '??')) | ||
| 528 | + outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation) | ||
| 529 | + qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95')) | ||
| 530 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount})) | ||
| 531 | + # 특수문자가 포함되어있는 경우 사용자 패배 | ||
| 532 | + elif '?' in utterance or '!' in utterance or '^' in utterance or ';' in utterance: | ||
| 533 | + outputList.append(simpleText(utterance + '??')) | ||
| 534 | + outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation) | ||
| 535 | + qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95')) | ||
| 536 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount})) | ||
| 537 | + # 글자수가 5초과인 경우 사용자 패배 | ||
| 538 | + elif len(list(utterance)) > 5: | ||
| 539 | + outputList.append(simpleText(utterance + '??')) | ||
| 540 | + outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation) | ||
| 541 | + qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95')) | ||
| 542 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount})) | ||
| 543 | + # 중간에 띄어쓰기가 있는 경우 사용자 패배 | ||
| 544 | + elif ' ' in utterance: | ||
| 545 | + outputList.append(simpleText(utterance + '??')) | ||
| 546 | + outputList = tones.getMessageOutputList(font, 'foul_lose_word_relay', imageUrl, 0, petName, relation) | ||
| 547 | + qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95')) | ||
| 548 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount})) | ||
| 549 | + # 끝말잇기 규칙에 어긋나지 않은 경우 db에서 매칭되는 단어를 찾기 | ||
| 550 | + else: | ||
| 551 | + find = False | ||
| 552 | + beforeKeyWord = getContextParamValue(payload, 'utterance', 'wr_keyword') | ||
| 553 | + # 사용자가 펫이 제시한 단어에 맞지 않는 응답을 한 경우 | ||
| 554 | + if beforeKeyWord[-1] != utterance[0]: | ||
| 555 | + outputList = tones.getMessageOutputList(font, 'lose_word_relay', imageUrl, 0, petName, relation) | ||
| 556 | + qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95')) | ||
| 557 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'wr_repeat_count': repeatCount})) | ||
| 558 | + else: | ||
| 559 | + lastWord = utterance[-1] | ||
| 560 | + for keyword in keywordList: | ||
| 561 | + # 사용자의 응답에 펫이 이어서 끝말잇기를 진행하는 경우 | ||
| 562 | + if keyword[0] == lastWord: | ||
| 563 | + outputList.append(simpleText(utterance + '..?')) | ||
| 564 | + outputList += tones.getMessageOutputList(font, 'process_word_relay', imageUrl, 0, petName, relation) | ||
| 565 | + outputList.append(simpleText(keyword + '!')) | ||
| 566 | + contextList.append(contextValue('utterance', 1, {'wr_keyword': keyword, 'word_relay': 'process', 'wr_repeat_count': repeatCount})) | ||
| 567 | + find = True | ||
| 568 | + break | ||
| 569 | + # 사용자의 응답에 펫이 응답을 하지 못하는 경우(db에서 찾지못함) | ||
| 570 | + if not find: | ||
| 571 | + outputList.append(simpleText(utterance + '?!')) | ||
| 572 | + outputList += tones.getMessageOutputList(font, 'win_word_relay', imageUrl, 30, petName, relation) | ||
| 573 | + qrList.append(blockQuickReply('이겼다!', '이겼다!', '5e5cbe0d7b777800010f7d95')) | ||
| 574 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'win', 'wr_repeat_count': repeatCount})) | ||
| 575 | + | ||
| 576 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 577 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'process_word_relay') | ||
| 578 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 579 | + | ||
| 580 | +def get_finish_word_relay_message(): | ||
| 581 | + contextList = [] | ||
| 582 | + qrList = [] | ||
| 583 | + outputList = [] | ||
| 584 | + | ||
| 585 | + payload = request.get_json() | ||
| 586 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 587 | + | ||
| 588 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 589 | + petId = getPetId(kakaoUserKey) | ||
| 590 | + petName = getPetName(petId) | ||
| 591 | + relation = getRelation(kakaoUserKey, petId) | ||
| 592 | + font = getFont(kakaoUserKey, petId) | ||
| 593 | + | ||
| 594 | + category = '' | ||
| 595 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 596 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 597 | + | ||
| 598 | + outputList += tones.getMessageOutputList(font, 'finish_word_relay', imageUrl, 90, petName, relation) | ||
| 599 | + | ||
| 600 | + qrList = [] | ||
| 601 | + qrList = addRandomHintQR(qrList, petName) | ||
| 602 | + qrList = qrList + basicButtonWindow(petName) | ||
| 603 | + | ||
| 604 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 605 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'finish_word_relay') | ||
| 606 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/question.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | +import random | ||
| 8 | + | ||
| 9 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 10 | +#from Functions.getInstance import * | ||
| 11 | +from Functions.checkFunction import * | ||
| 12 | +from Functions.updateDatabase import * | ||
| 13 | +from Functions.messageTypes import * | ||
| 14 | +import tones | ||
| 15 | + | ||
| 16 | +import OpenbuilderSkills.system | ||
| 17 | + | ||
| 18 | +def get_recentBehavior_message(): | ||
| 19 | + payload = request.get_json() | ||
| 20 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 21 | + | ||
| 22 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 23 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 24 | + petId = getPetId(kakaoUserKey) | ||
| 25 | + petName = getPetName(petId) | ||
| 26 | + relation = getRelation(kakaoUserKey,petId) | ||
| 27 | + font = getFont(kakaoUserKey,petId) | ||
| 28 | + now = datetime.datetime.now() | ||
| 29 | + | ||
| 30 | + # 펫 이미지 리스트 불러오기 | ||
| 31 | + category = '' | ||
| 32 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 33 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 34 | + | ||
| 35 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 36 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 37 | + contextList = [] | ||
| 38 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 39 | + try: | ||
| 40 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 41 | + except: | ||
| 42 | + repeatCount = 1 | ||
| 43 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 44 | + qrList = [] | ||
| 45 | + qrList = addRandomHintQR(qrList, petName) | ||
| 46 | + qrList = qrList + basicButtonWindow(petName) | ||
| 47 | + | ||
| 48 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 49 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 50 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 51 | + else: | ||
| 52 | + # 60초 안에 두번이상 인식된 적 있는지 확인 | ||
| 53 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 54 | + if isDetected: | ||
| 55 | + outputList = tones.getMessageOutputList(font, 'dog_detected', imageUrl, 90, petName, relation) | ||
| 56 | + else: | ||
| 57 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 58 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 59 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 60 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 61 | + | ||
| 62 | + | ||
| 63 | +def get_isMeal_message(): | ||
| 64 | + payload = request.get_json() | ||
| 65 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 66 | + | ||
| 67 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 68 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 69 | + petId = getPetId(kakaoUserKey) | ||
| 70 | + petName = getPetName(petId) | ||
| 71 | + relation = getRelation(kakaoUserKey,petId) | ||
| 72 | + font = getFont(kakaoUserKey,petId) | ||
| 73 | + now = datetime.datetime.now() | ||
| 74 | + # 60초 안에 인식된적 있는지 확인 | ||
| 75 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 76 | + # 펫 이미지 리스트 불러오기 | ||
| 77 | + category = '' | ||
| 78 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 79 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 80 | + | ||
| 81 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 82 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 83 | + contextList = [] | ||
| 84 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 85 | + try: | ||
| 86 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 87 | + except: | ||
| 88 | + repeatCount = 1 | ||
| 89 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 90 | + qrList = [] | ||
| 91 | + qrList = addRandomHintQR(qrList, petName) | ||
| 92 | + qrList = qrList + basicButtonWindow(petName) | ||
| 93 | + | ||
| 94 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 95 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 96 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 97 | + else: | ||
| 98 | + if isDetected: | ||
| 99 | + outputList = tones.getMessageOutputList(font, 'state_eat', imageUrl, 90, petName, relation) | ||
| 100 | + else: | ||
| 101 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 102 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 103 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 104 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 105 | + | ||
| 106 | + | ||
| 107 | +def get_isSleep_message(): | ||
| 108 | + payload = request.get_json() | ||
| 109 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 110 | + | ||
| 111 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 112 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 113 | + petId = getPetId(kakaoUserKey) | ||
| 114 | + petName = getPetName(petId) | ||
| 115 | + relation = getRelation(kakaoUserKey,petId) | ||
| 116 | + font = getFont(kakaoUserKey,petId) | ||
| 117 | + now = datetime.datetime.now() | ||
| 118 | + # 60초 안에 인식된적 있는지 확인 | ||
| 119 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 120 | + # 펫 이미지 리스트 불러오기 | ||
| 121 | + category = '' | ||
| 122 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 123 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 124 | + | ||
| 125 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 126 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 127 | + contextList = [] | ||
| 128 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 129 | + try: | ||
| 130 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 131 | + except: | ||
| 132 | + repeatCount = 1 | ||
| 133 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 134 | + qrList = [] | ||
| 135 | + qrList = addRandomHintQR(qrList, petName) | ||
| 136 | + qrList = qrList + basicButtonWindow(petName) | ||
| 137 | + | ||
| 138 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 139 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 140 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 141 | + else: | ||
| 142 | + if isDetected: | ||
| 143 | + outputList = tones.getMessageOutputList(font, 'state_sleep', imageUrl, 90, petName, relation) | ||
| 144 | + else: | ||
| 145 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 146 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 147 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 148 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 149 | + | ||
| 150 | + | ||
| 151 | +def get_isPlay_message(): | ||
| 152 | + payload = request.get_json() | ||
| 153 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 154 | + | ||
| 155 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 156 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 157 | + petId = getPetId(kakaoUserKey) | ||
| 158 | + petName = getPetName(petId) | ||
| 159 | + relation = getRelation(kakaoUserKey,petId) | ||
| 160 | + font = getFont(kakaoUserKey,petId) | ||
| 161 | + now = datetime.datetime.now() | ||
| 162 | + # 60초 안에 인식된적 있는지 확인 | ||
| 163 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 164 | + # 펫 이미지 리스트 불러오기 | ||
| 165 | + category = '' | ||
| 166 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 167 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 168 | + | ||
| 169 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 170 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 171 | + contextList = [] | ||
| 172 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 173 | + try: | ||
| 174 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 175 | + except: | ||
| 176 | + repeatCount = 1 | ||
| 177 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 178 | + qrList = [] | ||
| 179 | + qrList = addRandomHintQR(qrList, petName) | ||
| 180 | + qrList = qrList + basicButtonWindow(petName) | ||
| 181 | + | ||
| 182 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 183 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 184 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 185 | + else: | ||
| 186 | + if isDetected: | ||
| 187 | + outputList = tones.getMessageOutputList(font, 'state_play', imageUrl, 90, petName, relation) | ||
| 188 | + else: | ||
| 189 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 190 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 191 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 192 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 193 | + | ||
| 194 | +def get_whatIs_message(): | ||
| 195 | + payload = request.get_json() | ||
| 196 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 197 | + | ||
| 198 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 199 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 200 | + petId = getPetId(kakaoUserKey) | ||
| 201 | + petName = getPetName(petId) | ||
| 202 | + relation = getRelation(kakaoUserKey, petId) | ||
| 203 | + font = getFont(kakaoUserKey, petId) | ||
| 204 | + | ||
| 205 | + category = '' | ||
| 206 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 207 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 208 | + | ||
| 209 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 210 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 211 | + contextList = [] | ||
| 212 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 213 | + try: | ||
| 214 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 215 | + except: | ||
| 216 | + repeatCount = 1 | ||
| 217 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 218 | + qrList = [] | ||
| 219 | + qrList = addRandomHintQR(qrList, petName) | ||
| 220 | + qrList = qrList + basicButtonWindow(petName) | ||
| 221 | + | ||
| 222 | + if checkContextParamValue(payload, 'utterance', 'nonsense_quiz', 'incorrect'): | ||
| 223 | + quizNumber = getContextParamValue(payload, 'utterance', 'nonsense_quiz_number') | ||
| 224 | + outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_X', imageUrl, 90, petName, relation) | ||
| 225 | + elif checkContextParamValue(payload, 'utterance', 'noise', 'alive'): | ||
| 226 | + outputList = tones.getMessageOutputList(font, 'whyNoise', imageUrl, 0, petName, relation) | ||
| 227 | + qrList = [] | ||
| 228 | + qrList.append(blockQuickReply('😭', '😭', '5e5ab273b060a50001e5cecd')) | ||
| 229 | + else: | ||
| 230 | + outputList = tones.getMessageOutputList(font, 'whatIs', imageUrl, 30, petName, relation) | ||
| 231 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 232 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 233 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 234 | + | ||
| 235 | +def get_isPet_message(): | ||
| 236 | + payload = request.get_json() | ||
| 237 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 238 | + | ||
| 239 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 240 | + petId = getPetId(kakaoUserKey) | ||
| 241 | + petName = getPetName(petId) | ||
| 242 | + relation = getRelation(kakaoUserKey, petId) | ||
| 243 | + font = getFont(kakaoUserKey, petId) | ||
| 244 | + | ||
| 245 | + category = '' | ||
| 246 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 247 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 248 | + | ||
| 249 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 250 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 251 | + contextList = [] | ||
| 252 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 253 | + try: | ||
| 254 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 255 | + except: | ||
| 256 | + repeatCount = 1 | ||
| 257 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 258 | + qrList = [] | ||
| 259 | + qrList = addRandomHintQR(qrList, petName) | ||
| 260 | + qrList = qrList + basicButtonWindow(petName) | ||
| 261 | + outputList = tones.getMessageOutputList(font, 'isPet', imageUrl, 90, petName, relation) | ||
| 262 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 263 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 264 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 265 | + | ||
| 266 | +def get_isHungry_message(): | ||
| 267 | + payload = request.get_json() | ||
| 268 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 269 | + | ||
| 270 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 271 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 272 | + petId = getPetId(kakaoUserKey) | ||
| 273 | + petName = getPetName(petId) | ||
| 274 | + relation = getRelation(kakaoUserKey, petId) | ||
| 275 | + font = getFont(kakaoUserKey, petId) | ||
| 276 | + now = datetime.datetime.now() | ||
| 277 | + # 60초 안에 인식된적 있는지 확인 | ||
| 278 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 279 | + # 펫 이미지 리스트 불러오기 | ||
| 280 | + category = '' | ||
| 281 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 282 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 283 | + | ||
| 284 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 285 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 286 | + contextList = [] | ||
| 287 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 288 | + try: | ||
| 289 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 290 | + except: | ||
| 291 | + repeatCount = 1 | ||
| 292 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 293 | + qrList = [] | ||
| 294 | + qrList = addRandomHintQR(qrList, petName) | ||
| 295 | + qrList = qrList + basicButtonWindow(petName) | ||
| 296 | + | ||
| 297 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 298 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 299 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 300 | + else: | ||
| 301 | + if isDetected: | ||
| 302 | + outputList = tones.getMessageOutputList(font, 'state_eat', imageUrl, 90, petName, relation) | ||
| 303 | + else: | ||
| 304 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 305 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 306 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 307 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 308 | + | ||
| 309 | +def get_whatThink_message(): | ||
| 310 | + payload = request.get_json() | ||
| 311 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 312 | + | ||
| 313 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 314 | + petId = getPetId(kakaoUserKey) | ||
| 315 | + petName = getPetName(petId) | ||
| 316 | + relation = getRelation(kakaoUserKey, petId) | ||
| 317 | + font = getFont(kakaoUserKey, petId) | ||
| 318 | + | ||
| 319 | + category = '' | ||
| 320 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 321 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 322 | + | ||
| 323 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 324 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 325 | + contextList = [] | ||
| 326 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 327 | + try: | ||
| 328 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 329 | + except: | ||
| 330 | + repeatCount = 1 | ||
| 331 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 332 | + qrList = [] | ||
| 333 | + qrList = addRandomHintQR(qrList, petName) | ||
| 334 | + qrList = qrList + basicButtonWindow(petName) | ||
| 335 | + outputList = tones.getMessageOutputList(font, 'whatThink', imageUrl, 30, petName, relation) | ||
| 336 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 337 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 338 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 339 | + | ||
| 340 | +def get_isLonely_message(): | ||
| 341 | + payload = request.get_json() | ||
| 342 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 343 | + | ||
| 344 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 345 | + petId = getPetId(kakaoUserKey) | ||
| 346 | + petName = getPetName(petId) | ||
| 347 | + relation = getRelation(kakaoUserKey, petId) | ||
| 348 | + font = getFont(kakaoUserKey, petId) | ||
| 349 | + | ||
| 350 | + category = '' | ||
| 351 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 352 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 353 | + | ||
| 354 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 355 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 356 | + contextList = [] | ||
| 357 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 358 | + try: | ||
| 359 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 360 | + except: | ||
| 361 | + repeatCount = 1 | ||
| 362 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 363 | + qrList = [] | ||
| 364 | + qrList = addRandomHintQR(qrList, petName) | ||
| 365 | + qrList = qrList + basicButtonWindow(petName) | ||
| 366 | + outputList = tones.getMessageOutputList(font, 'isLonely', imageUrl, 30, petName, relation) | ||
| 367 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 368 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 369 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 370 | + | ||
| 371 | +def get_isHard_message(): | ||
| 372 | + payload = request.get_json() | ||
| 373 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 374 | + | ||
| 375 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 376 | + petId = getPetId(kakaoUserKey) | ||
| 377 | + petName = getPetName(petId) | ||
| 378 | + relation = getRelation(kakaoUserKey, petId) | ||
| 379 | + font = getFont(kakaoUserKey, petId) | ||
| 380 | + | ||
| 381 | + category = '' | ||
| 382 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 383 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 384 | + | ||
| 385 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 386 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 387 | + contextList = [] | ||
| 388 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 389 | + try: | ||
| 390 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 391 | + except: | ||
| 392 | + repeatCount = 1 | ||
| 393 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 394 | + qrList = [] | ||
| 395 | + qrList = addRandomHintQR(qrList, petName) | ||
| 396 | + qrList = qrList + basicButtonWindow(petName) | ||
| 397 | + outputList = tones.getMessageOutputList(font, 'isHard', imageUrl, 30, petName, relation) | ||
| 398 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 399 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 400 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 401 | + | ||
| 402 | +def get_isWorry_message(): | ||
| 403 | + payload = request.get_json() | ||
| 404 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 405 | + | ||
| 406 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 407 | + petId = getPetId(kakaoUserKey) | ||
| 408 | + petName = getPetName(petId) | ||
| 409 | + relation = getRelation(kakaoUserKey, petId) | ||
| 410 | + font = getFont(kakaoUserKey, petId) | ||
| 411 | + | ||
| 412 | + category = '' | ||
| 413 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 414 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 415 | + | ||
| 416 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 417 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 418 | + contextList = [] | ||
| 419 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 420 | + try: | ||
| 421 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 422 | + except: | ||
| 423 | + repeatCount = 1 | ||
| 424 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 425 | + qrList = [] | ||
| 426 | + qrList = addRandomHintQR(qrList, petName) | ||
| 427 | + qrList = qrList + basicButtonWindow(petName) | ||
| 428 | + outputList = tones.getMessageOutputList(font, 'isWorry', imageUrl, 30, petName, relation) | ||
| 429 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 430 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 431 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 432 | + | ||
| 433 | +def get_isBoring_message(): | ||
| 434 | + payload = request.get_json() | ||
| 435 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 436 | + | ||
| 437 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 438 | + petId = getPetId(kakaoUserKey) | ||
| 439 | + petName = getPetName(petId) | ||
| 440 | + relation = getRelation(kakaoUserKey, petId) | ||
| 441 | + font = getFont(kakaoUserKey, petId) | ||
| 442 | + | ||
| 443 | + category = '' | ||
| 444 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 445 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 446 | + | ||
| 447 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 448 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 449 | + contextList = [] | ||
| 450 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 451 | + try: | ||
| 452 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 453 | + except: | ||
| 454 | + repeatCount = 1 | ||
| 455 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 456 | + qrList = [] | ||
| 457 | + qrList = addRandomHintQR(qrList, petName) | ||
| 458 | + qrList = qrList + basicButtonWindow(petName) | ||
| 459 | + outputList = tones.getMessageOutputList(font, 'isBoring', imageUrl, 30, petName, relation) | ||
| 460 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 461 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 462 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 463 | + | ||
| 464 | +def get_whatGender_message(): | ||
| 465 | + payload = request.get_json() | ||
| 466 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 467 | + | ||
| 468 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 469 | + petId = getPetId(kakaoUserKey) | ||
| 470 | + petName = getPetName(petId) | ||
| 471 | + relation = getRelation(kakaoUserKey, petId) | ||
| 472 | + font = getFont(kakaoUserKey, petId) | ||
| 473 | + | ||
| 474 | + category = '' | ||
| 475 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 476 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 477 | + | ||
| 478 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 479 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 480 | + contextList = [] | ||
| 481 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 482 | + try: | ||
| 483 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 484 | + except: | ||
| 485 | + repeatCount = 1 | ||
| 486 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 487 | + qrList = [] | ||
| 488 | + qrList = addRandomHintQR(qrList, petName) | ||
| 489 | + qrList = qrList + basicButtonWindow(petName) | ||
| 490 | + outputList = tones.getMessageOutputList(font, 'whatGender', imageUrl, 30, petName, relation) | ||
| 491 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 492 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 493 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 494 | + | ||
| 495 | +def get_howOld_message(): | ||
| 496 | + payload = request.get_json() | ||
| 497 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 498 | + | ||
| 499 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 500 | + petId = getPetId(kakaoUserKey) | ||
| 501 | + petName = getPetName(petId) | ||
| 502 | + relation = getRelation(kakaoUserKey, petId) | ||
| 503 | + font = getFont(kakaoUserKey, petId) | ||
| 504 | + | ||
| 505 | + category = '' | ||
| 506 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 507 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 508 | + | ||
| 509 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 510 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 511 | + contextList = [] | ||
| 512 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 513 | + try: | ||
| 514 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 515 | + except: | ||
| 516 | + repeatCount = 1 | ||
| 517 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 518 | + qrList = [] | ||
| 519 | + qrList = addRandomHintQR(qrList, petName) | ||
| 520 | + qrList = qrList + basicButtonWindow(petName) | ||
| 521 | + outputList = tones.getMessageOutputList(font, 'howOld', imageUrl, 30, petName, relation) | ||
| 522 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 523 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 524 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 525 | + | ||
| 526 | +def get_whatBreed_message(): | ||
| 527 | + payload = request.get_json() | ||
| 528 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 529 | + | ||
| 530 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 531 | + petId = getPetId(kakaoUserKey) | ||
| 532 | + petName = getPetName(petId) | ||
| 533 | + relation = getRelation(kakaoUserKey, petId) | ||
| 534 | + font = getFont(kakaoUserKey, petId) | ||
| 535 | + | ||
| 536 | + category = '' | ||
| 537 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 538 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 539 | + | ||
| 540 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 541 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 542 | + contextList = [] | ||
| 543 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 544 | + try: | ||
| 545 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 546 | + except: | ||
| 547 | + repeatCount = 1 | ||
| 548 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 549 | + qrList = [] | ||
| 550 | + qrList = addRandomHintQR(qrList, petName) | ||
| 551 | + qrList = qrList + basicButtonWindow(petName) | ||
| 552 | + outputList = tones.getMessageOutputList(font, 'whatBreed', imageUrl, 30, petName, relation) | ||
| 553 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 554 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 555 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 556 | + | ||
| 557 | +def get_isNeutered_message(): | ||
| 558 | + payload = request.get_json() | ||
| 559 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 560 | + | ||
| 561 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 562 | + petId = getPetId(kakaoUserKey) | ||
| 563 | + petName = getPetName(petId) | ||
| 564 | + relation = getRelation(kakaoUserKey, petId) | ||
| 565 | + font = getFont(kakaoUserKey, petId) | ||
| 566 | + | ||
| 567 | + category = '' | ||
| 568 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 569 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 570 | + | ||
| 571 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 572 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 573 | + contextList = [] | ||
| 574 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 575 | + try: | ||
| 576 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 577 | + except: | ||
| 578 | + repeatCount = 1 | ||
| 579 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 580 | + qrList = [] | ||
| 581 | + qrList = addRandomHintQR(qrList, petName) | ||
| 582 | + qrList = qrList + basicButtonWindow(petName) | ||
| 583 | + outputList = tones.getMessageOutputList(font, 'isNeutered', imageUrl, 30, petName, relation) | ||
| 584 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 585 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 586 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 587 | + | ||
| 588 | +def get_isDisease_message(): | ||
| 589 | + payload = request.get_json() | ||
| 590 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 591 | + | ||
| 592 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 593 | + petId = getPetId(kakaoUserKey) | ||
| 594 | + petName = getPetName(petId) | ||
| 595 | + relation = getRelation(kakaoUserKey, petId) | ||
| 596 | + font = getFont(kakaoUserKey, petId) | ||
| 597 | + | ||
| 598 | + category = '' | ||
| 599 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 600 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 601 | + | ||
| 602 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 603 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 604 | + contextList = [] | ||
| 605 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 606 | + try: | ||
| 607 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 608 | + except: | ||
| 609 | + repeatCount = 1 | ||
| 610 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 611 | + qrList = [] | ||
| 612 | + qrList = addRandomHintQR(qrList, petName) | ||
| 613 | + qrList = qrList + basicButtonWindow(petName) | ||
| 614 | + outputList = tones.getMessageOutputList(font, 'isDisease', imageUrl, 30, petName, relation) | ||
| 615 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 616 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 617 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 618 | + | ||
| 619 | +def get_whereIs_message(): | ||
| 620 | + payload = request.get_json() | ||
| 621 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 622 | + | ||
| 623 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 624 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 625 | + petId = getPetId(kakaoUserKey) | ||
| 626 | + petName = getPetName(petId) | ||
| 627 | + relation = getRelation(kakaoUserKey,petId) | ||
| 628 | + font = getFont(kakaoUserKey,petId) | ||
| 629 | + now = datetime.datetime.now() | ||
| 630 | + | ||
| 631 | + # 펫 이미지 리스트 불러오기 | ||
| 632 | + category = '' | ||
| 633 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 634 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 635 | + | ||
| 636 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 637 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 638 | + contextList = [] | ||
| 639 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 640 | + try: | ||
| 641 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 642 | + except: | ||
| 643 | + repeatCount = 1 | ||
| 644 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 645 | + qrList = [] | ||
| 646 | + qrList = addRandomHintQR(qrList, petName) | ||
| 647 | + qrList = qrList + basicButtonWindow(petName) | ||
| 648 | + | ||
| 649 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 650 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 651 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 652 | + else: | ||
| 653 | + # 60초 안에 두번이상 인식된 적 있는지 확인 | ||
| 654 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 655 | + if isDetected: | ||
| 656 | + outputList = tones.getMessageOutputList(font, 'whereIs', imageUrl, 90, petName, relation) | ||
| 657 | + else: | ||
| 658 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 659 | + | ||
| 660 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 661 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 662 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 663 | + | ||
| 664 | +def get_isHide_message(): | ||
| 665 | + payload = request.get_json() | ||
| 666 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 667 | + | ||
| 668 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 669 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 670 | + petId = getPetId(kakaoUserKey) | ||
| 671 | + petName = getPetName(petId) | ||
| 672 | + relation = getRelation(kakaoUserKey, petId) | ||
| 673 | + font = getFont(kakaoUserKey, petId) | ||
| 674 | + now = datetime.datetime.now() | ||
| 675 | + | ||
| 676 | + # 펫 이미지 리스트 불러오기 | ||
| 677 | + category = '' | ||
| 678 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 679 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 680 | + | ||
| 681 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 682 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 683 | + contextList = [] | ||
| 684 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 685 | + try: | ||
| 686 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 687 | + except: | ||
| 688 | + repeatCount = 1 | ||
| 689 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 690 | + qrList = [] | ||
| 691 | + qrList = addRandomHintQR(qrList, petName) | ||
| 692 | + qrList = qrList + basicButtonWindow(petName) | ||
| 693 | + | ||
| 694 | + if getAccountIdusingUserKey(kakaoUserKey) == '미연동': | ||
| 695 | + outputList = tones.getMessageOutputList(font, 'unconnected_panalty', imageUrl, 30, petName, relation) | ||
| 696 | + contextList.append(contextValue('utterance', 1, {'noise': 'alive'})) | ||
| 697 | + else: | ||
| 698 | + # 60초 안에 두번이상 인식된 적 있는지 확인 | ||
| 699 | + isDetected = checkObjectDetection(accountId, ['dog', 'cat'], 60, 2) | ||
| 700 | + if isDetected: | ||
| 701 | + outputList = tones.getMessageOutputList(font, 'isHide', imageUrl, 90, petName, relation) | ||
| 702 | + else: | ||
| 703 | + outputList = tones.getMessageOutputList(font, 'not_detected', imageUrl, 90, petName, relation) | ||
| 704 | + | ||
| 705 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 706 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 707 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 708 | + | ||
| 709 | +def get_wantEat_message(): | ||
| 710 | + payload = request.get_json() | ||
| 711 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 712 | + | ||
| 713 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 714 | + petId = getPetId(kakaoUserKey) | ||
| 715 | + petName = getPetName(petId) | ||
| 716 | + relation = getRelation(kakaoUserKey, petId) | ||
| 717 | + font = getFont(kakaoUserKey, petId) | ||
| 718 | + | ||
| 719 | + category = '' | ||
| 720 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 721 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 722 | + | ||
| 723 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 724 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 725 | + contextList = [] | ||
| 726 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 727 | + try: | ||
| 728 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 729 | + except: | ||
| 730 | + repeatCount = 1 | ||
| 731 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 732 | + qrList = [] | ||
| 733 | + qrList = addRandomHintQR(qrList, petName) | ||
| 734 | + qrList = qrList + basicButtonWindow(petName) | ||
| 735 | + outputList = tones.getMessageOutputList(font, 'wantEat', imageUrl, 30, petName, relation) | ||
| 736 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 737 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 738 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 739 | + | ||
| 740 | +def get_wantSee_message(): | ||
| 741 | + payload = request.get_json() | ||
| 742 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 743 | + | ||
| 744 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 745 | + petId = getPetId(kakaoUserKey) | ||
| 746 | + petName = getPetName(petId) | ||
| 747 | + relation = getRelation(kakaoUserKey, petId) | ||
| 748 | + font = getFont(kakaoUserKey, petId) | ||
| 749 | + | ||
| 750 | + category = '' | ||
| 751 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 752 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 753 | + | ||
| 754 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 755 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 756 | + contextList = [] | ||
| 757 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 758 | + try: | ||
| 759 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 760 | + except: | ||
| 761 | + repeatCount = 1 | ||
| 762 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 763 | + qrList = [] | ||
| 764 | + qrList = addRandomHintQR(qrList, petName) | ||
| 765 | + qrList = qrList + basicButtonWindow(petName) | ||
| 766 | + outputList = tones.getMessageOutputList(font, 'wantSee', imageUrl, 30, petName, relation) | ||
| 767 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 768 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 769 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 770 | + | ||
| 771 | +def get_howCanTalk_message(): | ||
| 772 | + payload = request.get_json() | ||
| 773 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 774 | + | ||
| 775 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 776 | + petId = getPetId(kakaoUserKey) | ||
| 777 | + petName = getPetName(petId) | ||
| 778 | + relation = getRelation(kakaoUserKey, petId) | ||
| 779 | + font = getFont(kakaoUserKey, petId) | ||
| 780 | + | ||
| 781 | + category = '' | ||
| 782 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 783 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 784 | + | ||
| 785 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 786 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 787 | + contextList = [] | ||
| 788 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 789 | + try: | ||
| 790 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 791 | + except: | ||
| 792 | + repeatCount = 1 | ||
| 793 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 794 | + qrList = [] | ||
| 795 | + qrList = addRandomHintQR(qrList, petName) | ||
| 796 | + qrList = qrList + basicButtonWindow(petName) | ||
| 797 | + outputList = tones.getMessageOutputList(font, 'howCanTalk', imageUrl, 90, petName, relation) | ||
| 798 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 799 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 800 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 801 | + | ||
| 802 | +def get_isAngry_message(): | ||
| 803 | + payload = request.get_json() | ||
| 804 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 805 | + | ||
| 806 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 807 | + petId = getPetId(kakaoUserKey) | ||
| 808 | + petName = getPetName(petId) | ||
| 809 | + relation = getRelation(kakaoUserKey, petId) | ||
| 810 | + font = getFont(kakaoUserKey, petId) | ||
| 811 | + | ||
| 812 | + category = '' | ||
| 813 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 814 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 815 | + | ||
| 816 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 817 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 818 | + contextList = [] | ||
| 819 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 820 | + try: | ||
| 821 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 822 | + except: | ||
| 823 | + repeatCount = 1 | ||
| 824 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 825 | + qrList = [] | ||
| 826 | + qrList = addRandomHintQR(qrList, petName) | ||
| 827 | + qrList = qrList + basicButtonWindow(petName) | ||
| 828 | + outputList = tones.getMessageOutputList(font, 'isAngry', imageUrl, 30, petName, relation) | ||
| 829 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 830 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 831 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 832 | + | ||
| 833 | +def get_whyNoise_message(): | ||
| 834 | + payload = request.get_json() | ||
| 835 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 836 | + | ||
| 837 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 838 | + petId = getPetId(kakaoUserKey) | ||
| 839 | + petName = getPetName(petId) | ||
| 840 | + relation = getRelation(kakaoUserKey, petId) | ||
| 841 | + font = getFont(kakaoUserKey, petId) | ||
| 842 | + | ||
| 843 | + category = '' | ||
| 844 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 845 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 846 | + | ||
| 847 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 848 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 849 | + contextList = [] | ||
| 850 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 851 | + try: | ||
| 852 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 853 | + except: | ||
| 854 | + repeatCount = 1 | ||
| 855 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 856 | + | ||
| 857 | + outputList = tones.getMessageOutputList(font, 'whyNoise', imageUrl, 0, petName, relation) | ||
| 858 | + qrList = [] | ||
| 859 | + qrList.append(blockQuickReply('😭', '😭', '5e5ab273b060a50001e5cecd')) | ||
| 860 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 861 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 862 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 863 | + | ||
| 864 | +def get_why_message(): | ||
| 865 | + payload = request.get_json() | ||
| 866 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 867 | + | ||
| 868 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 869 | + petId = getPetId(kakaoUserKey) | ||
| 870 | + petName = getPetName(petId) | ||
| 871 | + relation = getRelation(kakaoUserKey, petId) | ||
| 872 | + font = getFont(kakaoUserKey, petId) | ||
| 873 | + | ||
| 874 | + category = '' | ||
| 875 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 876 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 877 | + | ||
| 878 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 879 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 880 | + contextList = [] | ||
| 881 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 882 | + try: | ||
| 883 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 884 | + except: | ||
| 885 | + repeatCount = 1 | ||
| 886 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 887 | + qrList = [] | ||
| 888 | + qrList = addRandomHintQR(qrList, petName) | ||
| 889 | + qrList = qrList + basicButtonWindow(petName) | ||
| 890 | + | ||
| 891 | + if checkContextParamValue(payload, 'utterance', 'noise', 'alive'): | ||
| 892 | + outputList = tones.getMessageOutputList(font, 'whyNoise', imageUrl, 0, petName, relation) | ||
| 893 | + qrList = [] | ||
| 894 | + qrList.append(blockQuickReply('😭', '😭', '5e5ab273b060a50001e5cecd')) | ||
| 895 | + else: | ||
| 896 | + outputList = tones.getMessageOutputList(font, 'why', imageUrl, 30, petName, relation) | ||
| 897 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 898 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 899 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/setting.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | +import random | ||
| 8 | + | ||
| 9 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 10 | +from Functions.getInstance import * | ||
| 11 | +from Functions.checkFunction import * | ||
| 12 | +from Functions.updateDatabase import * | ||
| 13 | +from Functions.messageTypes import * | ||
| 14 | +from Functions import pyjosa | ||
| 15 | + | ||
| 16 | +# 환경설정 시작 | ||
| 17 | +def get_startSetting_message(): | ||
| 18 | + contextList = [] | ||
| 19 | + outputList = [] | ||
| 20 | + qrList = [] | ||
| 21 | + | ||
| 22 | + payload = request.get_json() | ||
| 23 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 24 | + petId = getPetId(kakaoUserKey) | ||
| 25 | + petName = getPetName(petId) | ||
| 26 | + nickname = getUserNickname(kakaoUserKey) | ||
| 27 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 28 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 29 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 30 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 31 | + | ||
| 32 | + # 프로필 리스트 | ||
| 33 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 34 | + | ||
| 35 | + # setting button window | ||
| 36 | + qrList += settingButtonWindow(kakaoUserKey, petName) | ||
| 37 | + | ||
| 38 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 39 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]메인', datetime.datetime.now(), 'none') | ||
| 40 | + | ||
| 41 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 42 | + | ||
| 43 | +def get_quitSetting_message(): | ||
| 44 | + contextList = [] | ||
| 45 | + outputList = [] | ||
| 46 | + qrList = [] | ||
| 47 | + | ||
| 48 | + payload = request.get_json() | ||
| 49 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 50 | + petId = getPetId(kakaoUserKey) | ||
| 51 | + petName = getPetName(petId) | ||
| 52 | + | ||
| 53 | + outputList.append(simpleText('[시스템] 설정이 완료되었습니다')) | ||
| 54 | + | ||
| 55 | + # 챗봇 노란버튼 | ||
| 56 | + qrList = basicButtonWindow(petName) | ||
| 57 | + | ||
| 58 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 59 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]종료', datetime.datetime.now(), 'none') | ||
| 60 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 61 | + | ||
| 62 | +def get_tryConnectAfterRegister_message(): | ||
| 63 | + contextList = [] | ||
| 64 | + outputList = [] | ||
| 65 | + qrList = [] | ||
| 66 | + | ||
| 67 | + payload = request.get_json() | ||
| 68 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 69 | + | ||
| 70 | + outputList.append(simpleText('스마트폰 공기계를 구하셨나보네요😃!')) | ||
| 71 | + outputList.append(simpleText('기기연동을 바로 진행하겠습니다')) | ||
| 72 | + qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5e576884ffa7480001ef080b')) | ||
| 73 | + qrList.append(blockQuickReply('진행합니다', '진행합니다', '5d3fa9d48192ac0001fc4ed1')) | ||
| 74 | + | ||
| 75 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 76 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]기기연동시도', datetime.datetime.now(), 'none') | ||
| 77 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 78 | + | ||
| 79 | +def get_quitConnectAfterRegister_message(): | ||
| 80 | + contextList = [] | ||
| 81 | + outputList = [] | ||
| 82 | + qrList = [] | ||
| 83 | + | ||
| 84 | + payload = request.get_json() | ||
| 85 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 86 | + petId = getPetId(kakaoUserKey) | ||
| 87 | + petName = getPetName(petId) | ||
| 88 | + nickname = getUserNickname(kakaoUserKey) | ||
| 89 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 90 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 91 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 92 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 93 | + | ||
| 94 | + outputList.append(simpleText('준비가 되면 다시 찾아와주세요')) | ||
| 95 | + | ||
| 96 | + # 프로필 리스트 | ||
| 97 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 98 | + | ||
| 99 | + # setting button window | ||
| 100 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 101 | + | ||
| 102 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 103 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]기기연동취소', datetime.datetime.now(), 'none') | ||
| 104 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 105 | + | ||
| 106 | +# 해당 챗봇과 연동된 모든 사용자데이터를 삭제 시도 | ||
| 107 | +def get_tryRemoveUser_message(): | ||
| 108 | + contextList = [] | ||
| 109 | + outputList = [] | ||
| 110 | + qrList = [] | ||
| 111 | + | ||
| 112 | + payload = request.get_json() | ||
| 113 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 114 | + | ||
| 115 | + outputList.append(simpleText('[시스템] 기기 연동을 해제하시겠습니까?')) | ||
| 116 | + outputList.append(simpleText('⚠️계속 진행할 시 카카오톡 내의 사용자 정보가 모두 삭제됩니다')) | ||
| 117 | + outputList.append(simpleText('(어플리케이션의 계정정보는 삭제되지 않으며, 다시 이용하려면 기기연동을 다시 진행해야합니다.)')) | ||
| 118 | + qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5dc0040fb617ea000165f420')) | ||
| 119 | + qrList.append(blockQuickReply('계속하겠습니다⚠️', '계속하겠습니다⚠️', '5dc00419b617ea000165f422')) | ||
| 120 | + | ||
| 121 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 122 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]유저삭제시도', datetime.datetime.now(), 'none') | ||
| 123 | + | ||
| 124 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 125 | + | ||
| 126 | +# 유저 삭제 과정 철회 | ||
| 127 | +def get_quitRemoveUser_message(): | ||
| 128 | + contextList = [] | ||
| 129 | + outputList = [] | ||
| 130 | + qrList = [] | ||
| 131 | + | ||
| 132 | + payload = request.get_json() | ||
| 133 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 134 | + petId = getPetId(kakaoUserKey) | ||
| 135 | + petName = getPetName(petId) | ||
| 136 | + nickname = getUserNickname(kakaoUserKey) | ||
| 137 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 138 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 139 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 140 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 141 | + | ||
| 142 | + outputList.append(simpleText('[시스템] 취소되었습니다')) | ||
| 143 | + | ||
| 144 | + # 프로필 리스트 | ||
| 145 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 146 | + | ||
| 147 | + # setting button window | ||
| 148 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 149 | + | ||
| 150 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 151 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]유저삭제취소', datetime.datetime.now(), 'none') | ||
| 152 | + | ||
| 153 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 154 | + | ||
| 155 | +# kakaoUserKey로 특정 유저 찾아서 삭제 | ||
| 156 | +def get_removeUser_message(): | ||
| 157 | + contextList = [] | ||
| 158 | + outputList = [] | ||
| 159 | + qrList = [] | ||
| 160 | + | ||
| 161 | + payload = request.get_json() | ||
| 162 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 163 | + | ||
| 164 | + # 유저의 모든 게시물 삭제 | ||
| 165 | + removeUserAllPost(kakaoUserKey) | ||
| 166 | + # S3에서 유저가 등록한 이미지 삭제 | ||
| 167 | + deleteUserImageInStorage(kakaoUserKey) | ||
| 168 | + # 유저 db 삭제 | ||
| 169 | + removeUser(kakaoUserKey) | ||
| 170 | + | ||
| 171 | + outputList.append(simpleText('[시스템] 기기 연동이 해제되었습니다')) | ||
| 172 | + outputList.append(simpleText('다시 연동하려면 인사를 건네주세요')) | ||
| 173 | + outputList.append(simpleText('(그만)')) | ||
| 174 | + | ||
| 175 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 176 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]유저삭제성공', datetime.datetime.now(), 'none') | ||
| 177 | + | ||
| 178 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 179 | + | ||
| 180 | +# 반려동물 말투 변경 시도 | ||
| 181 | +def get_tryChangeFont_message(): | ||
| 182 | + contextList = [] | ||
| 183 | + outputList = [] | ||
| 184 | + qrList = [] | ||
| 185 | + | ||
| 186 | + payload = request.get_json() | ||
| 187 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 188 | + petId = getPetId(kakaoUserKey) | ||
| 189 | + petName = getPetName(petId) | ||
| 190 | + | ||
| 191 | + outputList.append(simpleText('[시스템] ' + petName + '의 말투를 재설정합니다')) | ||
| 192 | + outputList.append(simpleText('말투를 골라주세요')) | ||
| 193 | + qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5dc0040fb617ea000165f420')) | ||
| 194 | + fonts = getUserFonts(kakaoUserKey) | ||
| 195 | + fontList = [] | ||
| 196 | + for font in fonts: | ||
| 197 | + fontList.append(getFontFromVar(font['font'])) | ||
| 198 | + qrList = fontSettingWindow(fontList) | ||
| 199 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 200 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]말투변경시도', datetime.datetime.now(), 'none') | ||
| 201 | + | ||
| 202 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 203 | + | ||
| 204 | +# 말투 변경 과정 철회 | ||
| 205 | +def get_quitChangeFont_message(): | ||
| 206 | + contextList = [] | ||
| 207 | + outputList = [] | ||
| 208 | + qrList = [] | ||
| 209 | + | ||
| 210 | + payload = request.get_json() | ||
| 211 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 212 | + petId = getPetId(kakaoUserKey) | ||
| 213 | + petName = getPetName(petId) | ||
| 214 | + nickname = getUserNickname(kakaoUserKey) | ||
| 215 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 216 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 217 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 218 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 219 | + | ||
| 220 | + outputList.append(simpleText('[시스템] 취소되었습니다')) | ||
| 221 | + | ||
| 222 | + # 프로필 리스트 | ||
| 223 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 224 | + | ||
| 225 | + # setting button window | ||
| 226 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 227 | + | ||
| 228 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 229 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]말투변경취소', datetime.datetime.now(), 'none') | ||
| 230 | + | ||
| 231 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 232 | + | ||
| 233 | +# 반려동물과의 관계(relation) 변경 시도 | ||
| 234 | +def get_tryChangeRelation_message(): | ||
| 235 | + contextList = [] | ||
| 236 | + outputList = [] | ||
| 237 | + qrList = [] | ||
| 238 | + | ||
| 239 | + payload = request.get_json() | ||
| 240 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 241 | + petId = getPetId(kakaoUserKey) | ||
| 242 | + petName = getPetName(petId) | ||
| 243 | + | ||
| 244 | + outputList.append(simpleText('[시스템] ' + petName + '가 앞으로 당신을 뭐라고 불러주면 좋을까요?')) | ||
| 245 | + qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5dc0040fb617ea000165f420')) | ||
| 246 | + qrList = relationSettingWindow() | ||
| 247 | + | ||
| 248 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 249 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]호칭변경시도', datetime.datetime.now(), 'none') | ||
| 250 | + | ||
| 251 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 252 | + | ||
| 253 | +# 반려동물과의 관계(relation) 변경 과정 철회 | ||
| 254 | +def get_quitChangeRelation_message(): | ||
| 255 | + contextList = [] | ||
| 256 | + outputList = [] | ||
| 257 | + qrList = [] | ||
| 258 | + | ||
| 259 | + payload = request.get_json() | ||
| 260 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 261 | + petId = getPetId(kakaoUserKey) | ||
| 262 | + petName = getPetName(petId) | ||
| 263 | + nickname = getUserNickname(kakaoUserKey) | ||
| 264 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 265 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 266 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 267 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 268 | + | ||
| 269 | + outputList.append(simpleText('[시스템] 취소되었습니다')) | ||
| 270 | + | ||
| 271 | + # 프로필 리스트 | ||
| 272 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 273 | + | ||
| 274 | + # setting button window | ||
| 275 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 276 | + | ||
| 277 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 278 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]호칭변경취소', datetime.datetime.now(), 'none') | ||
| 279 | + | ||
| 280 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 281 | + | ||
| 282 | +# 닉네임 변경 시도 | ||
| 283 | +def get_tryChangeNickname_message(): | ||
| 284 | + contextList = [] | ||
| 285 | + outputList = [] | ||
| 286 | + qrList = [] | ||
| 287 | + | ||
| 288 | + payload = request.get_json() | ||
| 289 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 290 | + | ||
| 291 | + outputList.append(simpleText('[시스템] 새로운 닉네임을 입력해주세요')) | ||
| 292 | + | ||
| 293 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 294 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]닉네임변경시도', datetime.datetime.now(), 'none') | ||
| 295 | + contextList.append(contextValue('nickname', 1, {'change_nickname': 'alive'})) | ||
| 296 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 297 | + | ||
| 298 | +# 닉네임 변경 과정 철회 | ||
| 299 | +def get_quitChangeNickname_message(): | ||
| 300 | + contextList = [] | ||
| 301 | + outputList = [] | ||
| 302 | + qrList = [] | ||
| 303 | + | ||
| 304 | + payload = request.get_json() | ||
| 305 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 306 | + petId = getPetId(kakaoUserKey) | ||
| 307 | + petName = getPetName(petId) | ||
| 308 | + nickname = getUserNickname(kakaoUserKey) | ||
| 309 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 310 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 311 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 312 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 313 | + | ||
| 314 | + outputList.append(simpleText('[시스템] 취소되었습니다')) | ||
| 315 | + | ||
| 316 | + # 프로필 리스트 | ||
| 317 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 318 | + | ||
| 319 | + # setting button window | ||
| 320 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 321 | + | ||
| 322 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 323 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]닉네임변경취소', datetime.datetime.now(), 'none') | ||
| 324 | + | ||
| 325 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/statement.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | +import random | ||
| 8 | + | ||
| 9 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 10 | +from Functions.getInstance import * | ||
| 11 | +from Functions.checkFunction import * | ||
| 12 | +from Functions.updateDatabase import * | ||
| 13 | +from Functions.messageTypes import * | ||
| 14 | + | ||
| 15 | +import tones | ||
| 16 | + | ||
| 17 | +def get_hello_message(): | ||
| 18 | + payload = request.get_json() | ||
| 19 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 20 | + # 유저 발화(utterance) 불러오기 | ||
| 21 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 22 | + # accountId 불러오기 | ||
| 23 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 24 | + # petId 불러오기 | ||
| 25 | + petId = getPetId(kakaoUserKey) | ||
| 26 | + # petName 불러오기 | ||
| 27 | + petName = getPetName(petId) | ||
| 28 | + # relation 불러오기 | ||
| 29 | + relation = getRelation(kakaoUserKey, petId) | ||
| 30 | + # font 불러오기 | ||
| 31 | + font = getFont(kakaoUserKey, petId) | ||
| 32 | + # 현재 시간 불러오기 | ||
| 33 | + now = datetime.datetime.now() | ||
| 34 | + | ||
| 35 | + # 펫 이미지 리스트 불러오기 | ||
| 36 | + category = '' | ||
| 37 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 38 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 39 | + | ||
| 40 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 41 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 42 | + contextList = [] | ||
| 43 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 44 | + try: | ||
| 45 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 46 | + except: | ||
| 47 | + repeatCount = 1 | ||
| 48 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 49 | + qrList = [] | ||
| 50 | + qrList = addRandomHintQR(qrList, petName) | ||
| 51 | + qrList = qrList + basicButtonWindow(petName) | ||
| 52 | + outputList = tones.getMessageOutputList(font, 'hello', imageUrl, 90, petName, relation) | ||
| 53 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 54 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 55 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 56 | + | ||
| 57 | +def get_showPicture_message(): | ||
| 58 | + payload = request.get_json() | ||
| 59 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 60 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 61 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 62 | + petId = getPetId(kakaoUserKey) | ||
| 63 | + petName = getPetName(petId) | ||
| 64 | + relation = getRelation(kakaoUserKey, petId) | ||
| 65 | + font = getFont(kakaoUserKey, petId) | ||
| 66 | + now = datetime.datetime.now() | ||
| 67 | + | ||
| 68 | + # 펫 이미지 리스트 불러오기 | ||
| 69 | + category = '' | ||
| 70 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 71 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 72 | + | ||
| 73 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 74 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 75 | + contextList = [] | ||
| 76 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 77 | + try: | ||
| 78 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 79 | + except: | ||
| 80 | + repeatCount = 1 | ||
| 81 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 82 | + qrList = [] | ||
| 83 | + qrList = addRandomHintQR(qrList, petName) | ||
| 84 | + qrList = qrList + basicButtonWindow(petName) | ||
| 85 | + outputList = tones.getMessageOutputList(font, 'showPicture', imageUrl, 90, petName, relation) | ||
| 86 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 87 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 88 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 89 | + | ||
| 90 | +def get_hey_message(): | ||
| 91 | + payload = request.get_json() | ||
| 92 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 93 | + | ||
| 94 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 95 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 96 | + petId = getPetId(kakaoUserKey) | ||
| 97 | + petName = getPetName(petId) | ||
| 98 | + relation = getRelation(kakaoUserKey, petId) | ||
| 99 | + font = getFont(kakaoUserKey, petId) | ||
| 100 | + now = datetime.datetime.now() | ||
| 101 | + | ||
| 102 | + category = '' | ||
| 103 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 104 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 105 | + | ||
| 106 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 107 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 108 | + contextList = [] | ||
| 109 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 110 | + try: | ||
| 111 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 112 | + except: | ||
| 113 | + repeatCount = 1 | ||
| 114 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 115 | + qrList = [] | ||
| 116 | + qrList = addRandomHintQR(qrList, petName) | ||
| 117 | + qrList = qrList + basicButtonWindow(petName) | ||
| 118 | + outputList = tones.getMessageOutputList(font, 'hey', imageUrl, 90, petName, relation) | ||
| 119 | + | ||
| 120 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 121 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 122 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 123 | + | ||
| 124 | +def get_yes_message(): | ||
| 125 | + payload = request.get_json() | ||
| 126 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 127 | + | ||
| 128 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 129 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 130 | + petId = getPetId(kakaoUserKey) | ||
| 131 | + petName = getPetName(petId) | ||
| 132 | + relation = getRelation(kakaoUserKey, petId) | ||
| 133 | + font = getFont(kakaoUserKey, petId) | ||
| 134 | + now = datetime.datetime.now() | ||
| 135 | + category = '' | ||
| 136 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 137 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 138 | + | ||
| 139 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 140 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 141 | + contextList = [] | ||
| 142 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 143 | + try: | ||
| 144 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 145 | + except: | ||
| 146 | + repeatCount = 1 | ||
| 147 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 148 | + qrList = [] | ||
| 149 | + qrList = addRandomHintQR(qrList, petName) | ||
| 150 | + qrList = qrList + basicButtonWindow(petName) | ||
| 151 | + outputList = tones.getMessageOutputList(font, 'yes', imageUrl, 90, petName, relation) | ||
| 152 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 153 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 154 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 155 | + | ||
| 156 | +def get_bye_message(): | ||
| 157 | + payload = request.get_json() | ||
| 158 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 159 | + | ||
| 160 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 161 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 162 | + petId = getPetId(kakaoUserKey) | ||
| 163 | + petName = getPetName(petId) | ||
| 164 | + relation = getRelation(kakaoUserKey, petId) | ||
| 165 | + font = getFont(kakaoUserKey, petId) | ||
| 166 | + now = datetime.datetime.now() | ||
| 167 | + category = '' | ||
| 168 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 169 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 170 | + | ||
| 171 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 172 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 173 | + contextList = [] | ||
| 174 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 175 | + try: | ||
| 176 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 177 | + except: | ||
| 178 | + repeatCount = 1 | ||
| 179 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 180 | + qrList = [] | ||
| 181 | + qrList = addRandomHintQR(qrList, petName) | ||
| 182 | + qrList = qrList + basicButtonWindow(petName) | ||
| 183 | + outputList = tones.getMessageOutputList(font, 'bye', imageUrl, 90, petName, relation) | ||
| 184 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 185 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 186 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 187 | + | ||
| 188 | +def get_love_message(): | ||
| 189 | + payload = request.get_json() | ||
| 190 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 191 | + | ||
| 192 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 193 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 194 | + petId = getPetId(kakaoUserKey) | ||
| 195 | + petName = getPetName(petId) | ||
| 196 | + relation = getRelation(kakaoUserKey, petId) | ||
| 197 | + font = getFont(kakaoUserKey, petId) | ||
| 198 | + now = datetime.datetime.now() | ||
| 199 | + | ||
| 200 | + category = '' | ||
| 201 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 202 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 203 | + | ||
| 204 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 205 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 206 | + contextList = [] | ||
| 207 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 208 | + try: | ||
| 209 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 210 | + except: | ||
| 211 | + repeatCount = 1 | ||
| 212 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 213 | + qrList = [] | ||
| 214 | + qrList = addRandomHintQR(qrList, petName) | ||
| 215 | + qrList = qrList + basicButtonWindow(petName) | ||
| 216 | + outputList = tones.getMessageOutputList(font, 'love', imageUrl, 90, petName, relation) | ||
| 217 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 218 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 219 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 220 | + | ||
| 221 | +def get_cute_message(): | ||
| 222 | + payload = request.get_json() | ||
| 223 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 224 | + | ||
| 225 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 226 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 227 | + petId = getPetId(kakaoUserKey) | ||
| 228 | + petName = getPetName(petId) | ||
| 229 | + relation = getRelation(kakaoUserKey, petId) | ||
| 230 | + font = getFont(kakaoUserKey, petId) | ||
| 231 | + now = datetime.datetime.now() | ||
| 232 | + | ||
| 233 | + category = '' | ||
| 234 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 235 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 236 | + | ||
| 237 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 238 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 239 | + contextList = [] | ||
| 240 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 241 | + try: | ||
| 242 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 243 | + except: | ||
| 244 | + repeatCount = 1 | ||
| 245 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 246 | + qrList = [] | ||
| 247 | + qrList = addRandomHintQR(qrList, petName) | ||
| 248 | + qrList = qrList + basicButtonWindow(petName) | ||
| 249 | + outputList = tones.getMessageOutputList(font, 'cute', imageUrl, 90, petName, relation) | ||
| 250 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 251 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 252 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 253 | + | ||
| 254 | +def get_fine_message(): | ||
| 255 | + payload = request.get_json() | ||
| 256 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 257 | + | ||
| 258 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 259 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 260 | + petId = getPetId(kakaoUserKey) | ||
| 261 | + petName = getPetName(petId) | ||
| 262 | + relation = getRelation(kakaoUserKey, petId) | ||
| 263 | + font = getFont(kakaoUserKey, petId) | ||
| 264 | + now = datetime.datetime.now() | ||
| 265 | + | ||
| 266 | + category = '' | ||
| 267 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 268 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 269 | + | ||
| 270 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 271 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 272 | + contextList = [] | ||
| 273 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 274 | + try: | ||
| 275 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 276 | + except: | ||
| 277 | + repeatCount = 1 | ||
| 278 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 279 | + qrList = [] | ||
| 280 | + qrList = addRandomHintQR(qrList, petName) | ||
| 281 | + qrList = qrList + basicButtonWindow(petName) | ||
| 282 | + outputList = tones.getMessageOutputList(font, 'fine', imageUrl, 90, petName, relation) | ||
| 283 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 284 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 285 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 286 | + | ||
| 287 | +def get_missYou_message(): | ||
| 288 | + payload = request.get_json() | ||
| 289 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 290 | + | ||
| 291 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 292 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 293 | + petId = getPetId(kakaoUserKey) | ||
| 294 | + petName = getPetName(petId) | ||
| 295 | + relation = getRelation(kakaoUserKey, petId) | ||
| 296 | + font = getFont(kakaoUserKey, petId) | ||
| 297 | + now = datetime.datetime.now() | ||
| 298 | + | ||
| 299 | + category = '' | ||
| 300 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 301 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 302 | + | ||
| 303 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 304 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 305 | + contextList = [] | ||
| 306 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 307 | + try: | ||
| 308 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 309 | + except: | ||
| 310 | + repeatCount = 1 | ||
| 311 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 312 | + qrList = [] | ||
| 313 | + qrList = addRandomHintQR(qrList, petName) | ||
| 314 | + qrList = qrList + basicButtonWindow(petName) | ||
| 315 | + outputList = tones.getMessageOutputList(font, 'missYou', imageUrl, 90, petName, relation) | ||
| 316 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 317 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 318 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 319 | + | ||
| 320 | +def get_goodJob_message(): | ||
| 321 | + payload = request.get_json() | ||
| 322 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 323 | + | ||
| 324 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 325 | + petId = getPetId(kakaoUserKey) | ||
| 326 | + petName = getPetName(petId) | ||
| 327 | + relation = getRelation(kakaoUserKey, petId) | ||
| 328 | + font = getFont(kakaoUserKey, petId) | ||
| 329 | + now = datetime.datetime.now() | ||
| 330 | + | ||
| 331 | + category = '' | ||
| 332 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 333 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 334 | + | ||
| 335 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 336 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 337 | + contextList = [] | ||
| 338 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 339 | + try: | ||
| 340 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 341 | + except: | ||
| 342 | + repeatCount = 1 | ||
| 343 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 344 | + qrList = [] | ||
| 345 | + qrList = addRandomHintQR(qrList, petName) | ||
| 346 | + qrList = qrList + basicButtonWindow(petName) | ||
| 347 | + outputList = tones.getMessageOutputList(font, 'goodJob', imageUrl, 90, petName, relation) | ||
| 348 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 349 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 350 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 351 | + | ||
| 352 | +def get_goodNight_message(): | ||
| 353 | + payload = request.get_json() | ||
| 354 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 355 | + | ||
| 356 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 357 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 358 | + petId = getPetId(kakaoUserKey) | ||
| 359 | + petName = getPetName(petId) | ||
| 360 | + relation = getRelation(kakaoUserKey, petId) | ||
| 361 | + font = getFont(kakaoUserKey, petId) | ||
| 362 | + now = datetime.datetime.now() | ||
| 363 | + | ||
| 364 | + category = '' | ||
| 365 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 366 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 367 | + | ||
| 368 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 369 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 370 | + contextList = [] | ||
| 371 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 372 | + try: | ||
| 373 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 374 | + except: | ||
| 375 | + repeatCount = 1 | ||
| 376 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 377 | + qrList = [] | ||
| 378 | + qrList = addRandomHintQR(qrList, petName) | ||
| 379 | + qrList = qrList + basicButtonWindow(petName) | ||
| 380 | + outputList = tones.getMessageOutputList(font, 'goodNight', imageUrl, 90, petName, relation) | ||
| 381 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 382 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 383 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 384 | + | ||
| 385 | +def get_sorry_message(): | ||
| 386 | + payload = request.get_json() | ||
| 387 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 388 | + | ||
| 389 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 390 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 391 | + petId = getPetId(kakaoUserKey) | ||
| 392 | + petName = getPetName(petId) | ||
| 393 | + relation = getRelation(kakaoUserKey, petId) | ||
| 394 | + font = getFont(kakaoUserKey, petId) | ||
| 395 | + now = datetime.datetime.now() | ||
| 396 | + | ||
| 397 | + category = '' | ||
| 398 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 399 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 400 | + | ||
| 401 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 402 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 403 | + contextList = [] | ||
| 404 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 405 | + try: | ||
| 406 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 407 | + except: | ||
| 408 | + repeatCount = 1 | ||
| 409 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 410 | + qrList = [] | ||
| 411 | + qrList = addRandomHintQR(qrList, petName) | ||
| 412 | + qrList = qrList + basicButtonWindow(petName) | ||
| 413 | + outputList = tones.getMessageOutputList(font, 'sorry', imageUrl, 90, petName, relation) | ||
| 414 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 415 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 416 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 417 | + | ||
| 418 | +def get_scold_message(): | ||
| 419 | + payload = request.get_json() | ||
| 420 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 421 | + | ||
| 422 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 423 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 424 | + petId = getPetId(kakaoUserKey) | ||
| 425 | + petName = getPetName(petId) | ||
| 426 | + relation = getRelation(kakaoUserKey, petId) | ||
| 427 | + font = getFont(kakaoUserKey, petId) | ||
| 428 | + now = datetime.datetime.now() | ||
| 429 | + | ||
| 430 | + category = '' | ||
| 431 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 432 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 433 | + | ||
| 434 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 435 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 436 | + contextList = [] | ||
| 437 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 438 | + try: | ||
| 439 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 440 | + except: | ||
| 441 | + repeatCount = 1 | ||
| 442 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 443 | + qrList = [] | ||
| 444 | + qrList = addRandomHintQR(qrList, petName) | ||
| 445 | + qrList = qrList + basicButtonWindow(petName) | ||
| 446 | + outputList = tones.getMessageOutputList(font, 'scold', imageUrl, 90, petName, relation) | ||
| 447 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 448 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 449 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 450 | + | ||
| 451 | +def get_thanks_message(): | ||
| 452 | + payload = request.get_json() | ||
| 453 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 454 | + | ||
| 455 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 456 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 457 | + petId = getPetId(kakaoUserKey) | ||
| 458 | + petName = getPetName(petId) | ||
| 459 | + relation = getRelation(kakaoUserKey, petId) | ||
| 460 | + font = getFont(kakaoUserKey, petId) | ||
| 461 | + now = datetime.datetime.now() | ||
| 462 | + | ||
| 463 | + category = '' | ||
| 464 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 465 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 466 | + | ||
| 467 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 468 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 469 | + contextList = [] | ||
| 470 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 471 | + try: | ||
| 472 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 473 | + except: | ||
| 474 | + repeatCount = 1 | ||
| 475 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 476 | + qrList = [] | ||
| 477 | + qrList = addRandomHintQR(qrList, petName) | ||
| 478 | + qrList = qrList + basicButtonWindow(petName) | ||
| 479 | + outputList = tones.getMessageOutputList(font, 'thanks', imageUrl, 90, petName, relation) | ||
| 480 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 481 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 482 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 483 | + | ||
| 484 | +def get_notCute_message(): | ||
| 485 | + payload = request.get_json() | ||
| 486 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 487 | + | ||
| 488 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 489 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 490 | + petId = getPetId(kakaoUserKey) | ||
| 491 | + petName = getPetName(petId) | ||
| 492 | + relation = getRelation(kakaoUserKey, petId) | ||
| 493 | + font = getFont(kakaoUserKey, petId) | ||
| 494 | + now = datetime.datetime.now() | ||
| 495 | + | ||
| 496 | + category = '' | ||
| 497 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 498 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 499 | + | ||
| 500 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 501 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 502 | + contextList = [] | ||
| 503 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 504 | + try: | ||
| 505 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 506 | + except: | ||
| 507 | + repeatCount = 1 | ||
| 508 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 509 | + qrList = [] | ||
| 510 | + qrList = addRandomHintQR(qrList, petName) | ||
| 511 | + qrList = qrList + basicButtonWindow(petName) | ||
| 512 | + outputList = tones.getMessageOutputList(font, 'notCute', imageUrl, 90, petName, relation) | ||
| 513 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 514 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 515 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 516 | + | ||
| 517 | +def get_dontNeedToKnow_message(): | ||
| 518 | + payload = request.get_json() | ||
| 519 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 520 | + | ||
| 521 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 522 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 523 | + petId = getPetId(kakaoUserKey) | ||
| 524 | + petName = getPetName(petId) | ||
| 525 | + relation = getRelation(kakaoUserKey, petId) | ||
| 526 | + font = getFont(kakaoUserKey, petId) | ||
| 527 | + now = datetime.datetime.now() | ||
| 528 | + | ||
| 529 | + category = '' | ||
| 530 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 531 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 532 | + | ||
| 533 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 534 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 535 | + contextList = [] | ||
| 536 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 537 | + try: | ||
| 538 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 539 | + except: | ||
| 540 | + repeatCount = 1 | ||
| 541 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 542 | + qrList = [] | ||
| 543 | + qrList = addRandomHintQR(qrList, petName) | ||
| 544 | + qrList = qrList + basicButtonWindow(petName) | ||
| 545 | + outputList = tones.getMessageOutputList(font, 'dontNeedToKnow', imageUrl, 90, petName, relation) | ||
| 546 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 547 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 548 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 549 | + | ||
| 550 | +def get_cheerUp_message(): | ||
| 551 | + payload = request.get_json() | ||
| 552 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 553 | + | ||
| 554 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 555 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 556 | + petId = getPetId(kakaoUserKey) | ||
| 557 | + petName = getPetName(petId) | ||
| 558 | + relation = getRelation(kakaoUserKey, petId) | ||
| 559 | + font = getFont(kakaoUserKey, petId) | ||
| 560 | + now = datetime.datetime.now() | ||
| 561 | + | ||
| 562 | + category = '' | ||
| 563 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 564 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 565 | + | ||
| 566 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 567 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 568 | + contextList = [] | ||
| 569 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 570 | + try: | ||
| 571 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 572 | + except: | ||
| 573 | + repeatCount = 1 | ||
| 574 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 575 | + qrList = [] | ||
| 576 | + qrList = addRandomHintQR(qrList, petName) | ||
| 577 | + qrList = qrList + basicButtonWindow(petName) | ||
| 578 | + outputList = tones.getMessageOutputList(font, 'cheerUp', imageUrl, 90, petName, relation) | ||
| 579 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 580 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 581 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 582 | + | ||
| 583 | +def get_yourRight_message(): | ||
| 584 | + payload = request.get_json() | ||
| 585 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 586 | + | ||
| 587 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 588 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 589 | + petId = getPetId(kakaoUserKey) | ||
| 590 | + petName = getPetName(petId) | ||
| 591 | + relation = getRelation(kakaoUserKey, petId) | ||
| 592 | + font = getFont(kakaoUserKey, petId) | ||
| 593 | + now = datetime.datetime.now() | ||
| 594 | + | ||
| 595 | + category = '' | ||
| 596 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 597 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 598 | + | ||
| 599 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 600 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 601 | + contextList = [] | ||
| 602 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 603 | + try: | ||
| 604 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 605 | + except: | ||
| 606 | + repeatCount = 1 | ||
| 607 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 608 | + qrList = [] | ||
| 609 | + qrList = addRandomHintQR(qrList, petName) | ||
| 610 | + qrList = qrList + basicButtonWindow(petName) | ||
| 611 | + outputList = tones.getMessageOutputList(font, 'yourRight', imageUrl, 90, petName, relation) | ||
| 612 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 613 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 614 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 615 | + | ||
| 616 | +def get_promise_message(): | ||
| 617 | + payload = request.get_json() | ||
| 618 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 619 | + | ||
| 620 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 621 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 622 | + petId = getPetId(kakaoUserKey) | ||
| 623 | + petName = getPetName(petId) | ||
| 624 | + relation = getRelation(kakaoUserKey, petId) | ||
| 625 | + font = getFont(kakaoUserKey, petId) | ||
| 626 | + now = datetime.datetime.now() | ||
| 627 | + | ||
| 628 | + category = '' | ||
| 629 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 630 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 631 | + | ||
| 632 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 633 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 634 | + contextList = [] | ||
| 635 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 636 | + try: | ||
| 637 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 638 | + except: | ||
| 639 | + repeatCount = 1 | ||
| 640 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 641 | + qrList = [] | ||
| 642 | + qrList = addRandomHintQR(qrList, petName) | ||
| 643 | + qrList = qrList + basicButtonWindow(petName) | ||
| 644 | + outputList = tones.getMessageOutputList(font, 'promise', imageUrl, 90, petName, relation) | ||
| 645 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 646 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 647 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 648 | + | ||
| 649 | +def get_dontSleep_message(): | ||
| 650 | + payload = request.get_json() | ||
| 651 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 652 | + | ||
| 653 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 654 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 655 | + petId = getPetId(kakaoUserKey) | ||
| 656 | + petName = getPetName(petId) | ||
| 657 | + relation = getRelation(kakaoUserKey, petId) | ||
| 658 | + font = getFont(kakaoUserKey, petId) | ||
| 659 | + now = datetime.datetime.now() | ||
| 660 | + | ||
| 661 | + category = '' | ||
| 662 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 663 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 664 | + | ||
| 665 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 666 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 667 | + contextList = [] | ||
| 668 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 669 | + try: | ||
| 670 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 671 | + except: | ||
| 672 | + repeatCount = 1 | ||
| 673 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 674 | + qrList = [] | ||
| 675 | + qrList = addRandomHintQR(qrList, petName) | ||
| 676 | + qrList = qrList + basicButtonWindow(petName) | ||
| 677 | + outputList = tones.getMessageOutputList(font, 'dontSleep', imageUrl, 90, petName, relation) | ||
| 678 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 679 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 680 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 681 | + | ||
| 682 | +def get_idiot_message(): | ||
| 683 | + payload = request.get_json() | ||
| 684 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 685 | + | ||
| 686 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 687 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 688 | + petId = getPetId(kakaoUserKey) | ||
| 689 | + petName = getPetName(petId) | ||
| 690 | + relation = getRelation(kakaoUserKey, petId) | ||
| 691 | + font = getFont(kakaoUserKey, petId) | ||
| 692 | + now = datetime.datetime.now() | ||
| 693 | + | ||
| 694 | + category = '' | ||
| 695 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 696 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 697 | + | ||
| 698 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 699 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 700 | + contextList = [] | ||
| 701 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 702 | + try: | ||
| 703 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 704 | + except: | ||
| 705 | + repeatCount = 1 | ||
| 706 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 707 | + qrList = [] | ||
| 708 | + qrList = addRandomHintQR(qrList, petName) | ||
| 709 | + qrList = qrList + basicButtonWindow(petName) | ||
| 710 | + outputList = tones.getMessageOutputList(font, 'idiot', imageUrl, 90, petName, relation) | ||
| 711 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 712 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 713 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 714 | + | ||
| 715 | +def get_onlyYou_message(): | ||
| 716 | + payload = request.get_json() | ||
| 717 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 718 | + | ||
| 719 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 720 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 721 | + petId = getPetId(kakaoUserKey) | ||
| 722 | + petName = getPetName(petId) | ||
| 723 | + relation = getRelation(kakaoUserKey, petId) | ||
| 724 | + font = getFont(kakaoUserKey, petId) | ||
| 725 | + | ||
| 726 | + category = '' | ||
| 727 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 728 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 729 | + | ||
| 730 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 731 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 732 | + contextList = [] | ||
| 733 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 734 | + try: | ||
| 735 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 736 | + except: | ||
| 737 | + repeatCount = 1 | ||
| 738 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 739 | + qrList = [] | ||
| 740 | + qrList = addRandomHintQR(qrList, petName) | ||
| 741 | + qrList = qrList + basicButtonWindow(petName) | ||
| 742 | + outputList = tones.getMessageOutputList(font, 'onlyYou', imageUrl, 90, petName, relation) | ||
| 743 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 744 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 745 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 746 | + | ||
| 747 | +def get_swearWord_message(): | ||
| 748 | + payload = request.get_json() | ||
| 749 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 750 | + | ||
| 751 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 752 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 753 | + petId = getPetId(kakaoUserKey) | ||
| 754 | + petName = getPetName(petId) | ||
| 755 | + relation = getRelation(kakaoUserKey, petId) | ||
| 756 | + font = getFont(kakaoUserKey, petId) | ||
| 757 | + | ||
| 758 | + category = '' | ||
| 759 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 760 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 761 | + | ||
| 762 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 763 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 764 | + contextList = [] | ||
| 765 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 766 | + try: | ||
| 767 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 768 | + except: | ||
| 769 | + repeatCount = 1 | ||
| 770 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 771 | + qrList = [] | ||
| 772 | + qrList = addRandomHintQR(qrList, petName) | ||
| 773 | + qrList = qrList + basicButtonWindow(petName) | ||
| 774 | + outputList = tones.getMessageOutputList(font, 'swearWord', imageUrl, 90, petName, relation) | ||
| 775 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 776 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 777 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 778 | + | ||
| 779 | +def get_dontKnow_message(): | ||
| 780 | + payload = request.get_json() | ||
| 781 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 782 | + | ||
| 783 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 784 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 785 | + petId = getPetId(kakaoUserKey) | ||
| 786 | + petName = getPetName(petId) | ||
| 787 | + relation = getRelation(kakaoUserKey, petId) | ||
| 788 | + font = getFont(kakaoUserKey, petId) | ||
| 789 | + | ||
| 790 | + category = '' | ||
| 791 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 792 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 793 | + | ||
| 794 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 795 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 796 | + contextList = [] | ||
| 797 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 798 | + try: | ||
| 799 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 800 | + except: | ||
| 801 | + repeatCount = 1 | ||
| 802 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 803 | + qrList = [] | ||
| 804 | + qrList = addRandomHintQR(qrList, petName) | ||
| 805 | + qrList = qrList + basicButtonWindow(petName) | ||
| 806 | + | ||
| 807 | + if checkContextParamValue(payload, 'utterance', 'nonsense_quiz', 'incorrect'): | ||
| 808 | + quizNumber = getContextParamValue(payload, 'utterance', 'nonsense_quiz_number') | ||
| 809 | + outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_X', imageUrl, 90, petName, relation) | ||
| 810 | + elif checkContextParamValue(payload, 'utterance', 'word_relay', 'process'): | ||
| 811 | + outputList = tones.getMessageOutputList(font, 'lose_word_relay', imageUrl, 0, petName, relation) | ||
| 812 | + qrList.append(blockQuickReply('😅', '😅', '5e5cbe0d7b777800010f7d95')) | ||
| 813 | + contextList.append(contextValue('utterance', 1, {'word_relay': 'lose', 'repeat_count': repeatCount})) | ||
| 814 | + else: | ||
| 815 | + outputList = tones.getMessageOutputList(font, 'dontKnow', imageUrl, 90, petName, relation) | ||
| 816 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 817 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 818 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 819 | + | ||
| 820 | +def get_wantKnow_message(): | ||
| 821 | + payload = request.get_json() | ||
| 822 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 823 | + | ||
| 824 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 825 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 826 | + petId = getPetId(kakaoUserKey) | ||
| 827 | + petName = getPetName(petId) | ||
| 828 | + relation = getRelation(kakaoUserKey, petId) | ||
| 829 | + font = getFont(kakaoUserKey, petId) | ||
| 830 | + | ||
| 831 | + category = '' | ||
| 832 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 833 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 834 | + | ||
| 835 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 836 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 837 | + contextList = [] | ||
| 838 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 839 | + try: | ||
| 840 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 841 | + except: | ||
| 842 | + repeatCount = 1 | ||
| 843 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 844 | + qrList = [] | ||
| 845 | + qrList = addRandomHintQR(qrList, petName) | ||
| 846 | + qrList = qrList + basicButtonWindow(petName) | ||
| 847 | + | ||
| 848 | + if checkContextParamValue(payload, 'utterance', 'nonsense_quiz', 'incorrect'): | ||
| 849 | + quizNumber = getContextParamValue(payload, 'utterance', 'nonsense_quiz_number') | ||
| 850 | + outputList = tones.getMessageOutputList(font, 'nonsense_quiz_' + quizNumber + '_X', imageUrl, 90, petName, relation) | ||
| 851 | + else: | ||
| 852 | + outputList = tones.getMessageOutputList(font, 'wantKnow', imageUrl, 90, petName, relation) | ||
| 853 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 854 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 855 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 856 | + | ||
| 857 | +def get_amazing_message(): | ||
| 858 | + payload = request.get_json() | ||
| 859 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 860 | + | ||
| 861 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 862 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 863 | + petId = getPetId(kakaoUserKey) | ||
| 864 | + petName = getPetName(petId) | ||
| 865 | + relation = getRelation(kakaoUserKey, petId) | ||
| 866 | + font = getFont(kakaoUserKey, petId) | ||
| 867 | + | ||
| 868 | + category = '' | ||
| 869 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 870 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 871 | + | ||
| 872 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 873 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 874 | + contextList = [] | ||
| 875 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 876 | + try: | ||
| 877 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 878 | + except: | ||
| 879 | + repeatCount = 1 | ||
| 880 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 881 | + qrList = [] | ||
| 882 | + qrList = addRandomHintQR(qrList, petName) | ||
| 883 | + qrList = qrList + basicButtonWindow(petName) | ||
| 884 | + outputList = tones.getMessageOutputList(font, 'amazing', imageUrl, 90, petName, relation) | ||
| 885 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 886 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 887 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 888 | + | ||
| 889 | +def get_smart_message(): | ||
| 890 | + payload = request.get_json() | ||
| 891 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 892 | + | ||
| 893 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 894 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 895 | + petId = getPetId(kakaoUserKey) | ||
| 896 | + petName = getPetName(petId) | ||
| 897 | + relation = getRelation(kakaoUserKey, petId) | ||
| 898 | + font = getFont(kakaoUserKey, petId) | ||
| 899 | + | ||
| 900 | + category = '' | ||
| 901 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 902 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 903 | + | ||
| 904 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 905 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 906 | + contextList = [] | ||
| 907 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 908 | + try: | ||
| 909 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 910 | + except: | ||
| 911 | + repeatCount = 1 | ||
| 912 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 913 | + qrList = [] | ||
| 914 | + qrList = addRandomHintQR(qrList, petName) | ||
| 915 | + qrList = qrList + basicButtonWindow(petName) | ||
| 916 | + outputList = tones.getMessageOutputList(font, 'smart', imageUrl, 90, petName, relation) | ||
| 917 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 918 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 919 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 920 | + | ||
| 921 | +def get_buySnack_message(): | ||
| 922 | + payload = request.get_json() | ||
| 923 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 924 | + | ||
| 925 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 926 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 927 | + petId = getPetId(kakaoUserKey) | ||
| 928 | + petName = getPetName(petId) | ||
| 929 | + relation = getRelation(kakaoUserKey, petId) | ||
| 930 | + font = getFont(kakaoUserKey, petId) | ||
| 931 | + | ||
| 932 | + category = '' | ||
| 933 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 934 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 935 | + | ||
| 936 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 937 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 938 | + contextList = [] | ||
| 939 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 940 | + try: | ||
| 941 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 942 | + except: | ||
| 943 | + repeatCount = 1 | ||
| 944 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 945 | + qrList = [] | ||
| 946 | + qrList = addRandomHintQR(qrList, petName) | ||
| 947 | + qrList = qrList + basicButtonWindow(petName) | ||
| 948 | + outputList = tones.getMessageOutputList(font, 'buySnack', imageUrl, 90, petName, relation) | ||
| 949 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 950 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 951 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 952 | + | ||
| 953 | +def get_letsPlay_message(): | ||
| 954 | + payload = request.get_json() | ||
| 955 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 956 | + | ||
| 957 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 958 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 959 | + petId = getPetId(kakaoUserKey) | ||
| 960 | + petName = getPetName(petId) | ||
| 961 | + relation = getRelation(kakaoUserKey, petId) | ||
| 962 | + font = getFont(kakaoUserKey, petId) | ||
| 963 | + | ||
| 964 | + category = '' | ||
| 965 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 966 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 967 | + | ||
| 968 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 969 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 970 | + contextList = [] | ||
| 971 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 972 | + try: | ||
| 973 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 974 | + except: | ||
| 975 | + repeatCount = 1 | ||
| 976 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 977 | + qrList = [] | ||
| 978 | + qrList = addRandomHintQR(qrList, petName) | ||
| 979 | + qrList = qrList + basicButtonWindow(petName) | ||
| 980 | + outputList = tones.getMessageOutputList(font, 'letsPlay', imageUrl, 90, petName, relation) | ||
| 981 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 982 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 983 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 984 | + | ||
| 985 | +def get_notInterest_message(): | ||
| 986 | + payload = request.get_json() | ||
| 987 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 988 | + | ||
| 989 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 990 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 991 | + petId = getPetId(kakaoUserKey) | ||
| 992 | + petName = getPetName(petId) | ||
| 993 | + relation = getRelation(kakaoUserKey, petId) | ||
| 994 | + font = getFont(kakaoUserKey, petId) | ||
| 995 | + | ||
| 996 | + category = '' | ||
| 997 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 998 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 999 | + | ||
| 1000 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1001 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1002 | + contextList = [] | ||
| 1003 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1004 | + try: | ||
| 1005 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1006 | + except: | ||
| 1007 | + repeatCount = 1 | ||
| 1008 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1009 | + qrList = [] | ||
| 1010 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1011 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1012 | + outputList = tones.getMessageOutputList(font, 'notInterest', imageUrl, 90, petName, relation) | ||
| 1013 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1014 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1015 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1016 | + | ||
| 1017 | +def get_howToDo_message(): | ||
| 1018 | + payload = request.get_json() | ||
| 1019 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1020 | + | ||
| 1021 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1022 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1023 | + petId = getPetId(kakaoUserKey) | ||
| 1024 | + petName = getPetName(petId) | ||
| 1025 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1026 | + font = getFont(kakaoUserKey, petId) | ||
| 1027 | + | ||
| 1028 | + category = '' | ||
| 1029 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1030 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1031 | + | ||
| 1032 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1033 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1034 | + contextList = [] | ||
| 1035 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1036 | + try: | ||
| 1037 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1038 | + except: | ||
| 1039 | + repeatCount = 1 | ||
| 1040 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1041 | + qrList = [] | ||
| 1042 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1043 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1044 | + outputList = tones.getMessageOutputList(font, 'howToDo', imageUrl, 90, petName, relation) | ||
| 1045 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1046 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1047 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1048 | + | ||
| 1049 | +def get_goodMorning_message(): | ||
| 1050 | + payload = request.get_json() | ||
| 1051 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1052 | + | ||
| 1053 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1054 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1055 | + petId = getPetId(kakaoUserKey) | ||
| 1056 | + petName = getPetName(petId) | ||
| 1057 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1058 | + font = getFont(kakaoUserKey, petId) | ||
| 1059 | + | ||
| 1060 | + category = '' | ||
| 1061 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1062 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1063 | + | ||
| 1064 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1065 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1066 | + contextList = [] | ||
| 1067 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1068 | + try: | ||
| 1069 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1070 | + except: | ||
| 1071 | + repeatCount = 1 | ||
| 1072 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1073 | + qrList = [] | ||
| 1074 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1075 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1076 | + outputList = tones.getMessageOutputList(font, 'goodMorning', imageUrl, 90, petName, relation) | ||
| 1077 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1078 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1079 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1080 | + | ||
| 1081 | +def get_nextTime_message(): | ||
| 1082 | + payload = request.get_json() | ||
| 1083 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1084 | + | ||
| 1085 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1086 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1087 | + petId = getPetId(kakaoUserKey) | ||
| 1088 | + petName = getPetName(petId) | ||
| 1089 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1090 | + font = getFont(kakaoUserKey, petId) | ||
| 1091 | + | ||
| 1092 | + category = '' | ||
| 1093 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1094 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1095 | + | ||
| 1096 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1097 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1098 | + contextList = [] | ||
| 1099 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1100 | + try: | ||
| 1101 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1102 | + except: | ||
| 1103 | + repeatCount = 1 | ||
| 1104 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1105 | + qrList = [] | ||
| 1106 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1107 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1108 | + outputList = tones.getMessageOutputList(font, 'nextTime', imageUrl, 90, petName, relation) | ||
| 1109 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1110 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1111 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1112 | + | ||
| 1113 | +def get_bonApeti_message(): | ||
| 1114 | + payload = request.get_json() | ||
| 1115 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1116 | + | ||
| 1117 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1118 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1119 | + petId = getPetId(kakaoUserKey) | ||
| 1120 | + petName = getPetName(petId) | ||
| 1121 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1122 | + font = getFont(kakaoUserKey, petId) | ||
| 1123 | + | ||
| 1124 | + category = '' | ||
| 1125 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1126 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1127 | + | ||
| 1128 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1129 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1130 | + contextList = [] | ||
| 1131 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1132 | + try: | ||
| 1133 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1134 | + except: | ||
| 1135 | + repeatCount = 1 | ||
| 1136 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1137 | + qrList = [] | ||
| 1138 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1139 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1140 | + outputList = tones.getMessageOutputList(font, 'bonApeti', imageUrl, 90, petName, relation) | ||
| 1141 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1142 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1143 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1144 | + | ||
| 1145 | +def get_ofCourse_message(): | ||
| 1146 | + payload = request.get_json() | ||
| 1147 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1148 | + | ||
| 1149 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1150 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1151 | + petId = getPetId(kakaoUserKey) | ||
| 1152 | + petName = getPetName(petId) | ||
| 1153 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1154 | + font = getFont(kakaoUserKey, petId) | ||
| 1155 | + | ||
| 1156 | + category = '' | ||
| 1157 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1158 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1159 | + | ||
| 1160 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1161 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1162 | + contextList = [] | ||
| 1163 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1164 | + try: | ||
| 1165 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1166 | + except: | ||
| 1167 | + repeatCount = 1 | ||
| 1168 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1169 | + qrList = [] | ||
| 1170 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1171 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1172 | + outputList = tones.getMessageOutputList(font, 'ofCourse', imageUrl, 90, petName, relation) | ||
| 1173 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1174 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1175 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1176 | + | ||
| 1177 | +def get_doNotEatPeoFood_message(): | ||
| 1178 | + payload = request.get_json() | ||
| 1179 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1180 | + | ||
| 1181 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1182 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1183 | + petId = getPetId(kakaoUserKey) | ||
| 1184 | + petName = getPetName(petId) | ||
| 1185 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1186 | + font = getFont(kakaoUserKey, petId) | ||
| 1187 | + | ||
| 1188 | + category = '' | ||
| 1189 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1190 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1191 | + | ||
| 1192 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1193 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1194 | + contextList = [] | ||
| 1195 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1196 | + try: | ||
| 1197 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1198 | + except: | ||
| 1199 | + repeatCount = 1 | ||
| 1200 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1201 | + qrList = [] | ||
| 1202 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1203 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1204 | + outputList = tones.getMessageOutputList(font, 'doNotEatPeoFood', imageUrl, 90, petName, relation) | ||
| 1205 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1206 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1207 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1208 | + | ||
| 1209 | +def get_IKnow_message(): | ||
| 1210 | + payload = request.get_json() | ||
| 1211 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1212 | + | ||
| 1213 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1214 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1215 | + petId = getPetId(kakaoUserKey) | ||
| 1216 | + petName = getPetName(petId) | ||
| 1217 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1218 | + font = getFont(kakaoUserKey, petId) | ||
| 1219 | + | ||
| 1220 | + category = '' | ||
| 1221 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1222 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1223 | + | ||
| 1224 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1225 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1226 | + contextList = [] | ||
| 1227 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1228 | + try: | ||
| 1229 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1230 | + except: | ||
| 1231 | + repeatCount = 1 | ||
| 1232 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1233 | + qrList = [] | ||
| 1234 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1235 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1236 | + outputList = tones.getMessageOutputList(font, 'IKnow', imageUrl, 90, petName, relation) | ||
| 1237 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1238 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1239 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1240 | + | ||
| 1241 | +def get_letsGo_message(): | ||
| 1242 | + payload = request.get_json() | ||
| 1243 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1244 | + | ||
| 1245 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1246 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1247 | + petId = getPetId(kakaoUserKey) | ||
| 1248 | + petName = getPetName(petId) | ||
| 1249 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1250 | + font = getFont(kakaoUserKey, petId) | ||
| 1251 | + | ||
| 1252 | + category = '' | ||
| 1253 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1254 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1255 | + | ||
| 1256 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1257 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1258 | + contextList = [] | ||
| 1259 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1260 | + try: | ||
| 1261 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1262 | + except: | ||
| 1263 | + repeatCount = 1 | ||
| 1264 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1265 | + qrList = [] | ||
| 1266 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1267 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1268 | + outputList = tones.getMessageOutputList(font, 'letsGo', imageUrl, 90, petName, relation) | ||
| 1269 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1270 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1271 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1272 | + | ||
| 1273 | +def get_dontCry_message(): | ||
| 1274 | + payload = request.get_json() | ||
| 1275 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1276 | + | ||
| 1277 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1278 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1279 | + petId = getPetId(kakaoUserKey) | ||
| 1280 | + petName = getPetName(petId) | ||
| 1281 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1282 | + font = getFont(kakaoUserKey, petId) | ||
| 1283 | + | ||
| 1284 | + category = '' | ||
| 1285 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1286 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1287 | + | ||
| 1288 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1289 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1290 | + contextList = [] | ||
| 1291 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1292 | + try: | ||
| 1293 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1294 | + except: | ||
| 1295 | + repeatCount = 1 | ||
| 1296 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1297 | + qrList = [] | ||
| 1298 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1299 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1300 | + outputList = tones.getMessageOutputList(font, 'dontCry', imageUrl, 90, petName, relation) | ||
| 1301 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1302 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1303 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1304 | + | ||
| 1305 | +def get_wantChangeFont_message(): | ||
| 1306 | + payload = request.get_json() | ||
| 1307 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1308 | + | ||
| 1309 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1310 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1311 | + petId = getPetId(kakaoUserKey) | ||
| 1312 | + petName = getPetName(petId) | ||
| 1313 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1314 | + font = getFont(kakaoUserKey, petId) | ||
| 1315 | + | ||
| 1316 | + category = '' | ||
| 1317 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1318 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1319 | + | ||
| 1320 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1321 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1322 | + contextList = [] | ||
| 1323 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1324 | + try: | ||
| 1325 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1326 | + except: | ||
| 1327 | + repeatCount = 1 | ||
| 1328 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1329 | + qrList = [] | ||
| 1330 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1331 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1332 | + outputList = tones.getMessageOutputList(font, 'wantChangeFont', imageUrl, 90, petName, relation) | ||
| 1333 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1334 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1335 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1336 | + | ||
| 1337 | +def get_funny_message(): | ||
| 1338 | + payload = request.get_json() | ||
| 1339 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1340 | + | ||
| 1341 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1342 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1343 | + petId = getPetId(kakaoUserKey) | ||
| 1344 | + petName = getPetName(petId) | ||
| 1345 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1346 | + font = getFont(kakaoUserKey, petId) | ||
| 1347 | + | ||
| 1348 | + category = '' | ||
| 1349 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1350 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1351 | + | ||
| 1352 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1353 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1354 | + contextList = [] | ||
| 1355 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1356 | + try: | ||
| 1357 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1358 | + except: | ||
| 1359 | + repeatCount = 1 | ||
| 1360 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1361 | + qrList = [] | ||
| 1362 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1363 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1364 | + outputList = tones.getMessageOutputList(font, 'funny', imageUrl, 90, petName, relation) | ||
| 1365 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1366 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1367 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1368 | + | ||
| 1369 | +def get_funTime_message(): | ||
| 1370 | + payload = request.get_json() | ||
| 1371 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1372 | + | ||
| 1373 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1374 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1375 | + petId = getPetId(kakaoUserKey) | ||
| 1376 | + petName = getPetName(petId) | ||
| 1377 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1378 | + font = getFont(kakaoUserKey, petId) | ||
| 1379 | + | ||
| 1380 | + category = '' | ||
| 1381 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1382 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1383 | + | ||
| 1384 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1385 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1386 | + contextList = [] | ||
| 1387 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1388 | + try: | ||
| 1389 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1390 | + except: | ||
| 1391 | + repeatCount = 1 | ||
| 1392 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1393 | + qrList = [] | ||
| 1394 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1395 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1396 | + outputList = tones.getMessageOutputList(font, 'funTime', imageUrl, 90, petName, relation) | ||
| 1397 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1398 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1399 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1400 | + | ||
| 1401 | +def get_forgive_message(): | ||
| 1402 | + payload = request.get_json() | ||
| 1403 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1404 | + | ||
| 1405 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1406 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1407 | + petId = getPetId(kakaoUserKey) | ||
| 1408 | + petName = getPetName(petId) | ||
| 1409 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1410 | + font = getFont(kakaoUserKey, petId) | ||
| 1411 | + | ||
| 1412 | + category = '' | ||
| 1413 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1414 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1415 | + | ||
| 1416 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1417 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1418 | + contextList = [] | ||
| 1419 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1420 | + try: | ||
| 1421 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1422 | + except: | ||
| 1423 | + repeatCount = 1 | ||
| 1424 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1425 | + qrList = [] | ||
| 1426 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1427 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1428 | + outputList = tones.getMessageOutputList(font, 'forgive', imageUrl, 90, petName, relation) | ||
| 1429 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1430 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1431 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1432 | + | ||
| 1433 | +def get_meToo_message(): | ||
| 1434 | + payload = request.get_json() | ||
| 1435 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1436 | + | ||
| 1437 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1438 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1439 | + petId = getPetId(kakaoUserKey) | ||
| 1440 | + petName = getPetName(petId) | ||
| 1441 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1442 | + font = getFont(kakaoUserKey, petId) | ||
| 1443 | + | ||
| 1444 | + category = '' | ||
| 1445 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1446 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1447 | + | ||
| 1448 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1449 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1450 | + contextList = [] | ||
| 1451 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1452 | + try: | ||
| 1453 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1454 | + except: | ||
| 1455 | + repeatCount = 1 | ||
| 1456 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1457 | + qrList = [] | ||
| 1458 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1459 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1460 | + outputList = tones.getMessageOutputList(font, 'meToo', imageUrl, 90, petName, relation) | ||
| 1461 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1462 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1463 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1464 | + | ||
| 1465 | +def get_study_message(): | ||
| 1466 | + payload = request.get_json() | ||
| 1467 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1468 | + | ||
| 1469 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1470 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1471 | + petId = getPetId(kakaoUserKey) | ||
| 1472 | + petName = getPetName(petId) | ||
| 1473 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1474 | + font = getFont(kakaoUserKey, petId) | ||
| 1475 | + | ||
| 1476 | + category = '' | ||
| 1477 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1478 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1479 | + | ||
| 1480 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1481 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1482 | + contextList = [] | ||
| 1483 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1484 | + try: | ||
| 1485 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1486 | + except: | ||
| 1487 | + repeatCount = 1 | ||
| 1488 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1489 | + qrList = [] | ||
| 1490 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1491 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1492 | + outputList = tones.getMessageOutputList(font, 'study', imageUrl, 90, petName, relation) | ||
| 1493 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1494 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1495 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1496 | + | ||
| 1497 | +def get_letsEatPeoFood_message(): | ||
| 1498 | + payload = request.get_json() | ||
| 1499 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1500 | + | ||
| 1501 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1502 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1503 | + petId = getPetId(kakaoUserKey) | ||
| 1504 | + petName = getPetName(petId) | ||
| 1505 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1506 | + font = getFont(kakaoUserKey, petId) | ||
| 1507 | + | ||
| 1508 | + category = '' | ||
| 1509 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1510 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1511 | + | ||
| 1512 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1513 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1514 | + contextList = [] | ||
| 1515 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1516 | + try: | ||
| 1517 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1518 | + except: | ||
| 1519 | + repeatCount = 1 | ||
| 1520 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1521 | + qrList = [] | ||
| 1522 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1523 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1524 | + outputList = tones.getMessageOutputList(font, 'letsEatPeoFood', imageUrl, 90, petName, relation) | ||
| 1525 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1526 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1527 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1528 | + | ||
| 1529 | +def get_noJam_message(): | ||
| 1530 | + payload = request.get_json() | ||
| 1531 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1532 | + | ||
| 1533 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1534 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1535 | + petId = getPetId(kakaoUserKey) | ||
| 1536 | + petName = getPetName(petId) | ||
| 1537 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1538 | + font = getFont(kakaoUserKey, petId) | ||
| 1539 | + | ||
| 1540 | + category = '' | ||
| 1541 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1542 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1543 | + | ||
| 1544 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1545 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1546 | + contextList = [] | ||
| 1547 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1548 | + try: | ||
| 1549 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1550 | + except: | ||
| 1551 | + repeatCount = 1 | ||
| 1552 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1553 | + qrList = [] | ||
| 1554 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1555 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1556 | + outputList = tones.getMessageOutputList(font, 'noJam', imageUrl, 90, petName, relation) | ||
| 1557 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1558 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1559 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1560 | + | ||
| 1561 | +def get_letsFight_message(): | ||
| 1562 | + payload = request.get_json() | ||
| 1563 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1564 | + | ||
| 1565 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1566 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1567 | + petId = getPetId(kakaoUserKey) | ||
| 1568 | + petName = getPetName(petId) | ||
| 1569 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1570 | + font = getFont(kakaoUserKey, petId) | ||
| 1571 | + | ||
| 1572 | + category = '' | ||
| 1573 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1574 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1575 | + | ||
| 1576 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1577 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1578 | + contextList = [] | ||
| 1579 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1580 | + try: | ||
| 1581 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1582 | + except: | ||
| 1583 | + repeatCount = 1 | ||
| 1584 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1585 | + qrList = [] | ||
| 1586 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1587 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1588 | + outputList = tones.getMessageOutputList(font, 'letsFight', imageUrl, 90, petName, relation) | ||
| 1589 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1590 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1591 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1592 | + | ||
| 1593 | +def get_betterThanYou_message(): | ||
| 1594 | + payload = request.get_json() | ||
| 1595 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1596 | + | ||
| 1597 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1598 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1599 | + petId = getPetId(kakaoUserKey) | ||
| 1600 | + petName = getPetName(petId) | ||
| 1601 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1602 | + font = getFont(kakaoUserKey, petId) | ||
| 1603 | + | ||
| 1604 | + category = '' | ||
| 1605 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1606 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1607 | + | ||
| 1608 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1609 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1610 | + contextList = [] | ||
| 1611 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1612 | + try: | ||
| 1613 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1614 | + except: | ||
| 1615 | + repeatCount = 1 | ||
| 1616 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1617 | + qrList = [] | ||
| 1618 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1619 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1620 | + outputList = tones.getMessageOutputList(font, 'betterThanYou', imageUrl, 90, petName, relation) | ||
| 1621 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1622 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1623 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1624 | + | ||
| 1625 | +def get_withYou_message(): | ||
| 1626 | + payload = request.get_json() | ||
| 1627 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1628 | + | ||
| 1629 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1630 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1631 | + petId = getPetId(kakaoUserKey) | ||
| 1632 | + petName = getPetName(petId) | ||
| 1633 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1634 | + font = getFont(kakaoUserKey, petId) | ||
| 1635 | + | ||
| 1636 | + category = '' | ||
| 1637 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1638 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1639 | + | ||
| 1640 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1641 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1642 | + contextList = [] | ||
| 1643 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1644 | + try: | ||
| 1645 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1646 | + except: | ||
| 1647 | + repeatCount = 1 | ||
| 1648 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1649 | + qrList = [] | ||
| 1650 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1651 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1652 | + outputList = tones.getMessageOutputList(font, 'withYou', imageUrl, 90, petName, relation) | ||
| 1653 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1654 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1655 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1656 | + | ||
| 1657 | +def get_letsTalk_message(): | ||
| 1658 | + payload = request.get_json() | ||
| 1659 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1660 | + | ||
| 1661 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1662 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1663 | + petId = getPetId(kakaoUserKey) | ||
| 1664 | + petName = getPetName(petId) | ||
| 1665 | + relation = getRelation(kakaoUserKey, petId) | ||
| 1666 | + font = getFont(kakaoUserKey, petId) | ||
| 1667 | + | ||
| 1668 | + category = '' | ||
| 1669 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 1670 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 1671 | + | ||
| 1672 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 1673 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 1674 | + contextList = [] | ||
| 1675 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 1676 | + try: | ||
| 1677 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 1678 | + except: | ||
| 1679 | + repeatCount = 1 | ||
| 1680 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 1681 | + qrList = [] | ||
| 1682 | + qrList = addRandomHintQR(qrList, petName) | ||
| 1683 | + qrList = qrList + basicButtonWindow(petName) | ||
| 1684 | + outputList = tones.getMessageOutputList(font, 'letsTalk', imageUrl, 90, petName, relation) | ||
| 1685 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1686 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 1687 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/system.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | + | ||
| 5 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 6 | +from Functions.getInstance import * | ||
| 7 | +from Functions.updateDatabase import * | ||
| 8 | +from Functions.checkFunction import * | ||
| 9 | +from Functions import pyjosa | ||
| 10 | +from Functions.messageTypes import * | ||
| 11 | +import tones | ||
| 12 | + | ||
| 13 | +from OpenbuilderSkills import minigame | ||
| 14 | + | ||
| 15 | +import Api.Urls.imageUrls | ||
| 16 | +import Config.systemKey | ||
| 17 | + | ||
| 18 | +from flask import request | ||
| 19 | + | ||
| 20 | +import ast | ||
| 21 | + | ||
| 22 | +from pyfcm import FCMNotification | ||
| 23 | +api_key = Config.systemKey.FCM_API_KEY | ||
| 24 | +push_service = FCMNotification(api_key=api_key) | ||
| 25 | + | ||
| 26 | +import datetime | ||
| 27 | +import time | ||
| 28 | +import random | ||
| 29 | + | ||
| 30 | +from urllib import parse | ||
| 31 | + | ||
| 32 | +# 챗봇 캐로셀 한번에 최대로 띄우는 카드뷰 갯수 | ||
| 33 | +post_size_by_page = 10 | ||
| 34 | + | ||
| 35 | +def get_fallBack_message(): | ||
| 36 | + # 특정 확률에 따라 넌센스퀴즈 시작 | ||
| 37 | + rv = random.randrange(0, 10) | ||
| 38 | + if rv < 3: | ||
| 39 | + return minigame.get_start_nonsense_quiz_message() | ||
| 40 | + payload = request.get_json() | ||
| 41 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 42 | + petId = getPetId(kakaoUserKey) | ||
| 43 | + petName = getPetName(petId) | ||
| 44 | + relation = getRelation(kakaoUserKey, petId) | ||
| 45 | + font = getFont(kakaoUserKey, petId) | ||
| 46 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 47 | + # 펫 이미지 리스트 불러오기 | ||
| 48 | + category = '' | ||
| 49 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 50 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 51 | + | ||
| 52 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 53 | + addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none') | ||
| 54 | + contextList = [] | ||
| 55 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 56 | + try: | ||
| 57 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 58 | + except: | ||
| 59 | + repeatCount = 1 | ||
| 60 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 61 | + | ||
| 62 | + intent = getIntentName(payload) | ||
| 63 | + beforeIntent = getContextParamValue(payload, 'intent', 'before') | ||
| 64 | + try: | ||
| 65 | + intentRepeatCount = int(getContextParamValue(payload, 'intent', 'repeat')) | ||
| 66 | + except: | ||
| 67 | + intentRepeatCount = 1 | ||
| 68 | + contextList += intentRepeatContext(beforeIntent, intent, intentRepeatCount) | ||
| 69 | + | ||
| 70 | + qrList = [] | ||
| 71 | + qrList = addRandomHintQR(qrList, petName) | ||
| 72 | + qrList = qrList + basicButtonWindow(petName) | ||
| 73 | + | ||
| 74 | + # 사용자가 이미지를 채팅창에 입력한 경우 | ||
| 75 | + if 'http://dn-m.talk.kakao.com/talkm/' in utterance: | ||
| 76 | + outputList = tones.getMessageOutputList(font, 'fallBackImage', imageUrl, 90, petName, relation) | ||
| 77 | + else: | ||
| 78 | + outputList = tones.getMessageOutputList(font, 'fallBack', imageUrl, 90, petName, relation) | ||
| 79 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 80 | + addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none') | ||
| 81 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 82 | + | ||
| 83 | +def get_repeatSameUtterance_message(): | ||
| 84 | + payload = request.get_json() | ||
| 85 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 86 | + | ||
| 87 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 88 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 89 | + petId = getPetId(kakaoUserKey) | ||
| 90 | + petName = getPetName(petId) | ||
| 91 | + relation = getRelation(kakaoUserKey, petId) | ||
| 92 | + font = getFont(kakaoUserKey, petId) | ||
| 93 | + now = datetime.datetime.now() | ||
| 94 | + category = '' | ||
| 95 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 96 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 97 | + | ||
| 98 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 99 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 100 | + contextList = [] | ||
| 101 | + | ||
| 102 | + qrList = [] | ||
| 103 | + qrList = addRandomHintQR(qrList, petName) | ||
| 104 | + qrList = qrList + basicButtonWindow(petName) | ||
| 105 | + outputList = tones.getMessageOutputList(font, 'repeatSameUtterance', imageUrl, 10, petName, relation) | ||
| 106 | + contextList.append(contextValue('utterance', 1, {'repeat': '2', 'before': utterance})) | ||
| 107 | + | ||
| 108 | + # 같은말을 반복하는 경우의 패널티 | ||
| 109 | + rv = random.randrange(17,23) | ||
| 110 | + incDogipoint(kakaoUserKey, -rv) | ||
| 111 | + | ||
| 112 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 113 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 114 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 115 | + | ||
| 116 | +def get_repeatFallback_message(): | ||
| 117 | + payload = request.get_json() | ||
| 118 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 119 | + | ||
| 120 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 121 | + intent = getIntentName(payload) | ||
| 122 | + | ||
| 123 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 124 | + petId = getPetId(kakaoUserKey) | ||
| 125 | + petName = getPetName(petId) | ||
| 126 | + relation = getRelation(kakaoUserKey, petId) | ||
| 127 | + font = getFont(kakaoUserKey, petId) | ||
| 128 | + now = datetime.datetime.now() | ||
| 129 | + category = '' | ||
| 130 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 131 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 132 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 133 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 134 | + contextList = [] | ||
| 135 | + | ||
| 136 | + qrList = [] | ||
| 137 | + qrList = addRandomHintQR(qrList, petName) | ||
| 138 | + qrList = qrList + basicButtonWindow(petName) | ||
| 139 | + outputList = tones.getMessageOutputList(font, 'repeatFallback', imageUrl, 10, petName, relation) | ||
| 140 | + contextList.append(contextValue('intent', 1, {'repeat': '3', 'before': intent})) | ||
| 141 | + | ||
| 142 | + # 알아들을 수 없는 말을 반복하는 경우의 패널티 | ||
| 143 | + rv = random.randrange(17, 23) | ||
| 144 | + incDogipoint(kakaoUserKey, -rv) | ||
| 145 | + | ||
| 146 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 147 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 148 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 149 | + | ||
| 150 | +# qr코드 스캔을 통한 카메라 등록 권유: 현재 미사용 | ||
| 151 | +def get_tryAddCamera_message(): | ||
| 152 | + contextList = [] | ||
| 153 | + outputList = [] | ||
| 154 | + qrList = [] | ||
| 155 | + | ||
| 156 | + payload = request.get_json() | ||
| 157 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 158 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 159 | + deviceId = getDeviceIdUsingAccountId(accountId) | ||
| 160 | + | ||
| 161 | + # 사용자 등록 여부를 확인하여 등록된 사용자가 아니라면 등록창으로 | ||
| 162 | + if isUserRegistered(kakaoUserKey) == False: | ||
| 163 | + return get_startUserRegister_message() | ||
| 164 | + # 펫 설정이 끝나지 않았다면 펫리스트로 | ||
| 165 | + if isPetSettingFinished(kakaoUserKey) == False: | ||
| 166 | + return get_getPetList_message() | ||
| 167 | + | ||
| 168 | + fcmToken = getFcmTokenUsingDeviceId(deviceId) | ||
| 169 | + registration_id = fcmToken | ||
| 170 | + | ||
| 171 | + # 카메라 등록 요청 push 보내기 | ||
| 172 | + data_message = { | ||
| 173 | + "fromAPI": "requestDailyConfiguration" | ||
| 174 | + } | ||
| 175 | + result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message) | ||
| 176 | + | ||
| 177 | + outputList.append(simpleText('[시스템] [QR코드 스캔]을 진행합니다')) | ||
| 178 | + qrList.append(blockQuickReply('알겠습니다', '알겠습니다', '5cf531058192ac0001cab975')) | ||
| 179 | + | ||
| 180 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 181 | + | ||
| 182 | +# qr코드 스캔을 통한 카메라 등록 수행: 현재 미사용 | ||
| 183 | +def get_addCameraUseQRcode_message(): | ||
| 184 | + contextList = [] | ||
| 185 | + outputList = [] | ||
| 186 | + qrList = [] | ||
| 187 | + | ||
| 188 | + payload = request.get_json() | ||
| 189 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 190 | + | ||
| 191 | + # 사용자 등록 여부를 확인하여 등록된 사용자가 아니라면 등록창으로 | ||
| 192 | + if isUserRegistered(kakaoUserKey) == False: | ||
| 193 | + return get_startUserRegister_message() | ||
| 194 | + # 펫 설정이 끝나지 않았다면 펫리스트로 | ||
| 195 | + if isPetSettingFinished(kakaoUserKey) == False: | ||
| 196 | + return get_getPetList_message() | ||
| 197 | + | ||
| 198 | + data = ast.literal_eval(getQRcodeScanData(payload, 'addCameraDevice')) | ||
| 199 | + # 스캔한 device 정보 | ||
| 200 | + deviceId = data['deviceId'] | ||
| 201 | + passwordCode = data['passwordCode'] | ||
| 202 | + | ||
| 203 | + # device id로 fcmToken 불러오기 | ||
| 204 | + fcmToken = getFcmTokenUsingDeviceId(deviceId) | ||
| 205 | + registration_id = fcmToken | ||
| 206 | + | ||
| 207 | + try: | ||
| 208 | + # 해당 유저에게 이미 등록되어있는 device인지 확인하고 이미 있다면 passwordCode만 update | ||
| 209 | + if isDeviceIdRegisteredInUser(kakaoUserKey, deviceId) == True: | ||
| 210 | + updatePasswordCode(kakaoUserKey, deviceId, passwordCode) | ||
| 211 | + # 최초 등록이라면 스캔한 user에 해당 device 정보 저장 | ||
| 212 | + else: | ||
| 213 | + addDeviceToUser(kakaoUserKey, deviceId, passwordCode) | ||
| 214 | + | ||
| 215 | + # 카메라 등록 완료 push 보내기 | ||
| 216 | + data_message2 = { | ||
| 217 | + "fromAPI": "finishDailyConfiguration" | ||
| 218 | + } | ||
| 219 | + result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message2) | ||
| 220 | + outputList.append(simpleText('[시스템] 인증 완료되었습니다')) | ||
| 221 | + | ||
| 222 | + petId = getPetId(kakaoUserKey) | ||
| 223 | + petName = getPetName(petId) | ||
| 224 | + # 챗봇 노란버튼 | ||
| 225 | + qrList = basicButtonWindow(petName) | ||
| 226 | + | ||
| 227 | + except: | ||
| 228 | + outputList.append(simpleText('[시스템] [QR코드 스캔]을 실패했습니다')) | ||
| 229 | + qrList.append(blockQuickReply('재시도', '재시도', '5d70c2ee8192ac00011f6f97')) | ||
| 230 | + | ||
| 231 | + return ordinaryMessageType(contextList,outputList,qrList) | ||
| 232 | + | ||
| 233 | +# 영상을 수신할 device를 골라서 해당 device의 영상을 불러옴 | ||
| 234 | +def get_turnOnCamera_message(): | ||
| 235 | + contextList = [] | ||
| 236 | + outputList = [] | ||
| 237 | + qrList = [] | ||
| 238 | + buttonList = [] | ||
| 239 | + | ||
| 240 | + payload = request.get_json() | ||
| 241 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 242 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 243 | + petId = getPetId(kakaoUserKey) | ||
| 244 | + petName = getPetName(petId) | ||
| 245 | + | ||
| 246 | + deviceList = getDeviceListUsingUserKey(kakaoUserKey) | ||
| 247 | + if len(deviceList) == 0: | ||
| 248 | + outputList.append(simpleText('연동된 기기가 없어 ' + petName + '의 실시간 영상을 볼 수 없어요😔')) | ||
| 249 | + qrList = basicButtonWindow(petName) | ||
| 250 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 251 | + addMessageLogs('bot', kakaoUserKey, '[카드]미연동으로실시간확인실패', datetime.datetime.now(), 'none') | ||
| 252 | + | ||
| 253 | + elif not checkAppAlive(accountId): | ||
| 254 | + title = '오프라인' | ||
| 255 | + detail = '어플리케이션이 꺼져있습니다' | ||
| 256 | + card = buttonCard(title, detail, Api.Urls.imageUrls.nullType1, []) | ||
| 257 | + outputList.append(card) | ||
| 258 | + qrList = streamingWindow(petName) | ||
| 259 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 260 | + addMessageLogs('bot', kakaoUserKey, '[카드]앱종료로실시간확인실패', datetime.datetime.now(), 'none') | ||
| 261 | + | ||
| 262 | + else: | ||
| 263 | + deviceId = getDeviceIdUsingUserKey(kakaoUserKey) | ||
| 264 | + fixedPetName = pyjosa.replace_josa(petName + '(은)는') | ||
| 265 | + | ||
| 266 | + # deviceId로 fcmToken찾기 | ||
| 267 | + fcmToken = getFcmTokenUsingDeviceId(deviceId) | ||
| 268 | + devicePasswordCode = getPasswordCodeUsingDeviceId(deviceId) | ||
| 269 | + CODE = devicePasswordCode.split('_') | ||
| 270 | + roomName = CODE[0] + str(int(time.time())) | ||
| 271 | + | ||
| 272 | + # 갱신된 roomName push보내기 | ||
| 273 | + registration_id = fcmToken | ||
| 274 | + data_message = { | ||
| 275 | + "roomName": roomName, | ||
| 276 | + "fromAPI": "moveToDetection" | ||
| 277 | + } | ||
| 278 | + result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message) | ||
| 279 | + | ||
| 280 | + # 스트리밍서버에 스트리밍 요청 url | ||
| 281 | + streamingUrl = Config.systemKey.STREAMING_SERVER_URL + '/room/' + roomName + '?deviceId=' + deviceId + '&passwordCode=' + devicePasswordCode + '&fixedPetName=' + fixedPetName | ||
| 282 | + streamingUrl = parse.urlparse(streamingUrl).geturl() | ||
| 283 | + title = petName + '보기' | ||
| 284 | + rv = random.randrange(0, 2) | ||
| 285 | + if rv == 0: | ||
| 286 | + detail = '해당 페이지는 사용 후 만료됩니다' | ||
| 287 | + else: | ||
| 288 | + detail = '와이파이 환경에서의 사용을 권장합니다' | ||
| 289 | + buttonList.append(singleButton('webLink', petName + ' 실시간확인 ▶', streamingUrl)) | ||
| 290 | + streamingCard = buttonCard(title, detail, "https://dogibogi-storage.s3-ap-northeast-1.amazonaws.com/cardImage/pusa_wide_01.jpg", buttonList) | ||
| 291 | + outputList.append(streamingCard) | ||
| 292 | + | ||
| 293 | + qrList = streamingWindow(petName) | ||
| 294 | + | ||
| 295 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 296 | + addMessageLogs('bot', kakaoUserKey, '[카드]실시간확인', datetime.datetime.now(), 'none') | ||
| 297 | + | ||
| 298 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 299 | + | ||
| 300 | +# 어플리케이션 상태 진단 | ||
| 301 | +def get_appStatus_message(): | ||
| 302 | + contextList = [] | ||
| 303 | + outputList = [] | ||
| 304 | + qrList = [] | ||
| 305 | + | ||
| 306 | + payload = request.get_json() | ||
| 307 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 308 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 309 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 310 | + petId = getPetId(kakaoUserKey) | ||
| 311 | + petName = getPetName(petId) | ||
| 312 | + | ||
| 313 | + # 앱이 살아있는지 확인 | ||
| 314 | + if checkAppAlive(accountId): | ||
| 315 | + logData = getLastAndroidLogData(accountId) | ||
| 316 | + temperature = logData['battery_temperature'] | ||
| 317 | + percent = logData['battery_percent'] | ||
| 318 | + title = '어플리케이션 상태' | ||
| 319 | + detail = '🌡️기기 온도: ' + getDeviceTemperature(temperature) + '\n' + '🔋잔여 배터리: ' + getDeviceBatteryPercent(percent) | ||
| 320 | + card = buttonCard(title, detail, "https://dogibogi-storage.s3-ap-northeast-1.amazonaws.com/cardImage/pusa_wide_01.jpg", []) | ||
| 321 | + outputList.append(card) | ||
| 322 | + else: | ||
| 323 | + title = '오프라인' | ||
| 324 | + detail = '어플리케이션이 꺼져있습니다' | ||
| 325 | + card = buttonCard(title, detail, Api.Urls.imageUrls.nullType1, []) | ||
| 326 | + outputList.append(card) | ||
| 327 | + qrList = streamingWindow(petName) | ||
| 328 | + | ||
| 329 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 330 | + addMessageLogs('bot', kakaoUserKey, '[카드]어플진단', datetime.datetime.now(), 'none') | ||
| 331 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 332 | + | ||
| 333 | +# 어플리케이션 강제 종료 시도 | ||
| 334 | +def get_tryAppRemoteQuit_message(): | ||
| 335 | + contextList = [] | ||
| 336 | + outputList = [] | ||
| 337 | + qrList = [] | ||
| 338 | + | ||
| 339 | + payload = request.get_json() | ||
| 340 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 341 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 342 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 343 | + petId = getPetId(kakaoUserKey) | ||
| 344 | + petName = getPetName(petId) | ||
| 345 | + | ||
| 346 | + # 앱이 살아있는지 확인 | ||
| 347 | + if checkAppAlive(accountId): | ||
| 348 | + outputList.append(simpleText('⚠️정말로 집에있는 어플리케이션을 종료하시겠습니까?')) | ||
| 349 | + qrList.append(blockQuickReply('예', '예', '5e5f61693ad5250001d681e0')) | ||
| 350 | + qrList.append(blockQuickReply('아니오', '아니오', '5d369987ffa748000122e9a1')) | ||
| 351 | + else: | ||
| 352 | + outputList.append(simpleText('이미 오프라인 상태입니다')) | ||
| 353 | + qrList = streamingWindow(petName) | ||
| 354 | + | ||
| 355 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 356 | + addMessageLogs('bot', kakaoUserKey, '[카드]어플강제종료시도', datetime.datetime.now(), 'none') | ||
| 357 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 358 | + | ||
| 359 | +# 어플리케이션 강제 종료 | ||
| 360 | +def get_appRemoteQuit_message(): | ||
| 361 | + contextList = [] | ||
| 362 | + outputList = [] | ||
| 363 | + qrList = [] | ||
| 364 | + | ||
| 365 | + payload = request.get_json() | ||
| 366 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 367 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 368 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 369 | + petId = getPetId(kakaoUserKey) | ||
| 370 | + petName = getPetName(petId) | ||
| 371 | + | ||
| 372 | + deviceId = getDeviceIdUsingUserKey(kakaoUserKey) | ||
| 373 | + fcmToken = getFcmTokenUsingDeviceId(deviceId) | ||
| 374 | + registration_id = fcmToken | ||
| 375 | + data_message = { | ||
| 376 | + "fromAPI": "remoteQuit" | ||
| 377 | + } | ||
| 378 | + result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message) | ||
| 379 | + | ||
| 380 | + outputList.append(simpleText('어플리케이션이 종료되었습니다')) | ||
| 381 | + outputList.append(simpleText('다시 어플을 실행해야 ' + petName + '을 볼 수 있어요')) | ||
| 382 | + | ||
| 383 | + qrList = [] | ||
| 384 | + qrList = addRandomHintQR(qrList, petName) | ||
| 385 | + qrList = qrList + basicButtonWindow(petName) | ||
| 386 | + | ||
| 387 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 388 | + addMessageLogs('bot', kakaoUserKey, '[카드]어플강제종료', datetime.datetime.now(), 'none') | ||
| 389 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 390 | + | ||
| 391 | +# qr코드 스캔을 통한 account 정보 불러와서 신규 유저 등록 | ||
| 392 | +def get_userRegisterUseQRcode_message(): | ||
| 393 | + contextList = [] | ||
| 394 | + outputList = [] | ||
| 395 | + qrList = [] | ||
| 396 | + | ||
| 397 | + payload = request.get_json() | ||
| 398 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 399 | + pfKey = getPlusFriendUserKeyFromPayload(payload) | ||
| 400 | + updatefinishConfiguration(kakaoUserKey, False) | ||
| 401 | + | ||
| 402 | + try: | ||
| 403 | + # 스캔한 qr code data | ||
| 404 | + data = ast.literal_eval(getQRcodeScanData(payload, 'userRegister')) | ||
| 405 | + accountId = data['id'] | ||
| 406 | + petIds = data['petIds'] | ||
| 407 | + | ||
| 408 | + # 이미 유저가 있는 경우 기존 pet list를 삭제하고 스캔한 정보로 최신화 | ||
| 409 | + if isUserRegistered(kakaoUserKey): | ||
| 410 | + clearUserPetList(kakaoUserKey) | ||
| 411 | + updateAccountIdToUser(kakaoUserKey, accountId) | ||
| 412 | + addPetsToUser(kakaoUserKey, petIds) | ||
| 413 | + # 유저가 없는 경우 신규 유저 등록 | ||
| 414 | + else: | ||
| 415 | + addNewUser(kakaoUserKey, pfKey, accountId, petIds) | ||
| 416 | + | ||
| 417 | + # 해당 account에서 deviceId 불러오기 | ||
| 418 | + deviceId = getDeviceIdUsingAccountId(accountId) | ||
| 419 | + # deviceId로 passwordCode 불러오기 | ||
| 420 | + passwordCode = getPasswordCodeUsingDeviceId(deviceId) | ||
| 421 | + # user device list 에 deviceId, passwordCode 추가 | ||
| 422 | + addDeviceToUser(kakaoUserKey, deviceId, passwordCode) | ||
| 423 | + | ||
| 424 | + # deviceId로 fcmToken 찾기 | ||
| 425 | + fcmToken = getFcmTokenUsingDeviceId(deviceId) | ||
| 426 | + # 해당 디바이스에 fcmToken 이용해서 push날리기 | ||
| 427 | + registration_id = fcmToken | ||
| 428 | + data_message = { | ||
| 429 | + "fromAPI": "connectKakaoConfiguration" | ||
| 430 | + } | ||
| 431 | + result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message) | ||
| 432 | + | ||
| 433 | + outputList.append(simpleText('기기연동이 완료되었어요')) | ||
| 434 | + outputList.append(simpleText('이제 아래 버튼을 눌러 남은 설정을 완료해주시겠어요?')) | ||
| 435 | + qrList.append(blockQuickReply('진행할게요', '진행할게요', '5d42e91d92690d00012b208b')) | ||
| 436 | + | ||
| 437 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 438 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동완료', datetime.datetime.now(), 'none') | ||
| 439 | + | ||
| 440 | + except: | ||
| 441 | + outputList.append(simpleText('기기연동을 실패했습니다😔')) | ||
| 442 | + outputList.append(simpleText('어플리케이션 회원가입뒤에 나오는 QR코드를 스캔해야해요')) | ||
| 443 | + outputList.append(simpleText('올바른 QR코드를 스캔했는지 다시 확인해보시겠어요?')) | ||
| 444 | + qrList.append(blockQuickReply('기기연동 다시진행', '기기연동 다시진행', '5d3fa9d48192ac0001fc4ed1')) | ||
| 445 | + qrList.append(blockQuickReply('무슨말인지 모르겠어요🤔', '무슨말인지 모르겠어요🤔', '5d412052b617ea0001a327bb')) | ||
| 446 | + | ||
| 447 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 448 | + | ||
| 449 | +# qr코드 스캔없이 신규 유저 등록 | ||
| 450 | +def get_userRegisterWithoutDevice_message(): | ||
| 451 | + contextList = [] | ||
| 452 | + outputList = [] | ||
| 453 | + qrList = [] | ||
| 454 | + | ||
| 455 | + payload = request.get_json() | ||
| 456 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 457 | + | ||
| 458 | + outputList.append(simpleText('네🙂 그러면 채팅을 위해 간단히 몇가지만 물어볼게요')) | ||
| 459 | + outputList.append(simpleText('지금 같이 살고있는 반려동물의 이름을 말해주시겠어요?')) | ||
| 460 | + | ||
| 461 | + qrList.append(blockQuickReply('반려동물이 없어요😓', '반려동물이 없어요😓', '5e63c1efa04f9b0001891113')) | ||
| 462 | + | ||
| 463 | + contextList.append(contextValue('register', 1, {'without_device': 'alive'})) | ||
| 464 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 465 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동없이유저등록', datetime.datetime.now(), 'none') | ||
| 466 | + | ||
| 467 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 468 | + | ||
| 469 | +def get_settingPetNameWithoutDevice(): | ||
| 470 | + outputList = [] | ||
| 471 | + qrList = [] | ||
| 472 | + contextList = [] | ||
| 473 | + payload = request.get_json() | ||
| 474 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 475 | + pfKey = getPlusFriendUserKeyFromPayload(payload) | ||
| 476 | + | ||
| 477 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 478 | + petName = getFixedPetName(utterance) | ||
| 479 | + | ||
| 480 | + petId = getNewPetId() | ||
| 481 | + addNewPet(petId, petName, '', '', '', '', '') | ||
| 482 | + accountId = '미연동' | ||
| 483 | + petIds = [ | ||
| 484 | + { | ||
| 485 | + 'petId': petId, | ||
| 486 | + 'relation': '', | ||
| 487 | + 'font': '' | ||
| 488 | + } | ||
| 489 | + ] | ||
| 490 | + # 신규 유저 등록 | ||
| 491 | + addNewUser(kakaoUserKey, pfKey, accountId, petIds) | ||
| 492 | + | ||
| 493 | + outputList.append(simpleText(petName + '.. 정말 귀여운 이름이에요😊')) | ||
| 494 | + outputList.append(simpleText(pyjosa.replace_josa(petName + '(와)과 채팅을 하기 위해서는 ' + petName + '사진이 필요해요'))) | ||
| 495 | + outputList.append(simpleText('아래 버튼을 눌러 계속 진행해주세요')) | ||
| 496 | + qrList.append(blockQuickReply('진행할게요', '진행할게요', '5d42e91d92690d00012b208b')) | ||
| 497 | + | ||
| 498 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 499 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동없이유저등록완료', datetime.datetime.now(), 'none') | ||
| 500 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 501 | + | ||
| 502 | +# 유저 등록 진행 시작. 사용자에게 유저 등록 제안 | ||
| 503 | +def get_startUserRegister_message(): | ||
| 504 | + contextList = [] | ||
| 505 | + outputList = [] | ||
| 506 | + qrList = [] | ||
| 507 | + | ||
| 508 | + payload = request.get_json() | ||
| 509 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 510 | + | ||
| 511 | + outputList.append(simpleText('우리집 멍멍이와 채팅하러 오셨군요!😃')) | ||
| 512 | + outputList.append(simpleText('지금바로 카카오톡과 어플리케이션 연동을 진행해볼까요?')) | ||
| 513 | + qrList.append(blockQuickReply('연동 바로진행🔗', '연동 바로진행🔗', '5d3fa9d48192ac0001fc4ed1')) | ||
| 514 | + qrList.append(blockQuickReply('연동없이 시작하기🐾', '연동없이 시작하기🐾', '5e57326992690d0001c9c4c1')) | ||
| 515 | + qrList.append(blockQuickReply('도기보기를 알고싶어요😲', '도기보기를 알고싶어요😲', '5d4112cbb617ea0001a32762')) | ||
| 516 | + qrList.append(blockQuickReply('다음에 다시올게요🙄', '다음에 다시올게요🙄', '5e578234ffa7480001ef0a0c')) | ||
| 517 | + | ||
| 518 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 519 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동시작', datetime.datetime.now(), 'none') | ||
| 520 | + | ||
| 521 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 522 | + | ||
| 523 | +# TODO 카드리스트를 제거하여 간소화하는 방안으로 | ||
| 524 | +# 유저 등록 완료후 환경설정. 펫 리스트 출력 | ||
| 525 | +def get_getPetList_message(): | ||
| 526 | + contextList = [] | ||
| 527 | + outputList = [] | ||
| 528 | + qrList = [] | ||
| 529 | + buttonList = [] | ||
| 530 | + | ||
| 531 | + payload = request.get_json() | ||
| 532 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 533 | + | ||
| 534 | + petId = getPetId(kakaoUserKey) | ||
| 535 | + petName = getPetName(petId) | ||
| 536 | + relation = getRelation(kakaoUserKey,petId) | ||
| 537 | + font = getFont(kakaoUserKey,petId) | ||
| 538 | + | ||
| 539 | + # users - pets - imageUrls에 있는 url 중 하나 랜덤으로 꺼내서 imageUrl로 쓰기 | ||
| 540 | + category = '' | ||
| 541 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 542 | + # url들 중 하나 뽑아서 imageUrl로 설정 | ||
| 543 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 544 | + | ||
| 545 | + title = petName | ||
| 546 | + if relation != '' and font != '' and imageUrl != '': | ||
| 547 | + detail = getPetPersonality(relation,font) | ||
| 548 | + buttonList.append(singleButton('block', petName + '짤 더 올리기', '5d42e91d92690d00012b208b')) | ||
| 549 | + pet1 = buttonCard(title, detail, imageUrl, buttonList) | ||
| 550 | + outputList.append(pet1) | ||
| 551 | + # 챗봇 노란버튼 | ||
| 552 | + qrList = basicButtonWindow(petName) | ||
| 553 | + return ordinaryMessageType(contextList,outputList,qrList) | ||
| 554 | + else: | ||
| 555 | + buttonList.append(singleButton('block', '🐶도기설정', '5d42e91d92690d00012b208b')) | ||
| 556 | + detail = '🐶도기설정 미완료' | ||
| 557 | + pet1 = buttonCard(title, detail, Api.Urls.imageUrls.nullType1, buttonList) | ||
| 558 | + outputList.append(pet1) | ||
| 559 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 560 | + | ||
| 561 | + | ||
| 562 | +# kakao측 url list(string type)을 split해서 dict로 저장 | ||
| 563 | +def splitKakaoImageUrlList(imageUrlList): | ||
| 564 | + imageUrlList = imageUrlList.replace("List", "") | ||
| 565 | + imageUrlList = imageUrlList.replace("(", "") | ||
| 566 | + imageUrlList = imageUrlList.replace(")", "") | ||
| 567 | + imageUrlList = list(imageUrlList.split(", ")) | ||
| 568 | + return imageUrlList | ||
| 569 | + | ||
| 570 | +# 펫 이미지 추가(설정) | ||
| 571 | +# firebase storage에 petImage/[kakaoUserKey] directory에 저장 | ||
| 572 | +def get_addPetImage_message(): | ||
| 573 | + contextList = [] | ||
| 574 | + outputList = [] | ||
| 575 | + qrList = [] | ||
| 576 | + | ||
| 577 | + payload = request.get_json() | ||
| 578 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 579 | + | ||
| 580 | + petId = getPetId(kakaoUserKey) | ||
| 581 | + petName = getPetName(petId) | ||
| 582 | + relation = getRelation(kakaoUserKey,petId) | ||
| 583 | + font = getFont(kakaoUserKey,petId) | ||
| 584 | + | ||
| 585 | + # payload에서 이미지 url list 가져오기 | ||
| 586 | + kakaoImageUrlList = getQRcodeScanData(payload, 'addPetImage') | ||
| 587 | + | ||
| 588 | + # kakao image url split해서 dict에 저장 | ||
| 589 | + imageUrlList = splitKakaoImageUrlList(kakaoImageUrlList) | ||
| 590 | + | ||
| 591 | + # TODO Pending: background processing 하고싶은데.. 잘모르겠다 | ||
| 592 | + # kakaoUserKey와 imageUrls 입력받아서 해당 이미지를 AWS S3 storage에 저장 | ||
| 593 | + uploadResizedImageToStorage(kakaoUserKey,petId,imageUrlList) | ||
| 594 | + uploadImageToStorage(kakaoUserKey, petId, imageUrlList) | ||
| 595 | + | ||
| 596 | + outputList.append(simpleText('정상적으로 업로드되었습니다')) | ||
| 597 | + outputList.append(simpleText('업로드한 사진은 사진첩에서 언제든지 꺼내볼 수 있어요!')) | ||
| 598 | + # 설정 완료했는데 이미지만 추가하는 경우 | ||
| 599 | + if relation != '' and font != '': | ||
| 600 | + qrList = basicButtonWindow(petName) | ||
| 601 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 602 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]펫이미지추가', datetime.datetime.now(), 'none') | ||
| 603 | + # 이미지 추가하고 이어서 font 설정 | ||
| 604 | + else: | ||
| 605 | + outputList.append(simpleText('그럼 이제 ' + petName + '의 말투를 골라주세요')) | ||
| 606 | + # quick Reply List에 설정 가능한 말투들 추가: 버튼으로 적용 | ||
| 607 | + fonts = getUserFonts(kakaoUserKey) | ||
| 608 | + fontList = [] | ||
| 609 | + for font in fonts: | ||
| 610 | + fontList.append(getFontFromVar(font['font'])) | ||
| 611 | + qrList = fontSettingWindow(fontList) | ||
| 612 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 613 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]펫이미지설정', datetime.datetime.now(), 'none') | ||
| 614 | + | ||
| 615 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 616 | + | ||
| 617 | +# 펫 폰트 설정(font) | ||
| 618 | +# 이미지 추가할 때 받은 문구들로 font 설정해서 db에 저장 | ||
| 619 | +def get_setPetFont_message(): | ||
| 620 | + contextList = [] | ||
| 621 | + outputList = [] | ||
| 622 | + qrList = [] | ||
| 623 | + | ||
| 624 | + payload = request.get_json() | ||
| 625 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 626 | + petId = getPetId(kakaoUserKey) | ||
| 627 | + petName = getPetName(petId) | ||
| 628 | + | ||
| 629 | + # 앞서 버튼으로 입력한 말투들을 font로 가져옴 | ||
| 630 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 631 | + font = getFontFromUtterance(utterance) | ||
| 632 | + # 가져온 font db에 저장 | ||
| 633 | + updateFont(kakaoUserKey,petId,font) | ||
| 634 | + | ||
| 635 | + # 최초의 설정에서 말투를 설정한 경우 호칭설정으로 진행 | ||
| 636 | + if getRelation(kakaoUserKey,petId) == "": | ||
| 637 | + outputList.append(simpleText(petName + '와는 무슨사이인가요?')) | ||
| 638 | + qrList = relationSettingWindow() | ||
| 639 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 640 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]말투설정', datetime.datetime.now(), 'none') | ||
| 641 | + # 환경설정에서 말투를 바꾸는 경우 | ||
| 642 | + else: | ||
| 643 | + nickname = getUserNickname(kakaoUserKey) | ||
| 644 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 645 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 646 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 647 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 648 | + outputList.append(simpleText('[시스템] 변경되었습니다')) | ||
| 649 | + # 프로필 리스트 | ||
| 650 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 651 | + # setting button window | ||
| 652 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 653 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 654 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]말투변경성공', datetime.datetime.now(), 'none') | ||
| 655 | + | ||
| 656 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 657 | + | ||
| 658 | +# 펫 관계 설정(relation) | ||
| 659 | +# 폰트 설정할 때 받은 utterance로 relation 설정해서 db에 저장 | ||
| 660 | +def get_setPetRelation_message(): | ||
| 661 | + contextList = [] | ||
| 662 | + outputList = [] | ||
| 663 | + qrList = [] | ||
| 664 | + | ||
| 665 | + payload = request.get_json() | ||
| 666 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 667 | + petId = getPetId(kakaoUserKey) | ||
| 668 | + petName = getPetName(petId) | ||
| 669 | + | ||
| 670 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 671 | + relation = utterance | ||
| 672 | + updateRelation(kakaoUserKey,petId,relation) | ||
| 673 | + | ||
| 674 | + # 이미 챗봇에서 초기설정을 한번 진행했고, 환경설정에서 관계를 재설정하는 경우 | ||
| 675 | + if getFinishConfiguration(kakaoUserKey): | ||
| 676 | + nickname = getUserNickname(kakaoUserKey) | ||
| 677 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 678 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 679 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 680 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 681 | + outputList.append(simpleText('[시스템] 변경되었습니다')) | ||
| 682 | + # 프로필 리스트 | ||
| 683 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname) | ||
| 684 | + # setting button window | ||
| 685 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 686 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 687 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]호칭변경성공', datetime.datetime.now(), 'none') | ||
| 688 | + # 최초의 설정에서 관계를 설정한 경우 카드뷰로 진행 | ||
| 689 | + else : | ||
| 690 | + outputList.append(simpleText('설정이 완료되었습니다')) | ||
| 691 | + card_list = serviceIntroductionCardList(petName) | ||
| 692 | + outputList.append(cardArray(card_list)) | ||
| 693 | + outputList.append(simpleText('앗! 때마침 ' + petName + '에게 카톡이 왔어요!💌')) | ||
| 694 | + qrList.append(blockQuickReply('확인해보기!', '확인해보기!', '5d43e36692690d000134afab')) | ||
| 695 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 696 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]호칭설정', datetime.datetime.now(), 'none') | ||
| 697 | + | ||
| 698 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 699 | + | ||
| 700 | +# 사진보기 | ||
| 701 | +def get_openPhotoAlbum_message(): | ||
| 702 | + contextList = [] | ||
| 703 | + outputList = [] | ||
| 704 | + qrList = [] | ||
| 705 | + | ||
| 706 | + payload = request.get_json() | ||
| 707 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 708 | + petId = getPetId(kakaoUserKey) | ||
| 709 | + petName = getPetName(petId) | ||
| 710 | + | ||
| 711 | + postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page) | ||
| 712 | + pageSize = len(postPagelist) | ||
| 713 | + pageNumber = 0 | ||
| 714 | + | ||
| 715 | + # list가 비어있으면 사진 추가 권유하기 | ||
| 716 | + if len(postPagelist) == 0: | ||
| 717 | + outputList.append(simpleText('[시스템] 사진첩에 ' + petName + '사진을 추가하시겠어요?')) | ||
| 718 | + qrList.append(blockQuickReply('추가할게요😃', '추가할게요😃', '5d42e91d92690d00012b208b')) | ||
| 719 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 720 | + | ||
| 721 | + card_list = myImagePostCardList(postPagelist, pageNumber) | ||
| 722 | + outputList.append(cardArray(card_list)) | ||
| 723 | + | ||
| 724 | + qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName) | ||
| 725 | + | ||
| 726 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 727 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]사진보기', datetime.datetime.now(), 'none') | ||
| 728 | + contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)})) | ||
| 729 | + | ||
| 730 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 731 | + | ||
| 732 | +# 사진 삭제 | ||
| 733 | +def get_deletePhotoPost_message(): | ||
| 734 | + outputList = [] | ||
| 735 | + qrList = [] | ||
| 736 | + contextList = [] | ||
| 737 | + | ||
| 738 | + payload = request.get_json() | ||
| 739 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 740 | + petId = getPetId(kakaoUserKey) | ||
| 741 | + petName = getPetName(petId) | ||
| 742 | + | ||
| 743 | + title = getContextParamValue(payload, 'post', 'title') | ||
| 744 | + | ||
| 745 | + # 해당 게시물 삭제하기 | ||
| 746 | + deleteImagePost(kakaoUserKey, title) | ||
| 747 | + outputList.append(simpleText('[시스템] 삭제되었습니다')) | ||
| 748 | + | ||
| 749 | + postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page) | ||
| 750 | + pageSize = len(postPagelist) | ||
| 751 | + pageNumber = 0 | ||
| 752 | + | ||
| 753 | + # list가 비어있으면 사진 추가 권유하기 | ||
| 754 | + if len(postPagelist) == 0: | ||
| 755 | + outputList.append(simpleText('[시스템] 사진첩에 ' + petName + '사진을 추가하시겠어요?')) | ||
| 756 | + qrList.append(blockQuickReply('추가할게요😃', '추가할게요😃', '5d42e91d92690d00012b208b')) | ||
| 757 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 758 | + card_list = myImagePostCardList(postPagelist, pageNumber) | ||
| 759 | + outputList.append(cardArray(card_list)) | ||
| 760 | + | ||
| 761 | + qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName) | ||
| 762 | + | ||
| 763 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 764 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]사진삭제', datetime.datetime.now(), 'none') | ||
| 765 | + contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)})) | ||
| 766 | + | ||
| 767 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 768 | + | ||
| 769 | +# 다음페이지 사진 보기 | ||
| 770 | +def get_photoAlbumNextPage_message(): | ||
| 771 | + contextList = [] | ||
| 772 | + outputList = [] | ||
| 773 | + qrList = [] | ||
| 774 | + | ||
| 775 | + payload = request.get_json() | ||
| 776 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 777 | + petId = getPetId(kakaoUserKey) | ||
| 778 | + petName = getPetName(petId) | ||
| 779 | + | ||
| 780 | + postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page) | ||
| 781 | + pageSize = len(postPagelist) | ||
| 782 | + try: | ||
| 783 | + pageNumber = int(getContextParamValue(payload, 'post', 'my_page')) + 1 | ||
| 784 | + except: | ||
| 785 | + pageNumber = 0 | ||
| 786 | + card_list = myImagePostCardList(postPagelist, pageNumber) | ||
| 787 | + outputList.append(cardArray(card_list)) | ||
| 788 | + | ||
| 789 | + qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName) | ||
| 790 | + | ||
| 791 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 792 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]내사진보기', datetime.datetime.now(), 'none') | ||
| 793 | + contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)})) | ||
| 794 | + | ||
| 795 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 796 | + | ||
| 797 | +# 이전페이지 사진 보기 | ||
| 798 | +def get_photoAlbumBackPage_message(): | ||
| 799 | + contextList = [] | ||
| 800 | + outputList = [] | ||
| 801 | + qrList = [] | ||
| 802 | + | ||
| 803 | + payload = request.get_json() | ||
| 804 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 805 | + petId = getPetId(kakaoUserKey) | ||
| 806 | + petName = getPetName(petId) | ||
| 807 | + | ||
| 808 | + postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page) | ||
| 809 | + pageSize = len(postPagelist) | ||
| 810 | + try: | ||
| 811 | + pageNumber = int(getContextParamValue(payload, 'post', 'my_page')) - 1 | ||
| 812 | + except: | ||
| 813 | + pageNumber = 0 | ||
| 814 | + card_list = myImagePostCardList(postPagelist, pageNumber) | ||
| 815 | + outputList.append(cardArray(card_list)) | ||
| 816 | + | ||
| 817 | + qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName) | ||
| 818 | + | ||
| 819 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 820 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]내사진보기', datetime.datetime.now(), 'none') | ||
| 821 | + contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)})) | ||
| 822 | + | ||
| 823 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 824 | + | ||
| 825 | +# 다른 펫들의 사진보기 | ||
| 826 | +def get_openOthersPhotoAlbum_message(): | ||
| 827 | + contextList = [] | ||
| 828 | + outputList = [] | ||
| 829 | + qrList = [] | ||
| 830 | + | ||
| 831 | + payload = request.get_json() | ||
| 832 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 833 | + photoPostList = getOthersRandomPhotoPostList(kakaoUserKey) | ||
| 834 | + | ||
| 835 | + card_list = imagePostCardList(photoPostList, kakaoUserKey) | ||
| 836 | + outputList.append(cardArray(card_list)) | ||
| 837 | + | ||
| 838 | + qrList = qrList + othersPhotoWindow() | ||
| 839 | + | ||
| 840 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 841 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]다른사람사진', datetime.datetime.now(), 'none') | ||
| 842 | + contextList.append(contextValue('post', 1, {'like': 'alive'})) | ||
| 843 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 844 | + | ||
| 845 | +# 다른 펫들의 사진 랭킹순으로 보기 | ||
| 846 | +def get_openOthersPhotoByRank_message(): | ||
| 847 | + contextList = [] | ||
| 848 | + outputList = [] | ||
| 849 | + qrList = [] | ||
| 850 | + | ||
| 851 | + payload = request.get_json() | ||
| 852 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 853 | + photoPostList = getPhotoPostListByRank(kakaoUserKey) | ||
| 854 | + | ||
| 855 | + card_list = imagePostCardList(photoPostList, kakaoUserKey) | ||
| 856 | + outputList.append(cardArray(card_list)) | ||
| 857 | + | ||
| 858 | + qrList = qrList + othersPhotoWindow() | ||
| 859 | + | ||
| 860 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 861 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]다른사람사진랭킹순', datetime.datetime.now(), 'none') | ||
| 862 | + contextList.append(contextValue('post', 1, {'like': 'alive'})) | ||
| 863 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 864 | + | ||
| 865 | +# 다른 펫들의 사진 최신순으로 보기 | ||
| 866 | +def get_openOthersPhotoByNewest_message(): | ||
| 867 | + contextList = [] | ||
| 868 | + outputList = [] | ||
| 869 | + qrList = [] | ||
| 870 | + | ||
| 871 | + payload = request.get_json() | ||
| 872 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 873 | + photoPostList = getPhotoPostListByNewest(kakaoUserKey) | ||
| 874 | + | ||
| 875 | + card_list = imagePostCardList(photoPostList, kakaoUserKey) | ||
| 876 | + outputList.append(cardArray(card_list)) | ||
| 877 | + | ||
| 878 | + qrList = qrList + othersPhotoWindow() | ||
| 879 | + | ||
| 880 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 881 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]다른사람사진최신순', datetime.datetime.now(), 'none') | ||
| 882 | + contextList.append(contextValue('post', 1, {'like': 'alive'})) | ||
| 883 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 884 | + | ||
| 885 | + | ||
| 886 | + | ||
| 887 | +# 사진첩에서 좋아요 누른경우 | ||
| 888 | +def get_pushPhotoLike_message(): | ||
| 889 | + outputList = [] | ||
| 890 | + qrList = [] | ||
| 891 | + contextList = [] | ||
| 892 | + payload = request.get_json() | ||
| 893 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 894 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 895 | + | ||
| 896 | + utterance2 = utterance.replace('[시스템] ', '') | ||
| 897 | + u1 = utterance2.split('님의 ') | ||
| 898 | + nickname = u1[0] | ||
| 899 | + userkey = getKakaoUserKeyUsingNickName(nickname) | ||
| 900 | + u2 = u1[1].split('에 ') | ||
| 901 | + postTitle = u2[0] | ||
| 902 | + | ||
| 903 | + updatePostLike(userkey, postTitle, 1) | ||
| 904 | + photoPostList = getOthersRandomPhotoPostList(kakaoUserKey) | ||
| 905 | + | ||
| 906 | + card_list = imagePostCardList(photoPostList, kakaoUserKey) | ||
| 907 | + outputList.append(cardArray(card_list)) | ||
| 908 | + | ||
| 909 | + qrList = qrList + othersPhotoWindow() | ||
| 910 | + | ||
| 911 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 912 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]사진좋아요', datetime.datetime.now(), 'none') | ||
| 913 | + contextList.append(contextValue('post', 1, {'like': 'alive'})) | ||
| 914 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 915 | + | ||
| 916 | + | ||
| 917 | +# 내 사진에 좋아요 누른 경우 | ||
| 918 | +def get_pushLikeMyPhoto_message(): | ||
| 919 | + outputList = [] | ||
| 920 | + qrList = [] | ||
| 921 | + contextList = [] | ||
| 922 | + payload = request.get_json() | ||
| 923 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 924 | + | ||
| 925 | + photoPostList = getOthersRandomPhotoPostList(kakaoUserKey) | ||
| 926 | + card_list = imagePostCardList(photoPostList, kakaoUserKey) | ||
| 927 | + outputList.append(cardArray(card_list)) | ||
| 928 | + | ||
| 929 | + qrList = qrList + othersPhotoWindow() | ||
| 930 | + | ||
| 931 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 932 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]내사진에좋아요', datetime.datetime.now(), 'none') | ||
| 933 | + contextList.append(contextValue('post', 1, {'like': 'alive'})) | ||
| 934 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 935 | + | ||
| 936 | + | ||
| 937 | +def get_backToMain_message(): | ||
| 938 | + payload = request.get_json() | ||
| 939 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 940 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 941 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 942 | + petId = getPetId(kakaoUserKey) | ||
| 943 | + petName = getPetName(petId) | ||
| 944 | + relation = getRelation(kakaoUserKey, petId) | ||
| 945 | + font = getFont(kakaoUserKey, petId) | ||
| 946 | + now = datetime.datetime.now() | ||
| 947 | + | ||
| 948 | + # 펫 이미지 리스트 불러오기 | ||
| 949 | + category = '' | ||
| 950 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 951 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 952 | + | ||
| 953 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 954 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 955 | + contextList = [] | ||
| 956 | + qrList = [] | ||
| 957 | + qrList = addRandomHintQR(qrList, petName) | ||
| 958 | + qrList = qrList + basicButtonWindow(petName) | ||
| 959 | + outputList = tones.getMessageOutputList(font, 'backToMain', imageUrl, 90, petName, relation) | ||
| 960 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 961 | + addMessageLogs('bot', kakaoUserKey, '[시스템]메인으로', now, 'none') | ||
| 962 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 963 | + | ||
| 964 | +# 환경 설정 모두 완료 | ||
| 965 | +def get_finishUserConfiguration_message(): | ||
| 966 | + payload = request.get_json() | ||
| 967 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 968 | + petId = getPetId(kakaoUserKey) | ||
| 969 | + petName = getPetName(petId) | ||
| 970 | + font = getFont(kakaoUserKey,petId) | ||
| 971 | + relation = getRelation(kakaoUserKey,petId) | ||
| 972 | + | ||
| 973 | + category = '' | ||
| 974 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 975 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 976 | + | ||
| 977 | + deviceList = getDeviceListUsingUserKey(kakaoUserKey) | ||
| 978 | + # 기기연동하지 않고 환경설정 완료한 경우 | ||
| 979 | + if len(deviceList) == 0: | ||
| 980 | + contextList = [] | ||
| 981 | + qrList = basicButtonWindow(petName) | ||
| 982 | + outputList = tones.getMessageOutputList(font, 'welcomeMessage', imageUrl, 90, petName, relation) | ||
| 983 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 984 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동없이설정완료', datetime.datetime.now(), 'none') | ||
| 985 | + | ||
| 986 | + else: | ||
| 987 | + # user로 account id 불러오기 | ||
| 988 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 989 | + # account id 로 device id 불러오기 | ||
| 990 | + deviceId = getDeviceIdUsingAccountId(accountId) | ||
| 991 | + # device id로 fcmToken 불러오기 | ||
| 992 | + fcmToken = getFcmTokenUsingDeviceId(deviceId) | ||
| 993 | + | ||
| 994 | + # 어플리케이션에 환경설정 완료 push 날리기: 해당 푸쉬를 받아야 메인화면으로 넘어갈 수 있다 | ||
| 995 | + registration_id = fcmToken | ||
| 996 | + data_message = { | ||
| 997 | + "fromAPI": "finishConfiguration" | ||
| 998 | + } | ||
| 999 | + result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message) | ||
| 1000 | + | ||
| 1001 | + contextList = [] | ||
| 1002 | + qrList = basicButtonWindow(petName) | ||
| 1003 | + outputList = tones.getMessageOutputList(font, 'welcomeMessage', imageUrl, 90, petName, relation) | ||
| 1004 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1005 | + addMessageLogs('bot', kakaoUserKey, '[초기설정]설정완료', datetime.datetime.now(), 'none') | ||
| 1006 | + | ||
| 1007 | + updatefinishConfiguration(kakaoUserKey, True) | ||
| 1008 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1009 | + | ||
| 1010 | +# account 로그아웃 상태, 사용자에게 재로그인 요청 | ||
| 1011 | +def get_requestAccountLogin_message(): | ||
| 1012 | + contextList = [] | ||
| 1013 | + outputList = [] | ||
| 1014 | + qrList = [] | ||
| 1015 | + payload = request.get_json() | ||
| 1016 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1017 | + | ||
| 1018 | + outputList.append(simpleText('[시스템] 기존 계정이 로그아웃되었습니다')) | ||
| 1019 | + outputList.append(simpleText('어플리케이션을 다시 로그인해주시거나 기존 사용자 데이터를 초기화 후에 재시도해주세요')) | ||
| 1020 | + outputList.append(simpleText('사용자데이터를 초기화할까요?')) | ||
| 1021 | + | ||
| 1022 | + qrList.append(blockQuickReply('다시 로그인했습니다', '다시 로그인했습니다', '5d2452c3b617ea00011545ae')) | ||
| 1023 | + qrList.append(blockQuickReply('초기화하겠습니다⚠️', '초기화하겠습니다⚠️', '5dc00419b617ea000165f422')) | ||
| 1024 | + | ||
| 1025 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1026 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]사용자초기화시도', datetime.datetime.now(), 'none') | ||
| 1027 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1028 | + | ||
| 1029 | +def get_photoPostSpec_message(): | ||
| 1030 | + outputList = [] | ||
| 1031 | + qrList = [] | ||
| 1032 | + contextList = [] | ||
| 1033 | + payload = request.get_json() | ||
| 1034 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1035 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1036 | + petId = getPetId(kakaoUserKey) | ||
| 1037 | + petName = getPetName(petId) | ||
| 1038 | + | ||
| 1039 | + utterance2 = utterance.replace('[시스템] ', '') | ||
| 1040 | + postTitle = utterance2.replace(' 더보기🔍', '') | ||
| 1041 | + | ||
| 1042 | + card_list = [] | ||
| 1043 | + button_list = [] | ||
| 1044 | + try: | ||
| 1045 | + postLike = getPostLike(kakaoUserKey, postTitle) | ||
| 1046 | + postImageUrl = getPostImageUrl(kakaoUserKey, postTitle) | ||
| 1047 | + button_list.append(single_button('message', '제목수정', '[시스템] ' + postTitle + ' 수정✏️')) | ||
| 1048 | + button_list.append(single_button('message', '사진삭제', '[시스템] ' + postTitle + ' 삭제🗑️')) | ||
| 1049 | + card_list.append(squareCard(postTitle, '♡ ' + str(postLike), postImageUrl, 500, 500, button_list)) | ||
| 1050 | + outputList.append(cardArray(card_list)) | ||
| 1051 | + qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516')) | ||
| 1052 | + contextList.append(contextValue('post', 1, {'like': 'alive'})) | ||
| 1053 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1054 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]더보기', datetime.datetime.now(), 'none') | ||
| 1055 | + except: | ||
| 1056 | + outputList.append(simpleText('해당 게시물을 불러올 수 없습니다😓')) | ||
| 1057 | + qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516')) | ||
| 1058 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1059 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]더보기오류', datetime.datetime.now(), 'none') | ||
| 1060 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1061 | + | ||
| 1062 | +def get_tryFixPhotoPostTitle_message(): | ||
| 1063 | + outputList = [] | ||
| 1064 | + qrList = [] | ||
| 1065 | + contextList = [] | ||
| 1066 | + payload = request.get_json() | ||
| 1067 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1068 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1069 | + | ||
| 1070 | + utterance2 = utterance.replace('[시스템] ', '') | ||
| 1071 | + postTitle = utterance2.replace(' 수정✏️', '') | ||
| 1072 | + | ||
| 1073 | + outputList.append(simpleText('[시스템] 새로운 제목을 채팅창에 입력해주세요')) | ||
| 1074 | + contextList.append(contextValue('post', 1, {'fix_title': 'alive', 'kakaoUserKey': kakaoUserKey, 'title': postTitle})) | ||
| 1075 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1076 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]제목수정시도', datetime.datetime.now(), 'none') | ||
| 1077 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1078 | + | ||
| 1079 | +def get_fixPhotoPostTitle_message(): | ||
| 1080 | + outputList = [] | ||
| 1081 | + qrList = [] | ||
| 1082 | + contextList = [] | ||
| 1083 | + payload = request.get_json() | ||
| 1084 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1085 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1086 | + | ||
| 1087 | + beforeTitle = getContextParamValue(payload, 'post', 'title') | ||
| 1088 | + afterTitle = utterance | ||
| 1089 | + | ||
| 1090 | + if not isPostTitleValid(afterTitle): | ||
| 1091 | + outputList.append(simpleText('[시스템] 이미 존재하는 제목입니다')) | ||
| 1092 | + outputList.append(simpleText('[시스템] 새로운 제목을 채팅창에 입력해주세요')) | ||
| 1093 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1094 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]제목수정재시도', datetime.datetime.now(), 'none') | ||
| 1095 | + contextList.append(contextValue('post', 1, {'fix_title': 'alive', 'kakaoUserKey': kakaoUserKey, 'title': beforeTitle})) | ||
| 1096 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1097 | + updatePostTitle(kakaoUserKey, beforeTitle, afterTitle) | ||
| 1098 | + outputList.append(simpleText('[시스템] 변경되었습니다')) | ||
| 1099 | + | ||
| 1100 | + card_list = [] | ||
| 1101 | + button_list = [] | ||
| 1102 | + postLike = getPostLike(kakaoUserKey, afterTitle) | ||
| 1103 | + postImageUrl = getPostImageUrl(kakaoUserKey, afterTitle) | ||
| 1104 | + card_list.append(squareCard(afterTitle, '♡ ' + str(postLike), postImageUrl, 500, 500, button_list)) | ||
| 1105 | + outputList.append(cardArray(card_list)) | ||
| 1106 | + qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516')) | ||
| 1107 | + # qrList = qrList + basicButtonWindow(petName) | ||
| 1108 | + | ||
| 1109 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1110 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]더보기', datetime.datetime.now(), 'none') | ||
| 1111 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1112 | + | ||
| 1113 | +def get_tryDeletePhotoPost_message(): | ||
| 1114 | + outputList = [] | ||
| 1115 | + qrList = [] | ||
| 1116 | + contextList = [] | ||
| 1117 | + payload = request.get_json() | ||
| 1118 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1119 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 1120 | + | ||
| 1121 | + utterance2 = utterance.replace('[시스템] ', '') | ||
| 1122 | + postTitle = utterance2.replace(' 삭제🗑️', '') | ||
| 1123 | + | ||
| 1124 | + outputList.append(simpleText('[시스템] 정말로 삭제하시겠습니까?')) | ||
| 1125 | + qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516')) | ||
| 1126 | + qrList.append(blockQuickReply('삭제하기🗑️', '삭제하기🗑️', '')) | ||
| 1127 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1128 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]사진삭제시도', datetime.datetime.now(), 'none') | ||
| 1129 | + contextList.append( | ||
| 1130 | + contextValue('post', 1, {'delete_post': 'alive', 'kakaoUserKey': kakaoUserKey, 'title': postTitle})) | ||
| 1131 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1132 | + | ||
| 1133 | +def get_changeNickname_message(): | ||
| 1134 | + contextList = [] | ||
| 1135 | + outputList = [] | ||
| 1136 | + qrList = [] | ||
| 1137 | + payload = request.get_json() | ||
| 1138 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1139 | + petId = getPetId(kakaoUserKey) | ||
| 1140 | + petName = getPetName(petId) | ||
| 1141 | + newNickname = getUserUtteranceFromPayload(payload) | ||
| 1142 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 1143 | + myFonts = getUserProfileFonts(kakaoUserKey) | ||
| 1144 | + myDogiPoint = getUserDogiPoint(kakaoUserKey) | ||
| 1145 | + myBadges = getUserProfileBadges(kakaoUserKey) | ||
| 1146 | + | ||
| 1147 | + if not isNicknameValid(newNickname): | ||
| 1148 | + outputList.append(simpleText('[시스템] 이미 존재하는 닉네임이에요')) | ||
| 1149 | + outputList.append(simpleText('새로운 닉네임을 채팅창에 입력해주세요')) | ||
| 1150 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1151 | + addMessageLogs('bot', kakaoUserKey, '[사진첩]닉네임변경재시도', datetime.datetime.now(), 'none') | ||
| 1152 | + contextList.append(contextValue('nickname', 1, {'change_nickname': 'alive'})) | ||
| 1153 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1154 | + updateNickname(kakaoUserKey, newNickname) | ||
| 1155 | + outputList.append(simpleText('[시스템] 변경되었습니다')) | ||
| 1156 | + # 프로필 리스트 | ||
| 1157 | + outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, newNickname) | ||
| 1158 | + # setting button window | ||
| 1159 | + qrList = settingButtonWindow(kakaoUserKey, petName) | ||
| 1160 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1161 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]닉네임변경', datetime.datetime.now(), 'none') | ||
| 1162 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 1163 | + | ||
| 1164 | +def get_suggestConnect_message(): | ||
| 1165 | + contextList = [] | ||
| 1166 | + outputList = [] | ||
| 1167 | + qrList = [] | ||
| 1168 | + payload = request.get_json() | ||
| 1169 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 1170 | + petId = getPetId(kakaoUserKey) | ||
| 1171 | + petName = getPetName(petId) | ||
| 1172 | + | ||
| 1173 | + outputList.append(simpleText('[시스템] 댕댕어 번역에 오류가 발생하고있어요🥺')) | ||
| 1174 | + outputList.append(simpleText('남는 스마트폰을 연동시키면 ' + petName + '와 더욱 잘 대화할 수 있을텐데요..')) | ||
| 1175 | + | ||
| 1176 | + qrList.append(blockQuickReply('기기연동하러가기🔗', '기기연동하러가기🔗', '5e576874ffa7480001ef0808')) | ||
| 1177 | + qrList.append(blockQuickReply('생각해볼게요🤫', '생각해볼게요🤫', '5e576884ffa7480001ef080b')) | ||
| 1178 | + | ||
| 1179 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 1180 | + addMessageLogs('bot', kakaoUserKey, '[환경설정]기기연동권유', datetime.datetime.now(), 'none') | ||
| 1181 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/userAction.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 9 | +from Functions.getInstance import * | ||
| 10 | +from Functions.checkFunction import * | ||
| 11 | +from Functions.updateDatabase import * | ||
| 12 | +from Functions.messageTypes import * | ||
| 13 | +import tones | ||
| 14 | + | ||
| 15 | +def get_userComebackLate_message(): | ||
| 16 | + payload = request.get_json() | ||
| 17 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 18 | + | ||
| 19 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 20 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 21 | + petId = getPetId(kakaoUserKey) | ||
| 22 | + petName = getPetName(petId) | ||
| 23 | + relation = getRelation(kakaoUserKey, petId) | ||
| 24 | + font = getFont(kakaoUserKey, petId) | ||
| 25 | + now = datetime.datetime.now() | ||
| 26 | + | ||
| 27 | + category = '' | ||
| 28 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 29 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 30 | + | ||
| 31 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 32 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 33 | + contextList = [] | ||
| 34 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 35 | + try: | ||
| 36 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 37 | + except: | ||
| 38 | + repeatCount = 1 | ||
| 39 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 40 | + qrList = [] | ||
| 41 | + qrList = addRandomHintQR(qrList, petName) | ||
| 42 | + qrList = qrList + basicButtonWindow(petName) | ||
| 43 | + outputList = tones.getMessageOutputList(font, 'userComebackLate', imageUrl, 90, petName, relation) | ||
| 44 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 45 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 46 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 47 | + | ||
| 48 | +def get_userEat_message(): | ||
| 49 | + payload = request.get_json() | ||
| 50 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 51 | + | ||
| 52 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 53 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 54 | + petId = getPetId(kakaoUserKey) | ||
| 55 | + petName = getPetName(petId) | ||
| 56 | + relation = getRelation(kakaoUserKey, petId) | ||
| 57 | + font = getFont(kakaoUserKey, petId) | ||
| 58 | + now = datetime.datetime.now() | ||
| 59 | + | ||
| 60 | + category = '' | ||
| 61 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 62 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 63 | + | ||
| 64 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 65 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 66 | + contextList = [] | ||
| 67 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 68 | + try: | ||
| 69 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 70 | + except: | ||
| 71 | + repeatCount = 1 | ||
| 72 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 73 | + qrList = [] | ||
| 74 | + qrList = addRandomHintQR(qrList, petName) | ||
| 75 | + qrList = qrList + basicButtonWindow(petName) | ||
| 76 | + outputList = tones.getMessageOutputList(font, 'userEat', imageUrl, 90, petName, relation) | ||
| 77 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 78 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 79 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 80 | + | ||
| 81 | +def get_userComebackHome_message(): | ||
| 82 | + payload = request.get_json() | ||
| 83 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 84 | + | ||
| 85 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 86 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 87 | + petId = getPetId(kakaoUserKey) | ||
| 88 | + petName = getPetName(petId) | ||
| 89 | + relation = getRelation(kakaoUserKey, petId) | ||
| 90 | + font = getFont(kakaoUserKey, petId) | ||
| 91 | + now = datetime.datetime.now() | ||
| 92 | + | ||
| 93 | + category = '' | ||
| 94 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 95 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 96 | + | ||
| 97 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 98 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 99 | + contextList = [] | ||
| 100 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 101 | + try: | ||
| 102 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 103 | + except: | ||
| 104 | + repeatCount = 1 | ||
| 105 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 106 | + qrList = [] | ||
| 107 | + qrList = addRandomHintQR(qrList, petName) | ||
| 108 | + qrList = qrList + basicButtonWindow(petName) | ||
| 109 | + outputList = tones.getMessageOutputList(font, 'userComebackHome', imageUrl, 90, petName, relation) | ||
| 110 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 111 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 112 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 113 | + | ||
| 114 | +def get_userDrink_message(): | ||
| 115 | + payload = request.get_json() | ||
| 116 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 117 | + | ||
| 118 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 119 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 120 | + petId = getPetId(kakaoUserKey) | ||
| 121 | + petName = getPetName(petId) | ||
| 122 | + relation = getRelation(kakaoUserKey, petId) | ||
| 123 | + font = getFont(kakaoUserKey, petId) | ||
| 124 | + now = datetime.datetime.now() | ||
| 125 | + | ||
| 126 | + category = '' | ||
| 127 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 128 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 129 | + | ||
| 130 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 131 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 132 | + contextList = [] | ||
| 133 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 134 | + try: | ||
| 135 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 136 | + except: | ||
| 137 | + repeatCount = 1 | ||
| 138 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 139 | + qrList = [] | ||
| 140 | + qrList = addRandomHintQR(qrList, petName) | ||
| 141 | + qrList = qrList + basicButtonWindow(petName) | ||
| 142 | + outputList = tones.getMessageOutputList(font, 'userDrink', imageUrl, 90, petName, relation) | ||
| 143 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 144 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 145 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 146 | + | ||
| 147 | +def get_userGame_message(): | ||
| 148 | + payload = request.get_json() | ||
| 149 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 150 | + | ||
| 151 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 152 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 153 | + petId = getPetId(kakaoUserKey) | ||
| 154 | + petName = getPetName(petId) | ||
| 155 | + relation = getRelation(kakaoUserKey, petId) | ||
| 156 | + font = getFont(kakaoUserKey, petId) | ||
| 157 | + now = datetime.datetime.now() | ||
| 158 | + | ||
| 159 | + category = '' | ||
| 160 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 161 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 162 | + | ||
| 163 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 164 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 165 | + contextList = [] | ||
| 166 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 167 | + try: | ||
| 168 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 169 | + except: | ||
| 170 | + repeatCount = 1 | ||
| 171 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 172 | + qrList = [] | ||
| 173 | + qrList = addRandomHintQR(qrList, petName) | ||
| 174 | + qrList = qrList + basicButtonWindow(petName) | ||
| 175 | + outputList = tones.getMessageOutputList(font, 'userGame', imageUrl, 90, petName, relation) | ||
| 176 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 177 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 178 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 179 | + | ||
| 180 | +def get_userPublicTransit_message(): | ||
| 181 | + payload = request.get_json() | ||
| 182 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 183 | + | ||
| 184 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 185 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 186 | + petId = getPetId(kakaoUserKey) | ||
| 187 | + petName = getPetName(petId) | ||
| 188 | + relation = getRelation(kakaoUserKey, petId) | ||
| 189 | + font = getFont(kakaoUserKey, petId) | ||
| 190 | + now = datetime.datetime.now() | ||
| 191 | + | ||
| 192 | + category = '' | ||
| 193 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 194 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 195 | + | ||
| 196 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 197 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 198 | + contextList = [] | ||
| 199 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 200 | + try: | ||
| 201 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 202 | + except: | ||
| 203 | + repeatCount = 1 | ||
| 204 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 205 | + qrList = [] | ||
| 206 | + qrList = addRandomHintQR(qrList, petName) | ||
| 207 | + qrList = qrList + basicButtonWindow(petName) | ||
| 208 | + outputList = tones.getMessageOutputList(font, 'userPublicTransit', imageUrl, 90, petName, relation) | ||
| 209 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 210 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 211 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 212 | + | ||
| 213 | +def get_userToilet_message(): | ||
| 214 | + payload = request.get_json() | ||
| 215 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 216 | + | ||
| 217 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 218 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 219 | + petId = getPetId(kakaoUserKey) | ||
| 220 | + petName = getPetName(petId) | ||
| 221 | + relation = getRelation(kakaoUserKey, petId) | ||
| 222 | + font = getFont(kakaoUserKey, petId) | ||
| 223 | + now = datetime.datetime.now() | ||
| 224 | + | ||
| 225 | + category = '' | ||
| 226 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 227 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 228 | + | ||
| 229 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 230 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 231 | + contextList = [] | ||
| 232 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 233 | + try: | ||
| 234 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 235 | + except: | ||
| 236 | + repeatCount = 1 | ||
| 237 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 238 | + qrList = [] | ||
| 239 | + qrList = addRandomHintQR(qrList, petName) | ||
| 240 | + qrList = qrList + basicButtonWindow(petName) | ||
| 241 | + outputList = tones.getMessageOutputList(font, 'userToilet', imageUrl, 90, petName, relation) | ||
| 242 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 243 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 244 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 245 | + | ||
| 246 | +def get_userHangover_message(): | ||
| 247 | + payload = request.get_json() | ||
| 248 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 249 | + | ||
| 250 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 251 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 252 | + petId = getPetId(kakaoUserKey) | ||
| 253 | + petName = getPetName(petId) | ||
| 254 | + relation = getRelation(kakaoUserKey, petId) | ||
| 255 | + font = getFont(kakaoUserKey, petId) | ||
| 256 | + now = datetime.datetime.now() | ||
| 257 | + | ||
| 258 | + category = '' | ||
| 259 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 260 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 261 | + | ||
| 262 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 263 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 264 | + contextList = [] | ||
| 265 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 266 | + try: | ||
| 267 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 268 | + except: | ||
| 269 | + repeatCount = 1 | ||
| 270 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 271 | + qrList = [] | ||
| 272 | + qrList = addRandomHintQR(qrList, petName) | ||
| 273 | + qrList = qrList + basicButtonWindow(petName) | ||
| 274 | + outputList = tones.getMessageOutputList(font, 'userHangover', imageUrl, 90, petName, relation) | ||
| 275 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 276 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 277 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 278 | + | ||
| 279 | +def get_userExercise_message(): | ||
| 280 | + payload = request.get_json() | ||
| 281 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 282 | + | ||
| 283 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 284 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 285 | + petId = getPetId(kakaoUserKey) | ||
| 286 | + petName = getPetName(petId) | ||
| 287 | + relation = getRelation(kakaoUserKey, petId) | ||
| 288 | + font = getFont(kakaoUserKey, petId) | ||
| 289 | + now = datetime.datetime.now() | ||
| 290 | + | ||
| 291 | + category = '' | ||
| 292 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 293 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 294 | + | ||
| 295 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 296 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 297 | + contextList = [] | ||
| 298 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 299 | + try: | ||
| 300 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 301 | + except: | ||
| 302 | + repeatCount = 1 | ||
| 303 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 304 | + qrList = [] | ||
| 305 | + qrList = addRandomHintQR(qrList, petName) | ||
| 306 | + qrList = qrList + basicButtonWindow(petName) | ||
| 307 | + outputList = tones.getMessageOutputList(font, 'userExercise', imageUrl, 90, petName, relation) | ||
| 308 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 309 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 310 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 311 | + | ||
| 312 | +def get_userWatchMedia_message(): | ||
| 313 | + payload = request.get_json() | ||
| 314 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 315 | + | ||
| 316 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 317 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 318 | + petId = getPetId(kakaoUserKey) | ||
| 319 | + petName = getPetName(petId) | ||
| 320 | + relation = getRelation(kakaoUserKey, petId) | ||
| 321 | + font = getFont(kakaoUserKey, petId) | ||
| 322 | + now = datetime.datetime.now() | ||
| 323 | + | ||
| 324 | + category = '' | ||
| 325 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 326 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 327 | + | ||
| 328 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 329 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 330 | + contextList = [] | ||
| 331 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 332 | + try: | ||
| 333 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 334 | + except: | ||
| 335 | + repeatCount = 1 | ||
| 336 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 337 | + qrList = [] | ||
| 338 | + qrList = addRandomHintQR(qrList, petName) | ||
| 339 | + qrList = qrList + basicButtonWindow(petName) | ||
| 340 | + outputList = tones.getMessageOutputList(font, 'userWatchMedia', imageUrl, 90, petName, relation) | ||
| 341 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 342 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 343 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 344 | + | ||
| 345 | +def get_userGoingToEat_message(): | ||
| 346 | + payload = request.get_json() | ||
| 347 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 348 | + | ||
| 349 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 350 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 351 | + petId = getPetId(kakaoUserKey) | ||
| 352 | + petName = getPetName(petId) | ||
| 353 | + relation = getRelation(kakaoUserKey, petId) | ||
| 354 | + font = getFont(kakaoUserKey, petId) | ||
| 355 | + now = datetime.datetime.now() | ||
| 356 | + | ||
| 357 | + category = '' | ||
| 358 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 359 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 360 | + | ||
| 361 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 362 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 363 | + contextList = [] | ||
| 364 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 365 | + try: | ||
| 366 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 367 | + except: | ||
| 368 | + repeatCount = 1 | ||
| 369 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 370 | + qrList = [] | ||
| 371 | + qrList = addRandomHintQR(qrList, petName) | ||
| 372 | + qrList = qrList + basicButtonWindow(petName) | ||
| 373 | + outputList = tones.getMessageOutputList(font, 'userGoingToEat', imageUrl, 90, petName, relation) | ||
| 374 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 375 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 376 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 377 | + | ||
| 378 | +def get_userFinishEat_message(): | ||
| 379 | + payload = request.get_json() | ||
| 380 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 381 | + | ||
| 382 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 383 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 384 | + petId = getPetId(kakaoUserKey) | ||
| 385 | + petName = getPetName(petId) | ||
| 386 | + relation = getRelation(kakaoUserKey, petId) | ||
| 387 | + font = getFont(kakaoUserKey, petId) | ||
| 388 | + now = datetime.datetime.now() | ||
| 389 | + | ||
| 390 | + category = '' | ||
| 391 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 392 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 393 | + | ||
| 394 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 395 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 396 | + contextList = [] | ||
| 397 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 398 | + try: | ||
| 399 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 400 | + except: | ||
| 401 | + repeatCount = 1 | ||
| 402 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 403 | + qrList = [] | ||
| 404 | + qrList = addRandomHintQR(qrList, petName) | ||
| 405 | + qrList = qrList + basicButtonWindow(petName) | ||
| 406 | + outputList = tones.getMessageOutputList(font, 'userFinishEat', imageUrl, 90, petName, relation) | ||
| 407 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 408 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 409 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 410 | + | ||
| 411 | +def get_userDoNothing_message(): | ||
| 412 | + payload = request.get_json() | ||
| 413 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 414 | + | ||
| 415 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 416 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 417 | + petId = getPetId(kakaoUserKey) | ||
| 418 | + petName = getPetName(petId) | ||
| 419 | + relation = getRelation(kakaoUserKey, petId) | ||
| 420 | + font = getFont(kakaoUserKey, petId) | ||
| 421 | + now = datetime.datetime.now() | ||
| 422 | + | ||
| 423 | + category = '' | ||
| 424 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 425 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 426 | + | ||
| 427 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 428 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 429 | + contextList = [] | ||
| 430 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 431 | + try: | ||
| 432 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 433 | + except: | ||
| 434 | + repeatCount = 1 | ||
| 435 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 436 | + qrList = [] | ||
| 437 | + qrList = addRandomHintQR(qrList, petName) | ||
| 438 | + qrList = qrList + basicButtonWindow(petName) | ||
| 439 | + outputList = tones.getMessageOutputList(font, 'userDoNothing', imageUrl, 90, petName, relation) | ||
| 440 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 441 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 442 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 443 | + | ||
| 444 | +def get_userDoTiredThing_message(): | ||
| 445 | + payload = request.get_json() | ||
| 446 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 447 | + | ||
| 448 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 449 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 450 | + petId = getPetId(kakaoUserKey) | ||
| 451 | + petName = getPetName(petId) | ||
| 452 | + relation = getRelation(kakaoUserKey, petId) | ||
| 453 | + font = getFont(kakaoUserKey, petId) | ||
| 454 | + now = datetime.datetime.now() | ||
| 455 | + | ||
| 456 | + category = '' | ||
| 457 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 458 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 459 | + | ||
| 460 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 461 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 462 | + contextList = [] | ||
| 463 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 464 | + try: | ||
| 465 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 466 | + except: | ||
| 467 | + repeatCount = 1 | ||
| 468 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 469 | + qrList = [] | ||
| 470 | + qrList = addRandomHintQR(qrList, petName) | ||
| 471 | + qrList = qrList + basicButtonWindow(petName) | ||
| 472 | + outputList = tones.getMessageOutputList(font, 'userDoTiredThing', imageUrl, 90, petName, relation) | ||
| 473 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 474 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 475 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 476 | + | ||
| 477 | +def get_userLate_message(): | ||
| 478 | + payload = request.get_json() | ||
| 479 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 480 | + | ||
| 481 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 482 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 483 | + petId = getPetId(kakaoUserKey) | ||
| 484 | + petName = getPetName(petId) | ||
| 485 | + relation = getRelation(kakaoUserKey, petId) | ||
| 486 | + font = getFont(kakaoUserKey, petId) | ||
| 487 | + now = datetime.datetime.now() | ||
| 488 | + | ||
| 489 | + category = '' | ||
| 490 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 491 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 492 | + | ||
| 493 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 494 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 495 | + contextList = [] | ||
| 496 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 497 | + try: | ||
| 498 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 499 | + except: | ||
| 500 | + repeatCount = 1 | ||
| 501 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 502 | + qrList = [] | ||
| 503 | + qrList = addRandomHintQR(qrList, petName) | ||
| 504 | + qrList = qrList + basicButtonWindow(petName) | ||
| 505 | + outputList = tones.getMessageOutputList(font, 'userLate', imageUrl, 90, petName, relation) | ||
| 506 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 507 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 508 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 509 | + | ||
| 510 | +def get_userComebackSoon_message(): | ||
| 511 | + payload = request.get_json() | ||
| 512 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 513 | + | ||
| 514 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 515 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 516 | + petId = getPetId(kakaoUserKey) | ||
| 517 | + petName = getPetName(petId) | ||
| 518 | + relation = getRelation(kakaoUserKey, petId) | ||
| 519 | + font = getFont(kakaoUserKey, petId) | ||
| 520 | + now = datetime.datetime.now() | ||
| 521 | + | ||
| 522 | + category = '' | ||
| 523 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 524 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 525 | + | ||
| 526 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 527 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 528 | + contextList = [] | ||
| 529 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 530 | + try: | ||
| 531 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 532 | + except: | ||
| 533 | + repeatCount = 1 | ||
| 534 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 535 | + qrList = [] | ||
| 536 | + qrList = addRandomHintQR(qrList, petName) | ||
| 537 | + qrList = qrList + basicButtonWindow(petName) | ||
| 538 | + outputList = tones.getMessageOutputList(font, 'userComebackSoon', imageUrl, 90, petName, relation) | ||
| 539 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 540 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 541 | + return ordinaryMessageType(contextList, outputList, qrList) |
dogibogi/OpenbuilderSkills/userEmotion.py
0 → 100644
| 1 | +#-*-coding: utf-8 -*- | ||
| 2 | +import os | ||
| 3 | +import sys | ||
| 4 | +from flask import request | ||
| 5 | +import datetime | ||
| 6 | + | ||
| 7 | + | ||
| 8 | +sys.path.append(os.path.dirname(os.path.dirname("main"))) | ||
| 9 | +from Functions.getInstance import * | ||
| 10 | +from Functions.checkFunction import * | ||
| 11 | +from Functions.updateDatabase import * | ||
| 12 | +from Functions.messageTypes import * | ||
| 13 | +import tones | ||
| 14 | + | ||
| 15 | +def get_userLaugh_message(): | ||
| 16 | + payload = request.get_json() | ||
| 17 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 18 | + | ||
| 19 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 20 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 21 | + petId = getPetId(kakaoUserKey) | ||
| 22 | + petName = getPetName(petId) | ||
| 23 | + relation = getRelation(kakaoUserKey, petId) | ||
| 24 | + font = getFont(kakaoUserKey, petId) | ||
| 25 | + now = datetime.datetime.now() | ||
| 26 | + | ||
| 27 | + category = '' | ||
| 28 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 29 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 30 | + | ||
| 31 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 32 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 33 | + contextList = [] | ||
| 34 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 35 | + try: | ||
| 36 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 37 | + except: | ||
| 38 | + repeatCount = 1 | ||
| 39 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 40 | + qrList = [] | ||
| 41 | + qrList = addRandomHintQR(qrList, petName) | ||
| 42 | + qrList = qrList + basicButtonWindow(petName) | ||
| 43 | + outputList = tones.getMessageOutputList(font, 'laugh', imageUrl, 90, petName, relation) | ||
| 44 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 45 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 46 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 47 | + | ||
| 48 | +def get_userCry_message(): | ||
| 49 | + payload = request.get_json() | ||
| 50 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 51 | + | ||
| 52 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 53 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 54 | + petId = getPetId(kakaoUserKey) | ||
| 55 | + petName = getPetName(petId) | ||
| 56 | + relation = getRelation(kakaoUserKey, petId) | ||
| 57 | + font = getFont(kakaoUserKey, petId) | ||
| 58 | + now = datetime.datetime.now() | ||
| 59 | + | ||
| 60 | + category = '' | ||
| 61 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 62 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 63 | + | ||
| 64 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 65 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 66 | + contextList = [] | ||
| 67 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 68 | + try: | ||
| 69 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 70 | + except: | ||
| 71 | + repeatCount = 1 | ||
| 72 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 73 | + qrList = [] | ||
| 74 | + qrList = addRandomHintQR(qrList, petName) | ||
| 75 | + qrList = qrList + basicButtonWindow(petName) | ||
| 76 | + outputList = tones.getMessageOutputList(font, 'cry', imageUrl, 90, petName, relation) | ||
| 77 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 78 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 79 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 80 | + | ||
| 81 | +def get_userSad_message(): | ||
| 82 | + payload = request.get_json() | ||
| 83 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 84 | + | ||
| 85 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 86 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 87 | + petId = getPetId(kakaoUserKey) | ||
| 88 | + petName = getPetName(petId) | ||
| 89 | + relation = getRelation(kakaoUserKey, petId) | ||
| 90 | + font = getFont(kakaoUserKey, petId) | ||
| 91 | + now = datetime.datetime.now() | ||
| 92 | + | ||
| 93 | + category = '' | ||
| 94 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 95 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 96 | + | ||
| 97 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 98 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 99 | + contextList = [] | ||
| 100 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 101 | + try: | ||
| 102 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 103 | + except: | ||
| 104 | + repeatCount = 1 | ||
| 105 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 106 | + qrList = [] | ||
| 107 | + qrList = addRandomHintQR(qrList, petName) | ||
| 108 | + qrList = qrList + basicButtonWindow(petName) | ||
| 109 | + outputList = tones.getMessageOutputList(font, 'userSad', imageUrl, 90, petName, relation) | ||
| 110 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 111 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 112 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 113 | + | ||
| 114 | +def get_userTired_message(): | ||
| 115 | + payload = request.get_json() | ||
| 116 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 117 | + | ||
| 118 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 119 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 120 | + petId = getPetId(kakaoUserKey) | ||
| 121 | + petName = getPetName(petId) | ||
| 122 | + relation = getRelation(kakaoUserKey, petId) | ||
| 123 | + font = getFont(kakaoUserKey, petId) | ||
| 124 | + now = datetime.datetime.now() | ||
| 125 | + | ||
| 126 | + category = '' | ||
| 127 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 128 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 129 | + | ||
| 130 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 131 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 132 | + contextList = [] | ||
| 133 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 134 | + try: | ||
| 135 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 136 | + except: | ||
| 137 | + repeatCount = 1 | ||
| 138 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 139 | + qrList = [] | ||
| 140 | + qrList = addRandomHintQR(qrList, petName) | ||
| 141 | + qrList = qrList + basicButtonWindow(petName) | ||
| 142 | + outputList = tones.getMessageOutputList(font, 'userTired', imageUrl, 90, petName, relation) | ||
| 143 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 144 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 145 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 146 | + | ||
| 147 | +def get_userHungry_message(): | ||
| 148 | + payload = request.get_json() | ||
| 149 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 150 | + | ||
| 151 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 152 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 153 | + petId = getPetId(kakaoUserKey) | ||
| 154 | + petName = getPetName(petId) | ||
| 155 | + relation = getRelation(kakaoUserKey, petId) | ||
| 156 | + font = getFont(kakaoUserKey, petId) | ||
| 157 | + now = datetime.datetime.now() | ||
| 158 | + | ||
| 159 | + category = '' | ||
| 160 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 161 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 162 | + | ||
| 163 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 164 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 165 | + contextList = [] | ||
| 166 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 167 | + try: | ||
| 168 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 169 | + except: | ||
| 170 | + repeatCount = 1 | ||
| 171 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 172 | + qrList = [] | ||
| 173 | + qrList = addRandomHintQR(qrList, petName) | ||
| 174 | + qrList = qrList + basicButtonWindow(petName) | ||
| 175 | + outputList = tones.getMessageOutputList(font, 'userHungry', imageUrl, 90, petName, relation) | ||
| 176 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 177 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 178 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 179 | + | ||
| 180 | +def get_userWorry_message(): | ||
| 181 | + payload = request.get_json() | ||
| 182 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 183 | + | ||
| 184 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 185 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 186 | + petId = getPetId(kakaoUserKey) | ||
| 187 | + petName = getPetName(petId) | ||
| 188 | + relation = getRelation(kakaoUserKey, petId) | ||
| 189 | + font = getFont(kakaoUserKey, petId) | ||
| 190 | + now = datetime.datetime.now() | ||
| 191 | + | ||
| 192 | + category = '' | ||
| 193 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 194 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 195 | + | ||
| 196 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 197 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 198 | + contextList = [] | ||
| 199 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 200 | + try: | ||
| 201 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 202 | + except: | ||
| 203 | + repeatCount = 1 | ||
| 204 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 205 | + qrList = [] | ||
| 206 | + qrList = addRandomHintQR(qrList, petName) | ||
| 207 | + qrList = qrList + basicButtonWindow(petName) | ||
| 208 | + outputList = tones.getMessageOutputList(font, 'userWorry', imageUrl, 90, petName, relation) | ||
| 209 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 210 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 211 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 212 | + | ||
| 213 | +def get_userBoring_message(): | ||
| 214 | + payload = request.get_json() | ||
| 215 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 216 | + | ||
| 217 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 218 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 219 | + petId = getPetId(kakaoUserKey) | ||
| 220 | + petName = getPetName(petId) | ||
| 221 | + relation = getRelation(kakaoUserKey, petId) | ||
| 222 | + font = getFont(kakaoUserKey, petId) | ||
| 223 | + now = datetime.datetime.now() | ||
| 224 | + | ||
| 225 | + category = '' | ||
| 226 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 227 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 228 | + | ||
| 229 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 230 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 231 | + contextList = [] | ||
| 232 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 233 | + try: | ||
| 234 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 235 | + except: | ||
| 236 | + repeatCount = 1 | ||
| 237 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 238 | + qrList = [] | ||
| 239 | + qrList = addRandomHintQR(qrList, petName) | ||
| 240 | + qrList = qrList + basicButtonWindow(petName) | ||
| 241 | + outputList = tones.getMessageOutputList(font, 'userBoring', imageUrl, 90, petName, relation) | ||
| 242 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 243 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 244 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 245 | + | ||
| 246 | +def get_userAnnoying_message(): | ||
| 247 | + payload = request.get_json() | ||
| 248 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 249 | + | ||
| 250 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 251 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 252 | + petId = getPetId(kakaoUserKey) | ||
| 253 | + petName = getPetName(petId) | ||
| 254 | + relation = getRelation(kakaoUserKey, petId) | ||
| 255 | + font = getFont(kakaoUserKey, petId) | ||
| 256 | + now = datetime.datetime.now() | ||
| 257 | + | ||
| 258 | + category = '' | ||
| 259 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 260 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 261 | + | ||
| 262 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 263 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 264 | + contextList = [] | ||
| 265 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 266 | + try: | ||
| 267 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 268 | + except: | ||
| 269 | + repeatCount = 1 | ||
| 270 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 271 | + qrList = [] | ||
| 272 | + qrList = addRandomHintQR(qrList, petName) | ||
| 273 | + qrList = qrList + basicButtonWindow(petName) | ||
| 274 | + outputList = tones.getMessageOutputList(font, 'userAnnoying', imageUrl, 90, petName, relation) | ||
| 275 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 276 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 277 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 278 | + | ||
| 279 | +def get_userScrewed_message(): | ||
| 280 | + payload = request.get_json() | ||
| 281 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 282 | + | ||
| 283 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 284 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 285 | + petId = getPetId(kakaoUserKey) | ||
| 286 | + petName = getPetName(petId) | ||
| 287 | + relation = getRelation(kakaoUserKey, petId) | ||
| 288 | + font = getFont(kakaoUserKey, petId) | ||
| 289 | + now = datetime.datetime.now() | ||
| 290 | + | ||
| 291 | + category = '' | ||
| 292 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 293 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 294 | + | ||
| 295 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 296 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 297 | + contextList = [] | ||
| 298 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 299 | + try: | ||
| 300 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 301 | + except: | ||
| 302 | + repeatCount = 1 | ||
| 303 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 304 | + qrList = [] | ||
| 305 | + qrList = addRandomHintQR(qrList, petName) | ||
| 306 | + qrList = qrList + basicButtonWindow(petName) | ||
| 307 | + outputList = tones.getMessageOutputList(font, 'userScrewed', imageUrl, 90, petName, relation) | ||
| 308 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 309 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 310 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 311 | + | ||
| 312 | +def get_userHassle_message(): | ||
| 313 | + payload = request.get_json() | ||
| 314 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 315 | + | ||
| 316 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 317 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 318 | + petId = getPetId(kakaoUserKey) | ||
| 319 | + petName = getPetName(petId) | ||
| 320 | + relation = getRelation(kakaoUserKey, petId) | ||
| 321 | + font = getFont(kakaoUserKey, petId) | ||
| 322 | + now = datetime.datetime.now() | ||
| 323 | + | ||
| 324 | + category = '' | ||
| 325 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 326 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 327 | + | ||
| 328 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 329 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 330 | + contextList = [] | ||
| 331 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 332 | + try: | ||
| 333 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 334 | + except: | ||
| 335 | + repeatCount = 1 | ||
| 336 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 337 | + qrList = [] | ||
| 338 | + qrList = addRandomHintQR(qrList, petName) | ||
| 339 | + qrList = qrList + basicButtonWindow(petName) | ||
| 340 | + outputList = tones.getMessageOutputList(font, 'userHassle', imageUrl, 90, petName, relation) | ||
| 341 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 342 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 343 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 344 | + | ||
| 345 | +def get_userCheerful_message(): | ||
| 346 | + payload = request.get_json() | ||
| 347 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 348 | + | ||
| 349 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 350 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 351 | + petId = getPetId(kakaoUserKey) | ||
| 352 | + petName = getPetName(petId) | ||
| 353 | + relation = getRelation(kakaoUserKey, petId) | ||
| 354 | + font = getFont(kakaoUserKey, petId) | ||
| 355 | + now = datetime.datetime.now() | ||
| 356 | + | ||
| 357 | + category = '' | ||
| 358 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 359 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 360 | + | ||
| 361 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 362 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 363 | + contextList = [] | ||
| 364 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 365 | + try: | ||
| 366 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 367 | + except: | ||
| 368 | + repeatCount = 1 | ||
| 369 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 370 | + qrList = [] | ||
| 371 | + qrList = addRandomHintQR(qrList, petName) | ||
| 372 | + qrList = qrList + basicButtonWindow(petName) | ||
| 373 | + outputList = tones.getMessageOutputList(font, 'userCheerful', imageUrl, 90, petName, relation) | ||
| 374 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 375 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 376 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 377 | + | ||
| 378 | +def get_userUpset_message(): | ||
| 379 | + payload = request.get_json() | ||
| 380 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 381 | + | ||
| 382 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 383 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 384 | + petId = getPetId(kakaoUserKey) | ||
| 385 | + petName = getPetName(petId) | ||
| 386 | + relation = getRelation(kakaoUserKey, petId) | ||
| 387 | + font = getFont(kakaoUserKey, petId) | ||
| 388 | + now = datetime.datetime.now() | ||
| 389 | + | ||
| 390 | + category = '' | ||
| 391 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 392 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 393 | + | ||
| 394 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 395 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 396 | + contextList = [] | ||
| 397 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 398 | + try: | ||
| 399 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 400 | + except: | ||
| 401 | + repeatCount = 1 | ||
| 402 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 403 | + qrList = [] | ||
| 404 | + qrList = addRandomHintQR(qrList, petName) | ||
| 405 | + qrList = qrList + basicButtonWindow(petName) | ||
| 406 | + outputList = tones.getMessageOutputList(font, 'userUpset', imageUrl, 90, petName, relation) | ||
| 407 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 408 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 409 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 410 | + | ||
| 411 | +def get_userLonely_message(): | ||
| 412 | + payload = request.get_json() | ||
| 413 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 414 | + | ||
| 415 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 416 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 417 | + petId = getPetId(kakaoUserKey) | ||
| 418 | + petName = getPetName(petId) | ||
| 419 | + relation = getRelation(kakaoUserKey, petId) | ||
| 420 | + font = getFont(kakaoUserKey, petId) | ||
| 421 | + now = datetime.datetime.now() | ||
| 422 | + | ||
| 423 | + category = '' | ||
| 424 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 425 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 426 | + | ||
| 427 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 428 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 429 | + contextList = [] | ||
| 430 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 431 | + try: | ||
| 432 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 433 | + except: | ||
| 434 | + repeatCount = 1 | ||
| 435 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 436 | + qrList = [] | ||
| 437 | + qrList = addRandomHintQR(qrList, petName) | ||
| 438 | + qrList = qrList + basicButtonWindow(petName) | ||
| 439 | + outputList = tones.getMessageOutputList(font, 'userLonely', imageUrl, 90, petName, relation) | ||
| 440 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 441 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 442 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 443 | + | ||
| 444 | +def get_userDelicious_message(): | ||
| 445 | + payload = request.get_json() | ||
| 446 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 447 | + | ||
| 448 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 449 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 450 | + petId = getPetId(kakaoUserKey) | ||
| 451 | + petName = getPetName(petId) | ||
| 452 | + relation = getRelation(kakaoUserKey, petId) | ||
| 453 | + font = getFont(kakaoUserKey, petId) | ||
| 454 | + now = datetime.datetime.now() | ||
| 455 | + | ||
| 456 | + category = '' | ||
| 457 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 458 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 459 | + | ||
| 460 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 461 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 462 | + contextList = [] | ||
| 463 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 464 | + try: | ||
| 465 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 466 | + except: | ||
| 467 | + repeatCount = 1 | ||
| 468 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 469 | + qrList = [] | ||
| 470 | + qrList = addRandomHintQR(qrList, petName) | ||
| 471 | + qrList = qrList + basicButtonWindow(petName) | ||
| 472 | + outputList = tones.getMessageOutputList(font, 'userDelicious', imageUrl, 90, petName, relation) | ||
| 473 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 474 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 475 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 476 | + | ||
| 477 | +def get_userNonsense_message(): | ||
| 478 | + payload = request.get_json() | ||
| 479 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 480 | + | ||
| 481 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 482 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 483 | + petId = getPetId(kakaoUserKey) | ||
| 484 | + petName = getPetName(petId) | ||
| 485 | + relation = getRelation(kakaoUserKey, petId) | ||
| 486 | + font = getFont(kakaoUserKey, petId) | ||
| 487 | + now = datetime.datetime.now() | ||
| 488 | + | ||
| 489 | + category = '' | ||
| 490 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 491 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 492 | + | ||
| 493 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 494 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 495 | + contextList = [] | ||
| 496 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 497 | + try: | ||
| 498 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 499 | + except: | ||
| 500 | + repeatCount = 1 | ||
| 501 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 502 | + qrList = [] | ||
| 503 | + qrList = addRandomHintQR(qrList, petName) | ||
| 504 | + qrList = qrList + basicButtonWindow(petName) | ||
| 505 | + outputList = tones.getMessageOutputList(font, 'userNonsense', imageUrl, 90, petName, relation) | ||
| 506 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 507 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 508 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 509 | + | ||
| 510 | +def get_userAngry_message(): | ||
| 511 | + payload = request.get_json() | ||
| 512 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 513 | + | ||
| 514 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 515 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 516 | + petId = getPetId(kakaoUserKey) | ||
| 517 | + petName = getPetName(petId) | ||
| 518 | + relation = getRelation(kakaoUserKey, petId) | ||
| 519 | + font = getFont(kakaoUserKey, petId) | ||
| 520 | + now = datetime.datetime.now() | ||
| 521 | + | ||
| 522 | + category = '' | ||
| 523 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 524 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 525 | + | ||
| 526 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 527 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 528 | + contextList = [] | ||
| 529 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 530 | + try: | ||
| 531 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 532 | + except: | ||
| 533 | + repeatCount = 1 | ||
| 534 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 535 | + qrList = [] | ||
| 536 | + qrList = addRandomHintQR(qrList, petName) | ||
| 537 | + qrList = qrList + basicButtonWindow(petName) | ||
| 538 | + outputList = tones.getMessageOutputList(font, 'userAngry', imageUrl, 90, petName, relation) | ||
| 539 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 540 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 541 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 542 | + | ||
| 543 | +def get_userCold_message(): | ||
| 544 | + payload = request.get_json() | ||
| 545 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 546 | + | ||
| 547 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 548 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 549 | + petId = getPetId(kakaoUserKey) | ||
| 550 | + petName = getPetName(petId) | ||
| 551 | + relation = getRelation(kakaoUserKey, petId) | ||
| 552 | + font = getFont(kakaoUserKey, petId) | ||
| 553 | + now = datetime.datetime.now() | ||
| 554 | + | ||
| 555 | + category = '' | ||
| 556 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 557 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 558 | + | ||
| 559 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 560 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 561 | + contextList = [] | ||
| 562 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 563 | + try: | ||
| 564 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 565 | + except: | ||
| 566 | + repeatCount = 1 | ||
| 567 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 568 | + qrList = [] | ||
| 569 | + qrList = addRandomHintQR(qrList, petName) | ||
| 570 | + qrList = qrList + basicButtonWindow(petName) | ||
| 571 | + outputList = tones.getMessageOutputList(font, 'userCold', imageUrl, 90, petName, relation) | ||
| 572 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 573 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 574 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 575 | + | ||
| 576 | +def get_userHot_message(): | ||
| 577 | + payload = request.get_json() | ||
| 578 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 579 | + | ||
| 580 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 581 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 582 | + petId = getPetId(kakaoUserKey) | ||
| 583 | + petName = getPetName(petId) | ||
| 584 | + relation = getRelation(kakaoUserKey, petId) | ||
| 585 | + font = getFont(kakaoUserKey, petId) | ||
| 586 | + now = datetime.datetime.now() | ||
| 587 | + | ||
| 588 | + category = '' | ||
| 589 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 590 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 591 | + | ||
| 592 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 593 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 594 | + contextList = [] | ||
| 595 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 596 | + try: | ||
| 597 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 598 | + except: | ||
| 599 | + repeatCount = 1 | ||
| 600 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 601 | + qrList = [] | ||
| 602 | + qrList = addRandomHintQR(qrList, petName) | ||
| 603 | + qrList = qrList + basicButtonWindow(petName) | ||
| 604 | + outputList = tones.getMessageOutputList(font, 'userHot', imageUrl, 90, petName, relation) | ||
| 605 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 606 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 607 | + return ordinaryMessageType(contextList, outputList, qrList) | ||
| 608 | + | ||
| 609 | +def get_userSleepy_message(): | ||
| 610 | + payload = request.get_json() | ||
| 611 | + kakaoUserKey = getKakaoUserKeyFromPayload(payload) | ||
| 612 | + | ||
| 613 | + utterance = getUserUtteranceFromPayload(payload) | ||
| 614 | + accountId = getAccountIdusingUserKey(kakaoUserKey) | ||
| 615 | + petId = getPetId(kakaoUserKey) | ||
| 616 | + petName = getPetName(petId) | ||
| 617 | + relation = getRelation(kakaoUserKey, petId) | ||
| 618 | + font = getFont(kakaoUserKey, petId) | ||
| 619 | + now = datetime.datetime.now() | ||
| 620 | + | ||
| 621 | + category = '' | ||
| 622 | + imageUrls = getPetImageUrls(kakaoUserKey, category) | ||
| 623 | + imageUrl = getObjectByRandom(imageUrls) | ||
| 624 | + | ||
| 625 | + # 사용자가 보낸 메시지 messageLogs Collection에 저장 | ||
| 626 | + addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none') | ||
| 627 | + contextList = [] | ||
| 628 | + beforeUtterance = getContextParamValue(payload, 'utterance', 'before') | ||
| 629 | + try: | ||
| 630 | + repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat')) | ||
| 631 | + except: | ||
| 632 | + repeatCount = 1 | ||
| 633 | + contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount) | ||
| 634 | + qrList = [] | ||
| 635 | + qrList = addRandomHintQR(qrList, petName) | ||
| 636 | + qrList = qrList + basicButtonWindow(petName) | ||
| 637 | + outputList = tones.getMessageOutputList(font, 'userSleepy', imageUrl, 90, petName, relation) | ||
| 638 | + # 메시지 로그 저장 sender: bot, receiver: user | ||
| 639 | + addMessageLogs('bot', kakaoUserKey, outputList, now, 'none') | ||
| 640 | + return ordinaryMessageType(contextList, outputList, qrList) |
-
Please register or login to post a comment