오세헌

organized repo

1 +{
2 + // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
3 + // 기존 특성에 대한 설명을 보려면 가리킵니다.
4 + // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
5 + "version": "0.2.0",
6 + "configurations": [
7 + {
8 + "type": "pwa-node",
9 + "request": "launch",
10 + "name": "Launch Program",
11 + "skipFiles": [
12 + "<node_internals>/**"
13 + ],
14 + "program": "${workspaceFolder}/app.js",
15 + "runtimeExecutable": "${env:HOME}/.nvm/versions/node/v16.15.0/bin/node"
16 + }
17 + ]
18 +}
...\ No newline at end of file ...\ No newline at end of file
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
This diff is collapsed. Click to expand it.
1 +{
2 + "name": "trans",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.17.1",
13 + "request": "^2.88.2"
14 + }
15 +}
1 +{
2 + // IntelliSense를 사용하여 가능한 특성에 대해 알아보세요.
3 + // 기존 특성에 대한 설명을 보려면 가리킵니다.
4 + // 자세한 내용을 보려면 https://go.microsoft.com/fwlink/?linkid=830387을(를) 방문하세요.
5 + "version": "0.2.0",
6 + "configurations": [
7 + {
8 + "type": "pwa-node",
9 + "request": "launch",
10 + "name": "Launch Program",
11 + "skipFiles": [
12 + "<node_internals>/**"
13 + ],
14 + "program": "${workspaceFolder}/app.js",
15 + "runtimeExecutable": "${env:HOME}/.nvm/versions/node/v16.15.0/bin/node"
16 + }
17 + ]
18 +}
...\ No newline at end of file ...\ No newline at end of file
1 +const express = require('express');
2 +const fs = require('fs');
3 +const path = require('path');
4 +const HTTPS = require('https');
5 +
6 +const app = express();
7 +// 본인이 소유한 도메인으로 변경해야 함
8 +// www 붙여야 함
9 +const domain = "2019102197.osschatbot2022.ml"
10 +const sslport = 23023;
11 +
12 +app.get('/', function (req, res) {
13 + res.send('Hello World');
14 +})
15 +
16 +try {
17 + const option = {
18 + ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'),
19 + key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(),
20 + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(),
21 + };
22 +
23 + HTTPS.createServer(option, app).listen(sslport, () => {
24 + console.log(`[HTTPS] Server is started on port ${sslport}`);
25 + });
26 +} catch (error) {
27 + console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.');
28 + console.log(error);
29 +}
30 +
This diff could not be displayed because it is too large.
1 +{
2 + "name": "ssl",
3 + "version": "1.0.0",
4 + "description": "",
5 + "main": "app.js",
6 + "scripts": {
7 + "test": "echo \"Error: no test specified\" && exit 1"
8 + },
9 + "author": "",
10 + "license": "ISC",
11 + "dependencies": {
12 + "express": "^4.17.1",
13 + "npm": "^8.11.0"
14 + }
15 +}