백승욱

Edit main.js and config.json

1 { 1 {
2 "TOKEN" : "Insert user token value", 2 "TOKEN" : "Insert user token value",
3 "KOFIC_KEY" : "Insert user key value", 3 "KOFIC_KEY" : "Insert user key value",
4 - "domain" : "Insert user domain" 4 + "domain" : "Insert user domain",
5 + "USER_ID" : "Insert user id"
5 } 6 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -3,7 +3,7 @@ var express = require('express'); ...@@ -3,7 +3,7 @@ var express = require('express');
3 const request = require('request'); 3 const request = require('request');
4 const config = require('./config.json'); 4 const config = require('./config.json');
5 //============================================================= 5 //=============================================================
6 -const LINE_URL = 'https://api.line.me/v2/bot/message/reply' 6 +const LINE_URL = 'https://api.line.me/v2/bot/message';
7 const TOKEN = config.TOKEN; 7 const TOKEN = config.TOKEN;
8 const KOFIC_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest'; 8 const KOFIC_URL = 'http://www.kobis.or.kr/kobisopenapi/webservice/rest';
9 const KOFIC_KEY = config.KOFIC_KEY; 9 const KOFIC_KEY = config.KOFIC_KEY;
...@@ -20,37 +20,81 @@ app.use(bodyParser.json()); ...@@ -20,37 +20,81 @@ app.use(bodyParser.json());
20 var BoxOffice = require('./DailyBoxOfficeList.js'); 20 var BoxOffice = require('./DailyBoxOfficeList.js');
21 var MovieList = require('./MovieList.js'); 21 var MovieList = require('./MovieList.js');
22 var MovieInfo = require('./MovieInfo.js'); 22 var MovieInfo = require('./MovieInfo.js');
23 +var MovieReco = require('./MovieRecommend.js');
24 +var Exception = require('./Exception.js');
25 +//=============================================================
26 +const user_id = config.USER_ID;
27 +//=============================================================
28 +
29 +
30 +// SHOW MENU
31 +function ShowMenu() {
32 + request.post({
33 + url: LINE_URL + '/push',
34 + headers: {
35 + 'Authorization': `Bearer ${TOKEN}`
36 + },
37 + json: {
38 + "to": `${USER_ID}`,
39 + "messages": [
40 + {
41 + "type": "text",
42 + "text": "0번 : 메뉴 출력\n1번 : 최신영화 추천\n2번 : 장르별 영화 추천\n3번 : 영화 검색하기\n영화코드 입력 : 영화 상세정보 조회"
43 + }
44 + ]
45 + }
46 + }, (error, response, body) => {
47 + console.log(body)
48 + });
49 +}
50 +
51 +ShowMenu();
52 +
23 53
24 // RECEIVE MESSAGE 54 // RECEIVE MESSAGE
25 app.post('/hook', function (req, res) { 55 app.post('/hook', function (req, res) {
26 56
27 var eventObj = req.body.events[0]; 57 var eventObj = req.body.events[0];
28 58
29 - // console.log for debugging
30 - console.log('======================', new Date(), '======================');
31 - console.log('[request]', req.body);
32 - console.log('[request source] ', eventObj.source);
33 - console.log('[request message]', eventObj.message);
34 -
35 Response(eventObj.replyToken, eventObj.message.text); 59 Response(eventObj.replyToken, eventObj.message.text);
36 60
37 res.sendStatus(200); 61 res.sendStatus(200);
38 }); 62 });
39 63
40 64
65 +var flag_2 = 0;
66 +var flag_3 = 0;
67 +
41 // RESPONSE TO MESSAGE 68 // RESPONSE TO MESSAGE
42 function Response(replyToken, message) { 69 function Response(replyToken, message) {
43 - // 사용자가 보낸 라인 메시지 문자열 안에 특정 문자열이 있으면, 특정 함수 실행 70 + if (isNaN(message) === false && message.length === 8) {
44 - if (message.includes('최신') || message.includes('순위') || message.includes('오늘') || message.includes('추천')) {
45 - BoxOffice.ShowYesterdayRank(replyToken);
46 - } else if (isNaN(message) === false && message.length === 8) {
47 - // (예시) 영화 줄거리 출력
48 MovieInfo.MovieInfo(replyToken, message); 71 MovieInfo.MovieInfo(replyToken, message);
49 } 72 }
50 - else if (typeof (message) === 'string') { 73 + else if (message == '0' || message == '0번') {
51 - // (예시) 영화 목록 출력 74 + ShowMenu();
75 + }
76 + else if (message == '1' || message == '1번') {
77 + BoxOffice.ShowYesterdayRank(replyToken);
78 + }
79 + else if ((message == '2' || message == '2번') && flag_2 == 0) {
80 + flag_2 = 1;
81 + Exception.test_1(replyToken);
82 + }
83 + else if ((message == '3' || message == '3번') && flag_3 == 0) {
84 + flag_3 = 1;
85 + Exception.test_2(replyToken);
86 + }
87 + else if (flag_2 == 1) {
88 + flag_2 = 0;
89 + MovieReco.movieRecommend(replyToken, message);
90 + }
91 + else if (flag_3 == 1) {
92 + flag_3 = 0;
52 MovieList.movielist(replyToken, message); 93 MovieList.movielist(replyToken, message);
53 } 94 }
95 + else {
96 + Exception.SayIDontKnow(replyToken);
97 + }
54 } 98 }
55 99
56 100
......