taegwon

Really Really final app.js

...@@ -9,14 +9,14 @@ var choosen = new Array(); ...@@ -9,14 +9,14 @@ var choosen = new Array();
9 var express = require('express'); 9 var express = require('express');
10 const request = require('request'); 10 const request = require('request');
11 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 11 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
12 -const TOKEN = '/OxzMlYdmehXwfIxEHS7MSlX470jmkfxfp6kWPMTALlk+hwhqErglwOfMB/cOGVlZCOdMQHSy+Fb48XUJa6C1FHx16wxqcRgRhwGkl6pO5QP65jb8qSmN7/esJvzp2y4ozwkW+Hy+6giAx8pPPMzeQdB04t89/1O/w1cDnyilFU=' 12 +const TOKEN = 'TOKEN'
13 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' 13 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
14 -const PAPAGO_ID = 'PAPAGO ID' 14 +const PAPAGO_ID = 'PAPAGOID'
15 -const PAPAGO_SECRET = 'PAPAGO SECRET' 15 +const PAPAGO_SECRET = 'PAPAGOSECRET'
16 var fs = require('fs'); 16 var fs = require('fs');
17 const path = require('path'); 17 const path = require('path');
18 const HTTPS = require('https'); 18 const HTTPS = require('https');
19 -const domain = "2021105602.osschatbot2022.tk" 19 +const domain = "DOMAIN"
20 const sslport = 23023; 20 const sslport = 23023;
21 const bodyParser = require('body-parser'); 21 const bodyParser = require('body-parser');
22 const res = require('express/lib/response'); 22 const res = require('express/lib/response');
...@@ -37,10 +37,15 @@ app.post('/hook', function (req, res) { ...@@ -37,10 +37,15 @@ app.post('/hook', function (req, res) {
37 console.log('[request source] ', eventObj.source); 37 console.log('[request source] ', eventObj.source);
38 console.log('[request message]', eventObj.message); 38 console.log('[request message]', eventObj.message);
39 39
40 - if (eventObj.message.text == 'start') { 40 + if(eventObj.message.text == 'reset'){
41 + count=0;
42 + selected_food = '';
43 + located = '';
44 + real_data ='';
45 + }else if (eventObj.message.text == 'start') {
41 46
42 count++; 47 count++;
43 - start_msg(eventObj.replyToken, eventObj.message.text); 48 + start_msg(eventObj.replyToken);
44 }else if((eventObj.message.text === 'y' || eventObj.message.text == 'n' )&& count ==1) 49 }else if((eventObj.message.text === 'y' || eventObj.message.text == 'n' )&& count ==1)
45 { 50 {
46 if(eventObj.message.text == 'n') 51 if(eventObj.message.text == 'n')
...@@ -130,6 +135,7 @@ app.post('/hook', function (req, res) { ...@@ -130,6 +135,7 @@ app.post('/hook', function (req, res) {
130 { 135 {
131 located = eventObj.message.text; 136 located = eventObj.message.text;
132 load_map(eventObj.replyToken); 137 load_map(eventObj.replyToken);
138 + cout++;
133 }else if(count == 11 && end) 139 }else if(count == 11 && end)
134 { 140 {
135 async function ending () { 141 async function ending () {
...@@ -147,40 +153,26 @@ app.post('/hook', function (req, res) { ...@@ -147,40 +153,26 @@ app.post('/hook', function (req, res) {
147 res.sendStatus(200); 153 res.sendStatus(200);
148 }); 154 });
149 155
150 -async function start_msg(replyToken, message) { 156 +async function start_msg(replyToken)
157 +{
151 await request.post( 158 await request.post(
152 { 159 {
153 - url: PAPAGO_URL, 160 + url: TARGET_URL,
154 headers: { 161 headers: {
155 - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 162 + 'Authorization': `Bearer ${TOKEN}`
156 - 'X-Naver-Client-Id': `${PAPAGO_ID}`,
157 - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
158 }, 163 },
159 - body: 'source=en&target=ko&text=' + "Hi! This is Menu recommend Chatbot! If you follow the instructions, I will recommend the menu. 진행하시겠습니까? (y/n)", 164 + json: {
160 - json: true 165 + "replyToken": replyToken,
161 - }, (error, response, body) => { 166 + "messages": [
162 - if (!error && response.statusCode == 200) {
163 - console.log(body.message);
164 - var transMessage = body.message.result.translatedText;
165 - request.post(
166 { 167 {
167 - url: TARGET_URL, 168 + "type": "text",
168 - headers: { 169 + "text": "안녕하세요 메뉴 추천 챗봇입니다! 안내에 따라 주시면 제가 메뉴를 추천해 드리겠습니다.\n진행하시겠습니까? (y/n)\n(reset를 입력하면 초기화됩니다.)"
169 - 'Authorization': `Bearer ${TOKEN}` 170 +
170 - }, 171 + }
171 - json: { 172 + ]
172 - "replyToken": replyToken,
173 - "messages": [
174 - {
175 - "type": "text",
176 - "text": transMessage
177 - }
178 - ]
179 - }
180 - }, (error, response, body) => {
181 - console.log(body)
182 - });
183 } 173 }
174 + }, (error, response, body) => {
175 + console.log(body)
184 }); 176 });
185 } 177 }
186 178
...@@ -193,7 +185,7 @@ async function opt_1(replyToken, message) { ...@@ -193,7 +185,7 @@ async function opt_1(replyToken, message) {
193 'X-Naver-Client-Id': `${PAPAGO_ID}`, 185 'X-Naver-Client-Id': `${PAPAGO_ID}`,
194 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` 186 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
195 }, 187 },
196 - body: 'source=en&target=ko&text=' + "1.한식 2.중식 3.Japanese food 4.Western food 5.Guitar", 188 + body: 'source=en&target=ko&text=' + "1.한식 2.중식 3.일식 4.양식 5.기타",
197 json: true 189 json: true
198 }, (error, response, body) => { 190 }, (error, response, body) => {
199 if (!error && response.statusCode == 200) { 191 if (!error && response.statusCode == 200) {
...@@ -401,7 +393,7 @@ async function Rmx(replyToken,message) { ...@@ -401,7 +393,7 @@ async function Rmx(replyToken,message) {
401 'X-Naver-Client-Id': `${PAPAGO_ID}`, 393 'X-Naver-Client-Id': `${PAPAGO_ID}`,
402 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` 394 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
403 }, 395 },
404 - body: 'source=en&target=ko&text=' + "추천 음식은" + message + "입니다. 음식을 고르시오.", 396 + body: 'source=en&target=ko&text=' + "추천 음식은 " + message + "입니다. 음식을 고르시오.",
405 json: true 397 json: true
406 }, (error, response, body) => { 398 }, (error, response, body) => {
407 if (!error && response.statusCode == 200) { 399 if (!error && response.statusCode == 200) {
...@@ -438,7 +430,7 @@ async function Rmx_1(replyToken,message) { ...@@ -438,7 +430,7 @@ async function Rmx_1(replyToken,message) {
438 'X-Naver-Client-Id': `${PAPAGO_ID}`, 430 'X-Naver-Client-Id': `${PAPAGO_ID}`,
439 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` 431 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
440 }, 432 },
441 - body: 'source=en&target=ko&text=' + "추천음식을 보겠습니까? (y/n)", 433 + body: 'source=en&target=ko&text=' + "추천 음식을 보겠습니까? (y/n)",
442 json: true 434 json: true
443 }, (error, response, body) => { 435 }, (error, response, body) => {
444 if (!error && response.statusCode == 200) { 436 if (!error && response.statusCode == 200) {
...@@ -481,7 +473,7 @@ async function load_map(replyToken) ...@@ -481,7 +473,7 @@ async function load_map(replyToken)
481 "messages": [ 473 "messages": [
482 { 474 {
483 "type": "text", 475 "type": "text",
484 - "text": "지도 : " + map_txt 476 + "text": "지도 : " + map_txt + "\n press any key to stop"
485 } 477 }
486 ] 478 ]
487 } 479 }
...@@ -560,7 +552,7 @@ async function intersection() ...@@ -560,7 +552,7 @@ async function intersection()
560 { 552 {
561 const spawn = await require('child_process').spawn; 553 const spawn = await require('child_process').spawn;
562 for (var i = 0, j = 0; i < 3; i += 2, j++) { 554 for (var i = 0, j = 0; i < 3; i += 2, j++) {
563 - var result = await spawn('python', ['CHATBOT/fileread_practice.py', directory[i][Number(choosen[i]) - 1], directory[i + 1][Number(choosen[i + 1]) - 1], save_file_name[j]]); 555 + var result = await spawn('python', ['/home/ec2-user/menu_recommand_webpage/CHATBOT/fileread_practice.py', directory[i][Number(choosen[i]) - 1], directory[i + 1][Number(choosen[i + 1]) - 1], save_file_name[j]]);
564 await result.stdout.on('data', function (data) { 556 await result.stdout.on('data', function (data) {
565 console.log(data.toString()); 557 console.log(data.toString());
566 }); 558 });
...@@ -568,14 +560,14 @@ async function intersection() ...@@ -568,14 +560,14 @@ async function intersection()
568 console.log(data.toString()); 560 console.log(data.toString());
569 }); 561 });
570 } 562 }
571 - result = await spawn('python', ['CHATBOT/fileread_practice.py', save_file_name[0], save_file_name[1], save_file_name[2]]); 563 + result = await spawn('python', ['/home/ec2-user/menu_recommand_webpage/CHATBOT/fileread_practice.py', save_file_name[0], save_file_name[1], save_file_name[2]]);
572 result.stdout.on('data', function (data) { 564 result.stdout.on('data', function (data) {
573 console.log(data.toString()); 565 console.log(data.toString());
574 }); 566 });
575 await result.stderr.on('data', function (data) { 567 await result.stderr.on('data', function (data) {
576 console.log(data.toString()); 568 console.log(data.toString());
577 }); 569 });
578 - result = await spawn('python', ['CHATBOT/fileread_practice.py', save_file_name[2], directory[4][Number(choosen[4]) - 1], save_file_name[3]]); 570 + result = await spawn('python', ['/home/ec2-user/menu_recommand_webpage/CHATBOT/fileread_practice.py', save_file_name[2], directory[4][Number(choosen[4]) - 1], save_file_name[3]]);
579 result.stdout.on('data', function (data) { 571 result.stdout.on('data', function (data) {
580 console.log(data.toString()); 572 console.log(data.toString());
581 }); 573 });
......