Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var express = require('express'),
- path = require('path'),
- bluemix = require('./config/bluemix'),
- extend = require('util')._extend,
- watson = require('watson-developer-cloud'),
- http = require('http');
- var appDialog = express();
- // Bootstrap application settings
- require('./config/express')(appDialog);
- // if bluemix credentials exists, then override local
- var credentials = extend({
- url: 'https://gateway.watsonplatform.net/dialog/api',
- username: 'username',
- password: 'password',
- version: 'v1'
- }, bluemix.getServiceCreds('dialog')); // VCAP_SERVICES
- var dialog_id = 'ca487c02-6f47-4b29-bbf3-4024cab0633a';
- console.log('the dialog-id:', dialog_id);
- // Create the service wrappDialoger
- var dialog = watson.dialog(credentials);
- appDialog.post('/conversation', function(req, res, next) {
- var params = extend({ dialog_id: dialog_id }, req.body);
- dialog.conversation(params, function(err, results) {
- if (err)
- return next(err);
- else
- res.json({ dialog_id: dialog_id, conversation: results});
- });
- });
- /////////////////////////////////////////////////////////////////////////
- appDialog.post('/profile', function(req, res, next) {
- var params = extend({ dialog_id: dialog_id }, req.body);
- dialog.getProfile(params, function(err, results) {
- if (err)
- return next(err);
- else
- res.json(results);
- });
- });
- // error-handler settings
- require('./config/error-handler')(appDialog);
- // Set the server port
- http.createServer(appDialog).listen(process.env.VCAP_APP_PORT || 3000);
- /////////////////////////////////////////////////////////////////////////
- var appQA = express();
- appQA.use(express.logger('dev'));
- appQA.use(express.bodyParser());
- appQA.use(express.methodOverride());
- appQA.use(express.static(path.join(__dirname, 'public')));
- // Development only
- if ('development' == appQA.get('env')) {
- appQA.use(express.errorHandler());
- }
- // Expose static web page resources
- appQA.use("/", express.static(__dirname + '/public'));
- // Get access to our Watson module
- var watsonInstance = require('./watson/watson');
- //// Set up RESTful resources
- //// POST requests to /question are handled by ‘watson.question’
- appQA.post('/question', watsonInstance.question);
- http.createServer(appQA).listen(process.env.VCAP_APP_PORT || 3001);
- /////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement