Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express');
- const router = express.Router();
- const http = require('https')
- const config = {
- workspace: 'xxxxxxxxxxxxx',
- username: 'xxxxxxxxxxxxxx',
- password: 'xxxxxxxxxx',
- indentify: '123',
- url: 'https://gateway.watsonplatform.net/conversation/api/v1/workspaces/'
- }
- config.urlMessage = config.url + config.workspace + '/message?version=2017-05-26'
- let options = {
- hostname: 'gateway.watsonplatform.net',
- port: 443,
- path: '/conversation/api/v1/workspaces/' + config.workspace + '/message?version=2017-05-26',
- method: 'POST',
- auth: config.username + ':' + config.password,
- headers: {
- 'Content-Type': 'application/json'
- }
- }
- router.get('/', (req, res, next) => {
- let dados = {
- input: {
- text: req.query.texto
- },
- context: {
- conversation_id: config.indentify,
- system: {
- dialog_stack: [{dialog_node: "root" }],
- dialog_turn_counter: 1,
- dialog_request_counter: 1
- }
- }
- }
- let Retorno = res
- let reqWatson = http.request(options, (res) => {
- console.log('ok')
- res.setEncoding('utf8')
- res.on('data', (chuck) => {
- console.log('Result')
- return Retorno.json(chuck)
- })
- })
- reqWatson.on('error', (err) => {
- console.log('Erro')
- console.log(err)
- })
- reqWatson.write('datan');
- reqWatson.write('datan');
- reqWatson.end();
- });
- module.exports = router;
Add Comment
Please, Sign In to add comment