Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박시진
/
mamuri-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-05-27 22:01:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2d3cdf792eb790adb2a4231558c2b04b20b9ff37
2d3cdf79
1 parent
79e5f346
ADD: delete keyword function with line message api
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
15 deletions
server/chatbot/index.js
server/chatbot/index.js
View file @
2d3cdf7
...
...
@@ -46,14 +46,15 @@ const { multiCheckMamul, checkMamul } = require("./checkMamul/checkMamul");
const
client
=
new
line
.
Client
(
config
);
let
waitNewMamulList
=
[];
// 매물 키워드 입력 기다리는 목록
let
waitDeleteMamulList
=
[];
// 매물 삭제 키워드 입력 기다리는 목록
function
handleEvent
(
event
)
{
if
(
event
.
type
!==
"message"
||
event
.
message
.
type
!==
"text"
)
{
console
.
log
(
event
);
if
(
event
.
type
==
"postback"
)
{
if
(
event
.
postback
.
data
==
"newKeyword"
)
{
var
found
=
waitNewMamulList
.
indexOf
(
event
.
source
.
userId
);
if
(
found
==
-
1
)
{
var
found
New
=
waitNewMamulList
.
indexOf
(
event
.
source
.
userId
);
if
(
found
New
==
-
1
)
{
waitNewMamulList
.
push
(
event
.
source
.
userId
);
console
.
log
(
`waitNewMamulList Changed :
${
waitNewMamulList
}
`
);
return
Promise
.
resolve
(
...
...
@@ -75,9 +76,17 @@ function handleEvent(event) {
checkMamul
(
client
,
event
.
source
.
userId
),
);
}
else
if
(
event
.
postback
.
data
==
"deleteKeyword"
)
{
return
Promise
.
resolve
(
console
.
log
(
"키워드 삭제"
)
)
var
foundDelete
=
waitDeleteMamulList
.
indexOf
(
event
.
source
.
userId
);
if
(
foundDelete
==
-
1
)
{
waitDeleteMamulList
.
push
(
event
.
source
.
userId
);
console
.
log
(
`waitDeleteMamulList Changed :
${
waitDeleteMamulList
}
`
);
return
Promise
.
resolve
(
client
.
replyMessage
(
event
.
replyToken
,
{
type
:
"text"
,
text
:
"삭제할 매물 키워드를 알려주세요!"
,
})
);
}
}
else
if
(
event
.
postback
.
data
==
"checkKeywords"
)
{
return
Promise
.
resolve
(
console
.
log
(
"키워드 확인"
)
...
...
@@ -87,17 +96,11 @@ function handleEvent(event) {
return
Promise
.
resolve
(
null
);
}
else
{
console
.
log
(
event
);
var
found
=
waitNewMamulList
.
indexOf
(
event
.
source
.
userId
);
if
(
found
==
-
1
)
{
return
Promise
.
resolve
(
marketMultiSearch
(
event
.
message
.
text
).
then
((
res
)
=>
{
client
.
pushMessage
(
event
.
source
.
userId
,
setCarouselMessage
(
res
));
})
);
}
else
{
var
foundNew
=
waitNewMamulList
.
indexOf
(
event
.
source
.
userId
);
if
(
foundNew
!=
-
1
)
{
// TODO: 서버에 키워드 등록하는 api
waitNewMamulList
.
splice
(
found
,
1
);
console
.
log
(
waitNewMamulList
[
found
]);
waitNewMamulList
.
splice
(
found
New
,
1
);
console
.
log
(
waitNewMamulList
[
found
New
]);
return
Promise
.
resolve
(
db
.
addKeyword
(
event
.
message
.
text
,
event
.
source
.
userId
),
client
.
replyMessage
(
event
.
replyToken
,
{
...
...
@@ -109,6 +112,19 @@ function handleEvent(event) {
})
);
}
var
foundDelete
=
waitDeleteMamulList
.
indexOf
(
event
.
source
.
userId
);
if
(
foundDelete
!=
-
1
)
{
waitDeleteMamulList
.
splice
(
foundDelete
,
1
);
console
.
log
(
waitDeleteMamulList
[
foundDelete
]);
return
Promise
.
resolve
(
db
.
deleteKeyword
(
event
.
source
.
userId
,
event
.
message
.
text
),
client
.
replyMessage
(
event
.
replyToken
,
{
type
:
"text"
,
text
:
`매물이 삭제되었습니다!\n삭제된 매물:
${
event
.
message
.
text
}
`
,
})
)
}
}
}
...
...
Please
register
or
login
to post a comment