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
오규림
2021-06-01 00:44:35 +0900
1
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
3552251c30e61302a5215e918474fdb16f7b31f4
3552251c
1 parent
aa96233c
basic function
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
66 deletions
app.js
app.js
View file @
3552251
var
express
=
require
(
"express"
);
var
http
=
require
(
"http"
);
var
bodyParser
=
require
(
"body-parser"
);
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
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"2019102195.oss2021.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
app
.
get
(
"/Personal_color_chatbot"
,
function
(
req
,
res
)
{
var
data
=
{
type
:
"buttons"
,
buttons
:
[
"퍼스널 컬러 진단하기"
,
"봄웜"
,
"여름쿨"
,
"가을웜"
,
"겨울쿨"
],
};
request
.
post
(
{
url
:
BROAD_TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"안녕하세요! 테스트입니다."
},
{
"type"
:
"text"
,
"text"
:
"저에게 '테스트'라고 입력해주세요!"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
res
.
json
(
data
);
});
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
app
.
use
(
bodyParser
.
json
());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
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
==
'테스트'
){
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:[
{
"type"
:
"text"
,
"text"
:
"테스트라고 입력해주셨군요!"
},
{
"type"
:
"text"
,
"text"
:
"다음 단계로 넘어가고 싶으신가요? [Y/N]"
}
]
}
},(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
app
.
post
(
"/message"
,
function
(
req
,
res
)
{
var
msg
=
req
.
body
.
content
;
console
.
log
(
"전달받은 메세지: "
+
msg
);
var
send
=
{};
res
.
sendStatus
(
200
);
});
switch
(
msg
)
{
case
"퍼스널 컬러 진단하기"
:
send
=
{
message
:
{
text
:
"퍼스널 컬러 진단하기 선택"
,
},
};
break
;
function
color_chatbot_test1
(
replyToken
,
message
){
case
"봄웜"
:
send
=
{
message
:
{
text
:
"봄웜 선택"
,
},
};
break
;
}
case
"여름쿨"
:
send
=
{
message
:
{
text
:
"여름쿨 선택"
,
},
};
break
;
case
"가을웜"
:
send
=
{
message
:
{
text
:
"가을웜 선택"
,
},
};
break
;
case
"겨울쿨"
:
send
=
{
message
:
{
text
:
"겨을쿨 선택"
,
}
,
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
()
,
};
break
;
default
:
send
=
{
message
:
{
text
:
"알 수 없는 명령입니다."
,
},
};
break
;
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
res
.
json
(
send
);
});
http
.
createServer
(
app
).
listen
(
9090
,
function
()
{
console
.
log
(
"서버실행중.."
);
});
...
...
오규림
@2019102195 commented
2021-05-31 15:47:43 UTC
Master
카카오 오픈빌더 스킬 적용에 문제가 생겨서 라인으로 대체합니다. 라인에서 메세지를 주고 받는 기본적인 코드입니다. 코드 확인 후, 세부적인 내용 추가 부탁드립니다.
Please
register
or
login
to post a comment