Toggle navigation
Toggle navigation
This project
Loading...
Sign in
오세헌
/
Ingredient-to-Dish-ChatBot
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-09 13:21:38 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7d42572c2b959046e3fa29529a5e5ff465d54cd9
7d42572c
1 parent
8befe3f7
making output_message function
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
54 deletions
I_to_D_chatbot/reply.js
I_to_D_chatbot/reply.js
View file @
7d42572
...
...
@@ -19,6 +19,36 @@ app.post('/hook', function (req, res) {
var
source
=
eventObj
.
source
;
var
message
=
eventObj
.
message
;
function
output_message
(
results
,
list
)
{
var
num
=
list
[
Math
.
floor
(
Math
.
random
()
*
list
.
length
)];
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`메뉴는 "
${
results
[[
num
]].
menu
}
" 입니다.`
},
{
"type"
:
"text"
,
"text"
:
`필요한 재료는\n\n"
${
results
[[
num
]].
ingrediant
}
"\n\n입니다.`
},
{
"type"
:
"text"
,
"text"
:
`레시피\n\n
${
results
[[
num
]].
recipe
}
`
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
}
// request log
console
.
log
(
'======================'
,
new
Date
(),
'======================'
);
// mwsql
...
...
@@ -56,63 +86,13 @@ app.post('/hook', function (req, res) {
arr2
.
push
(
i
);
}
}
if
(
arr1
.
length
!=
0
)
{
var
num
=
arr1
[
Math
.
floor
(
Math
.
random
()
*
arr1
.
length
)];
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`메뉴는 "
${
results
[[
num
]].
menu
}
" 입니다.`
},
{
"type"
:
"text"
,
"text"
:
`필요한 재료는\n\n"
${
results
[[
num
]].
ingrediant
}
"\n\n입니다.`
},
{
"type"
:
"text"
,
"text"
:
`레시피\n\n
${
results
[[
num
]].
recipe
}
`
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
output_message
(
results
,
arr1
);
}
else
if
(
arr2
.
length
!=
0
)
{
var
num
=
arr2
[
Math
.
floor
(
Math
.
random
()
*
arr2
.
length
)];
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
TOKEN
}
`
},
json
:
{
"replyToken"
:
eventObj
.
replyToken
,
"messages"
:
[
{
"type"
:
"text"
,
"text"
:
`메뉴는 "
${
results
[[
num
]].
menu
}
" 입니다.`
},
{
"type"
:
"text"
,
"text"
:
`필요한 재료는\n\n"
${
results
[[
num
]].
ingrediant
}
"\n\n입니다.`
},
{
"type"
:
"text"
,
"text"
:
`레시피\n\n
${
results
[[
num
]].
recipe
}
`
}
]
}
},
(
error
,
response
,
body
)
=>
{
console
.
log
(
body
)
});
output_message
(
results
,
arr2
);
}
else
{
request
.
post
(
...
...
@@ -134,9 +114,11 @@ app.post('/hook', function (req, res) {
console
.
log
(
body
)
});
}
});
db
.
end
();
res
.
sendStatus
(
200
);
});
...
...
Please
register
or
login
to post a comment