Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const router = express.Router();
- router.post('/conversation/', (req, res) => {
- const { text, context = {} } = req.body;
- const params = {
- input: { text },
- workspace_id:'Workspace-id',
- context,
- };
- assistant.message(params, (err, response) => {
- if (err) res.status(500).json(err);
- res.json(response);
- });
- });
- module.exports = router;
- /*eslint-env node*/
- 'use strict';
- // This application uses express as its web server
- // for more info, see: http://expressjs.com
- const express = require('express');
- const bodyParser = require('body-parser');
- const path = require('path');
- // cfenv provides access to your Cloud Foundry environment
- // for more info, see: https://www.npmjs.com/package/cfenv
- const cfenv = require('cfenv');
- // create a new express server
- const app = express();
- const AssistantV1 = require('watson-developer-cloud/assistant/v1');
- const assistant = new AssistantV1({
- username: 'username',
- password: 'pass',
- url: 'https://gateway.watsonplatform.net/assistant/api/',
- version: '2018-02-16',
- });
- //Configuring the environment
- //Use body-parser to nodejs understand the user requests
- app.use(bodyParser.urlencoded({extended:false}));
- app.use(bodyParser.json());
- //establish the views directory
- app.set('views',path.join(__dirname,'views')); //__dirname get the main tab project
- //establish the views engine
- app.set('view engine','ejs');
- // serve the files out of ./public as our main files
- app.use(express.static(__dirname + '/public'));
- // get the app environment from Cloud Foundry
- var appEnv = cfenv.getAppEnv();
- //Routes
- app.use('/', require('./routes/index'));
- // start server on the specified port and binding host
- app.listen(appEnv.port, appEnv.bind, () => {
- // print a message when the server starts listening
- console.log("server starting on " + appEnv.url);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement