박찬수

folder commit

# 즐겨찾는 팀을 기반으로 한 축구경기 추천 챗봇
<!--Table of Contents-->
## Table of Contents
1. About the Project
2. Getting Started (Installation)
3. Usage
4. Roadmap
5. Contributing
6. License
7. Contact
<p align="right">(<a href="#top">back to top</a>)</p>
<!--About The Project-->
## About The Project
- 본 프로젝트에서는 사용자가 응원하는 축구팀을 즐겨찾기로 추가하여 챗봇과의 대화를 통해 축구경기에 대한 정보를 얻을 수 있게 서비스를 제공합니다.
### Built With
- [Node.js](https://nodejs.org/ko/)
<p align="right">(<a href="#top">back to top</a>)</p>
<!--Getting Started (Installation)-->
## Getting Started
### Prerequisites
- npm
```
npm install
```
### Installation
- Messaging API
1. Get a free API Key at <https://developers.line.biz/en/services/messaging-api/>
2. Clone the repo
```
git clone http://khuhub.khu.ac.kr/2018102191/enjoy_soccer.git
```
3.Install NPM packages
```
npm install
```
<p align="right">(<a href="#top">back to top</a>)</p>
<!--Usage-->
## Usage
<p align="right">(<a href="#top">back to top</a>)</p>
<!--Roadmap-->
## Roadmap
<p align="right">(<a href="#top">back to top</a>)</p>
<!--Contributing-->
## Contributing
1. Fork the Project
2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
3. Commit your Changes (git commit -m 'Add some AmazingFeature')
4. Push to the Branch (git push origin feature/AmazingFeature)
5. Open a Pull Request
<p align="right">(<a href="#top">back to top</a>)</p>
<!--License-->
## License
<p align="right">(<a href="#top">back to top</a>)</p>
<!--Contact-->
## Contact
- 박찬수 : suplife0@khu.ac.kr
- 백지원 : wldnjsl2001@khu.ac.kr
- 차가민 : gmcha0323@khu.ac.kr
- Project Link : http://khuhub.khu.ac.kr/2018102191/enjoy_soccer
<p align="right">(<a href="#top">back to top</a>)</p>
\ No newline at end of file
This diff is collapsed. Click to expand it.
{
"name": "reply",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"request": "^2.88.2"
}
}
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
const USER_ID = '사Uc4258407a7677769f74ba184ec036651'
//Single User
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "to": `${USER_ID}`,
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
// Multicast User
request.post(
{
url: MULTI_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"to": [`${USER_ID}`],
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body)
});
// Broadcast
request.post(
{
url: BROAD_TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body)
});
\ No newline at end of file
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' // reply api
const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2018102191.osschatbot2022.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
},
json: {
"replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
"messages":[
{
"type":"text",
"text":"Hello, user"
},
{
"type":"text",
"text":"May I help you?"
}
]
}
},(error, response, body) => {
console.log(body)
});
res.sendStatus(200);
});
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
};
HTTPS.createServer(option, app).listen(sslport, () => {
console.log(`[HTTPS] Server is started on port ${sslport}`);
});
} catch (error) {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}
// const request = require('request');
// const TARGET_URL = 'https://api.line.me/v2/bot/message/push'
// const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast'
// const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast'
// const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
// const USER_ID = '사Uc4258407a7677769f74ba184ec036651'
// var express = require('express');
// const request = require('request');
// const fs = require('fs');
// const path = require('path');
// const HTTPS = require('https');
// const domain = "2018102191.osschatbot2022.tk"
// const sslport = 23023;
// // Reply Script
// const bodyParser = require('body-parser');
// var app = express();
// app.use(bodyParser.json());
// app.post('/hook', function (req, res) {
// var eventObj = req.body.events[0];
// var source = eventObj.source;
// var message = eventObj.message;
// // request log
// console.log('======================', new Date() ,'======================');
// console.log('[request]', req.body);
// console.log('[request source] ', eventObj.source);
// console.log('[request message]', eventObj.message);
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}` // 인증정보 : channel token 값을 통해 인증.
// },
// json: {
// "replyToken":eventObj.replyToken, // reply token : 누구한테 보낼 것인지?를 판별하기 위해!
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
// res.sendStatus(200);
// });
// try {
// const option = {
// ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
// key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
// cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
// };
// HTTPS.createServer(option, app).listen(sslport, () => {
// console.log(`[HTTPS] Server is started on port ${sslport}`);
// });
// } catch (error) {
// console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
// console.log(error);
// }
// // Push Script
// function SinglePush()
// {
// request.post(
// {
// url: TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "to": `${USER_ID}`,
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
// }
// function MultiPush()
// {
// request.post(
// {
// url: MULTI_TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "to": [`${USER_ID}`],
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
// }
// function BroadCast()
// {
// request.post(
// {
// url: BROAD_TARGET_URL,
// headers: {
// 'Authorization': `Bearer ${TOKEN}`
// },
// json: {
// "messages":[
// {
// "type":"text",
// "text":"Hello, user"
// },
// {
// "type":"text",
// "text":"May I help you?"
// }
// ]
// }
// },(error, response, body) => {
// console.log(body)
// });
// }
// // Single User
// // request.post(
// // {
// // url: TARGET_URL,
// // headers: {
// // 'Authorization': `Bearer ${TOKEN}`
// // },
// // json: {
// // "to": `${USER_ID}`,
// // "messages":[
// // {
// // "type":"text",
// // "text":"Hello, user"
// // },
// // {
// // "type":"text",
// // "text":"May I help you?"
// // }
// // ]
// // }
// // },(error, response, body) => {
// // console.log(body)
// // });
// // Multicast User
// // request.post(
// // {
// // url: MULTI_TARGET_URL,
// // headers: {
// // 'Authorization': `Bearer ${TOKEN}`
// // },
// // json: {
// // "to": [`${USER_ID}`],
// // "messages":[
// // {
// // "type":"text",
// // "text":"Hello, user"
// // },
// // {
// // "type":"text",
// // "text":"May I help you?"
// // }
// // ]
// // }
// // },(error, response, body) => {
// // console.log(body)
// // });
// // Broadcast
// // request.post(
// // {
// // url: BROAD_TARGET_URL,
// // headers: {
// // 'Authorization': `Bearer ${TOKEN}`
// // },
// // json: {
// // "messages":[
// // {
// // "type":"text",
// // "text":"Hello, user"
// // },
// // {
// // "type":"text",
// // "text":"May I help you?"
// // }
// // ]
// // }
// // },(error, response, body) => {
// // console.log(body)
// // });
var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'XOyIf8jsoQKq3b1zqxE4wawAoFU2Hz433AO3w8/ye+i6+2KrXpyfFwY0Dk/xhHQLPgtgPTiEP/m4IRW+SlVhdtzfH6c0Lfdw6nJ95QOugHfNWfviAmn5Uojh8LQJeAy21bvaNMCy11f+qgLSRnXmCgdB04t89/1O/w1cDnyilFU='
const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
const PAPAGO_ID = 'UZMyxEhDtcZQ4JNNeohy'
const PAPAGO_SECRET = 'J2yR82NwYK'
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const domain = "2018102191.osschatbot2022.tk"
const sslport = 23023;
const bodyParser = require('body-parser');
var language = "en";
var app = express();
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
var source = eventObj.source;
var message = eventObj.message;
// request log
console.log('======================', new Date() ,'======================');
console.log('[request]', req.body);
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
trans(eventObj.replyToken, eventObj.message.text);
res.sendStatus(200);
});
function trans(replyToken, message) {
console.log(message);
switch(message)
{
case "영어":
language = "en";
console.log("영어로 변경");
return;
break;
case "일본어":
language = "ja";
console.log("일본어로 변경");
return;
break;
case "프랑스어":
language = "fr";
console.log("프랑스어로 변경");
return;
break;
default:
break;
}
request.post(
{
url: PAPAGO_URL,
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'X-Naver-Client-Id': `${PAPAGO_ID}`,
'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
},
body: 'source=ko&target=' + language + '&text=' + message,
json:true
},(error, response, body) => {
if(!error && response.statusCode == 200) {
console.log(body.message);
var transMessage = body.message.result.translatedText;
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text":transMessage
}
]
}
},(error, response, body) => {
console.log(body)
});
}
});
}
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
};
HTTPS.createServer(option, app).listen(sslport, () => {
console.log(`[HTTPS] Server is started on port ${sslport}`);
});
} catch (error) {
console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
console.log(error);
}
\ No newline at end of file