Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오규림
/
Personal_color_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
suhyunpark
2021-06-06 22:11:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
00da1cf311077d0d7cf3f7b468d0065bdaa55555
00da1cf3
1 parent
70ae3c3d
Update Questions
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
274 additions
and
82 deletions
app.js
app.js
View file @
00da1cf
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"2019102175.oss-2021.tk"
const
sslport
=
23023
;
const
MULTI_TARGET_URL
=
'https://api.line.me/v2/bot/message/multicast'
const
BROAD_TARGET_URL
=
'https://api.line.me/v2/bot/message/broadcast'
var
spring
=
0
var
summer
=
0
var
fall
=
0
var
winter
=
0
var
files
=
[
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY0/MDAxNjIyNzI5NzM5NTQ5.JOX6SurxlH4Ip7rET53jG93MqyxB74mwouBh7beB7X0g.aC9QPmJmQPlFG9gMaGYJv_4uc0NZLeUI8GX0Gq6CRFUg.PNG.shinee_p98/brown.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTI4/MDAxNjIyNzI5NzQ3ODA3.CyDcjyTMLFqYJ_ECCQB6uhP5G96IlcjvneOBuf6OTlog.wMBN3zPFz7qUs6rYUmMetRV3_j0KxoA5hROt-Agts0Ag.PNG.shinee_p98/blue.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTU2/MDAxNjIyNzI5NzUyNjcz.Kk-ifPRihFIV_6U5rmo-JqTWEPHvJptzLBjRVh_36_Ig.v5Qu3GGWte5-swXhWb911TjsfDJ5welWfR7hPOrc7Jcg.PNG.shinee_p98/cyan.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjgy/MDAxNjIyNzI5NzU5MjA5.QUDMos5l0fTcjTokgIfrHuqy7UVF546VjRytwKItrNEg.aP3nTqJlvV3P2kZPLVA9ybcJ4k4_GiQjoHJICkHhLWwg.PNG.shinee_p98/green.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjEg/MDAxNjIyNzI5ODQyNDI5.BQd_licB-SC1fUbsbZBEwAiVHeqLffBSfxTIzMOYy5sg.6JzAY41JFZhQL9pa-B0HvEf4594017NxJ5dr2QDsth4g.PNG.shinee_p98/magenta.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTAw/MDAxNjIyNzI5ODQ3ODIx.hCVRLywItir-jvdf6dZ7NyIxmJC4PGc0HMufU9x8NCkg.EDGju3DjfxaydwBgai8NrSg8vZVKI0GMt3WXhIGckhUg.PNG.shinee_p98/orange.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjg0/MDAxNjIyNzI5ODUxOTA5.APYoGe3PsNbYWeaxiH87KLH2q3n6zOAJt4oC5QM8LEkg.bBMGuliyPvHXmb3hea344pa6rmTeDcor9YbaedD3NAEg.PNG.shinee_p98/purple.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjQ4/MDAxNjIyNzI5ODU1NzIw.fHgsAwcHld7WjzlfNWbN_Ui1CHGWAkheN9mJx5X5R34g.XuRPlq0ijc5GMO5MBRRizSBNHJyAOXkacwPEI2VasVwg.PNG.shinee_p98/red.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY5/MDAxNjIyNzI5ODYwMjUw.Y1ancRsttM8SsbqE482zIpnrQS5HzJhzeC8YkuNav20g.5oC4Rclbpv65ntWPjdW8a_W3RgPUBQNjfRkIOoMuVkog.PNG.shinee_p98/white.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjkw/MDAxNjIyNzI5ODY0OTcw.r2_Ug2vWSRNnpLlOJjA_8G1Nj_RU3GxQE--0u-vxfxcg.bNJ1n-oZXx9F1YcLktt4Q3OyAiFnea0lOv_nN92XFUEg.PNG.shinee_p98/yellow.png'
var
warm
=
0
var
cool
=
0
var
warm_index
=
0
var
cool_index
=
0
var
skinIndex
=
0
var
i
=
0
var
j
=
-
9
var
QuestionCount
=
9
var
QuestionIndex
=
0
var
count
=
16
var
WarmOrCool
=
[
warm
,
cool
];
var
season_color
=
[
spring
,
summer
,
fall
,
winter
]
var
Questions
=
[
'나의 피부색은 (1)노란기 (2)붉은기가 돈다.'
,
'나의 머리색은 (1)갈색 (2)검정색에 가깝다.'
,
'나의 혈관색은 (1)초록색 (2)푸른색에 가깝다. '
,
'나의 눈동자 색깔은 (1)밝은 갈색 (2)짙은 갈색이다. '
,
'나의 두피는 (1)노란색을 (2)푸른색을 띤다.'
,
'나는 (1)골드 (2)실버 쥬얼리가 더 잘 어울린다. '
,
'나는 (1)아이보리 (2)새하얀 화이트가 더 잘 어울린다.'
,
'나는 (1)브라운/카키 (2)핑크/블루 계열의 옷이 더 잘어울린다.'
,
'햇빛에 노출되었을 경우 (1)갈색으로 탄다 (2)붉게 그을린다.'
,
]
var
previews
=
[
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY0/MDAxNjIyNzI5NzM5NTQ5.JOX6SurxlH4Ip7rET53jG93MqyxB74mwouBh7beB7X0g.aC9QPmJmQPlFG9gMaGYJv_4uc0NZLeUI8GX0Gq6CRFUg.PNG.shinee_p98/brown/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTI4/MDAxNjIyNzI5NzQ3ODA3.CyDcjyTMLFqYJ_ECCQB6uhP5G96IlcjvneOBuf6OTlog.wMBN3zPFz7qUs6rYUmMetRV3_j0KxoA5hROt-Agts0Ag.PNG.shinee_p98/blue/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTU2/MDAxNjIyNzI5NzUyNjcz.Kk-ifPRihFIV_6U5rmo-JqTWEPHvJptzLBjRVh_36_Ig.v5Qu3GGWte5-swXhWb911TjsfDJ5welWfR7hPOrc7Jcg.PNG.shinee_p98/cyan/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjgy/MDAxNjIyNzI5NzU5MjA5.QUDMos5l0fTcjTokgIfrHuqy7UVF546VjRytwKItrNEg.aP3nTqJlvV3P2kZPLVA9ybcJ4k4_GiQjoHJICkHhLWwg.PNG.shinee_p98/green/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjEg/MDAxNjIyNzI5ODQyNDI5.BQd_licB-SC1fUbsbZBEwAiVHeqLffBSfxTIzMOYy5sg.6JzAY41JFZhQL9pa-B0HvEf4594017NxJ5dr2QDsth4g.PNG.shinee_p98/magenta/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTAw/MDAxNjIyNzI5ODQ3ODIx.hCVRLywItir-jvdf6dZ7NyIxmJC4PGc0HMufU9x8NCkg.EDGju3DjfxaydwBgai8NrSg8vZVKI0GMt3WXhIGckhUg.PNG.shinee_p98/orange/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjg0/MDAxNjIyNzI5ODUxOTA5.APYoGe3PsNbYWeaxiH87KLH2q3n6zOAJt4oC5QM8LEkg.bBMGuliyPvHXmb3hea344pa6rmTeDcor9YbaedD3NAEg.PNG.shinee_p98/purple/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjQ4/MDAxNjIyNzI5ODU1NzIw.fHgsAwcHld7WjzlfNWbN_Ui1CHGWAkheN9mJx5X5R34g.XuRPlq0ijc5GMO5MBRRizSBNHJyAOXkacwPEI2VasVwg.PNG.shinee_p98/red/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMTY5/MDAxNjIyNzI5ODYwMjUw.Y1ancRsttM8SsbqE482zIpnrQS5HzJhzeC8YkuNav20g.5oC4Rclbpv65ntWPjdW8a_W3RgPUBQNjfRkIOoMuVkog.PNG.shinee_p98/white/preview.png'
,
'https://postfiles.pstatic.net/MjAyMTA2MDNfMjkw/MDAxNjIyNzI5ODY0OTcw.r2_Ug2vWSRNnpLlOJjA_8G1Nj_RU3GxQE--0u-vxfxcg.bNJ1n-oZXx9F1YcLktt4Q3OyAiFnea0lOv_nN92XFUEg.PNG.shinee_p98/yellow/preview.png'
var
warm_files
=
[
'https://personal-color-chatbot.s3.amazonaws.com/warm_carmel.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/warm_coral.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/warm_green.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/warm_mint.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/warm_purple.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/warm_softgreen.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/warm_yellow.jpg'
,
]
var
number
=
[
3
,
5
,
6
,
7
,
9
]
var
i
=
0
var
cool_files
=
[
'https://personal-color-chatbot.s3.amazonaws.com/cool_blue.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/cool_lightpink.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/cool_lightpurple.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/cool_mint.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/cool_navy.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/cool_pink.png'
,
'https://personal-color-chatbot.s3.amazonaws.com/cool_yellow.png'
,
]
const
MULTI_TARGET_URL
=
'https://api.line.me/v2/bot/message/multicast'
const
BROAD_TARGET_URL
=
'https://api.line.me/v2/bot/message/broadcast'
const
USER_ID
=
'Ub99bb2ebebbbc1e06efe715b76ec9fcd'
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
...
...
@@ -59,15 +76,15 @@ request.post(
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"
안녕하세요!
"
"text"
:
"
STEP1: 제시된 질문에 대하여 자신에게 더 맞는 선택지를 고르세요 [1/2]
"
},
{
"type"
:
"text"
,
"text"
:
"
제시되는 4가지 사진 중 자신의 피부와 가장 잘 어울리는 사진의 번호를 입력하세요
"
"text"
:
"
STEP2: 제시된 이미지를 자신의 피부 위에 두고 자신에게 더 어울리는 색깔을 고르세요 [1/2]
"
},
{
"type"
:
"text"
,
"text"
:
"퍼스널 컬러 진단 테스트를 시작하
시겠습니까? [Y/N]
"
"text"
:
"퍼스널 컬러 진단 테스트를 시작하
려면 'start'를 입력하세요
"
}
]
}
...
...
@@ -76,23 +93,27 @@ request.post(
});
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
//start(eventObj.replyToken, eventObj.message.text)
TestSkinType
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
Color_Test
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
test1
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
test2
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
)
if
(
YourSkinTypeIs
(
warm
,
cool
)
==
0
)
Get_warmColor
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
else
if
(
YourSkinTypeIs
(
warm
,
cool
)
==
1
)
Get_coolColor
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
res
.
sendStatus
(
200
);
});
function
test1
(
replyToken
,
message
)
{
if
(
message
==
"Y"
)
{
function
TestSkinType
(
replyToken
,
message
)
{
if
(
message
==
"start"
)
{
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -103,24 +124,92 @@ function test1(replyToken, message) {
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"image"
,
"originalContentUrl"
:
files
[
0
],
"previewImageUrl"
:
previews
[
0
],
"type"
:
"text"
,
"text"
:
Questions
[
0
],
},
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
function
test2
(
replyToken
,
message
)
{
function
Color_Test
(
replyToken
,
message
)
{
if
(
message
==
"1"
||
message
==
"2"
||
message
==
"3"
||
message
==
"4"
)
{
if
(
message
==
"1"
||
message
==
"2"
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
Questions
[
i
],
},
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
if
(
QuestionCount
<=
0
)
{
if
(
YourSkinTypeIs
(
warm
,
cool
)
==
0
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"image"
,
"originalContentUrl"
:
warm_files
[
j
],
"previewImageUrl"
:
warm_files
[
j
],
},
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
else
if
(
YourSkinTypeIs
(
warm
,
cool
)
==
1
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"image"
,
"originalContentUrl"
:
cool_files
[
j
],
"previewImageUrl"
:
cool_files
[
j
],
},
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
}
if
(
count
==
0
)
{
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -131,52 +220,158 @@ function test2(replyToken, message) {
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"image"
,
"originalContentUrl"
:
files
[
i
],
"previewImageUrl"
:
previews
[
i
],
// "originalContentUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png",
// "previewImageUrl": "https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png",
"type"
:
"text"
,
"text"
:
"테스트가 완료되었습니다. 결과를 확인하시겠습니까? [Y/N] "
},
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
if
(
message
==
"1"
)
{
warm
+=
1
}
else
if
(
message
==
"2"
)
{
cool
+=
1
}
if
(
QuestionCount
<
0
)
{
if
(
message
==
'1'
&&
YourSkinTypeIs
(
warm
,
cool
)
==
0
)
spring
+=
1
else
if
(
message
==
'2'
&&
YourSkinTypeIs
(
warm
,
cool
)
==
0
)
fall
+=
1
else
if
(
message
==
'1'
&&
YourSkinTypeIs
(
warm
,
cool
)
==
1
)
summer
+=
1
else
if
(
message
==
'2'
&&
YourSkinTypeIs
(
warm
,
cool
)
==
1
)
winter
+=
1
}
if
(
message
==
"1"
)
spring
+=
1
else
if
(
message
==
"2"
)
summer
+=
1
else
if
(
message
==
"3"
)
fall
+=
1
else
if
(
message
==
"4"
)
winter
+=
1
console
.
log
(
spring
,
summer
,
fall
,
winter
)
i
+=
1
j
+=
1
QuestionCount
-=
1
;
count
-=
1
YourSkinTypeIs
(
warm
,
cool
);
if
(
YourSkinTypeIs
(
warm
,
cool
)
==
0
)
{
YourWarmColorIs
(
spring
,
fall
);
}
else
YourCoolColorIs
(
summer
,
winter
);
}
function
YourSkinTypeIs
(
warm
,
cool
)
{
var
WarmOrCool
=
[
warm
,
cool
];
if
(
warm
>
cool
)
{
skinIndex
=
0
;
}
else
skinIndex
=
1
;
return
skinIndex
;
}
function
YourWarmColorIs
(
spring
,
fall
)
{
if
(
spring
>
fall
)
warm_index
=
0
else
warm_index
=
1
return
warm_index
;
}
function
YourCoolColorIs
(
summer
,
winter
)
{
if
(
summer
>
winter
)
cool_index
=
3
else
cool_index
=
4
return
cool_index
;
}
// function start(replyToken, message) {
// if (message == "Y") {
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "replyToken": replyToken,
// "messages": [
// {
// "type": "text",
// "text": "네가지 사진 중 자신의 피부와 가장 잘 어울리는 색을 골라주세요"
// }
// ]
// }
// }, (error, response, body) => {
// console.log(body)
// });
// }
// }
function
Get_warmColor
(
replyToken
,
message
)
{
if
(
message
==
"Y"
)
{
if
(
YourWarmColorIs
(
spring
,
fall
)
==
0
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"봄 웜 입니다."
}
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
if
(
YourWarmColorIs
(
spring
,
fall
)
==
1
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"가을 웜 입니다."
}
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
}
function
Get_coolColor
(
replyToken
,
message
)
{
if
(
message
==
"Y"
)
{
if
(
YourCoolColorIs
(
summer
,
winter
)
==
3
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"여름 쿨 입니다."
}
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
if
(
YourCoolColorIs
(
summer
,
winter
)
==
4
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"겨울 쿨 입니다."
}
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
}
try
{
...
...
@@ -185,13 +380,10 @@ try {
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment