Toggle navigation
Toggle navigation
This project
Loading...
Sign in
방승일
/
find_mbti_bot
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
공정훈
2022-06-03 23:29:04 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
13e95c15e297c7d26d1031f382061dc52512c173
13e95c15
1 parent
9e11f381
Add search
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
2 deletions
app/app.js
app/app.js
View file @
13e95c1
const
express
=
require
(
'express'
);
const
app
=
express
();
const
bodyParser
=
require
(
'body-parser'
);
const
apiRouter
=
express
.
Router
();
...
...
@@ -12,6 +11,10 @@ app.use(bodyParser.urlencoded({
app
.
use
(
'/api'
,
apiRouter
);
// NAVER SEARCH API
const
CLIENT_ID
=
'fhcqiYQacNyJGILdJBzL'
;
const
CLIENT_SECRET
=
'dmxhW0M_NA'
;
let
userDB
=
new
Array
();
apiRouter
.
post
(
'/sayHello'
,
function
(
req
,
res
)
{
...
...
@@ -883,7 +886,14 @@ apiRouter.post('/result', (req, res) => {
label
:
"자세한 결과 보기"
,
message
:
"자세한 결과 보기"
,
blockId
:
"6297bc58ab89e678ee86b33a"
}]
},
{
action
:
"block"
,
label
:
"내 MBTI 특징은?"
,
message
:
"내 MBTI 특징은?"
,
blockId
:
"6299ef8aab89e678ee86da0d"
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
...
...
@@ -995,6 +1005,56 @@ function count_mbti(item_list, mbti_ch) {
return
result
;
}
apiRouter
.
post
(
'/searchmbti'
,
(
req
,
res
)
=>
{
var
userId
=
req
.
body
.
userRequest
.
user
.
id
;
var
userMbti
=
userDB
[
userId
][
4
];
var
api_url
=
'https://openapi.naver.com/v1/search/blog?query='
+
encodeURI
(
userMbti
+
'특징'
);
var
request
=
require
(
'request'
);
console
.
log
(
api_url
);
var
options
=
{
url
:
api_url
,
headers
:
{
'X-Naver-Client-Id'
:
CLIENT_ID
,
'X-Naver-Client-Secret'
:
CLIENT_SECRET
}
};
request
.
get
(
options
,
function
(
error
,
response
,
body
)
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
var
result
=
JSON
.
parse
(
body
);
console
.
log
(
result
.
items
);
const
responseBody
=
{
version
:
"2.0"
,
template
:
{
outputs
:
[
{
simpleText
:
{
text
:
result
.
items
[
0
].
link
}
}
],
quickReplies
:
[{
action
:
"block"
,
label
:
"MBTI 테스트 다시하기"
,
message
:
"MBTI 테스트 다시하기"
,
blockId
:
"6297b10d5ceed96c38544a06"
},
{
action
:
"block"
,
label
:
"자세한 결과 보기"
,
message
:
"자세한 결과 보기"
,
blockId
:
"6297bc58ab89e678ee86b33a"
}
]
}
}
res
.
status
(
200
).
send
(
responseBody
);
}
else
{
res
.
status
(
response
.
statusCode
).
end
();
console
.
log
(
'error = '
+
response
.
statusCode
);
}
});
});
app
.
listen
((
process
.
env
.
PORT
||
3000
),
function
()
{
console
.
log
(
'Example skill server listening on port 3000!'
);
});
\ No newline at end of file
...
...
Please
register
or
login
to post a comment