Guest User

Untitled

a guest
Feb 8th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. const express = require('express');
  2. const router = express.Router();
  3. const http = require('https')
  4.  
  5. const config = {
  6. workspace: 'xxxxxxxxxxxxx',
  7. username: 'xxxxxxxxxxxxxx',
  8. password: 'xxxxxxxxxx',
  9. indentify: '123',
  10. url: 'https://gateway.watsonplatform.net/conversation/api/v1/workspaces/'
  11. }
  12.  
  13. config.urlMessage = config.url + config.workspace + '/message?version=2017-05-26'
  14.  
  15.  
  16. let options = {
  17. hostname: 'gateway.watsonplatform.net',
  18. port: 443,
  19. path: '/conversation/api/v1/workspaces/' + config.workspace + '/message?version=2017-05-26',
  20. method: 'POST',
  21. auth: config.username + ':' + config.password,
  22. headers: {
  23. 'Content-Type': 'application/json'
  24. }
  25. }
  26.  
  27.  
  28. router.get('/', (req, res, next) => {
  29. let dados = {
  30. input: {
  31. text: req.query.texto
  32. },
  33. context: {
  34. conversation_id: config.indentify,
  35. system: {
  36. dialog_stack: [{dialog_node: "root" }],
  37. dialog_turn_counter: 1,
  38. dialog_request_counter: 1
  39. }
  40. }
  41. }
  42.  
  43. let Retorno = res
  44. let reqWatson = http.request(options, (res) => {
  45. console.log('ok')
  46. res.setEncoding('utf8')
  47. res.on('data', (chuck) => {
  48. console.log('Result')
  49. return Retorno.json(chuck)
  50. })
  51. })
  52.  
  53. reqWatson.on('error', (err) => {
  54. console.log('Erro')
  55. console.log(err)
  56. })
  57.  
  58. reqWatson.write('datan');
  59. reqWatson.write('datan');
  60. reqWatson.end();
  61. });
  62.  
  63. module.exports = router;
Add Comment
Please, Sign In to add comment