Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신정아
/
weather_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
1
Network
Create a new issue
Commits
Issue Boards
Authored by
Ubuntu
2020-06-04 07:14:00 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0590c1ec2171b51c86638998b1ba4c9acda949c4
0590c1ec
1 parent
ce129d08
0604 reply naver map
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
42 deletions
Experiments/messenger/trans/app.js
Experiments/messenger/trans/statics/replymap.jpg
Experiments/messenger/trans/app.js
View file @
0590c1e
...
...
@@ -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¢er=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
.
pos
t
(
request
.
ge
t
(
{
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
)
});
});
}
...
...
Experiments/messenger/trans/statics/replymap.jpg
0 → 100644
View file @
0590c1e
18.1 KB
Please
register
or
login
to post a comment