system.py
49.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
#-*-coding: utf-8 -*-
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname("main")))
from Functions.getInstance import *
from Functions.updateDatabase import *
from Functions.checkFunction import *
from Functions import pyjosa
from Functions.messageTypes import *
import tones
from OpenbuilderSkills import minigame
import Api.Urls.imageUrls
import Config.systemKey
from flask import request
import ast
from pyfcm import FCMNotification
api_key = Config.systemKey.FCM_API_KEY
push_service = FCMNotification(api_key=api_key)
import datetime
import time
import random
from urllib import parse
# 챗봇 캐로셀 한번에 최대로 띄우는 카드뷰 갯수
post_size_by_page = 10
def get_fallBack_message():
# 특정 확률에 따라 넌센스퀴즈 시작
rv = random.randrange(0, 10)
if rv < 3:
return minigame.get_start_nonsense_quiz_message()
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
utterance = getUserUtteranceFromPayload(payload)
# 펫 이미지 리스트 불러오기
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, datetime.datetime.now(), 'none')
contextList = []
beforeUtterance = getContextParamValue(payload, 'utterance', 'before')
try:
repeatCount = int(getContextParamValue(payload, 'utterance', 'repeat'))
except:
repeatCount = 1
contextList += utteranceRepeatContext(beforeUtterance, utterance, repeatCount)
intent = getIntentName(payload)
beforeIntent = getContextParamValue(payload, 'intent', 'before')
try:
intentRepeatCount = int(getContextParamValue(payload, 'intent', 'repeat'))
except:
intentRepeatCount = 1
contextList += intentRepeatContext(beforeIntent, intent, intentRepeatCount)
qrList = []
qrList = addRandomHintQR(qrList, petName)
qrList = qrList + basicButtonWindow(petName)
# 사용자가 이미지를 채팅창에 입력한 경우
if 'http://dn-m.talk.kakao.com/talkm/' in utterance:
outputList = tones.getMessageOutputList(font, 'fallBackImage', imageUrl, 90, petName, relation)
else:
outputList = tones.getMessageOutputList(font, 'fallBack', imageUrl, 90, petName, relation)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_repeatSameUtterance_message():
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
now = datetime.datetime.now()
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
contextList = []
qrList = []
qrList = addRandomHintQR(qrList, petName)
qrList = qrList + basicButtonWindow(petName)
outputList = tones.getMessageOutputList(font, 'repeatSameUtterance', imageUrl, 10, petName, relation)
contextList.append(contextValue('utterance', 1, {'repeat': '2', 'before': utterance}))
# 같은말을 반복하는 경우의 패널티
rv = random.randrange(17,23)
incDogipoint(kakaoUserKey, -rv)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_repeatFallback_message():
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
intent = getIntentName(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
now = datetime.datetime.now()
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
contextList = []
qrList = []
qrList = addRandomHintQR(qrList, petName)
qrList = qrList + basicButtonWindow(petName)
outputList = tones.getMessageOutputList(font, 'repeatFallback', imageUrl, 10, petName, relation)
contextList.append(contextValue('intent', 1, {'repeat': '3', 'before': intent}))
# 알아들을 수 없는 말을 반복하는 경우의 패널티
rv = random.randrange(17, 23)
incDogipoint(kakaoUserKey, -rv)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, outputList, now, 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# qr코드 스캔을 통한 카메라 등록 권유: 현재 미사용
def get_tryAddCamera_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
deviceId = getDeviceIdUsingAccountId(accountId)
# 사용자 등록 여부를 확인하여 등록된 사용자가 아니라면 등록창으로
if isUserRegistered(kakaoUserKey) == False:
return get_startUserRegister_message()
# 펫 설정이 끝나지 않았다면 펫리스트로
if isPetSettingFinished(kakaoUserKey) == False:
return get_getPetList_message()
fcmToken = getFcmTokenUsingDeviceId(deviceId)
registration_id = fcmToken
# 카메라 등록 요청 push 보내기
data_message = {
"fromAPI": "requestDailyConfiguration"
}
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message)
outputList.append(simpleText('[시스템] [QR코드 스캔]을 진행합니다'))
qrList.append(blockQuickReply('알겠습니다', '알겠습니다', '5cf531058192ac0001cab975'))
return ordinaryMessageType(contextList, outputList, qrList)
# qr코드 스캔을 통한 카메라 등록 수행: 현재 미사용
def get_addCameraUseQRcode_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
# 사용자 등록 여부를 확인하여 등록된 사용자가 아니라면 등록창으로
if isUserRegistered(kakaoUserKey) == False:
return get_startUserRegister_message()
# 펫 설정이 끝나지 않았다면 펫리스트로
if isPetSettingFinished(kakaoUserKey) == False:
return get_getPetList_message()
data = ast.literal_eval(getQRcodeScanData(payload, 'addCameraDevice'))
# 스캔한 device 정보
deviceId = data['deviceId']
passwordCode = data['passwordCode']
# device id로 fcmToken 불러오기
fcmToken = getFcmTokenUsingDeviceId(deviceId)
registration_id = fcmToken
try:
# 해당 유저에게 이미 등록되어있는 device인지 확인하고 이미 있다면 passwordCode만 update
if isDeviceIdRegisteredInUser(kakaoUserKey, deviceId) == True:
updatePasswordCode(kakaoUserKey, deviceId, passwordCode)
# 최초 등록이라면 스캔한 user에 해당 device 정보 저장
else:
addDeviceToUser(kakaoUserKey, deviceId, passwordCode)
# 카메라 등록 완료 push 보내기
data_message2 = {
"fromAPI": "finishDailyConfiguration"
}
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message2)
outputList.append(simpleText('[시스템] 인증 완료되었습니다'))
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
# 챗봇 노란버튼
qrList = basicButtonWindow(petName)
except:
outputList.append(simpleText('[시스템] [QR코드 스캔]을 실패했습니다'))
qrList.append(blockQuickReply('재시도', '재시도', '5d70c2ee8192ac00011f6f97'))
return ordinaryMessageType(contextList,outputList,qrList)
# 영상을 수신할 device를 골라서 해당 device의 영상을 불러옴
def get_turnOnCamera_message():
contextList = []
outputList = []
qrList = []
buttonList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
deviceList = getDeviceListUsingUserKey(kakaoUserKey)
if len(deviceList) == 0:
outputList.append(simpleText('연동된 기기가 없어 ' + petName + '의 실시간 영상을 볼 수 없어요😔'))
qrList = basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[카드]미연동으로실시간확인실패', datetime.datetime.now(), 'none')
elif not checkAppAlive(accountId):
title = '오프라인'
detail = '어플리케이션이 꺼져있습니다'
card = buttonCard(title, detail, Api.Urls.imageUrls.nullType1, [])
outputList.append(card)
qrList = streamingWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[카드]앱종료로실시간확인실패', datetime.datetime.now(), 'none')
else:
deviceId = getDeviceIdUsingUserKey(kakaoUserKey)
fixedPetName = pyjosa.replace_josa(petName + '(은)는')
# deviceId로 fcmToken찾기
fcmToken = getFcmTokenUsingDeviceId(deviceId)
devicePasswordCode = getPasswordCodeUsingDeviceId(deviceId)
CODE = devicePasswordCode.split('_')
roomName = CODE[0] + str(int(time.time()))
# 갱신된 roomName push보내기
registration_id = fcmToken
data_message = {
"roomName": roomName,
"fromAPI": "moveToDetection"
}
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message)
# 스트리밍서버에 스트리밍 요청 url
streamingUrl = Config.systemKey.STREAMING_SERVER_URL + '/room/' + roomName + '?deviceId=' + deviceId + '&passwordCode=' + devicePasswordCode + '&fixedPetName=' + fixedPetName
streamingUrl = parse.urlparse(streamingUrl).geturl()
title = petName + '보기'
rv = random.randrange(0, 2)
if rv == 0:
detail = '해당 페이지는 사용 후 만료됩니다'
else:
detail = '와이파이 환경에서의 사용을 권장합니다'
buttonList.append(singleButton('webLink', petName + ' 실시간확인 ▶', streamingUrl))
streamingCard = buttonCard(title, detail, "https://dogibogi-storage.s3-ap-northeast-1.amazonaws.com/cardImage/pusa_wide_01.jpg", buttonList)
outputList.append(streamingCard)
qrList = streamingWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[카드]실시간확인', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 어플리케이션 상태 진단
def get_appStatus_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
# 앱이 살아있는지 확인
if checkAppAlive(accountId):
logData = getLastAndroidLogData(accountId)
temperature = logData['battery_temperature']
percent = logData['battery_percent']
title = '어플리케이션 상태'
detail = '🌡️기기 온도: ' + getDeviceTemperature(temperature) + '\n' + '🔋잔여 배터리: ' + getDeviceBatteryPercent(percent)
card = buttonCard(title, detail, "https://dogibogi-storage.s3-ap-northeast-1.amazonaws.com/cardImage/pusa_wide_01.jpg", [])
outputList.append(card)
else:
title = '오프라인'
detail = '어플리케이션이 꺼져있습니다'
card = buttonCard(title, detail, Api.Urls.imageUrls.nullType1, [])
outputList.append(card)
qrList = streamingWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[카드]어플진단', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 어플리케이션 강제 종료 시도
def get_tryAppRemoteQuit_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
# 앱이 살아있는지 확인
if checkAppAlive(accountId):
outputList.append(simpleText('⚠️정말로 집에있는 어플리케이션을 종료하시겠습니까?'))
qrList.append(blockQuickReply('예', '예', '5e5f61693ad5250001d681e0'))
qrList.append(blockQuickReply('아니오', '아니오', '5d369987ffa748000122e9a1'))
else:
outputList.append(simpleText('이미 오프라인 상태입니다'))
qrList = streamingWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[카드]어플강제종료시도', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 어플리케이션 강제 종료
def get_appRemoteQuit_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
deviceId = getDeviceIdUsingUserKey(kakaoUserKey)
fcmToken = getFcmTokenUsingDeviceId(deviceId)
registration_id = fcmToken
data_message = {
"fromAPI": "remoteQuit"
}
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message)
outputList.append(simpleText('어플리케이션이 종료되었습니다'))
outputList.append(simpleText('다시 어플을 실행해야 ' + petName + '을 볼 수 있어요'))
qrList = []
qrList = addRandomHintQR(qrList, petName)
qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[카드]어플강제종료', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# qr코드 스캔을 통한 account 정보 불러와서 신규 유저 등록
def get_userRegisterUseQRcode_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
pfKey = getPlusFriendUserKeyFromPayload(payload)
updatefinishConfiguration(kakaoUserKey, False)
try:
# 스캔한 qr code data
data = ast.literal_eval(getQRcodeScanData(payload, 'userRegister'))
accountId = data['id']
petIds = data['petIds']
# 이미 유저가 있는 경우 기존 pet list를 삭제하고 스캔한 정보로 최신화
if isUserRegistered(kakaoUserKey):
clearUserPetList(kakaoUserKey)
updateAccountIdToUser(kakaoUserKey, accountId)
addPetsToUser(kakaoUserKey, petIds)
# 유저가 없는 경우 신규 유저 등록
else:
addNewUser(kakaoUserKey, pfKey, accountId, petIds)
# 해당 account에서 deviceId 불러오기
deviceId = getDeviceIdUsingAccountId(accountId)
# deviceId로 passwordCode 불러오기
passwordCode = getPasswordCodeUsingDeviceId(deviceId)
# user device list 에 deviceId, passwordCode 추가
addDeviceToUser(kakaoUserKey, deviceId, passwordCode)
# deviceId로 fcmToken 찾기
fcmToken = getFcmTokenUsingDeviceId(deviceId)
# 해당 디바이스에 fcmToken 이용해서 push날리기
registration_id = fcmToken
data_message = {
"fromAPI": "connectKakaoConfiguration"
}
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message)
outputList.append(simpleText('기기연동이 완료되었어요'))
outputList.append(simpleText('이제 아래 버튼을 눌러 남은 설정을 완료해주시겠어요?'))
qrList.append(blockQuickReply('진행할게요', '진행할게요', '5d42e91d92690d00012b208b'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동완료', datetime.datetime.now(), 'none')
except:
outputList.append(simpleText('기기연동을 실패했습니다😔'))
outputList.append(simpleText('어플리케이션 회원가입뒤에 나오는 QR코드를 스캔해야해요'))
outputList.append(simpleText('올바른 QR코드를 스캔했는지 다시 확인해보시겠어요?'))
qrList.append(blockQuickReply('기기연동 다시진행', '기기연동 다시진행', '5d3fa9d48192ac0001fc4ed1'))
qrList.append(blockQuickReply('무슨말인지 모르겠어요🤔', '무슨말인지 모르겠어요🤔', '5d412052b617ea0001a327bb'))
return ordinaryMessageType(contextList, outputList, qrList)
# qr코드 스캔없이 신규 유저 등록
def get_userRegisterWithoutDevice_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
outputList.append(simpleText('네🙂 그러면 채팅을 위해 간단히 몇가지만 물어볼게요'))
outputList.append(simpleText('지금 같이 살고있는 반려동물의 이름을 말해주시겠어요?'))
qrList.append(blockQuickReply('반려동물이 없어요😓', '반려동물이 없어요😓', '5e63c1efa04f9b0001891113'))
contextList.append(contextValue('register', 1, {'without_device': 'alive'}))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동없이유저등록', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_settingPetNameWithoutDevice():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
pfKey = getPlusFriendUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
petName = getFixedPetName(utterance)
petId = getNewPetId()
addNewPet(petId, petName, '', '', '', '', '')
accountId = '미연동'
petIds = [
{
'petId': petId,
'relation': '',
'font': ''
}
]
# 신규 유저 등록
addNewUser(kakaoUserKey, pfKey, accountId, petIds)
outputList.append(simpleText(petName + '.. 정말 귀여운 이름이에요😊'))
outputList.append(simpleText(pyjosa.replace_josa(petName + '(와)과 채팅을 하기 위해서는 ' + petName + '사진이 필요해요')))
outputList.append(simpleText('아래 버튼을 눌러 계속 진행해주세요'))
qrList.append(blockQuickReply('진행할게요', '진행할게요', '5d42e91d92690d00012b208b'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동없이유저등록완료', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 유저 등록 진행 시작. 사용자에게 유저 등록 제안
def get_startUserRegister_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
outputList.append(simpleText('우리집 멍멍이와 채팅하러 오셨군요!😃'))
outputList.append(simpleText('지금바로 카카오톡과 어플리케이션 연동을 진행해볼까요?'))
qrList.append(blockQuickReply('연동 바로진행🔗', '연동 바로진행🔗', '5d3fa9d48192ac0001fc4ed1'))
qrList.append(blockQuickReply('연동없이 시작하기🐾', '연동없이 시작하기🐾', '5e57326992690d0001c9c4c1'))
qrList.append(blockQuickReply('도기보기를 알고싶어요😲', '도기보기를 알고싶어요😲', '5d4112cbb617ea0001a32762'))
qrList.append(blockQuickReply('다음에 다시올게요🙄', '다음에 다시올게요🙄', '5e578234ffa7480001ef0a0c'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동시작', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# TODO 카드리스트를 제거하여 간소화하는 방안으로
# 유저 등록 완료후 환경설정. 펫 리스트 출력
def get_getPetList_message():
contextList = []
outputList = []
qrList = []
buttonList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey,petId)
font = getFont(kakaoUserKey,petId)
# users - pets - imageUrls에 있는 url 중 하나 랜덤으로 꺼내서 imageUrl로 쓰기
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
# url들 중 하나 뽑아서 imageUrl로 설정
imageUrl = getObjectByRandom(imageUrls)
title = petName
if relation != '' and font != '' and imageUrl != '':
detail = getPetPersonality(relation,font)
buttonList.append(singleButton('block', petName + '짤 더 올리기', '5d42e91d92690d00012b208b'))
pet1 = buttonCard(title, detail, imageUrl, buttonList)
outputList.append(pet1)
# 챗봇 노란버튼
qrList = basicButtonWindow(petName)
return ordinaryMessageType(contextList,outputList,qrList)
else:
buttonList.append(singleButton('block', '🐶도기설정', '5d42e91d92690d00012b208b'))
detail = '🐶도기설정 미완료'
pet1 = buttonCard(title, detail, Api.Urls.imageUrls.nullType1, buttonList)
outputList.append(pet1)
return ordinaryMessageType(contextList, outputList, qrList)
# kakao측 url list(string type)을 split해서 dict로 저장
def splitKakaoImageUrlList(imageUrlList):
imageUrlList = imageUrlList.replace("List", "")
imageUrlList = imageUrlList.replace("(", "")
imageUrlList = imageUrlList.replace(")", "")
imageUrlList = list(imageUrlList.split(", "))
return imageUrlList
# 펫 이미지 추가(설정)
# firebase storage에 petImage/[kakaoUserKey] directory에 저장
def get_addPetImage_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey,petId)
font = getFont(kakaoUserKey,petId)
# payload에서 이미지 url list 가져오기
kakaoImageUrlList = getQRcodeScanData(payload, 'addPetImage')
# kakao image url split해서 dict에 저장
imageUrlList = splitKakaoImageUrlList(kakaoImageUrlList)
# TODO Pending: background processing 하고싶은데.. 잘모르겠다
# kakaoUserKey와 imageUrls 입력받아서 해당 이미지를 AWS S3 storage에 저장
uploadResizedImageToStorage(kakaoUserKey,petId,imageUrlList)
uploadImageToStorage(kakaoUserKey, petId, imageUrlList)
outputList.append(simpleText('정상적으로 업로드되었습니다'))
outputList.append(simpleText('업로드한 사진은 사진첩에서 언제든지 꺼내볼 수 있어요!'))
# 설정 완료했는데 이미지만 추가하는 경우
if relation != '' and font != '':
qrList = basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[환경설정]펫이미지추가', datetime.datetime.now(), 'none')
# 이미지 추가하고 이어서 font 설정
else:
outputList.append(simpleText('그럼 이제 ' + petName + '의 말투를 골라주세요'))
# quick Reply List에 설정 가능한 말투들 추가: 버튼으로 적용
fonts = getUserFonts(kakaoUserKey)
fontList = []
for font in fonts:
fontList.append(getFontFromVar(font['font']))
qrList = fontSettingWindow(fontList)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]펫이미지설정', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 펫 폰트 설정(font)
# 이미지 추가할 때 받은 문구들로 font 설정해서 db에 저장
def get_setPetFont_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
# 앞서 버튼으로 입력한 말투들을 font로 가져옴
utterance = getUserUtteranceFromPayload(payload)
font = getFontFromUtterance(utterance)
# 가져온 font db에 저장
updateFont(kakaoUserKey,petId,font)
# 최초의 설정에서 말투를 설정한 경우 호칭설정으로 진행
if getRelation(kakaoUserKey,petId) == "":
outputList.append(simpleText(petName + '와는 무슨사이인가요?'))
qrList = relationSettingWindow()
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]말투설정', datetime.datetime.now(), 'none')
# 환경설정에서 말투를 바꾸는 경우
else:
nickname = getUserNickname(kakaoUserKey)
accountId = getAccountIdusingUserKey(kakaoUserKey)
myFonts = getUserProfileFonts(kakaoUserKey)
myDogiPoint = getUserDogiPoint(kakaoUserKey)
myBadges = getUserProfileBadges(kakaoUserKey)
outputList.append(simpleText('[시스템] 변경되었습니다'))
# 프로필 리스트
outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)
# setting button window
qrList = settingButtonWindow(kakaoUserKey, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[환경설정]말투변경성공', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 펫 관계 설정(relation)
# 폰트 설정할 때 받은 utterance로 relation 설정해서 db에 저장
def get_setPetRelation_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
utterance = getUserUtteranceFromPayload(payload)
relation = utterance
updateRelation(kakaoUserKey,petId,relation)
# 이미 챗봇에서 초기설정을 한번 진행했고, 환경설정에서 관계를 재설정하는 경우
if getFinishConfiguration(kakaoUserKey):
nickname = getUserNickname(kakaoUserKey)
accountId = getAccountIdusingUserKey(kakaoUserKey)
myFonts = getUserProfileFonts(kakaoUserKey)
myDogiPoint = getUserDogiPoint(kakaoUserKey)
myBadges = getUserProfileBadges(kakaoUserKey)
outputList.append(simpleText('[시스템] 변경되었습니다'))
# 프로필 리스트
outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)
# setting button window
qrList = settingButtonWindow(kakaoUserKey, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[환경설정]호칭변경성공', datetime.datetime.now(), 'none')
# 최초의 설정에서 관계를 설정한 경우 카드뷰로 진행
else :
outputList.append(simpleText('설정이 완료되었습니다'))
card_list = serviceIntroductionCardList(petName)
outputList.append(cardArray(card_list))
outputList.append(simpleText('앗! 때마침 ' + petName + '에게 카톡이 왔어요!💌'))
qrList.append(blockQuickReply('확인해보기!', '확인해보기!', '5d43e36692690d000134afab'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]호칭설정', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 사진보기
def get_openPhotoAlbum_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page)
pageSize = len(postPagelist)
pageNumber = 0
# list가 비어있으면 사진 추가 권유하기
if len(postPagelist) == 0:
outputList.append(simpleText('[시스템] 사진첩에 ' + petName + '사진을 추가하시겠어요?'))
qrList.append(blockQuickReply('추가할게요😃', '추가할게요😃', '5d42e91d92690d00012b208b'))
return ordinaryMessageType(contextList, outputList, qrList)
card_list = myImagePostCardList(postPagelist, pageNumber)
outputList.append(cardArray(card_list))
qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]사진보기', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)}))
return ordinaryMessageType(contextList, outputList, qrList)
# 사진 삭제
def get_deletePhotoPost_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
title = getContextParamValue(payload, 'post', 'title')
# 해당 게시물 삭제하기
deleteImagePost(kakaoUserKey, title)
outputList.append(simpleText('[시스템] 삭제되었습니다'))
postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page)
pageSize = len(postPagelist)
pageNumber = 0
# list가 비어있으면 사진 추가 권유하기
if len(postPagelist) == 0:
outputList.append(simpleText('[시스템] 사진첩에 ' + petName + '사진을 추가하시겠어요?'))
qrList.append(blockQuickReply('추가할게요😃', '추가할게요😃', '5d42e91d92690d00012b208b'))
return ordinaryMessageType(contextList, outputList, qrList)
card_list = myImagePostCardList(postPagelist, pageNumber)
outputList.append(cardArray(card_list))
qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]사진삭제', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)}))
return ordinaryMessageType(contextList, outputList, qrList)
# 다음페이지 사진 보기
def get_photoAlbumNextPage_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page)
pageSize = len(postPagelist)
try:
pageNumber = int(getContextParamValue(payload, 'post', 'my_page')) + 1
except:
pageNumber = 0
card_list = myImagePostCardList(postPagelist, pageNumber)
outputList.append(cardArray(card_list))
qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]내사진보기', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)}))
return ordinaryMessageType(contextList, outputList, qrList)
# 이전페이지 사진 보기
def get_photoAlbumBackPage_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
postPagelist = getPhotoPostPageList(kakaoUserKey, post_size_by_page)
pageSize = len(postPagelist)
try:
pageNumber = int(getContextParamValue(payload, 'post', 'my_page')) - 1
except:
pageNumber = 0
card_list = myImagePostCardList(postPagelist, pageNumber)
outputList.append(cardArray(card_list))
qrList = qrList + photoAlbumWindow(pageSize, pageNumber, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]내사진보기', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 3, {'like': 'alive', 'my_page': str(pageNumber)}))
return ordinaryMessageType(contextList, outputList, qrList)
# 다른 펫들의 사진보기
def get_openOthersPhotoAlbum_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
photoPostList = getOthersRandomPhotoPostList(kakaoUserKey)
card_list = imagePostCardList(photoPostList, kakaoUserKey)
outputList.append(cardArray(card_list))
qrList = qrList + othersPhotoWindow()
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]다른사람사진', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 1, {'like': 'alive'}))
return ordinaryMessageType(contextList, outputList, qrList)
# 다른 펫들의 사진 랭킹순으로 보기
def get_openOthersPhotoByRank_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
photoPostList = getPhotoPostListByRank(kakaoUserKey)
card_list = imagePostCardList(photoPostList, kakaoUserKey)
outputList.append(cardArray(card_list))
qrList = qrList + othersPhotoWindow()
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]다른사람사진랭킹순', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 1, {'like': 'alive'}))
return ordinaryMessageType(contextList, outputList, qrList)
# 다른 펫들의 사진 최신순으로 보기
def get_openOthersPhotoByNewest_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
photoPostList = getPhotoPostListByNewest(kakaoUserKey)
card_list = imagePostCardList(photoPostList, kakaoUserKey)
outputList.append(cardArray(card_list))
qrList = qrList + othersPhotoWindow()
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]다른사람사진최신순', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 1, {'like': 'alive'}))
return ordinaryMessageType(contextList, outputList, qrList)
# 사진첩에서 좋아요 누른경우
def get_pushPhotoLike_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
utterance2 = utterance.replace('[시스템] ', '')
u1 = utterance2.split('님의 ')
nickname = u1[0]
userkey = getKakaoUserKeyUsingNickName(nickname)
u2 = u1[1].split('에 ')
postTitle = u2[0]
updatePostLike(userkey, postTitle, 1)
photoPostList = getOthersRandomPhotoPostList(kakaoUserKey)
card_list = imagePostCardList(photoPostList, kakaoUserKey)
outputList.append(cardArray(card_list))
qrList = qrList + othersPhotoWindow()
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]사진좋아요', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 1, {'like': 'alive'}))
return ordinaryMessageType(contextList, outputList, qrList)
# 내 사진에 좋아요 누른 경우
def get_pushLikeMyPhoto_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
photoPostList = getOthersRandomPhotoPostList(kakaoUserKey)
card_list = imagePostCardList(photoPostList, kakaoUserKey)
outputList.append(cardArray(card_list))
qrList = qrList + othersPhotoWindow()
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]내사진에좋아요', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 1, {'like': 'alive'}))
return ordinaryMessageType(contextList, outputList, qrList)
def get_backToMain_message():
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
relation = getRelation(kakaoUserKey, petId)
font = getFont(kakaoUserKey, petId)
now = datetime.datetime.now()
# 펫 이미지 리스트 불러오기
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
# 사용자가 보낸 메시지 messageLogs Collection에 저장
addMessageLogs(kakaoUserKey, 'bot', utterance, now, 'none')
contextList = []
qrList = []
qrList = addRandomHintQR(qrList, petName)
qrList = qrList + basicButtonWindow(petName)
outputList = tones.getMessageOutputList(font, 'backToMain', imageUrl, 90, petName, relation)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[시스템]메인으로', now, 'none')
return ordinaryMessageType(contextList, outputList, qrList)
# 환경 설정 모두 완료
def get_finishUserConfiguration_message():
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
font = getFont(kakaoUserKey,petId)
relation = getRelation(kakaoUserKey,petId)
category = ''
imageUrls = getPetImageUrls(kakaoUserKey, category)
imageUrl = getObjectByRandom(imageUrls)
deviceList = getDeviceListUsingUserKey(kakaoUserKey)
# 기기연동하지 않고 환경설정 완료한 경우
if len(deviceList) == 0:
contextList = []
qrList = basicButtonWindow(petName)
outputList = tones.getMessageOutputList(font, 'welcomeMessage', imageUrl, 90, petName, relation)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]기기연동없이설정완료', datetime.datetime.now(), 'none')
else:
# user로 account id 불러오기
accountId = getAccountIdusingUserKey(kakaoUserKey)
# account id 로 device id 불러오기
deviceId = getDeviceIdUsingAccountId(accountId)
# device id로 fcmToken 불러오기
fcmToken = getFcmTokenUsingDeviceId(deviceId)
# 어플리케이션에 환경설정 완료 push 날리기: 해당 푸쉬를 받아야 메인화면으로 넘어갈 수 있다
registration_id = fcmToken
data_message = {
"fromAPI": "finishConfiguration"
}
result = push_service.notify_single_device(registration_id=registration_id, data_message=data_message)
contextList = []
qrList = basicButtonWindow(petName)
outputList = tones.getMessageOutputList(font, 'welcomeMessage', imageUrl, 90, petName, relation)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[초기설정]설정완료', datetime.datetime.now(), 'none')
updatefinishConfiguration(kakaoUserKey, True)
return ordinaryMessageType(contextList, outputList, qrList)
# account 로그아웃 상태, 사용자에게 재로그인 요청
def get_requestAccountLogin_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
outputList.append(simpleText('[시스템] 기존 계정이 로그아웃되었습니다'))
outputList.append(simpleText('어플리케이션을 다시 로그인해주시거나 기존 사용자 데이터를 초기화 후에 재시도해주세요'))
outputList.append(simpleText('사용자데이터를 초기화할까요?'))
qrList.append(blockQuickReply('다시 로그인했습니다', '다시 로그인했습니다', '5d2452c3b617ea00011545ae'))
qrList.append(blockQuickReply('초기화하겠습니다⚠️', '초기화하겠습니다⚠️', '5dc00419b617ea000165f422'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[환경설정]사용자초기화시도', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_photoPostSpec_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
utterance2 = utterance.replace('[시스템] ', '')
postTitle = utterance2.replace(' 더보기🔍', '')
card_list = []
button_list = []
try:
postLike = getPostLike(kakaoUserKey, postTitle)
postImageUrl = getPostImageUrl(kakaoUserKey, postTitle)
button_list.append(single_button('message', '제목수정', '[시스템] ' + postTitle + ' 수정✏️'))
button_list.append(single_button('message', '사진삭제', '[시스템] ' + postTitle + ' 삭제🗑️'))
card_list.append(squareCard(postTitle, '♡ ' + str(postLike), postImageUrl, 500, 500, button_list))
outputList.append(cardArray(card_list))
qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516'))
contextList.append(contextValue('post', 1, {'like': 'alive'}))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]더보기', datetime.datetime.now(), 'none')
except:
outputList.append(simpleText('해당 게시물을 불러올 수 없습니다😓'))
qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]더보기오류', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_tryFixPhotoPostTitle_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
utterance2 = utterance.replace('[시스템] ', '')
postTitle = utterance2.replace(' 수정✏️', '')
outputList.append(simpleText('[시스템] 새로운 제목을 채팅창에 입력해주세요'))
contextList.append(contextValue('post', 1, {'fix_title': 'alive', 'kakaoUserKey': kakaoUserKey, 'title': postTitle}))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]제목수정시도', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_fixPhotoPostTitle_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
beforeTitle = getContextParamValue(payload, 'post', 'title')
afterTitle = utterance
if not isPostTitleValid(afterTitle):
outputList.append(simpleText('[시스템] 이미 존재하는 제목입니다'))
outputList.append(simpleText('[시스템] 새로운 제목을 채팅창에 입력해주세요'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]제목수정재시도', datetime.datetime.now(), 'none')
contextList.append(contextValue('post', 1, {'fix_title': 'alive', 'kakaoUserKey': kakaoUserKey, 'title': beforeTitle}))
return ordinaryMessageType(contextList, outputList, qrList)
updatePostTitle(kakaoUserKey, beforeTitle, afterTitle)
outputList.append(simpleText('[시스템] 변경되었습니다'))
card_list = []
button_list = []
postLike = getPostLike(kakaoUserKey, afterTitle)
postImageUrl = getPostImageUrl(kakaoUserKey, afterTitle)
card_list.append(squareCard(afterTitle, '♡ ' + str(postLike), postImageUrl, 500, 500, button_list))
outputList.append(cardArray(card_list))
qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516'))
# qrList = qrList + basicButtonWindow(petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]더보기', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_tryDeletePhotoPost_message():
outputList = []
qrList = []
contextList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
utterance = getUserUtteranceFromPayload(payload)
utterance2 = utterance.replace('[시스템] ', '')
postTitle = utterance2.replace(' 삭제🗑️', '')
outputList.append(simpleText('[시스템] 정말로 삭제하시겠습니까?'))
qrList.append(blockQuickReply('돌아가기↩', '돌아가기↩', '5e4d343b8192ac000136c516'))
qrList.append(blockQuickReply('삭제하기🗑️', '삭제하기🗑️', ''))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]사진삭제시도', datetime.datetime.now(), 'none')
contextList.append(
contextValue('post', 1, {'delete_post': 'alive', 'kakaoUserKey': kakaoUserKey, 'title': postTitle}))
return ordinaryMessageType(contextList, outputList, qrList)
def get_changeNickname_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
newNickname = getUserUtteranceFromPayload(payload)
accountId = getAccountIdusingUserKey(kakaoUserKey)
myFonts = getUserProfileFonts(kakaoUserKey)
myDogiPoint = getUserDogiPoint(kakaoUserKey)
myBadges = getUserProfileBadges(kakaoUserKey)
if not isNicknameValid(newNickname):
outputList.append(simpleText('[시스템] 이미 존재하는 닉네임이에요'))
outputList.append(simpleText('새로운 닉네임을 채팅창에 입력해주세요'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[사진첩]닉네임변경재시도', datetime.datetime.now(), 'none')
contextList.append(contextValue('nickname', 1, {'change_nickname': 'alive'}))
return ordinaryMessageType(contextList, outputList, qrList)
updateNickname(kakaoUserKey, newNickname)
outputList.append(simpleText('[시스템] 변경되었습니다'))
# 프로필 리스트
outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, newNickname)
# setting button window
qrList = settingButtonWindow(kakaoUserKey, petName)
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[환경설정]닉네임변경', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)
def get_suggestConnect_message():
contextList = []
outputList = []
qrList = []
payload = request.get_json()
kakaoUserKey = getKakaoUserKeyFromPayload(payload)
petId = getPetId(kakaoUserKey)
petName = getPetName(petId)
outputList.append(simpleText('[시스템] 댕댕어 번역에 오류가 발생하고있어요🥺'))
outputList.append(simpleText('남는 스마트폰을 연동시키면 ' + petName + '와 더욱 잘 대화할 수 있을텐데요..'))
qrList.append(blockQuickReply('기기연동하러가기🔗', '기기연동하러가기🔗', '5e576874ffa7480001ef0808'))
qrList.append(blockQuickReply('생각해볼게요🤫', '생각해볼게요🤫', '5e576884ffa7480001ef080b'))
# 메시지 로그 저장 sender: bot, receiver: user
addMessageLogs('bot', kakaoUserKey, '[환경설정]기기연동권유', datetime.datetime.now(), 'none')
return ordinaryMessageType(contextList, outputList, qrList)