김예미

Final Commit!

......@@ -9,16 +9,17 @@ exports.handleMessage=function(sender_psid, received_message) {
template.greetingTemplate(function(result, res){
if(result==true){
response=res;
callSendAPI(sender_psid, response)
}
});
callSendAPI(sender_psid, response);
}else{
template.choiceLectProfTemplate(text, function(result, res){
if(result==true){
response=res;
console.log("text2:",response)
callSendAPI(sender_psid, response);
}
});
callSendAPI(sender_psid, response);
}
}
......@@ -50,9 +51,9 @@ exports.handlePostback =function(sender_psid, received_postback) {
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
callSendAPI(sender_psid, response);
}
}
......@@ -66,6 +67,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}else if(stat === 'stat_2'){
......@@ -73,6 +75,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}else if(stat === 'stat_3'){
......@@ -80,10 +83,10 @@ const handlePostback_choiceByProf = function(sender_psid, received){
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}
callSendAPI(sender_psid, response);
}
const handlePostback_choiceByLect = function(sender_psid, received){
......@@ -96,6 +99,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}else if(stat === 'stat_2'){
......@@ -103,6 +107,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}else if(stat === 'stat_3'){
......@@ -110,10 +115,10 @@ const handlePostback_choiceByLect = function(sender_psid, received){
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}
callSendAPI(sender_psid, response);
}
const handlePostback_help = function(sender_psid, received) {
......@@ -126,10 +131,10 @@ const handlePostback_help = function(sender_psid, received) {
if(result==true){
console.log(res);
response=res;
callSendAPI(sender_psid, response);
}
});
}
callSendAPI(sender_psid, response);
}
// Sends response messages via the Send API
......@@ -146,7 +151,8 @@ const callSendAPI = (sender_psid, response, cb=null) => {
}
}, (err, res, body) => {
if (!err) {
console.log('message sent!')
console.log('message sent!');
console.log('res: ',response);
} else {
console.error("Unable to send message:" + err);
}
......
......@@ -76,35 +76,45 @@ exports.getLectNameTemplate = function(cb){
}
exports.choiceLectProfTemplate=function(message,cb) {
var sqlquery = 'SELECT * FROM reviews WHERE lecturename = ? OR proname = ?';
var par = ['%'+message+'%','%'+message+'%'];
var sqlquery = 'SELECT * FROM reviews WHERE lecturename Like ? OR proname Like ?';
var par = ["%"+message+"%","%"+message+"%"];
db.query(sqlquery,par, function(error,results){
console.log("!~~!~!~!~!~!~!~!~!");
console.log("!~~!~!~!~!~!~!~~!~!");
console.log(results);
console.log("메세지: ",message);
if (error){
res.render('error');
}
if(results.length==0){
cb(true, {text: "검색 결과가 없습니다. 검색어를 다시 입력해주세요."});
}else if(results.length<=2){
LectProfList(results,0,results.length,false,'0',message, function(result, text){
if(result==true){
cb(true, text);
}
});
}else if(results.length>2){
LectProfList(results,0,2,true,'1',message, function(result, text){
if(result==true){
cb(true, text);
}
});
}else{
if(results.length==0){
console.log("0개로 들어 왔어용");
cb(true, {text: "검색 결과가 없습니다. 검색어를 다시 입력해주세요."});
}else if(results.length<=2){
console.log("2개로 들어 왔어용");
LectProfList(results,0,results.length,false,'0',message, function(result, text){
if(result==true){
console.log(text);
cb(true, text);
}
});
}else if(results.length>2){
console.log("3개로 들어 왔어용");
LectProfList(results,0,2,true,'1',message, function(result, text){
if(result==true){
console.log("text1: ",text);
cb(true, text);
}
});
}
}
});
}
const LectProfList = function(results,start,length,ismore,morecount,message,cb){
function LectProfList(results,start,length,ismore,morecount,message,cb){
console.log("LectProfList 함수에 들어옴");
if(length==1){
var title=results[start].lecturename+results[start].proname;
console.log("첫 버튼 하나짜리 처리하는데 들어옴");
var title=results[start].lecturename+"\n["+results[start].proname+"]";
var payload='CHOICE_BY_PROFstat_3'+results[start].idreviews;
var text={
"attachment":{
......@@ -124,7 +134,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){
};
cb(true, text);
}else if((length == 2)&&(!ismore)){
var title=[results[start].lecturename+results[start].proname, results[start+1].lecturename+results[start+1].proname];
console.log("2개짜리 처리하는데 들어옴");
var title=[results[start].lecturename+"\n["+results[start].proname+"]", results[start+1].lecturename+"\n["+results[start+1].proname+"]"];
var payload=['CHOICE_BY_PROFstat_3'+results[start].idreviews, 'CHOICE_BY_PROFstat_3'+results[start+1].idreviews];
var text={
"attachment":{
......@@ -149,7 +160,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){
};
cb(true, text);
}else if((length == 2)&&(ismore)){
var title=[results[start].lecturename+results[start].proname, results[start+1].lecturename+results[start+1].proname];
console.log("버튼 2개, 더보기까지 처리하는데 들어옴");
var title=[results[start].lecturename+"\n["+results[start].proname+"]", results[start+1].lecturename+"\n["+results[start+1].proname+"]"];
var payload=['CHOICE_BY_PROFstat_3'+results[start].idreviews, 'CHOICE_BY_PROFstat_3'+results[start+1].idreviews, 'CHOICE_BY_PROFstat_2'+message+'/'+morecount];
var text={
"attachment":{
......@@ -184,10 +196,12 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){
//stat_2
exports.moreProfTemplate = function(payload,cb){
var ms=payload.substr(20).split('/');
var more=1*(ms[0]); //to Number
var message=ms[1];
var message=ms[0]; //to Number
console.log("ms1: ",ms[1])
var more=parseInt(ms[1]);
console.log("more: ",more)
var sqlquery='SELECT * FROM reviews WHERE lecturename = ? OR proname = ?';
var sqlquery='SELECT * FROM reviews WHERE lecturename Like ? OR proname Like ?';
var par=['%'+message+'%','%'+message+'%'];
db.query(sqlquery, par, function(error,results){
if (error){
......@@ -195,13 +209,13 @@ exports.moreProfTemplate = function(payload,cb){
res.render('error');
}
if((results.length-2*(more+1))<=0){
LectProfList(results,2*more,results.length-2*n,false,'0',message, function(result, text){
LectProfList(results,2*more,results.length-2*more,false,'0',message, function(result, text){
if(result==true){
cb(true, text);
}
});
}else{
LectProfList(results,2*more,2,true,""+(more+1),message, function(result, text){
LectProfList(results,2*more,2,true,(more+1).toString(),message, function(result, text){
if(result==true){
cb(true, text);
}
......@@ -215,8 +229,8 @@ exports.moreLectTemplate= function(payload,cb){
var more=1*(ms[0]);
var message=ms[1];
var sqlquery='SELECT * FROM reviews WHERE lecturename = ? OR proname = ?';
var par=[message,message];
var sqlquery='SELECT * FROM reviews WHERE lecturename Like ? OR proname Like ?';
var par=['%'+message+'%','%'+message+'%'];
db.query(sqlquery, par, function(error,results){
if (error){
console.log(error);
......@@ -251,8 +265,8 @@ exports.rateTemplate= function(payload,cb){
}
var proname=results[0].proname;
var lecname=results[0].lecname;
var reviews=results[0].review.split(',');
var lecname=results[0].lecturename;
var reviews=results[0].review.split('.');
var review=reviews[0];
var rate=results[0].avg_rate;
var botsay=[];
......@@ -271,18 +285,18 @@ exports.rateTemplate= function(payload,cb){
botsay=["무조건 들어요!","갓갓 교수님의 갓갓 수업","안 들으면 후회해요ㅠㅠ", "수강신청 1순위!"];
}
var payload='MoreRate'+id;
var payload1='MoreRate'+id;
var text={
"attachment":{
"type":"template",
"payload":{
"template_type":"button",
"text": proname+" 교수님의 강의 ["+lecname+"]의 강의평입니다.\n **평균 평점: "+rate+"\n **봇의 한줄평: "+botsay[randNum]+"\n **학우의 한줄평: "+reivew,
"text": proname+" 교수님의 강의 ["+lecname+"]의 강의평입니다.\n **평균 평점: "+rate+"\n **봇의 한줄평: "+botsay[randNum]+"\n **학우의 한줄평: "+review,
"buttons":[
{
"type":"postback",
"title":"자세한 강의평 보기",
"payload":payload
"payload":payload1
}
]
}
......@@ -294,7 +308,6 @@ exports.rateTemplate= function(payload,cb){
exports.moreRateTemplate = function(payload,cb){
var id = payload.substr(8);
var total_review="";
var sqlquery='SELECT * FROM reviews WHERE idreviews = ?';
var par=[id];
......@@ -304,12 +317,9 @@ exports.moreRateTemplate = function(payload,cb){
res.render('error');
}
var reviews=results[0].review.split(',');
for(var review in reviews){
total_review+=review+"\n";
}
cb(true,{text:total_review});
var reviews=results[0].review;
console.log("전체리뷰:",reviews)
cb(true,{text:reviews});
});
}
......