Ubuntu

0604 linechatbot

1 var express = require('express'); 1 var express = require('express');
2 const request = require('request'); 2 const request = require('request');
3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 3 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
4 -const TOKEN = '채널 토큰' 4 +const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU='
5 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' 5 const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
6 -const PAPAGO_ID = '파파고 ID' 6 +const PAPAGO_ID = 'PA1ukOX3tRrte6BLkI2V'
7 -const PAPAGO_SECRET = '파파고 Client Secret' 7 +const PAPAGO_SECRET = 'AnRP59FJPm'
8 const fs = require('fs'); 8 const fs = require('fs');
9 const path = require('path'); 9 const path = require('path');
10 const HTTPS = require('https'); 10 const HTTPS = require('https');
11 -const domain = "도메인 명" 11 +const domain = "www.osschat.tk"
12 const sslport = 23023; 12 const sslport = 23023;
13 const bodyParser = require('body-parser'); 13 const bodyParser = require('body-parser');
14 var app = express(); 14 var app = express();
15 +var target = 'en'
15 app.use(bodyParser.json()); 16 app.use(bodyParser.json());
16 app.post('/hook', function (req, res) { 17 app.post('/hook', function (req, res) {
17 18
...@@ -26,6 +27,7 @@ app.post('/hook', function (req, res) { ...@@ -26,6 +27,7 @@ app.post('/hook', function (req, res) {
26 console.log('[request message]', eventObj.message); 27 console.log('[request message]', eventObj.message);
27 28
28 trans(eventObj.replyToken, eventObj.message.text); 29 trans(eventObj.replyToken, eventObj.message.text);
30 + //trans함수로 번역(reaplyToken과 message.text를 이용)
29 31
30 32
31 res.sendStatus(200); 33 res.sendStatus(200);
...@@ -33,6 +35,17 @@ app.post('/hook', function (req, res) { ...@@ -33,6 +35,17 @@ app.post('/hook', function (req, res) {
33 35
34 function trans(replyToken, message) { 36 function trans(replyToken, message) {
35 37
38 +
39 + if(message == '영어'){
40 + target='en'
41 + return
42 + }else if(message == '일본어'){
43 + target='ja'
44 + return
45 + }else if(message == '프랑스어'){
46 + target='fr'
47 + return
48 + }
36 request.post( 49 request.post(
37 { 50 {
38 url: PAPAGO_URL, 51 url: PAPAGO_URL,
...@@ -41,7 +54,8 @@ function trans(replyToken, message) { ...@@ -41,7 +54,8 @@ function trans(replyToken, message) {
41 'X-Naver-Client-Id': `${PAPAGO_ID}`, 54 'X-Naver-Client-Id': `${PAPAGO_ID}`,
42 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` 55 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
43 }, 56 },
44 - body: 'source=ko&target=en&text=' + message, 57 + body: `source=ko&target=${target}&text=` + message,//source는 한국어, 결과는 영어로 바꿈
58 + //=뒤에는 바뀌고 싶은 메세지가 들어감
45 json:true 59 json:true
46 },(error, response, body) => { 60 },(error, response, body) => {
47 if(!error && response.statusCode == 200) { 61 if(!error && response.statusCode == 200) {
......
...@@ -57,6 +57,14 @@ ...@@ -57,6 +57,14 @@
57 "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz", 57 "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.9.1.tgz",
58 "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" 58 "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug=="
59 }, 59 },
60 + "axios": {
61 + "version": "0.19.2",
62 + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
63 + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
64 + "requires": {
65 + "follow-redirects": "1.5.10"
66 + }
67 + },
60 "bcrypt-pbkdf": { 68 "bcrypt-pbkdf": {
61 "version": "1.0.2", 69 "version": "1.0.2",
62 "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", 70 "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
...@@ -259,6 +267,24 @@ ...@@ -259,6 +267,24 @@
259 "unpipe": "~1.0.0" 267 "unpipe": "~1.0.0"
260 } 268 }
261 }, 269 },
270 + "follow-redirects": {
271 + "version": "1.5.10",
272 + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
273 + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
274 + "requires": {
275 + "debug": "=3.1.0"
276 + },
277 + "dependencies": {
278 + "debug": {
279 + "version": "3.1.0",
280 + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
281 + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
282 + "requires": {
283 + "ms": "2.0.0"
284 + }
285 + }
286 + }
287 + },
262 "forever-agent": { 288 "forever-agent": {
263 "version": "0.6.1", 289 "version": "0.6.1",
264 "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", 290 "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
9 "author": "", 9 "author": "",
10 "license": "ISC", 10 "license": "ISC",
11 "dependencies": { 11 "dependencies": {
12 + "axios": "^0.19.2",
12 "express": "^4.17.1", 13 "express": "^4.17.1",
13 "request": "^2.88.2" 14 "request": "^2.88.2"
14 } 15 }
......