김연우

sorting destination

This diff is collapsed. Click to expand it.
1 { 1 {
2 - "name":"study-or-enjoy", 2 + "name": "study-or-enjoy",
3 - "version":"1.0.0", 3 + "version": "1.0.0",
4 - "description":"", 4 + "description": "",
5 - "main":"main.js", 5 + "main": "main.js",
6 - "scripts":{ 6 + "scripts": {
7 - "test":"mocha --debug-brk" 7 + "test": "mocha --debug-brk"
8 }, 8 },
9 - "repository":{ 9 + "repository": {
10 - "type":"git", 10 + "type": "git",
11 - "url":"http://khuhub.khu.ac.kr/2018102202/study-or-enjoy" 11 + "url": "http://khuhub.khu.ac.kr/2018102202/study-or-enjoy"
12 }, 12 },
13 - "author":"", 13 + "author": "",
14 - "license":"", 14 + "license": "",
15 - "dependencies":{ 15 + "dependencies": {
16 - "@types/axios":"^0.14.0", 16 + "@types/axios": "^0.14.0",
17 - "@types/selenium-webdriver":"^4.1.0", 17 + "@types/selenium-webdriver": "^4.1.0",
18 - "axios":"^0.27.2", 18 + "axios": "^0.27.2",
19 - "mocha":"^10.0.0", 19 + "express": "^4.18.1",
20 - "selenium-webdriver":"^4.1.2" 20 + "express-session": "^1.17.3",
21 + "mocha": "^10.0.0",
22 + "request": "^2.88.2",
23 + "selenium-webdriver": "^4.1.2"
21 }, 24 },
22 - "type":"commonjs", 25 + "type": "commonjs",
23 - "devDependencies":{ 26 + "devDependencies": {
24 - "@types/node":"^17.0.35", 27 + "@types/node": "^17.0.35",
25 - "eslint":"^8.16.0" 28 + "eslint": "^8.16.0"
26 } 29 }
27 -}
...\ No newline at end of file ...\ No newline at end of file
30 +}
......
...@@ -4,36 +4,176 @@ const results = []; ...@@ -4,36 +4,176 @@ const results = [];
4 var choice = "놀거리" 4 var choice = "놀거리"
5 5
6 //대분류 선택 과정 필요 6 //대분류 선택 과정 필요
7 +exports.chooseFile = function () {
8 + if (choice == "카페") {
9 + fs.createReadStream('cafe_list.csv')
10 + .pipe(csv())
11 + .on('data', (data) => results.push(data))
12 + .on('end', () => {
13 + console.log(results);
14 + });
15 + }
16 + else if (choice == "식사") {
17 + fs.createReadStream('meal_list.csv')
18 + .pipe(csv())
19 + .on('data', (data) => results.push(data))
20 + .on('end', () => {
21 + console.log(results);
22 + });
23 + }
24 + else if (choice == "놀거리") {
25 + fs.createReadStream('play_list.csv')
26 + .pipe(csv())
27 + .on('data', (data) => results.push(data))
28 + .on('end', () => {
29 + console.log(results);
30 + });
31 + }
32 + else if (choice == "술집") {
33 + fs.createReadStream('bar_list.csv')
34 + .pipe(csv())
35 + .on('data', (data) => results.push(data))
36 + .on('end', () => {
37 + console.log(results);
38 + });
39 + }
40 +}
41 +
42 +//chatbot - reply - app.js
43 +
44 +var first = false; //첫 시도인지
45 +var second = false; //첫번째 분류 선택했는지
46 +var destCar = "";
47 +
48 +const bodyParser = require('body-parser');
49 +var app = express();
50 +app.use(bodyParser.json());
51 +app.post('/hook', function (req, res) {
52 +
53 + var eventObj = req.body.events[0];
54 + var source = eventObj.source;
55 + var message = eventObj.message;
56 +
57 + // request log
58 + console.log('======================', new Date(), '======================');
59 + console.log('[request]', req.body);
60 + console.log('[request source] ', eventObj.source);
61 + console.log('[request message]', eventObj.message);
62 +
63 +
64 + if (first == false && eventObj.message.text == "처음") {
65 + request.post(
66 + {
67 + url: TARGET_URL,
68 + headers: {
69 + 'Authorization': `Bearer ${TOKEN}`
70 + },
71 + json: {
72 + "replyToken": eventObj.replyToken,
73 + "messages": [
74 + {
75 + "type": "text",
76 + "text": "카테고리를 선택해주세요.\n1. 식사\n2. 카페\n3. 술\n4. 놀거리\n(숫자만 입력해주세요)"
77 + }
78 + ]
79 + },
80 + }, (error, response, body) => {
81 + console.log(body)
82 + });
83 + first = true;
84 + }
7 85
8 -if(choice == "카페"){ 86 + else if (first == true && second == false) {
9 - fs.createReadStream('cafe_list.csv') 87 +
10 - .pipe(csv()) 88 + if (eventObj.message.text == 1) { //식사 선택
11 - .on('data', (data) => results.push(data)) 89 + request.post(
12 - .on('end', () => { 90 + {
13 - console.log(results); 91 + url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
92 + "replyToken": eventObj.replyToken,
93 + "messages": [{ "type": "text", "text": "[식사] 키워드를 선택해주세요\n1. 양식\n2. 한식\n3. 중식\n4. 일식\n5. 기타 " }]
94 + }
95 + }, (error, response, body) => {
96 + console.log(body)
97 + });
98 + destCar = "meal";
99 + } else if (eventObj.message.text == 2) { //카페 선택
100 + request.post(
101 + {
102 + url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
103 + "replyToken": eventObj.replyToken,
104 + "messages": [{ "type": "text", "text": "[카페] 키워드를 선택해주세요\n1. 감성\n2. 카공\n3. 디저트" }]
105 + }
106 + }, (error, response, body) => {
107 + console.log(body)
108 + });
109 + destCar = "cafe";
110 + } else if (eventObj.message.text == 3) { //술 선택
111 + request.post(
112 + {
113 + url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
114 + "replyToken": eventObj.replyToken,
115 + "messages": [{ "type": "text", "text": "[술] 키워드를 선택해주세요\n1. 소주\n2. 이자카야\n3. 막걸리\n4. 맥주" }]
116 + }
117 + }, (error, response, body) => {
118 + console.log(body)
119 + });
120 + destCar = "bar"
121 + } else if (eventObj.message.text == 4) { //놀거리 선택
122 + request.post(
123 + {
124 + url: TARGET_URL, headers: { 'Authorization': `Bearer ${TOKEN}` }, json: {
125 + "replyToken": eventObj.replyToken,
126 + "messages": [{ "type": "text", "text": "[놀거리] 키워드를 선택해주세요\n1. 노래방\n2. 피시방\n3. 기타" }]
127 + }
128 + }, (error, response, body) => {
129 + console.log(body)
130 + });
131 + destCar = "play"
132 + }
133 +
134 + second = true;
135 +
136 + }
137 +
138 + else if (first == true && second == true) {
139 + if (destCar == "meal") {
140 + if (eventObj.message.text == 1) { destination = "western"; console.log(destination) }
141 + else if (eventObj.message.text == 2) { destination = "korean"; console.log(destination)}
142 + else if (eventObj.message.text == 3) { destination = "chinese"; console.log(destination)}
143 + else if (eventObj.message.text == 4) { destination = "japanese"; console.log(destination)}
144 + else if (eventObj.message.text == 5) { destination = "meal_etc"; console.log(destination) }
145 + }
146 + else if (destCar == "cafe") {
147 + if (eventObj.message.text == 1) { destination = "sns"; console.log(destination) }
148 + else if (eventObj.message.text == 2) { destination = "study"; console.log(destination)}
149 + else if (eventObj.message.text == 3) { destination = "dessert"; console.log(destination)}
150 + }
151 + else if (destCar == "bar") {
152 + if (eventObj.message.text == 1) { destination = "soju"; console.log(destination) }
153 + else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)}
154 + else if (eventObj.message.text == 3) { destination = "makgeolli"; console.log(destination)}
155 + else if (eventObj.message.text == 4) { destination = "beer"; console.log(destination)}
156 + }
157 + else if (destCar == "play") {
158 + if (eventObj.message.text == 1) { destination = "karaoke"; console.log(destination) }
159 + else if (eventObj.message.text == 2) { destination = "izakaya"; console.log(destination)}
160 + else if (eventObj.message.text == 3) { destination = "play_etc"; console.log(destination)}
161 + }
162 + }
163 + res.sendStatus(200);
164 +});
165 +
166 +try {
167 + const option = {
168 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
169 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
170 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
171 + };
172 +
173 + HTTPS.createServer(option, app).listen(sslport, () => {
174 + console.log(`[HTTPS] Server is started on port ${sslport}`);
14 }); 175 });
15 -} 176 +} catch (error) {
16 -else if (choice == "식사"){ 177 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
17 - fs.createReadStream('meal_list.csv') 178 + console.log(error);
18 - .pipe(csv())
19 - .on('data', (data) => results.push(data))
20 - .on('end', () => {
21 - console.log(results);
22 - });
23 -}
24 -else if (choice == "놀거리"){
25 - fs.createReadStream('play_list.csv')
26 - .pipe(csv())
27 - .on('data', (data) => results.push(data))
28 - .on('end', () => {
29 - console.log(results);
30 - });
31 -}
32 -else if (choice == "술집"){
33 - fs.createReadStream('bar_list.csv')
34 - .pipe(csv())
35 - .on('data', (data) => results.push(data))
36 - .on('end', () => {
37 - console.log(results);
38 - });
39 } 179 }
...\ No newline at end of file ...\ No newline at end of file
......