Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Sign in
Toggle navigation
Menu
Open sidebar
Yuhong Chen
TechVisionariesBackend
Commits
c3ccd617
Commit
c3ccd617
authored
Apr 17, 2019
by
Yuhong
Browse files
good to go
parent
f8464e2c
Changes
1
Show whitespace changes
Inline
Side-by-side
src/router.js
View file @
c3ccd617
/* eslint-disable no-unused-vars,no-shadow */
/* @flow */
import
{
Router
}
from
'
express
'
;
import
logger
from
'
./logger
'
;
// import ConversationV1 from 'watson-developer-cloud';
const
Watson
=
require
(
'
watson-developer-cloud
'
);
const
conversationSDK
=
new
Watson
.
ConversationV1
({
username
:
'
MISSING VALUE
'
,
password
:
'
MISSING VALUE
'
,
workspace
:
'
MISSING VALUE
'
,
version_date
:
'
2017-05-26
'
,
username
:
'
apikey
'
,
password
:
'
PXfrcd6MbcMuQJ-xo8_NeZLfPbq6TpIahFe5n4H4A6M_
'
,
workspace
:
'
af76927c-be93-4c9d-bc8e-b93241818ffa
'
,
version_date
:
'
2019-04-16
'
,
url
:
'
https://gateway-lon.watsonplatform.net/assistant/api/v1/workspaces/af76927c-be93-4c9d-bc8e-b93241818ffa/message
'
,
});
module
.
exports
=
Watson
;
const
express
=
require
(
'
express
'
);
const
bodyParser
=
require
(
'
body-parser
'
);
const
cors
=
require
(
'
cors
'
);
const
app
=
express
();
app
.
use
(
express
.
static
(
'
/public
'
));
app
.
use
(
bodyParser
.
json
());
app
.
use
(
bodyParser
.
urlencoded
({
extended
:
false
}));
logger
.
info
(
conversationSDK
);
const
router
=
new
Router
();
router
.
post
(
'
/conversation
'
,
(
req
,
res
)
=>
{
/*
==========================^^^=========================
ROUTING CODE GOES HERE
==========================vvv=========================
*/
module
.
exports
=
(
app
,
conversationSDK
)
=>
{
router
.
post
(
'
/conversation
'
,
(
req
,
res
)
=>
{
const
{
text
,
context
=
{}
}
=
req
.
body
;
const
params
=
{
input
:
{
text
},
workspace_id
:
'
af76927c-be93-4c9d-bc8e-b93241818ffa
'
,
context
,
};
Watson
.
message
(
params
,
(
err
,
response
)
=>
{
if
(
err
)
res
.
status
(
500
).
json
(
err
);
res
.
json
(
response
);
});
logger
.
info
(
req
);
logger
.
info
(
res
);
});
});
};
export
default
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment