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-17 20:48:01 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
65b0091e4fdad32ac4d663868ad572fe78bb8431
65b0091e
1 parent
d0bf2097
EDIT : text message
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
33 deletions
I_to_D_chatbot/reply.js
I_to_D_chatbot/reply.js
View file @
65b0091
var
express
=
require
(
'express'
);
const
request
=
require
(
'request'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
const
TOKEN
=
'
zVAczqoJ+L9oykqhEj7HoP7f6Nyb+R3T1TntHXQhYihI+KIxH4SZDGpKu0jKsMXMHKBVXpmbybA+oaV8u/dfLppKe3NHXU9AdBVypy9NgfWiFPLlcwm3GdkVPAZGoS4nvOCXWDKUb+ixPKWjlbnChAdB04t89/1O/w1cDnyilFU=
'
const
TOKEN
=
''
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
...
...
@@ -13,35 +13,7 @@ app.use(bodyParser.json());
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
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
...
...
@@ -49,7 +21,7 @@ app.post('/hook', function (req, res) {
var
db
=
mysql
.
createConnection
({
host
:
'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com'
,
user
:
'chatbot'
,
password
:
'
11111111
'
,
password
:
''
,
database
:
'chatbot'
,
port
:
'3306'
});
...
...
@@ -77,11 +49,91 @@ app.post('/hook', function (req, res) {
arr2
.
push
(
i
);
}
}
if
(
arr1
.
length
!=
0
)
{
output_message
(
results
,
arr1
);
for
(
var
k
=
0
;
k
<
arr1
.
length
;
k
++
)
{
var
issamevalue
=
false
;
var
ingredients_list
=
results
[
arr1
[
k
]].
ingrediant
.
split
(
","
);
for
(
var
i
=
0
;
i
<
ingredients_list
.
length
;
i
++
)
{
const
currelm
=
ingredients_list
[
i
];
for
(
var
j
=
i
+
1
;
j
<
ingredients_list
.
length
;
j
++
)
{
if
(
currelm
===
ingredients_list
[
j
])
{
issamevalue
=
true
;
break
;
}
}
if
(
issamevalue
)
{
arr2
.
push
(
arr1
[
k
]);
arr1
.
splice
(
k
,
1
);
k
--
;
break
;
}
}
}
}
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
)
});
}
else
if
(
arr2
!=
undefined
)
{
output_message
(
results
,
arr2
);
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"
:
`입력하신 재료를 모두 포함하는 레시피를 찾지 못하였습니다.\n\n입력하신 재료를 최대한 많이 포함하는 레시피를 보여드리겠습니다.`
},
{
"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
)
});
}
else
{
request
.
post
(
...
...
Please
register
or
login
to post a comment