EC2 Default User

fix app.js to use fileread.py file

...@@ -3,15 +3,15 @@ var count = 0; ...@@ -3,15 +3,15 @@ var count = 0;
3 var choosen = new Array(); 3 var choosen = new Array();
4 var express = require('express'); 4 var express = require('express');
5 const request = require('request'); 5 const request = require('request');
6 -const TARGET_URL = '타겟 URL' 6 +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
7 -const TOKEN = '토큰' 7 +const TOKEN = 'Ur8nbk2bQAc9KavLSSJv0uzlKWCxCBnOJOKyqbRS1mMHWgJlEOPfb7v+X1DDEHocUmhU7KnPFN+KHt5S3SYd5QmF42aTeQpW2gDVTjyqty1Tn+p6QqEhI/uSz659PBHwczEYn0Plx+akfCNHDPJRpAdB04t89/1O/w1cDnyilFU='
8 -const PAPAGO_URL = '파파고 URL' 8 +const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
9 -const PAPAGO_ID = '파파고 ID' 9 +const PAPAGO_ID = '1Z83W3lUGLqnNbrDAk8A'
10 -const PAPAGO_SECRET = '파파고 시크릿' 10 +const PAPAGO_SECRET = 'ST7ElRPFPP'
11 -const fs = require('fs'); 11 +var fs = require('fs');
12 const path = require('path'); 12 const path = require('path');
13 const HTTPS = require('https'); 13 const HTTPS = require('https');
14 -const domain = "도메인" 14 +const domain = "2021105602.osschatbot2022.tk"
15 const sslport = 23023; 15 const sslport = 23023;
16 const bodyParser = require('body-parser'); 16 const bodyParser = require('body-parser');
17 const res = require('express/lib/response'); 17 const res = require('express/lib/response');
...@@ -35,7 +35,7 @@ app.post('/hook', function (req, res) { ...@@ -35,7 +35,7 @@ app.post('/hook', function (req, res) {
35 35
36 count++; 36 count++;
37 start_msg(eventObj.replyToken, eventObj.message.text); 37 start_msg(eventObj.replyToken, eventObj.message.text);
38 - }else if(eventObj.message.text == 'y' && count ==1) 38 + }else if(eventObj.message.text === 'y' && count ==1)
39 { 39 {
40 opt_1(eventObj.replyToken, eventObj.message.text); 40 opt_1(eventObj.replyToken, eventObj.message.text);
41 }else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3' || eventObj.message.text == '4' || eventObj.message.texts == '5') && count ==1) 41 }else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3' || eventObj.message.text == '4' || eventObj.message.texts == '5') && count ==1)
...@@ -74,9 +74,16 @@ app.post('/hook', function (req, res) { ...@@ -74,9 +74,16 @@ app.post('/hook', function (req, res) {
74 }else{ 74 }else{
75 err(eventObj.replyToken); 75 err(eventObj.replyToken);
76 } 76 }
77 + const spawn = require('child_process').spawn;
78 + const result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', '/home/ec2-user/menu_recommand_webpage-1/CHATBOT/1_person.txt', '/home/ec2-user/menu_recommand_webpage-1/CHATBOT/water.txt']);
79 + result.stdout.on('data', function (data) {
80 + console.log(data.toString());
81 + });
82 + result.stderr.on('data', function (data) {
83 + console.log(data.toString());
84 + });
77 85
78 res.sendStatus(200); 86 res.sendStatus(200);
79 -
80 }); 87 });
81 88
82 async function start_msg(replyToken, message) { 89 async function start_msg(replyToken, message) {
...@@ -358,8 +365,8 @@ async function load_map(replyToken) ...@@ -358,8 +365,8 @@ async function load_map(replyToken)
358 "replyToken": replyToken, 365 "replyToken": replyToken,
359 "messages": [ 366 "messages": [
360 { 367 {
361 - "type": "herf", 368 + "type": "text",
362 - "href": "file:///C:/Users/pnr02/Desktop/opensource_project/selectWestern.html" 369 + "text": "https://www.daleseo.com/js-sleep/"
363 } 370 }
364 ] 371 ]
365 } 372 }
...@@ -390,6 +397,21 @@ async function err(replyToken) ...@@ -390,6 +397,21 @@ async function err(replyToken)
390 }); 397 });
391 } 398 }
392 399
400 +async function read_file(dir, arr)
401 +{
402 + await fs.readFile(dir, function(err, data) {
403 + if(err) throw err;
404 + arr = data.toString().split("\n");
405 + n1=arr;
406 + });
407 +
408 +}
409 +
410 +function sleep(ms) {
411 + const wakeUpTime = Date.now() + ms;
412 + while (Date.now() < wakeUpTime) {}
413 + }
414 +
393 try { 415 try {
394 const option = { 416 const option = {
395 ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'), 417 ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
......