Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design2
/
2017110273
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
sdy
2021-06-03 13:05:53 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
455f16d7157c7d55ed303816fedbeb31d543d642
455f16d7
1 parent
332b0911
create actions
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
client/src/actions/action_watson.js
client/src/actions/types.js
client/src/actions/action_watson.js
0 → 100644
View file @
455f16d
import
{
INPUT_SUCCESS
,
INPUT_FAIL
,
SESSION_SUCCESS
,
SESSION_FAIL
,
MESSAGE_SUCCESS
,
MESSAGE_FAIL
,
}
from
"./types"
;
import
axios
from
"axios"
;
export
const
userMessage
=
(
message
)
=>
async
(
dispatch
)
=>
{
try
{
dispatch
({
type
:
INPUT_SUCCESS
,
payload
:
message
});
}
catch
(
err
)
{
dispatch
({
type
:
INPUT_FAIL
});
}
};
export
const
createSession
=
()
=>
async
(
dispatch
)
=>
{
try
{
const
res
=
await
axios
.
get
(
"/api/watson/session"
);
dispatch
({
type
:
SESSION_SUCCESS
,
payload
:
res
.
data
});
}
catch
(
err
)
{
dispatch
({
type
:
SESSION_FAIL
});
}
};
export
const
sendMessage
=
(
message
)
=>
async
(
dispatch
)
=>
{
try
{
const
body
=
{
input
:
message
};
const
res
=
await
axios
.
post
(
"/api/watson/message"
,
body
);
// bot message, bot options
console
.
log
(
"res : "
,
res
);
const
generic
=
res
.
data
.
output
.
generic
;
let
botMsg
=
''
,
botOptions
=
[];
generic
.
map
((
e
)
=>
{
if
(
e
.
response_type
===
'text'
)
{
botMsg
=
e
.
text
;
}
else
if
(
e
.
response_type
===
'option'
)
{
botOptions
=
e
.
options
;
}
})
dispatch
({
type
:
MESSAGE_SUCCESS
,
payload
:
generic
,
botMsg
:
botMsg
,
botLabels
:
botOptions
});
}
catch
(
err
)
{
dispatch
({
type
:
MESSAGE_FAIL
});
}
};
client/src/actions/types.js
0 → 100644
View file @
455f16d
export
const
INPUT_SUCCESS
=
"INPUT_SUCCESS"
;
export
const
INPUT_FAIL
=
"INPUT_FAIL"
;
export
const
SESSION_SUCCESS
=
"SESSION_SUCCESS"
;
export
const
SESSION_FAIL
=
"SESSION_FAIL"
;
export
const
MESSAGE_SUCCESS
=
"MESSAGE_SUCCESS"
;
export
const
MESSAGE_FAIL
=
"MESSAGE_FAIL"
;
Please
register
or
login
to post a comment