Ubuntu

0604 reply naver map

......@@ -2,9 +2,9 @@ var express = require('express');
const request = require('request');
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU='
const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
const PAPAGO_ID = 'PA1ukOX3tRrte6BLkI2V'
const PAPAGO_SECRET = 'AnRP59FJPm'
const PAPAGO_URL = 'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?w=300&h=300&center=127.1054221,37.3591614&level=16&format=jpg'
const PAPAGO_ID = '8p40s890zx'
const PAPAGO_SECRET = 'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ'
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
......@@ -14,6 +14,7 @@ const bodyParser = require('body-parser');
var app = express();
var target = 'en'
app.use(bodyParser.json());
app.use(express.static('statics'));
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
......@@ -35,51 +36,38 @@ app.post('/hook', function (req, res) {
function trans(replyToken, message) {
if(message == '영어'){
target='en'
return
}else if(message == '일본어'){
target='ja'
return
}else if(message == '프랑스어'){
target='fr'
return
if( message != '길찾기')
{
return
}
request.post(
request.get(
{
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=${target}&text=` + message,//source는 한국어, 결과는 영어로 바꿈
//=뒤에는 바뀌고 싶은 메세지가 들어감
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)
});
'X-NCP-APIGW-API-KEY-ID': `${PAPAGO_ID}`,
'X-NCP-APIGW-API-KEY': `${PAPAGO_SECRET}`
}
}).pipe(fs.createWriteStream('statics/replymap.jpg')).on('close', function() {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type": "image",
"originalContentUrl": "https://www.osschat.tk:23023/replymap.jpg",
"previewImageUrl": "https://www.osschat.tk:23023/replymap.jpg"
}//message
]
}//json
},(error, response, body) => {
console.log(body)
});
});
}
......