Showing
3 changed files
with
43 additions
and
9 deletions
1 | + | ||
1 | var express = require("express"); | 2 | var express = require("express"); |
2 | var app = express(); | 3 | var app = express(); |
3 | const line = require('@line/bot-sdk'); | 4 | const line = require('@line/bot-sdk'); |
... | @@ -10,7 +11,7 @@ const lex = require('greenlock-express').create({ | ... | @@ -10,7 +11,7 @@ const lex = require('greenlock-express').create({ |
10 | configDir: '/etc/letsencrypt', // 또는 ~/letsencrypt/etc | 11 | configDir: '/etc/letsencrypt', // 또는 ~/letsencrypt/etc |
11 | approveDomains: (opts, certs, cb) => { | 12 | approveDomains: (opts, certs, cb) => { |
12 | if (certs) { | 13 | if (certs) { |
13 | - opts.domains = ['oss.chatbot.bu.to', 'oss.chatbot.bu.to']; | 14 | + opts.domains = ['oss.chatbot.bu.to', 'www.oss.chatbot.bu.to']; |
14 | } else { | 15 | } else { |
15 | opts.email = 'sweun1@naver.com'; | 16 | opts.email = 'sweun1@naver.com'; |
16 | opts.agreeTos = true; | 17 | opts.agreeTos = true; |
... | @@ -45,7 +46,6 @@ const config = { | ... | @@ -45,7 +46,6 @@ const config = { |
45 | channelSecret: '75a2fd95ec26d716cac6fcdd520b9b9c' | 46 | channelSecret: '75a2fd95ec26d716cac6fcdd520b9b9c' |
46 | 47 | ||
47 | }; | 48 | }; |
48 | - | ||
49 | // create LINE SDK client | 49 | // create LINE SDK client |
50 | const client = new line.Client(config); | 50 | const client = new line.Client(config); |
51 | // create Express app | 51 | // create Express app |
... | @@ -53,15 +53,35 @@ const client = new line.Client(config); | ... | @@ -53,15 +53,35 @@ const client = new line.Client(config); |
53 | 53 | ||
54 | // register a webhook handler with middleware | 54 | // register a webhook handler with middleware |
55 | // about the middleware, please refer to doc | 55 | // about the middleware, please refer to doc |
56 | +const vision = require('@google-cloud/vision'); | ||
57 | + | ||
58 | +// Creates a client | ||
59 | +const visionclient = new vision.ImageAnnotatorClient(); | ||
60 | + | ||
61 | +/** | ||
62 | + * TODO(developer): Uncomment the following line before running the sample. | ||
63 | + */ | ||
64 | +// const fileName = 'Local image file, e.g. /path/to/image.png'; | ||
65 | + | ||
66 | +// Performs text detection on the local file | ||
67 | +const [result] = await visionclient.textDetection('/home/ubuntu/a/LINEBOT/photo/Fancy-TWICE.jpg'); | ||
68 | +const detections = result.textAnnotations; | ||
69 | +console.log('Text:'); | ||
70 | +detections.forEach(text => console.log(text)); | ||
71 | + | ||
72 | +//Do query to the api server | ||
73 | +vision.query(d, function(e, r, d){ | ||
74 | +if(e) console.log('ERROR:', e); | ||
75 | + console.log(JSON.stringify(d)); | ||
76 | +}); | ||
77 | + | ||
56 | 78 | ||
57 | 79 | ||
58 | app.post('/webhook', line.middleware(config), (req, res) => { | 80 | app.post('/webhook', line.middleware(config), (req, res) => { |
59 | -console.log(res.statusCode); | ||
60 | Promise | 81 | Promise |
61 | .all(req.body.events.map(handleEvent)) | 82 | .all(req.body.events.map(handleEvent)) |
62 | .then((result) => res.json(result)) | 83 | .then((result) => res.json(result)) |
63 | .catch((err)=>{console.log(err); | 84 | .catch((err)=>{console.log(err); |
64 | - console.log(err.originalError.response) | ||
65 | }) | 85 | }) |
66 | }); | 86 | }); |
67 | // event handler | 87 | // event handler |
... | @@ -79,7 +99,7 @@ function handleEvent(event) { | ... | @@ -79,7 +99,7 @@ function handleEvent(event) { |
79 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} | 99 | headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} |
80 | }; | 100 | }; |
81 | //papago 언어 감지 | 101 | //papago 언어 감지 |
82 | - request.post(detect_options,async (error,response,body)=>{ | 102 | + request.post(detect_options, (error,response,body)=>{ |
83 | if(!error && response.statusCode == 200){ | 103 | if(!error && response.statusCode == 200){ |
84 | var detect_body = JSON.parse(response.body); | 104 | var detect_body = JSON.parse(response.body); |
85 | var source = ''; | 105 | var source = ''; |
... | @@ -99,11 +119,13 @@ function handleEvent(event) { | ... | @@ -99,11 +119,13 @@ function handleEvent(event) { |
99 | url: translate_api_url, | 119 | url: translate_api_url, |
100 | // 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text) | 120 | // 한국어(source : ko), 영어(target: en), 카톡에서 받는 메시지(text) |
101 | form: {'source':source, 'target':target, 'text':event.message.text}, | 121 | form: {'source':source, 'target':target, 'text':event.message.text}, |
102 | - headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret,"Content-Type": "application/x-www-form-urlencoded"} | 122 | + headers: {'X-Naver-Client-Id': client_id, 'X-Naver-Client-Secret': client_secret} |
103 | - }; | ||
104 | 123 | ||
124 | + }; | ||
125 | + | ||
105 | // Naver Post API | 126 | // Naver Post API |
106 | - await request.post(options, function(error, response, body){ | 127 | + console.log("?!"); |
128 | + request.post(options, function(error, response, body){ | ||
107 | // Translate API Sucess | 129 | // Translate API Sucess |
108 | if(!error && response.statusCode == 200){ | 130 | if(!error && response.statusCode == 200){ |
109 | // JSON | 131 | // JSON |
... | @@ -111,12 +133,12 @@ function handleEvent(event) { | ... | @@ -111,12 +133,12 @@ function handleEvent(event) { |
111 | // Message 잘 찍히는지 확인 | 133 | // Message 잘 찍히는지 확인 |
112 | 134 | ||
113 | result.text = objBody.message.result.translatedText; | 135 | result.text = objBody.message.result.translatedText; |
114 | - console.log("source: "+objBody); | ||
115 | console.log("result: "+result.text); | 136 | console.log("result: "+result.text); |
116 | //번역된 문장 보내기 | 137 | //번역된 문장 보내기 |
117 | client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | 138 | client.replyMessage(event.replyToken,result).then(resolve).catch(reject); |
118 | } | 139 | } |
119 | }); | 140 | }); |
141 | + console.log("?!") | ||
120 | } | 142 | } |
121 | // 메시지의 언어가 영어 또는 한국어가 아닐 경우 | 143 | // 메시지의 언어가 영어 또는 한국어가 아닐 경우 |
122 | else{ | 144 | else{ | ... | ... |
googlevisionapikey.json
0 → 100644
1 | +{ | ||
2 | + "type": "service_account", | ||
3 | + "project_id": "glossy-mason-260811", | ||
4 | + "private_key_id": "61512bb3089e561aba7873d91b2a0194f8682af7", | ||
5 | + "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\nN5fVyJbgQW1EjVb94KOpw1VFgIZ1dQJbtPSVShqlESNujr2LQQVGFSjvOzX4D2e+\nG8MLea4OxTQYirlXpxlpWruUDlTn01sn7O55NkIn77SprRSLn24VLoXwprmZWbIM\ntBL1ugFY+v/H3rYS7H9s1lOBW8YbbpleptsZlgoOIQKBgQD7PficsNqm7lP364eq\nKnEmLroBjRW40IvwwBA3lgLq4n/oyLYpG/zu0egYLzdFtVVumSjmzCUdtvnhJFK8\nmaxBcOgpO903nn9YvG1OmftY2YXeTueYS1VE4ixEvEYmf173NXXRXRw/dh5gLqKZ\nAUsQkxSRomAT9aZ7c9PLO4t+KQKBgQD58lvqblQQwX4oKukezTbWcFEYi0j0+tzR\nIiNyDP/r6OiZJqTzYEvi3gA150Y4sAshXSZfk3mVn3SLo1kTZGHptHlqiXmafhoI\nF26wGOPv6EIAfxWw7cRJ0/W63LPJgYzA09SZBt8L0OTFW9habRY+71Q8ZLsO2vE+\nlinYr+i7UQKBgHpA04Lbg+oKuo0+7Mre0CQ2RIiQsGs3/4Bs1PdXZaAKCxeo4wrp\n9Y/4UCnEf+7JqAKjQIXd/ImTCdCGLkRburg1SqMV4DU6SNlTBxViVC4N2tgsKQGw\nVpOoQsZHnxMIk5tTRjtURXST83/18WTmfjJYf3/GNV5BAHu+Bucz2FLRAoGBANSf\n5q9EEcF7SN3UuyGXw2mifGpbusGkUoqZ9vtDscY3CP+Xz0S2i3fAEP/J8YOxxpYo\nTseJhinRTuynFdSYVW7hN1R5BHh3g5+Uh3XIhscElnkjowkzCwMfC/BdZZgq29kB\nmt5e6Ql9N8/odOFf4UfCgq8ppbNab1Ulmw2Zf2sxAoGBAITXJRZ3zDTYAlQXYg45\nSWRINpeS+SVRZGC0UiF1tqCa3b4oAAqyXemIKq0uxJ9eZcEf2lADBecKuQopamcU\nTuppCcGv8Ul6N8vAtMecy28xw+7VxAvyq019iFoJkEjsb/4imXwMYeQ1Zf3GpRvR\nMr6pWRac4gK79EQA50HNshQi\n-----END PRIVATE KEY-----\n", | ||
6 | + "client_email": "image-translation@glossy-mason-260811.iam.gserviceaccount.com", | ||
7 | + "client_id": "103095422514022317942", | ||
8 | + "auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
9 | + "token_uri": "https://oauth2.googleapis.com/token", | ||
10 | + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
11 | + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/image-translation%40glossy-mason-260811.iam.gserviceaccount.com" | ||
12 | +} |
photo/Fancy-TWICE.jpg
0 → 100644
7.73 KB
-
Please register or login to post a comment