Advertisement
Guest User

Untitled

a guest
Jan 15th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. 'use strict';
  2. var express = require('express'),
  3. path = require('path'),
  4. bluemix = require('./config/bluemix'),
  5. extend = require('util')._extend,
  6. watson = require('watson-developer-cloud'),
  7. http = require('http');
  8.  
  9. var appDialog = express();
  10. // Bootstrap application settings
  11. require('./config/express')(appDialog);
  12.  
  13. // if bluemix credentials exists, then override local
  14. var credentials = extend({
  15. url: 'https://gateway.watsonplatform.net/dialog/api',
  16. username: 'username',
  17. password: 'password',
  18. version: 'v1'
  19. }, bluemix.getServiceCreds('dialog')); // VCAP_SERVICES
  20.  
  21. var dialog_id = 'ca487c02-6f47-4b29-bbf3-4024cab0633a';
  22. console.log('the dialog-id:', dialog_id);
  23.  
  24. // Create the service wrappDialoger
  25. var dialog = watson.dialog(credentials);
  26.  
  27. appDialog.post('/conversation', function(req, res, next) {
  28. var params = extend({ dialog_id: dialog_id }, req.body);
  29. dialog.conversation(params, function(err, results) {
  30. if (err)
  31. return next(err);
  32. else
  33. res.json({ dialog_id: dialog_id, conversation: results});
  34. });
  35. });
  36. /////////////////////////////////////////////////////////////////////////
  37. appDialog.post('/profile', function(req, res, next) {
  38. var params = extend({ dialog_id: dialog_id }, req.body);
  39. dialog.getProfile(params, function(err, results) {
  40. if (err)
  41. return next(err);
  42. else
  43. res.json(results);
  44. });
  45. });
  46.  
  47. // error-handler settings
  48. require('./config/error-handler')(appDialog);
  49. // Set the server port
  50. http.createServer(appDialog).listen(process.env.VCAP_APP_PORT || 3000);
  51. /////////////////////////////////////////////////////////////////////////
  52. var appQA = express();
  53.  
  54. appQA.use(express.logger('dev'));
  55. appQA.use(express.bodyParser());
  56. appQA.use(express.methodOverride());
  57. appQA.use(express.static(path.join(__dirname, 'public')));
  58.  
  59. // Development only
  60. if ('development' == appQA.get('env')) {
  61. appQA.use(express.errorHandler());
  62. }
  63. // Expose static web page resources
  64. appQA.use("/", express.static(__dirname + '/public'));
  65.  
  66. // Get access to our Watson module
  67. var watsonInstance = require('./watson/watson');
  68.  
  69. //// Set up RESTful resources
  70. //// POST requests to /question are handled by ‘watson.question’
  71. appQA.post('/question', watsonInstance.question);
  72.  
  73. http.createServer(appQA).listen(process.env.VCAP_APP_PORT || 3001);
  74. /////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement