taegwon

Really Really final app.js

......@@ -9,14 +9,14 @@ var choosen = new Array();
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = '/OxzMlYdmehXwfIxEHS7MSlX470jmkfxfp6kWPMTALlk+hwhqErglwOfMB/cOGVlZCOdMQHSy+Fb48XUJa6C1FHx16wxqcRgRhwGkl6pO5QP65jb8qSmN7/esJvzp2y4ozwkW+Hy+6giAx8pPPMzeQdB04t89/1O/w1cDnyilFU='
const TOKEN = 'TOKEN'
const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
const PAPAGO_ID = 'PAPAGO ID'
const PAPAGO_SECRET = 'PAPAGO SECRET'
const PAPAGO_ID = 'PAPAGOID'
const PAPAGO_SECRET = 'PAPAGOSECRET'
var fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2021105602.osschatbot2022.tk"
const domain = "DOMAIN"
const sslport = 23023;
const bodyParser = require('body-parser');
const res = require('express/lib/response');
......@@ -37,10 +37,15 @@ app.post('/hook', function (req, res) {
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
if (eventObj.message.text == 'start') {
if(eventObj.message.text == 'reset'){
count=0;
selected_food = '';
located = '';
real_data ='';
}else if (eventObj.message.text == 'start') {
count++;
start_msg(eventObj.replyToken, eventObj.message.text);
start_msg(eventObj.replyToken);
}else if((eventObj.message.text === 'y' || eventObj.message.text == 'n' )&& count ==1)
{
if(eventObj.message.text == 'n')
......@@ -130,6 +135,7 @@ app.post('/hook', function (req, res) {
{
located = eventObj.message.text;
load_map(eventObj.replyToken);
cout++;
}else if(count == 11 && end)
{
async function ending () {
......@@ -147,40 +153,26 @@ app.post('/hook', function (req, res) {
res.sendStatus(200);
});
async function start_msg(replyToken, message) {
async function start_msg(replyToken)
{
await request.post(
{
url: PAPAGO_URL,
url: TARGET_URL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
'Authorization': `Bearer ${TOKEN}`
},
body: 'source=en&target=ko&text=' + "Hi! This is Menu recommend Chatbot! If you follow the instructions, I will recommend the menu. 진행하시겠습니까? (y/n)",
json: true
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
console.log(body.message);
var transMessage = body.message.result.translatedText;
request.post(
json: {
"replyToken": replyToken,
"messages": [
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken": replyToken,
"messages": [
{
"type": "text",
"text": transMessage
}
]
}
}, (error, response, body) => {
console.log(body)
});
"type": "text",
"text": "안녕하세요 메뉴 추천 챗봇입니다! 안내에 따라 주시면 제가 메뉴를 추천해 드리겠습니다.\n진행하시겠습니까? (y/n)\n(reset를 입력하면 초기화됩니다.)"
}
]
}
}, (error, response, body) => {
console.log(body)
});
}
......@@ -193,7 +185,7 @@ async function opt_1(replyToken, message) {
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
body: 'source=en&target=ko&text=' + "1.한식 2.중식 3.Japanese food 4.Western food 5.Guitar",
body: 'source=en&target=ko&text=' + "1.한식 2.중식 3.일식 4.양식 5.기타",
json: true
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
......@@ -401,7 +393,7 @@ async function Rmx(replyToken,message) {
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
body: 'source=en&target=ko&text=' + "추천 음식은" + message + "입니다. 음식을 고르시오.",
body: 'source=en&target=ko&text=' + "추천 음식은 " + message + "입니다. 음식을 고르시오.",
json: true
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
......@@ -438,7 +430,7 @@ async function Rmx_1(replyToken,message) {
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
body: 'source=en&target=ko&text=' + "추천음식을 보겠습니까? (y/n)",
body: 'source=en&target=ko&text=' + "추천 음식을 보겠습니까? (y/n)",
json: true
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
......@@ -481,7 +473,7 @@ async function load_map(replyToken)
"messages": [
{
"type": "text",
"text": "지도 : " + map_txt
"text": "지도 : " + map_txt + "\n press any key to stop"
}
]
}
......@@ -560,7 +552,7 @@ async function intersection()
{
const spawn = await require('child_process').spawn;
for (var i = 0, j = 0; i < 3; i += 2, j++) {
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]]);
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]]);
await result.stdout.on('data', function (data) {
console.log(data.toString());
});
......@@ -568,14 +560,14 @@ async function intersection()
console.log(data.toString());
});
}
result = await spawn('python', ['CHATBOT/fileread_practice.py', save_file_name[0], save_file_name[1], save_file_name[2]]);
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]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
await result.stderr.on('data', function (data) {
console.log(data.toString());
});
result = await spawn('python', ['CHATBOT/fileread_practice.py', save_file_name[2], directory[4][Number(choosen[4]) - 1], save_file_name[3]]);
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]]);
result.stdout.on('data', function (data) {
console.log(data.toString());
});
......