Showing
2 changed files
with
50 additions
and
34 deletions
... | @@ -9,16 +9,17 @@ exports.handleMessage=function(sender_psid, received_message) { | ... | @@ -9,16 +9,17 @@ exports.handleMessage=function(sender_psid, received_message) { |
9 | template.greetingTemplate(function(result, res){ | 9 | template.greetingTemplate(function(result, res){ |
10 | if(result==true){ | 10 | if(result==true){ |
11 | response=res; | 11 | response=res; |
12 | + callSendAPI(sender_psid, response) | ||
12 | } | 13 | } |
13 | }); | 14 | }); |
14 | - callSendAPI(sender_psid, response); | ||
15 | }else{ | 15 | }else{ |
16 | template.choiceLectProfTemplate(text, function(result, res){ | 16 | template.choiceLectProfTemplate(text, function(result, res){ |
17 | if(result==true){ | 17 | if(result==true){ |
18 | response=res; | 18 | response=res; |
19 | + console.log("text2:",response) | ||
20 | + callSendAPI(sender_psid, response); | ||
19 | } | 21 | } |
20 | }); | 22 | }); |
21 | - callSendAPI(sender_psid, response); | ||
22 | } | 23 | } |
23 | } | 24 | } |
24 | 25 | ||
... | @@ -50,9 +51,9 @@ exports.handlePostback =function(sender_psid, received_postback) { | ... | @@ -50,9 +51,9 @@ exports.handlePostback =function(sender_psid, received_postback) { |
50 | if(result==true){ | 51 | if(result==true){ |
51 | console.log(res); | 52 | console.log(res); |
52 | response=res; | 53 | response=res; |
54 | + callSendAPI(sender_psid, response); | ||
53 | } | 55 | } |
54 | }); | 56 | }); |
55 | - callSendAPI(sender_psid, response); | ||
56 | } | 57 | } |
57 | } | 58 | } |
58 | 59 | ||
... | @@ -66,6 +67,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){ | ... | @@ -66,6 +67,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){ |
66 | if(result==true){ | 67 | if(result==true){ |
67 | console.log(res); | 68 | console.log(res); |
68 | response=res; | 69 | response=res; |
70 | + callSendAPI(sender_psid, response); | ||
69 | } | 71 | } |
70 | }); | 72 | }); |
71 | }else if(stat === 'stat_2'){ | 73 | }else if(stat === 'stat_2'){ |
... | @@ -73,6 +75,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){ | ... | @@ -73,6 +75,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){ |
73 | if(result==true){ | 75 | if(result==true){ |
74 | console.log(res); | 76 | console.log(res); |
75 | response=res; | 77 | response=res; |
78 | + callSendAPI(sender_psid, response); | ||
76 | } | 79 | } |
77 | }); | 80 | }); |
78 | }else if(stat === 'stat_3'){ | 81 | }else if(stat === 'stat_3'){ |
... | @@ -80,10 +83,10 @@ const handlePostback_choiceByProf = function(sender_psid, received){ | ... | @@ -80,10 +83,10 @@ const handlePostback_choiceByProf = function(sender_psid, received){ |
80 | if(result==true){ | 83 | if(result==true){ |
81 | console.log(res); | 84 | console.log(res); |
82 | response=res; | 85 | response=res; |
86 | + callSendAPI(sender_psid, response); | ||
83 | } | 87 | } |
84 | }); | 88 | }); |
85 | } | 89 | } |
86 | - callSendAPI(sender_psid, response); | ||
87 | } | 90 | } |
88 | 91 | ||
89 | const handlePostback_choiceByLect = function(sender_psid, received){ | 92 | const handlePostback_choiceByLect = function(sender_psid, received){ |
... | @@ -96,6 +99,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){ | ... | @@ -96,6 +99,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){ |
96 | if(result==true){ | 99 | if(result==true){ |
97 | console.log(res); | 100 | console.log(res); |
98 | response=res; | 101 | response=res; |
102 | + callSendAPI(sender_psid, response); | ||
99 | } | 103 | } |
100 | }); | 104 | }); |
101 | }else if(stat === 'stat_2'){ | 105 | }else if(stat === 'stat_2'){ |
... | @@ -103,6 +107,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){ | ... | @@ -103,6 +107,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){ |
103 | if(result==true){ | 107 | if(result==true){ |
104 | console.log(res); | 108 | console.log(res); |
105 | response=res; | 109 | response=res; |
110 | + callSendAPI(sender_psid, response); | ||
106 | } | 111 | } |
107 | }); | 112 | }); |
108 | }else if(stat === 'stat_3'){ | 113 | }else if(stat === 'stat_3'){ |
... | @@ -110,10 +115,10 @@ const handlePostback_choiceByLect = function(sender_psid, received){ | ... | @@ -110,10 +115,10 @@ const handlePostback_choiceByLect = function(sender_psid, received){ |
110 | if(result==true){ | 115 | if(result==true){ |
111 | console.log(res); | 116 | console.log(res); |
112 | response=res; | 117 | response=res; |
118 | + callSendAPI(sender_psid, response); | ||
113 | } | 119 | } |
114 | }); | 120 | }); |
115 | } | 121 | } |
116 | - callSendAPI(sender_psid, response); | ||
117 | } | 122 | } |
118 | 123 | ||
119 | const handlePostback_help = function(sender_psid, received) { | 124 | const handlePostback_help = function(sender_psid, received) { |
... | @@ -126,10 +131,10 @@ const handlePostback_help = function(sender_psid, received) { | ... | @@ -126,10 +131,10 @@ const handlePostback_help = function(sender_psid, received) { |
126 | if(result==true){ | 131 | if(result==true){ |
127 | console.log(res); | 132 | console.log(res); |
128 | response=res; | 133 | response=res; |
134 | + callSendAPI(sender_psid, response); | ||
129 | } | 135 | } |
130 | }); | 136 | }); |
131 | } | 137 | } |
132 | - callSendAPI(sender_psid, response); | ||
133 | } | 138 | } |
134 | 139 | ||
135 | // Sends response messages via the Send API | 140 | // Sends response messages via the Send API |
... | @@ -146,7 +151,8 @@ const callSendAPI = (sender_psid, response, cb=null) => { | ... | @@ -146,7 +151,8 @@ const callSendAPI = (sender_psid, response, cb=null) => { |
146 | } | 151 | } |
147 | }, (err, res, body) => { | 152 | }, (err, res, body) => { |
148 | if (!err) { | 153 | if (!err) { |
149 | - console.log('message sent!') | 154 | + console.log('message sent!'); |
155 | + console.log('res: ',response); | ||
150 | } else { | 156 | } else { |
151 | console.error("Unable to send message:" + err); | 157 | console.error("Unable to send message:" + err); |
152 | } | 158 | } | ... | ... |
... | @@ -76,35 +76,45 @@ exports.getLectNameTemplate = function(cb){ | ... | @@ -76,35 +76,45 @@ exports.getLectNameTemplate = function(cb){ |
76 | } | 76 | } |
77 | 77 | ||
78 | exports.choiceLectProfTemplate=function(message,cb) { | 78 | exports.choiceLectProfTemplate=function(message,cb) { |
79 | - var sqlquery = 'SELECT * FROM reviews WHERE lecturename = ? OR proname = ?'; | 79 | + var sqlquery = 'SELECT * FROM reviews WHERE lecturename Like ? OR proname Like ?'; |
80 | - var par = ['%'+message+'%','%'+message+'%']; | 80 | + var par = ["%"+message+"%","%"+message+"%"]; |
81 | 81 | ||
82 | db.query(sqlquery,par, function(error,results){ | 82 | db.query(sqlquery,par, function(error,results){ |
83 | - console.log("!~~!~!~!~!~!~!~!~!"); | 83 | + console.log("!~~!~!~!~!~!~!~~!~!"); |
84 | + console.log(results); | ||
85 | + console.log("메세지: ",message); | ||
84 | if (error){ | 86 | if (error){ |
85 | res.render('error'); | 87 | res.render('error'); |
86 | - } | 88 | + }else{ |
87 | if(results.length==0){ | 89 | if(results.length==0){ |
90 | + console.log("0개로 들어 왔어용"); | ||
88 | cb(true, {text: "검색 결과가 없습니다. 검색어를 다시 입력해주세요."}); | 91 | cb(true, {text: "검색 결과가 없습니다. 검색어를 다시 입력해주세요."}); |
89 | }else if(results.length<=2){ | 92 | }else if(results.length<=2){ |
93 | + console.log("2개로 들어 왔어용"); | ||
90 | LectProfList(results,0,results.length,false,'0',message, function(result, text){ | 94 | LectProfList(results,0,results.length,false,'0',message, function(result, text){ |
91 | if(result==true){ | 95 | if(result==true){ |
96 | + console.log(text); | ||
92 | cb(true, text); | 97 | cb(true, text); |
93 | } | 98 | } |
94 | }); | 99 | }); |
95 | }else if(results.length>2){ | 100 | }else if(results.length>2){ |
101 | + console.log("3개로 들어 왔어용"); | ||
96 | LectProfList(results,0,2,true,'1',message, function(result, text){ | 102 | LectProfList(results,0,2,true,'1',message, function(result, text){ |
97 | if(result==true){ | 103 | if(result==true){ |
104 | + console.log("text1: ",text); | ||
98 | cb(true, text); | 105 | cb(true, text); |
99 | } | 106 | } |
100 | }); | 107 | }); |
101 | } | 108 | } |
109 | + } | ||
102 | }); | 110 | }); |
103 | } | 111 | } |
104 | 112 | ||
105 | -const LectProfList = function(results,start,length,ismore,morecount,message,cb){ | 113 | +function LectProfList(results,start,length,ismore,morecount,message,cb){ |
114 | + console.log("LectProfList 함수에 들어옴"); | ||
106 | if(length==1){ | 115 | if(length==1){ |
107 | - var title=results[start].lecturename+results[start].proname; | 116 | + console.log("첫 버튼 하나짜리 처리하는데 들어옴"); |
117 | + var title=results[start].lecturename+"\n["+results[start].proname+"]"; | ||
108 | var payload='CHOICE_BY_PROFstat_3'+results[start].idreviews; | 118 | var payload='CHOICE_BY_PROFstat_3'+results[start].idreviews; |
109 | var text={ | 119 | var text={ |
110 | "attachment":{ | 120 | "attachment":{ |
... | @@ -124,7 +134,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){ | ... | @@ -124,7 +134,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){ |
124 | }; | 134 | }; |
125 | cb(true, text); | 135 | cb(true, text); |
126 | }else if((length == 2)&&(!ismore)){ | 136 | }else if((length == 2)&&(!ismore)){ |
127 | - var title=[results[start].lecturename+results[start].proname, results[start+1].lecturename+results[start+1].proname]; | 137 | + console.log("2개짜리 처리하는데 들어옴"); |
138 | + var title=[results[start].lecturename+"\n["+results[start].proname+"]", results[start+1].lecturename+"\n["+results[start+1].proname+"]"]; | ||
128 | var payload=['CHOICE_BY_PROFstat_3'+results[start].idreviews, 'CHOICE_BY_PROFstat_3'+results[start+1].idreviews]; | 139 | var payload=['CHOICE_BY_PROFstat_3'+results[start].idreviews, 'CHOICE_BY_PROFstat_3'+results[start+1].idreviews]; |
129 | var text={ | 140 | var text={ |
130 | "attachment":{ | 141 | "attachment":{ |
... | @@ -149,7 +160,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){ | ... | @@ -149,7 +160,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){ |
149 | }; | 160 | }; |
150 | cb(true, text); | 161 | cb(true, text); |
151 | }else if((length == 2)&&(ismore)){ | 162 | }else if((length == 2)&&(ismore)){ |
152 | - var title=[results[start].lecturename+results[start].proname, results[start+1].lecturename+results[start+1].proname]; | 163 | + console.log("버튼 2개, 더보기까지 처리하는데 들어옴"); |
164 | + var title=[results[start].lecturename+"\n["+results[start].proname+"]", results[start+1].lecturename+"\n["+results[start+1].proname+"]"]; | ||
153 | var payload=['CHOICE_BY_PROFstat_3'+results[start].idreviews, 'CHOICE_BY_PROFstat_3'+results[start+1].idreviews, 'CHOICE_BY_PROFstat_2'+message+'/'+morecount]; | 165 | var payload=['CHOICE_BY_PROFstat_3'+results[start].idreviews, 'CHOICE_BY_PROFstat_3'+results[start+1].idreviews, 'CHOICE_BY_PROFstat_2'+message+'/'+morecount]; |
154 | var text={ | 166 | var text={ |
155 | "attachment":{ | 167 | "attachment":{ |
... | @@ -184,10 +196,12 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){ | ... | @@ -184,10 +196,12 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){ |
184 | //stat_2 | 196 | //stat_2 |
185 | exports.moreProfTemplate = function(payload,cb){ | 197 | exports.moreProfTemplate = function(payload,cb){ |
186 | var ms=payload.substr(20).split('/'); | 198 | var ms=payload.substr(20).split('/'); |
187 | - var more=1*(ms[0]); //to Number | 199 | + var message=ms[0]; //to Number |
188 | - var message=ms[1]; | 200 | + console.log("ms1: ",ms[1]) |
201 | + var more=parseInt(ms[1]); | ||
202 | + console.log("more: ",more) | ||
189 | 203 | ||
190 | - var sqlquery='SELECT * FROM reviews WHERE lecturename = ? OR proname = ?'; | 204 | + var sqlquery='SELECT * FROM reviews WHERE lecturename Like ? OR proname Like ?'; |
191 | var par=['%'+message+'%','%'+message+'%']; | 205 | var par=['%'+message+'%','%'+message+'%']; |
192 | db.query(sqlquery, par, function(error,results){ | 206 | db.query(sqlquery, par, function(error,results){ |
193 | if (error){ | 207 | if (error){ |
... | @@ -195,13 +209,13 @@ exports.moreProfTemplate = function(payload,cb){ | ... | @@ -195,13 +209,13 @@ exports.moreProfTemplate = function(payload,cb){ |
195 | res.render('error'); | 209 | res.render('error'); |
196 | } | 210 | } |
197 | if((results.length-2*(more+1))<=0){ | 211 | if((results.length-2*(more+1))<=0){ |
198 | - LectProfList(results,2*more,results.length-2*n,false,'0',message, function(result, text){ | 212 | + LectProfList(results,2*more,results.length-2*more,false,'0',message, function(result, text){ |
199 | if(result==true){ | 213 | if(result==true){ |
200 | cb(true, text); | 214 | cb(true, text); |
201 | } | 215 | } |
202 | }); | 216 | }); |
203 | }else{ | 217 | }else{ |
204 | - LectProfList(results,2*more,2,true,""+(more+1),message, function(result, text){ | 218 | + LectProfList(results,2*more,2,true,(more+1).toString(),message, function(result, text){ |
205 | if(result==true){ | 219 | if(result==true){ |
206 | cb(true, text); | 220 | cb(true, text); |
207 | } | 221 | } |
... | @@ -215,8 +229,8 @@ exports.moreLectTemplate= function(payload,cb){ | ... | @@ -215,8 +229,8 @@ exports.moreLectTemplate= function(payload,cb){ |
215 | var more=1*(ms[0]); | 229 | var more=1*(ms[0]); |
216 | var message=ms[1]; | 230 | var message=ms[1]; |
217 | 231 | ||
218 | - var sqlquery='SELECT * FROM reviews WHERE lecturename = ? OR proname = ?'; | 232 | + var sqlquery='SELECT * FROM reviews WHERE lecturename Like ? OR proname Like ?'; |
219 | - var par=[message,message]; | 233 | + var par=['%'+message+'%','%'+message+'%']; |
220 | db.query(sqlquery, par, function(error,results){ | 234 | db.query(sqlquery, par, function(error,results){ |
221 | if (error){ | 235 | if (error){ |
222 | console.log(error); | 236 | console.log(error); |
... | @@ -251,8 +265,8 @@ exports.rateTemplate= function(payload,cb){ | ... | @@ -251,8 +265,8 @@ exports.rateTemplate= function(payload,cb){ |
251 | } | 265 | } |
252 | 266 | ||
253 | var proname=results[0].proname; | 267 | var proname=results[0].proname; |
254 | - var lecname=results[0].lecname; | 268 | + var lecname=results[0].lecturename; |
255 | - var reviews=results[0].review.split(','); | 269 | + var reviews=results[0].review.split('.'); |
256 | var review=reviews[0]; | 270 | var review=reviews[0]; |
257 | var rate=results[0].avg_rate; | 271 | var rate=results[0].avg_rate; |
258 | var botsay=[]; | 272 | var botsay=[]; |
... | @@ -271,18 +285,18 @@ exports.rateTemplate= function(payload,cb){ | ... | @@ -271,18 +285,18 @@ exports.rateTemplate= function(payload,cb){ |
271 | botsay=["무조건 들어요!","갓갓 교수님의 갓갓 수업","안 들으면 후회해요ㅠㅠ", "수강신청 1순위!"]; | 285 | botsay=["무조건 들어요!","갓갓 교수님의 갓갓 수업","안 들으면 후회해요ㅠㅠ", "수강신청 1순위!"]; |
272 | } | 286 | } |
273 | 287 | ||
274 | - var payload='MoreRate'+id; | 288 | + var payload1='MoreRate'+id; |
275 | var text={ | 289 | var text={ |
276 | "attachment":{ | 290 | "attachment":{ |
277 | "type":"template", | 291 | "type":"template", |
278 | "payload":{ | 292 | "payload":{ |
279 | "template_type":"button", | 293 | "template_type":"button", |
280 | - "text": proname+" 교수님의 강의 ["+lecname+"]의 강의평입니다.\n **평균 평점: "+rate+"\n **봇의 한줄평: "+botsay[randNum]+"\n **학우의 한줄평: "+reivew, | 294 | + "text": proname+" 교수님의 강의 ["+lecname+"]의 강의평입니다.\n **평균 평점: "+rate+"\n **봇의 한줄평: "+botsay[randNum]+"\n **학우의 한줄평: "+review, |
281 | "buttons":[ | 295 | "buttons":[ |
282 | { | 296 | { |
283 | "type":"postback", | 297 | "type":"postback", |
284 | "title":"자세한 강의평 보기", | 298 | "title":"자세한 강의평 보기", |
285 | - "payload":payload | 299 | + "payload":payload1 |
286 | } | 300 | } |
287 | ] | 301 | ] |
288 | } | 302 | } |
... | @@ -294,7 +308,6 @@ exports.rateTemplate= function(payload,cb){ | ... | @@ -294,7 +308,6 @@ exports.rateTemplate= function(payload,cb){ |
294 | 308 | ||
295 | exports.moreRateTemplate = function(payload,cb){ | 309 | exports.moreRateTemplate = function(payload,cb){ |
296 | var id = payload.substr(8); | 310 | var id = payload.substr(8); |
297 | - var total_review=""; | ||
298 | 311 | ||
299 | var sqlquery='SELECT * FROM reviews WHERE idreviews = ?'; | 312 | var sqlquery='SELECT * FROM reviews WHERE idreviews = ?'; |
300 | var par=[id]; | 313 | var par=[id]; |
... | @@ -304,12 +317,9 @@ exports.moreRateTemplate = function(payload,cb){ | ... | @@ -304,12 +317,9 @@ exports.moreRateTemplate = function(payload,cb){ |
304 | res.render('error'); | 317 | res.render('error'); |
305 | } | 318 | } |
306 | 319 | ||
307 | - var reviews=results[0].review.split(','); | 320 | + var reviews=results[0].review; |
308 | - for(var review in reviews){ | 321 | + console.log("전체리뷰:",reviews) |
309 | - total_review+=review+"\n"; | 322 | + cb(true,{text:reviews}); |
310 | - } | ||
311 | - | ||
312 | - cb(true,{text:total_review}); | ||
313 | }); | 323 | }); |
314 | } | 324 | } |
315 | 325 | ... | ... |
-
Please register or login to post a comment