은승우

vision api.key

var express = require("express");
var app = express();
const line = require('@line/bot-sdk');
......@@ -10,7 +11,7 @@ const lex = require('greenlock-express').create({
configDir: '/etc/letsencrypt', // 또는 ~/letsencrypt/etc
approveDomains: (opts, certs, cb) => {
if (certs) {
opts.domains = ['oss.chatbot.bu.to', 'oss.chatbot.bu.to'];
opts.domains = ['oss.chatbot.bu.to', 'www.oss.chatbot.bu.to'];
} else {
opts.email = 'sweun1@naver.com';
opts.agreeTos = true;
......@@ -45,7 +46,6 @@ const config = {
channelSecret: '75a2fd95ec26d716cac6fcdd520b9b9c'
};
// create LINE SDK client
const client = new line.Client(config);
// create Express app
......@@ -53,15 +53,35 @@ const client = new line.Client(config);
// register a webhook handler with middleware
// about the middleware, please refer to doc
const vision = require('@google-cloud/vision');
// Creates a client
const visionclient = new vision.ImageAnnotatorClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const fileName = 'Local image file, e.g. /path/to/image.png';
// Performs text detection on the local file
const [result] = await visionclient.textDetection('/home/ubuntu/a/LINEBOT/photo/Fancy-TWICE.jpg');
const detections = result.textAnnotations;
console.log('Text:');
detections.forEach(text => console.log(text));
//Do query to the api server
vision.query(d, function(e, r, d){
if(e) console.log('ERROR:', e);
console.log(JSON.stringify(d));
});
app.post('/webhook', line.middleware(config), (req, res) => {
console.log(res.statusCode);
Promise
.all(req.body.events.map(handleEvent))
.then((result) => res.json(result))
.catch((err)=>{console.log(err);
console.log(err.originalError.response)
})
});
// event handler
......@@ -79,7 +99,7 @@ function handleEvent(event) {
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret}
};
//papago 언어 감지
request.post(detect_options,async (error,response,body)=>{
request.post(detect_options, (error,response,body)=>{
if(!error && response.statusCode == 200){
var detect_body = JSON.parse(response.body);
var source = '';
......@@ -99,11 +119,13 @@ function handleEvent(event) {
url: translate_api_url,
// 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text)
form: {'source':source, 'target':target, 'text':event.message.text},
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret,"Content-Type": "application/x-www-form-urlencoded"}
};
headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret}
};
// Naver Post API
await request.post(options, function(error, response, body){
console.log("?!");
request.post(options, function(error, response, body){
// Translate API Sucess
if(!error && response.statusCode == 200){
// JSON
......@@ -111,12 +133,12 @@ function handleEvent(event) {
// Message 잘 찍히는지 확인
result.text = objBody.message.result.translatedText;
console.log("source: "+objBody);
console.log("result: "+result.text);
//번역된 문장 보내기
client.replyMessage(event.replyToken,result).then(resolve).catch(reject);
}
});
console.log("?!")
}
// 메시지의 언어가 영어 또는 한국어가 아닐 경우
else{
......
{
"type": "service_account",
"project_id": "glossy-mason-260811",
"private_key_id": "61512bb3089e561aba7873d91b2a0194f8682af7",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD1TSGahm/uwaqk\n8vaVmmCuTHU1EvUsLXz4BvoP7n6qYXslcYILp1FFevmbforhpIB5TYOV2DagN1MR\ntRCsuOOw9B1D8oY6RX11Y7LKgc6UaSGsDE/3AdT+TdzGyA5KA7hBi9ezGZ8n0pb8\neu8r954q8odRXMWweJK6xOUCS5fsj9wJwlf6uloFmhVL7UI61aUi72I50FDehFtK\nHSl9xexIKvGDHzNM6unSKoquy0dLl4x8NdMK/e9iVJiUhY6BHB2K7um/rnnpIVeh\nx5KNjKra5c5B1MnS5Gr8D+ehpiaSf12b3o7B1EzMSGY6JmVl0i6T3jbOISr/gPgq\nzQ0Yct35AgMBAAECggEAEbR+varA5vx6/ttbgWpKWqJBnnJPGGBzIerM/zvhUBZn\nn0j9UC6ELu3kmLzONOGc9URrQDRCIxfDKubE/JZ+tq2z9AzL8+ZCmye2RqgOW0do\nSwT7e5JaB33itsVHRL/We4Kmr7JkeqkYRUJxQ1zkwWhObIiz6xwUyR6/gcYngccv\nN5fVyJbgQW1EjV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client_email": "image-translation@glossy-mason-260811.iam.gserviceaccount.com",
"client_id": "103095422514022317942",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/image-translation%40glossy-mason-260811.iam.gserviceaccount.com"
}