전언석
1 -var express = require('express');
2 -const request = require('request');
3 -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = 'A3e2T6lFz02I+kWl6BydLTnWCtxcsvioAr6g4FJMgvZyRcxzy+EdJntPO09XKEHOF08Pgg+L9rNEFKEYrhdhRNg5bmiGZdiaTJfp1DaY/uTVMjRU+hRM00OwvaWq4mxYt/GYLEDzrsQ3O8ezd9WbqQdB04t89/1O/w1cDnyilFU='
5 -const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
6 -const PAPAGO_ID = '파파고 ID'
7 -const PAPAGO_SECRET = '파파고 Client Secret'
8 -const fs = require('fs');
9 -const path = require('path');
10 -const HTTPS = require('https');
11 -const domain = "2019102197.osschatbot2022.ml"
12 -const sslport = 23023;
13 -const bodyParser = require('body-parser');
14 -var app = express();
15 -app.use(bodyParser.json());
16 -app.post('/hook', function (req, res) {
17 -
18 - var eventObj = req.body.events[0];
19 - var source = eventObj.source;
20 - var message = eventObj.message;
21 -
22 - // request log
23 - console.log('======================', new Date() ,'======================');
24 - console.log('[request]', req.body);
25 - console.log('[request source] ', eventObj.source);
26 - console.log('[request message]', eventObj.message);
27 -
28 - trans(eventObj.replyToken, eventObj.message.text);
29 -
30 -
31 - res.sendStatus(200);
32 -});
33 -
34 -function trans(replyToken, message) {
35 -
36 - request.post(
37 - {
38 - url: PAPAGO_URL,
39 - headers: {
40 - 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
41 - 'X-Naver-Client-Id': `${PAPAGO_ID}`,
42 - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
43 - },
44 - body: 'source=ko&target=en&text=' + message,
45 - json:true
46 - },(error, response, body) => {
47 - if(!error && response.statusCode == 200) {
48 - console.log(body.message);
49 - var transMessage = body.message.result.translatedText;
50 - request.post(
51 - {
52 - url: TARGET_URL,
53 - headers: {
54 - 'Authorization': `Bearer ${TOKEN}`
55 - },
56 - json: {
57 - "replyToken":replyToken,
58 - "messages":[
59 - {
60 - "type":"text",
61 - "text":transMessage
62 - }
63 - ]
64 - }
65 - },(error, response, body) => {
66 - console.log(body)
67 - });
68 - }
69 - });
70 -
71 -}
72 -
73 -try {
74 - const option = {
75 - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
76 - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
77 - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
78 - };
79 -
80 - HTTPS.createServer(option, app).listen(sslport, () => {
81 - console.log(`[HTTPS] Server is started on port ${sslport}`);
82 - });
83 - } catch (error) {
84 - console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
85 - console.log(error);
86 - }
87 -
...\ No newline at end of file ...\ No newline at end of file
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
18 18
19 --- 19 ---
20 ### 미리보기 20 ### 미리보기
21 +<img src="/images/example1.jpg" height="600px" width="500px">
21 22
22 --- 23 ---
23 ### 설명 24 ### 설명
...@@ -93,11 +94,12 @@ pip3 install pymysql ...@@ -93,11 +94,12 @@ pip3 install pymysql
93 pip3 install beautifulsoup4 94 pip3 install beautifulsoup4
94 ``` 95 ```
95 <br> 96 <br>
97 +
96 --- 98 ---
97 ### 진행정도 99 ### 진행정도
98 - [x] 챗봇을 올릴 aws 서비스 생성 100 - [x] 챗봇을 올릴 aws 서비스 생성
99 - [x] 만개의 레시피 사이트에서 메뉴, 재료, 레시피 크롤링 101 - [x] 만개의 레시피 사이트에서 메뉴, 재료, 레시피 크롤링
100 -- [ ] 생성된 데이터베이스를 이용하는 코드 작성 102 +- [x] 생성된 데이터베이스를 이용하는 코드 작성
101 103
102 --- 104 ---
103 ### 만든사람 105 ### 만든사람
......