taegwon

fix app.js chatbot message

var end = false;
var count = 0;
n1 = '';
var directory = [['korean_food_final.txt','chinese_food_final.txt','japanese_food_final.txt','western_food_final.txt','ect_food_final.txt'],['meat.txt','fish.txt','ect.txt','\0','\0'],['spicy_food_final.txt','not_spicy_food_final.txt','\0','\0','\0'],['water.txt','dry.txt','\0','\0','\0'],['hot_food_final.txt','cold_food_final.txt','\0','\0','\0']];
var save_file_name = ['fin_1.txt','fin_2.txt','fin_3.txt','fin.txt'];
var choosen = new Array();
var express = require('express');
const request = require('request');
......@@ -37,51 +40,52 @@ app.post('/hook', function (req, res) {
start_msg(eventObj.replyToken, eventObj.message.text);
}else if(eventObj.message.text === 'y' && count ==1)
{
count++;
opt_1(eventObj.replyToken, eventObj.message.text);
}else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3' || eventObj.message.text == '4' || eventObj.message.texts == '5') && count ==1)
}else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3' || eventObj.message.text == '4' || eventObj.message.texts == '5') && count ==2)
{
choosen.push(eventObj.message.text);
count++;
opt_2(eventObj.replyToken, eventObj.message.text);
}else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3') && count ==2)
}else if((eventObj.message.text === '1' || eventObj.message.text === '2' || eventObj.message.text === '3') && count ==3)
{
choosen.push(eventObj.message.text);
count++;
opt_3(eventObj.replyToken, eventObj.message.text);
}else if((eventObj.message.text === '1' || eventObj.message.text === '2') && count ==3)
}else if((eventObj.message.text === '1' || eventObj.message.text === '2') && count ==4)
{
choosen.push(eventObj.message.text);
count++;
opt_4(eventObj.replyToken, eventObj.message.text);
}else if((eventObj.message.text === '1' || eventObj.message.text === '2') && count ==4)
}else if((eventObj.message.text === '1' || eventObj.message.text === '2') && count ==5)
{
choosen.push(eventObj.message.text);
count++;
opt_5(eventObj.replyToken, eventObj.message.text);
}else if((eventObj.message.text === '1' || eventObj.message.text === '2') && count ==5)
}else if((eventObj.message.text === '1' || eventObj.message.text === '2') && count ==6)
{
choosen.push(eventObj.message.text);
count++;
Rmx_comment(eventObj.replyToken);
}else if(count == 6 && end)
}else if(count == 7 && end)
{
Rmx(eventObj.replyToken);
intersection();
read_file('fin.txt')
Rmx(eventObj.replyToken,n1);
count++;
}else if(count ==7 && end && eventObj.message.text == 'y')
}else if(count ==8 && end)
{
}else if(count == 9)
{
load_map(eventObj.replyToken);
count++;
}else{
err(eventObj.replyToken);
}
const spawn = require('child_process').spawn;
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']);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
console.log(data.toString());
});
res.sendStatus(200);
});
......@@ -322,7 +326,7 @@ async function Rmx_comment(replyToken)
"messages": [
{
"type": "text",
"text": "계속하려면 아무키나 입력하시오."
"text": "아무키나 입력해 추천 음식 보기."
}
]
}
......@@ -331,25 +335,40 @@ async function Rmx_comment(replyToken)
});
}
async function Rmx(replyToken)
{
async function Rmx(replyToken,message) {
await request.post(
{
url: TARGET_URL,
url: PAPAGO_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
json: {
"replyToken": replyToken,
"messages": [
body: 'source=en&target=ko&text=' + message,
json: true
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
console.log(body.message);
var transMessage = body.message.result.translatedText;
request.post(
{
"type": "text",
"text": "추천 음식은 ~~~~ 입니다.\n 음식점을 추천 받으시겠습니까? (y/n)"
}
]
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": transMessage
}
]
}
}, (error, response, body) => {
console.log(body)
});
}
}, (error, response, body) => {
console.log(body)
});
}
......@@ -397,16 +416,43 @@ async function err(replyToken)
});
}
async function read_file(dir, arr)
async function read_file(dir)
{
await fs.readFile(dir, function(err, data) {
if(err) throw err;
arr = data.toString().split("\n");
n1=arr;
n1 = data.toString().split("\n");
});
}
async function intersection()
{
const spawn = await require('child_process').spawn;
for (var i = 0, j = 0; i < 3; i += 2, j++) {
const result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', directory[i][Number(choosen[i]) - 1], directory[i + 1][Number(choosen[i + 1]) - 1], save_file_name[j]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
console.log(data.toString());
});
}
result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', save_file_name[0], save_file_name[1], save_file_name[2]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
console.log(data.toString());
});
result = spawn('python', ['/home/ec2-user/menu_recommand_webpage-1/CHATBOT/fileread_practice.py', save_file_name[2], directory[4][Number(choosen[4]) - 1], save_file_name[3]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
result.stderr.on('data', function (data) {
console.log(data.toString());
});
}
function sleep(ms) {
const wakeUpTime = Date.now() + ms;
while (Date.now() < wakeUpTime) {}
......