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-11 13:06:43 +0000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8467fe024f8178bf8dee99d48c22fd8f09cde0e4
8467fe02
1 parent
0590c1ec
0611 좌표반환 안 됨
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
11 deletions
Experiments/messenger/trans/app.js
Experiments/messenger/trans/app.js
View file @
8467fe0
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
var
express
=
require
(
'express'
);
//express 모듈을 사용
var
qs
=
require
(
'querystring'
)
const
request
=
require
(
'request'
);
//request 모듈을 사용
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
//라인 api
const
TOKEN
=
'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU='
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
MAP_URL
=
'https://naveropenapi.apigw.ntruss.com/map-static/v2/raster?w=300&h=300¢er=127.1054221,37.3591614&level=16&format=jpg'
const
GEO_URL
=
'https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode'
const
MAP_ID
=
'8p40s890zx'
const
MAP_SECRET
=
'twTXrNPSuUYNU4MG7bV9KjXzpTADVDQAlMFK7kAZ'
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
...
...
@@ -13,8 +15,13 @@ const sslport = 23023;
const
bodyParser
=
require
(
'body-parser'
);
var
app
=
express
();
var
target
=
'en'
var
premessage
=
'premessage'
var
start
=
'start'
app
.
use
(
bodyParser
.
json
());
app
.
use
(
express
.
static
(
'statics'
));
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
...
...
@@ -28,25 +35,56 @@ app.post('/hook', function (req, res) {
console
.
log
(
'[request message]'
,
eventObj
.
message
);
trans
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
//trans함수로 번역(reaplyToken과 message.text를 이용)
geo
(
eventObj
.
replyToken
,
eventObj
.
message
.
text
);
res
.
sendStatus
(
200
);
});
function
geo
(
replyToekn
,
message
){
if
(
premessage
!=
'길찾기'
)
{
return
}
start
=
qs
.
escape
(
message
)
const
GEO_URL
=
`https://naveropenapi.apigw.ntruss.com/map-geocode/v2/geocode?query=
${
start
}
`
request
.
get
(
{
url
:
GEO_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'X-NCP-APIGW-API-KEY-ID'
:
`
${
MAP_ID
}
`
,
'X-NCP-APIGW-API-KEY'
:
`
${
MAP_SECRET
}
`
}
},
function
(
error
,
response
,
body
)
{
console
.
log
(
body
)
});
}
function
trans
(
replyToken
,
message
)
{
if
(
message
!=
'길찾기'
)
{
return
}
premessage
=
message
request
.
get
(
{
url
:
PAPAGO
_URL
,
url
:
MAP
_URL
,
headers
:
{
'Content-Type'
:
'application/x-www-form-urlencoded; charset=UTF-8'
,
'X-NCP-APIGW-API-KEY-ID'
:
`
${
PAPAGO
_ID
}
`
,
'X-NCP-APIGW-API-KEY'
:
`
${
PAPAGO
_SECRET
}
`
'X-NCP-APIGW-API-KEY-ID'
:
`
${
MAP
_ID
}
`
,
'X-NCP-APIGW-API-KEY'
:
`
${
MAP
_SECRET
}
`
}
}).
pipe
(
fs
.
createWriteStream
(
'statics/replymap.jpg'
)).
on
(
'close'
,
function
()
{
request
.
post
(
...
...
@@ -86,4 +124,6 @@ try {
console
.
log
(
'[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'
);
console
.
log
(
error
);
}
\ No newline at end of file
\ No newline at end of file
...
...
Please
register
or
login
to post a comment