Showing
2 changed files
with
16 additions
and
28 deletions
... | @@ -2,9 +2,9 @@ var express = require('express'); | ... | @@ -2,9 +2,9 @@ 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 = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU=' | 4 | const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU=' |
5 | -const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt' | 5 | +const PAPAGO_URL = 'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?w=300&h=300¢er=127.1054221,37.3591614&level=16&format=jpg' |
6 | -const PAPAGO_ID = 'PA1ukOX3tRrte6BLkI2V' | 6 | +const PAPAGO_ID = '8p40s890zx' |
7 | -const PAPAGO_SECRET = 'AnRP59FJPm' | 7 | +const PAPAGO_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ' |
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'); |
... | @@ -14,6 +14,7 @@ const bodyParser = require('body-parser'); | ... | @@ -14,6 +14,7 @@ const bodyParser = require('body-parser'); |
14 | var app = express(); | 14 | var app = express(); |
15 | var target = 'en' | 15 | var target = 'en' |
16 | app.use(bodyParser.json()); | 16 | app.use(bodyParser.json()); |
17 | +app.use(express.static('statics')); | ||
17 | app.post('/hook', function (req, res) { | 18 | app.post('/hook', function (req, res) { |
18 | 19 | ||
19 | var eventObj = req.body.events[0]; | 20 | var eventObj = req.body.events[0]; |
... | @@ -35,32 +36,19 @@ app.post('/hook', function (req, res) { | ... | @@ -35,32 +36,19 @@ app.post('/hook', function (req, res) { |
35 | 36 | ||
36 | function trans(replyToken, message) { | 37 | function trans(replyToken, message) { |
37 | 38 | ||
38 | - | 39 | + if( message != '길찾기') |
39 | - if(message == '영어'){ | 40 | + { |
40 | - target='en' | ||
41 | - return | ||
42 | - }else if(message == '일본어'){ | ||
43 | - target='ja' | ||
44 | - return | ||
45 | - }else if(message == '프랑스어'){ | ||
46 | - target='fr' | ||
47 | return | 41 | return |
48 | } | 42 | } |
49 | - request.post( | 43 | + request.get( |
50 | { | 44 | { |
51 | url: PAPAGO_URL, | 45 | url: PAPAGO_URL, |
52 | headers: { | 46 | headers: { |
53 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', | 47 | 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', |
54 | - 'X-Naver-Client-Id': `${PAPAGO_ID}`, | 48 | + 'X-NCP-APIGW-API-KEY-ID': `${PAPAGO_ID}`, |
55 | - 'X-Naver-Client-Secret': `${PAPAGO_SECRET}` | 49 | + 'X-NCP-APIGW-API-KEY': `${PAPAGO_SECRET}` |
56 | - }, | 50 | + } |
57 | - body: `source=ko&target=${target}&text=` + message,//source는 한국어, 결과는 영어로 바꿈 | 51 | + }).pipe(fs.createWriteStream('statics/replymap.jpg')).on('close', function() { |
58 | - //=뒤에는 바뀌고 싶은 메세지가 들어감 | ||
59 | - json:true | ||
60 | - },(error, response, body) => { | ||
61 | - if(!error && response.statusCode == 200) { | ||
62 | - console.log(body.message); | ||
63 | - var transMessage = body.message.result.translatedText; | ||
64 | request.post( | 52 | request.post( |
65 | { | 53 | { |
66 | url: TARGET_URL, | 54 | url: TARGET_URL, |
... | @@ -71,15 +59,15 @@ function trans(replyToken, message) { | ... | @@ -71,15 +59,15 @@ function trans(replyToken, message) { |
71 | "replyToken":replyToken, | 59 | "replyToken":replyToken, |
72 | "messages":[ | 60 | "messages":[ |
73 | { | 61 | { |
74 | - "type":"text", | 62 | + "type": "image", |
75 | - "text":transMessage | 63 | + "originalContentUrl": "https://www.osschat.tk:23023/replymap.jpg", |
76 | - } | 64 | + "previewImageUrl": "https://www.osschat.tk:23023/replymap.jpg" |
65 | + }//message | ||
77 | ] | 66 | ] |
78 | - } | 67 | + }//json |
79 | },(error, response, body) => { | 68 | },(error, response, body) => { |
80 | console.log(body) | 69 | console.log(body) |
81 | }); | 70 | }); |
82 | - } | ||
83 | }); | 71 | }); |
84 | 72 | ||
85 | } | 73 | } | ... | ... |
18.1 KB
-
Please register or login to post a comment