Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최재은
/
밀당강의봇
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
김예미
2019-06-03 22:19:31 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
db0ee2c5bcfdd0b74da82cf4974a8cecc60d8f42
db0ee2c5
1 parent
de635751
Connect DB, prototype
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
263 additions
and
18 deletions
Database/facebookbot.sql
app.js
config/db-config.json
controller.js
models.js
package-lock.json
template.js
Database/facebookbot.sql
View file @
db0ee2c
This diff could not be displayed because it is too large.
app.js
View file @
db0ee2c
...
...
@@ -63,3 +63,4 @@ app.post('/webhook', (req, res) => {
}
});
...
...
config/db-config.json
View file @
db0ee2c
{
"host"
:
"localhost"
,
"user"
:
"root"
,
"password"
:
null
,
"host"
:
3306
,
"database"
:
"
facebookbot
"
"password"
:
"111111"
,
"host"
:
3306
,
"database"
:
"
ratedb
"
}
...
...
controller.js
View file @
db0ee2c
...
...
@@ -29,7 +29,7 @@ exports.handlePostback = (sender_psid, received_postback) => {
}
else
if
(
payload
.
substr
(
0
,
14
)
===
'CHOICE_BY_HELP'
){
handlePostback_help
(
sender_psid
,
recieved_postback
);
}
else
if
(
payload
.
substr
(
0
,
8
)
===
'MoreRate'
){
response
=
template
.
moreRa
g
eTemplate
(
received_postback
);
response
=
template
.
moreRa
t
eTemplate
(
received_postback
);
callSendAPI
(
sender_psid
,
response
);
}
}
...
...
models.js
deleted
100644 → 0
View file @
de63575
File mode changed
package-lock.json
View file @
db0ee2c
...
...
@@ -73,6 +73,11 @@
"tweetnacl"
:
"^0.14.3"
}
},
"bignumber.js"
:
{
"version"
:
"7.2.1"
,
"resolved"
:
"https://registry.npmjs.org/bignumber.js/-/bignumber.js-7.2.1.tgz"
,
"integrity"
:
"sha512-S4XzBk5sMB+Rcb/LNcpzXr57VRTxgAvaAEDAl1AwRx27j00hT84O6OkteE7u8UB3NuaaygCRrEpqox4uDOrbdQ=="
},
"bluebird"
:
{
"version"
:
"3.5.1"
,
"resolved"
:
"https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz"
,
...
...
@@ -369,6 +374,11 @@
"resolved"
:
"https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz"
,
"integrity"
:
"sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
},
"isarray"
:
{
"version"
:
"1.0.0"
,
"resolved"
:
"https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz"
,
"integrity"
:
"sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"isstream"
:
{
"version"
:
"0.1.2"
,
"resolved"
:
"https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz"
,
...
...
@@ -538,6 +548,17 @@
"resolved"
:
"https://registry.npmjs.org/ms/-/ms-2.0.0.tgz"
,
"integrity"
:
"sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"mysql"
:
{
"version"
:
"2.17.1"
,
"resolved"
:
"https://registry.npmjs.org/mysql/-/mysql-2.17.1.tgz"
,
"integrity"
:
"sha512-7vMqHQ673SAk5C8fOzTG2LpPcf3bNt0oL3sFpxPEEFp1mdlDcrLK0On7z8ZYKaaHrHwNcQ/MTUz7/oobZ2OyyA=="
,
"requires"
:
{
"bignumber.js"
:
"7.2.1"
,
"readable-stream"
:
"2.3.6"
,
"safe-buffer"
:
"5.1.2"
,
"sqlstring"
:
"2.3.1"
}
},
"negotiator"
:
{
"version"
:
"0.6.2"
,
"resolved"
:
"https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz"
,
...
...
@@ -571,6 +592,11 @@
"resolved"
:
"https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz"
,
"integrity"
:
"sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
},
"process-nextick-args"
:
{
"version"
:
"2.0.0"
,
"resolved"
:
"https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz"
,
"integrity"
:
"sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
},
"proxy-addr"
:
{
"version"
:
"2.0.5"
,
"resolved"
:
"https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz"
,
...
...
@@ -611,6 +637,20 @@
"unpipe"
:
"1.0.0"
}
},
"readable-stream"
:
{
"version"
:
"2.3.6"
,
"resolved"
:
"https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz"
,
"integrity"
:
"sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw=="
,
"requires"
:
{
"core-util-is"
:
"~1.0.0"
,
"inherits"
:
"~2.0.3"
,
"isarray"
:
"~1.0.0"
,
"process-nextick-args"
:
"~2.0.0"
,
"safe-buffer"
:
"~5.1.1"
,
"string_decoder"
:
"~1.1.1"
,
"util-deprecate"
:
"~1.0.1"
}
},
"regexp-clone"
:
{
"version"
:
"0.0.1"
,
"resolved"
:
"https://registry.npmjs.org/regexp-clone/-/regexp-clone-0.0.1.tgz"
,
...
...
@@ -750,6 +790,11 @@
"memory-pager"
:
"^1.0.2"
}
},
"sqlstring"
:
{
"version"
:
"2.3.1"
,
"resolved"
:
"https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz"
,
"integrity"
:
"sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A="
},
"sshpk"
:
{
"version"
:
"1.16.1"
,
"resolved"
:
"https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz"
,
...
...
@@ -771,6 +816,14 @@
"resolved"
:
"https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz"
,
"integrity"
:
"sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"string_decoder"
:
{
"version"
:
"1.1.1"
,
"resolved"
:
"https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz"
,
"integrity"
:
"sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg=="
,
"requires"
:
{
"safe-buffer"
:
"~5.1.0"
}
},
"toidentifier"
:
{
"version"
:
"1.0.0"
,
"resolved"
:
"https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz"
,
...
...
@@ -827,6 +880,11 @@
"punycode"
:
"^2.1.0"
}
},
"util-deprecate"
:
{
"version"
:
"1.0.2"
,
"resolved"
:
"https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz"
,
"integrity"
:
"sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"utils-merge"
:
{
"version"
:
"1.0.1"
,
"resolved"
:
"https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz"
,
...
...
template.js
View file @
db0ee2c
const
db
=
require
(
'./db
.js
'
);
const
db
=
require
(
'./db'
);
let
greetingText
=
"안녕하세요! 컴공/소융 강의평가 봇이에요. 아래에 버튼 3개를 눌러주세요."
;
// 인사말
let
greetingTitle
=
[
"교수명으로 검색"
,
"강의명으로 검색"
,
"HELP"
];
...
...
@@ -54,30 +54,220 @@ exports.getProfNameTemplate = (received) => {
}
exports
.
getLectNameTemplate
=
(
received
)
=>
{
//메세지
return
{
text
:
"성공"
}
//텍스트 메세지를 필드로 디비에서 수업/교수명 찾아서 목록 제공
return
{
"attachment"
:{
"type"
:
"template"
,
"payload"
:{
"template_type"
:
"button"
,
"text"
:
"강의명을 입력하세요."
,
"buttons"
:[
{
"type"
:
"postback"
,
"title"
:
"처음으로"
,
"payload"
:
'Greeting'
}
]
}
}
}
}
//stat_1
exports
.
choiceLectProfTemplate
=
(
received
)
=>
{
//버튼
let
message
=
received
.
text
;
db
.
query
(
'SELECT * FROM reviews WHERE lecturename LIKE ? OR proname LIKE ?'
,
[
message
,
message
],
function
(
error
,
results
){
if
(
err
){
console
.
log
(
err
);
res
.
render
(
'error'
);
}
if
(
results
==
0
){
return
{
text
:
"검색 결과가 없습니다. 검색어를 다시 입력해주세요."
}
}
else
if
(
results
.
length
<=
2
){
return
LectProfList
(
results
,
0
,
results
.
length
,
false
,
'0'
,
message
);
}
else
if
(
results
.
length
>
2
){
return
LectProfList
(
results
,
0
,
2
,
true
,
'1'
,
message
);
}
});
}
const
LectProfList
=
(
results
,
start
,
length
,
ismore
,
morecount
,
message
)
=>
{
if
(
length
==
1
){
return
{
"attachment"
:{
"type"
:
"template"
,
"payload"
:{
"template_type"
:
"button"
,
"text"
:
"검색 결과입니다. 평가를 조회할 강의를 선택하세요."
,
"buttons"
:[
{
"type"
:
"postback"
,
"title"
:
results
[
start
].
lecturename
+
results
[
start
].
proname
,
"payload"
:
'CHOICE_BY_PROFstat_3'
+
results
[
start
].
idreviews
}
]
}
}
}
}
else
if
((
length
==
2
)
&&
(
!
ismore
)){
return
{
"attachment"
:{
"type"
:
"template"
,
"payload"
:{
"template_type"
:
"button"
,
"text"
:
"검색 결과입니다. 평가를 조회할 강의를 선택하세요."
,
"buttons"
:[
{
"type"
:
"postback"
,
"title"
:
results
[
start
].
lecturename
+
results
[
start
].
proname
,
"payload"
:
'CHOICE_BY_PROFstat_3'
+
results
[
start
].
idreviews
},
{
"type"
:
"postback"
,
"title"
:
results
[
start
+
1
].
lecturename
+
results
[
start
+
1
].
proname
,
"payload"
:
'CHOICE_BY_PROFstat_3'
+
results
[
start
+
1
].
idreviews
}
]
}
}
}
}
else
if
((
length
==
2
)
&&
(
ismore
)){
return
{
"attachment"
:{
"type"
:
"template"
,
"payload"
:{
"template_type"
:
"button"
,
"text"
:
"검색 결과입니다. 평가를 조회할 강의를 선택하세요. 원하는 강의가 없다면 [더보기]를 눌러주세요."
,
"buttons"
:[
{
"type"
:
"postback"
,
"title"
:
results
[
start
].
lecturename
+
results
[
start
].
proname
,
"payload"
:
'CHOICE_BY_PROFstat_3'
+
results
[
start
].
idreviews
},
{
"type"
:
"postback"
,
"title"
:
results
[
start
+
1
].
lecturename
+
results
[
start
+
1
].
proname
,
"payload"
:
'CHOICE_BY_PROFstat_3'
+
results
[
start
+
1
].
idreviews
},
{
"type"
:
"postback"
,
"title"
:
"더보기"
,
"payload"
:
'CHOICE_BY_PROFstat_2'
+
message
+
'/'
+
morecount
}
]
}
}
}
}
}
//stat_2
exports
.
moreProfTemplate
=
(
received
)
=>
{
//버튼
let
ms
=
received
.
payload
.
substr
(
20
).
split
(
'/'
);
let
more
=
1
*
(
ms
[
0
]);
//to Number
let
message
=
ms
[
1
];
db
.
query
(
'SELECT * FROM reviews WHERE lecturename LIKE ? OR proname LIKE ?'
,
[
message
,
message
],
function
(
error
,
results
){
if
(
err
){
console
.
log
(
err
);
res
.
render
(
'error'
);
}
if
((
results
.
length
-
2
*
(
more
+
1
))
<=
0
){
return
LectProfList
(
results
,
2
*
more
,
results
.
length
-
2
*
n
,
false
,
'0'
,
message
);
}
else
{
return
LectProfList
(
results
,
2
*
more
,
2
,
true
,
""
+
(
more
+
1
),
message
);
}
});
}
exports
.
moreLectTemplate
=
(
received
)
=>
{
//버튼
let
ms
=
received
.
payload
.
substr
(
20
).
split
(
'/'
);
let
more
=
1
*
(
ms
[
0
]);
let
message
=
ms
[
1
];
db
.
query
(
'SELECT * FROM reviews WHERE lecturename LIKE ? OR proname LIKE ?'
,
[
message
,
message
],
function
(
error
,
results
){
if
(
err
){
console
.
log
(
err
);
res
.
render
(
'error'
);
}
if
((
results
.
length
-
2
*
(
more
+
1
))
<=
0
){
return
LectProfList
(
results
,
2
*
more
,
results
.
length
-
2
*
n
,
false
,
'0'
,
message
);
}
else
{
return
LectProfList
(
results
,
2
*
more
,
2
,
true
,
""
+
(
more
+
1
),
message
);
}
});
}
//stat_3
exports
.
rateTemplate
=
(
received
)
=>
{
//버튼
let
id
=
received
.
payload
.
substr
(
20
);
db
.
query
(
'SELECT * FROM reviews WHERE idreviews LIKE ?'
,
[
id
],
function
(
error
,
results
){
if
(
err
){
console
.
log
(
err
);
res
.
render
(
'error'
);
}
let
proname
=
results
[
0
].
proname
;
let
lecname
=
results
[
0
].
lecname
;
let
reviews
=
results
[
0
].
review
.
split
(
','
);
let
review
=
reviews
[
0
];
let
rate
=
results
[
0
].
avg_rate
;
let
botsay
=
[];
let
randNum
=
0
;
if
(
rate
!=
0
){
Math
.
floor
((
Math
.
random
()
*
(
3
-
0
+
1
))
+
0
);
}
if
(
rate
==
0
){
botsay
=
[
"신설 강좌거나 아직 강의평이 없어요!"
];
}
else
if
((
rate
>
1
)
&&
(
rate
<
2.5
)){
botsay
=
[
"음.. 말을 아낄게요."
,
"다시 생각해보시는게.."
,
"이전 단계로 돌아갈까요?"
,
"으응?"
];
}
else
if
((
rate
>=
2.5
)
&&
(
rate
<
4.0
)){
botsay
=
[
"무난무난"
,
"그럭저럭한 것 같아요."
,
"안 들어서 나쁠거 없어요."
,
"평범한 수업이네요"
];
}
else
{
botsay
=
[
"무조건 들어요!"
,
"갓갓 교수님의 갓갓 수업"
,
"안 들으면 후회해요ㅠㅠ"
,
"수강신청 1순위!"
];
}
return
{
"attachment"
:{
"type"
:
"template"
,
"payload"
:{
"template_type"
:
"button"
,
"text"
:
proname
+
" 교수님의 강의 ["
+
lecname
+
"]의 강의평입니다.\n **평균 평점: "
+
rate
+
"\n **봇의 한줄평: "
+
botsay
[
randNum
]
+
"\n **학우의 한줄평: "
+
reivew
,
"buttons"
:[
{
"type"
:
"postback"
,
"title"
:
"자세한 강의평 보기"
,
"payload"
:
'MoreRate'
+
id
}
]
}
}
}
});
}
exports
.
moreRateTemplate
=
(
received
)
=>
{
let
id
=
received
.
payload
.
substr
(
8
);
let
total_review
=
""
;
db
.
query
(
'SELECT * FROM reviews WHERE idreviews LIKE ?'
,
[
id
],
function
(
error
,
results
){
if
(
err
){
console
.
log
(
err
);
res
.
render
(
'error'
);
}
let
reviews
=
results
[
0
].
review
.
split
(
','
);
for
(
var
review
in
reviews
){
total_review
+=
review
+
"\n"
;
}
return
{
text
:
total_review
}
});
//payload:MoreRate(강의식별번호)
//포스트백 핸들 moreRateTemplate에서 해당 강의의 자세한 평 출력
}
//payload === 'HELP'
...
...
@@ -118,7 +308,3 @@ return {
}
}
}
exports
.
moreRageTemplate
=
(
received
)
=>
{
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment