Toggle navigation
Toggle navigation
This project
Loading...
Sign in
은승우
/
LINEBOT
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
은승우
2019-12-03 18:20:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aee89a185a7c0d6ded5d4965708fb23682c0d37f
aee89a18
1 parent
aebd940f
vision api.key
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
9 deletions
app.js
googlevisionapikey.json
photo/Fancy-TWICE.jpg
app.js
View file @
aee89a1
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
{
...
...
googlevisionapikey.json
0 → 100644
View file @
aee89a1
{
"type"
:
"service_account"
,
"project_id"
:
"glossy-mason-260811"
,
"private_key_id"
:
"61512bb3089e561aba7873d91b2a0194f8682af7"
,
"private_key"
:
"-----BEGIN PRIVATE KEY-----
\n
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQD1TSGahm/uwaqk
\n
8vaVmmCuTHU1EvUsLXz4BvoP7n6qYXslcYILp1FFevmbforhpIB5TYOV2DagN1MR
\n
tRCsuOOw9B1D8oY6RX11Y7LKgc6UaSGsDE/3AdT+TdzGyA5KA7hBi9ezGZ8n0pb8
\n
eu8r954q8odRXMWweJK6xOUCS5fsj9wJwlf6uloFmhVL7UI61aUi72I50FDehFtK
\n
HSl9xexIKvGDHzNM6unSKoquy0dLl4x8NdMK/e9iVJiUhY6BHB2K7um/rnnpIVeh
\n
x5KNjKra5c5B1MnS5Gr8D+ehpiaSf12b3o7B1EzMSGY6JmVl0i6T3jbOISr/gPgq
\n
zQ0Yct35AgMBAAECggEAEbR+varA5vx6/ttbgWpKWqJBnnJPGGBzIerM/zvhUBZn
\n
n0j9UC6ELu3kmLzONOGc9URrQDRCIxfDKubE/JZ+tq2z9AzL8+ZCmye2RqgOW0do
\n
SwT7e5JaB33itsVHRL/We4Kmr7JkeqkYRUJxQ1zkwWhObIiz6xwUyR6/gcYngccv
\n
N5fVyJbgQW1EjVb94KOpw1VFgIZ1dQJbtPSVShqlESNujr2LQQVGFSjvOzX4D2e+
\n
G8MLea4OxTQYirlXpxlpWruUDlTn01sn7O55NkIn77SprRSLn24VLoXwprmZWbIM
\n
tBL1ugFY+v/H3rYS7H9s1lOBW8YbbpleptsZlgoOIQKBgQD7PficsNqm7lP364eq
\n
KnEmLroBjRW40IvwwBA3lgLq4n/oyLYpG/zu0egYLzdFtVVumSjmzCUdtvnhJFK8
\n
maxBcOgpO903nn9YvG1OmftY2YXeTueYS1VE4ixEvEYmf173NXXRXRw/dh5gLqKZ
\n
AUsQkxSRomAT9aZ7c9PLO4t+KQKBgQD58lvqblQQwX4oKukezTbWcFEYi0j0+tzR
\n
IiNyDP/r6OiZJqTzYEvi3gA150Y4sAshXSZfk3mVn3SLo1kTZGHptHlqiXmafhoI
\n
F26wGOPv6EIAfxWw7cRJ0/W63LPJgYzA09SZBt8L0OTFW9habRY+71Q8ZLsO2vE+
\n
linYr+i7UQKBgHpA04Lbg+oKuo0+7Mre0CQ2RIiQsGs3/4Bs1PdXZaAKCxeo4wrp
\n
9Y/4UCnEf+7JqAKjQIXd/ImTCdCGLkRburg1SqMV4DU6SNlTBxViVC4N2tgsKQGw
\n
VpOoQsZHnxMIk5tTRjtURXST83/18WTmfjJYf3/GNV5BAHu+Bucz2FLRAoGBANSf
\n
5q9EEcF7SN3UuyGXw2mifGpbusGkUoqZ9vtDscY3CP+Xz0S2i3fAEP/J8YOxxpYo
\n
TseJhinRTuynFdSYVW7hN1R5BHh3g5+Uh3XIhscElnkjowkzCwMfC/BdZZgq29kB
\n
mt5e6Ql9N8/odOFf4UfCgq8ppbNab1Ulmw2Zf2sxAoGBAITXJRZ3zDTYAlQXYg45
\n
SWRINpeS+SVRZGC0UiF1tqCa3b4oAAqyXemIKq0uxJ9eZcEf2lADBecKuQopamcU
\n
TuppCcGv8Ul6N8vAtMecy28xw+7VxAvyq019iFoJkEjsb/4imXwMYeQ1Zf3GpRvR
\n
Mr6pWRac4gK79EQA50HNshQi
\n
-----END PRIVATE KEY-----
\n
"
,
"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"
}
photo/Fancy-TWICE.jpg
0 → 100644
View file @
aee89a1
7.73 KB
Please
register
or
login
to post a comment