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-03 00:01:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3905c745b77da824431644d29cbd2d3792d96722
3905c745
1 parent
3552251c
image test
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
39 deletions
app.js
app.js
View file @
3905c74
// 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 MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
// const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
// const fs = require('fs');
// const path = require('path');
// const HTTPS = require('https');
// const domain = "2019102175.oss-2021.tk"
// const sslport = 23023;
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'dClDD+86CVGoR/ozUsC1ViT0lyRMsFwQ3bOoUejOVI4yJ2AQRKHFyBF+CjYW5DLtF7EztDgigy+VSDFQxYNtvGqLGngGNYz1Fzq6kxxI7YqlDnVRV7gHFVkc42VfcEMQ/ozXTqeCY1JYFAmw30fBXQdB04t89/1O/w1cDnyilFU='
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
TOKEN
=
'Lei+CfpMSJB1lms9gmNi6kakwT2Zz5bv1E/vxXoewtNMoAaxoBEyQnniunTw19fCGl9KXU7UnVQE7IXAPgN0FyeG/bhBPvpdV0fEgpYBXM0PNiRoLsN8oMAlY99pXvq8QZ1KXefuTcr1WTBerglnagdB04t89/1O/w1cDnyilFU='
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"20191021
95.oss
2021.tk"
const
domain
=
"20191021
75.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'
const
USER_ID
=
'Ub99bb2ebebbbc1e06efe715b76ec9fcd'
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
...
...
@@ -20,23 +35,26 @@ request.post(
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"messages"
:[
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"안녕하세요! "
},
{
"type"
:
"text"
,
"text"
:
"안녕하세요! 테스트입니다.
"
"type"
:
"text"
,
"text"
:
"제시되는 4가지 사진 중 자신의 피부와 가장 잘 어울리는 사진의 번호를 입력하세요
"
},
{
"type"
:
"text"
,
"text"
:
"저에게 '테스트'라고 입력해주세요!
"
"type"
:
"text"
,
"text"
:
"퍼스널 컬러 진단 테스트를 시작하시겠습니까? [Y/N]
"
}
]
}
},(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
...
...
@@ -44,13 +62,16 @@ app.post('/hook', function (req, res) {
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
// request log
console
.
log
(
'======================'
,
new
Date
()
,
'======================'
);
console
.
log
(
'[request]'
,
req
.
body
);
console
.
log
(
'[request source] '
,
eventObj
.
source
);
console
.
log
(
'[request message]'
,
eventObj
.
message
);
if
(
eventObj
.
message
.
text
==
'테스트'
){
start
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
test1
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
res
.
sendStatus
(
200
);
});
function
start
(
replyToken
,
message
)
{
if
(
message
==
"Y"
)
{
request
.
post
(
{
url
:
TARGET_URL
,
...
...
@@ -58,45 +79,73 @@ app.post('/hook', function (req, res) {
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"image"
,
"originalContentUrl"
:
"https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png"
,
"previewImageUrl"
:
"https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png"
,
},
{
"type"
:
"image"
,
"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"
:
"테스트라고 입력해주셨군요!"
"type"
:
"image"
,
"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]"
"type"
:
"image"
,
"originalContentUrl"
:
"https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/img.png"
,
"previewImageUrl"
:
"https://blog.kakaocdn.net/dn/bf78xb/btqGzYCfgcc/QNj0SdL6KP6Ww89Mtgrmh1/preview.png"
,
},
],
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
}
function
test1
(
replyToken
,
message
)
{
if
(
message
==
"네"
)
{
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
"네가지 사진 중 자신의 피부와 가장 잘 어울리는 색을 골라주세요"
}
]
}
},(
error
,
response
,
body
)
=>
{
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
res
.
sendStatus
(
200
);
});
function
color_chatbot_test1
(
replyToken
,
message
){
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
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
(),
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
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
}
`
);
console
.
log
(
`[HTTPS] Server is started on port
${
sslport
}
`
);
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
\ No newline at end of file
}
...
...
Please
register
or
login
to post a comment