ibm bluemix - Node.js - Combine IBM Watson Discovery and Conversation Services -


i know may seem complicated have spent week , half trying , can not figure out. can point me in right direction. thank much!

i working ibm watson , node.js create conversation bot. have created bot , used 1 of ibm's example programs (conversation-simple) make website interact bot. works. trying use watson's discovery search documents , answer question query response. have discovery working can query , have node.js program query it.

i trying connect two! when conversation ready query discovery move intent called query.

it looks watson gives response , variable of response currenttext. wrong looks is.

  function buildmessagedomelements(newpayload, isuser) {     var textarray = isuser ? newpayload.input.text : newpayload.output.text;     if (object.prototype.tostring.call( textarray ) !== '[object array]') {       textarray = [textarray];     }     var messagearray = [];      textarray.foreach(function(currenttext) {       if (currenttext) {         var messagejson = {           // <div class='segments'>           'tagname': 'div',           'classnames': ['segments'],           'children': [{             // <div class='from-user/from-watson latest'>             'tagname': 'div',             'classnames': [(isuser ? 'from-user' : 'from-watson'), 'latest', ((messagearray.length === 0) ? 'top' : 'sub')],             'children': [{               // <div class='message-inner'>               'tagname': 'div',               'classnames': ['message-inner'],               'children': [{                 // <p>{messagetext}</p>                 'tagname': 'p',                 'text': currenttext               }]             }]           }]         };         messagearray.push(common.builddomelement(messagejson));       }     });      return messagearray;   } 

when goes respond here (or if somewhere else) how can check if intent query , if query watson discovery?

this how query discovery:

url2 = 'fakeurl'  var request = require("request"); var myjson = require("json"); global var body1; function getmybody(url, callback) {   request(   {     url: url,     auth: {'user': 'fakeusername','pass': 'fakepassword'},     json: true   },   function (error, response, body) {     if (error || response.statuscode !== 200) {       return callback(error || {statuscode: response.statuscode});     }     else{       callback(null, json.parse(json.stringify(body.results)));     }   }); }  getmybody(url2, function test8(err, body) {     body1 = body[0];     console.log(body1)   } ); 

this code prints:

{ id: 'a3990d05fee380f8d0e9b99fa87188a7',     score: 1.0697575,     os: { operatingsystem: 'windows 10 professional' },     price: '174.99',     text: 'lenovo thinkcentre m58 business desktop computer, intel core 2 duo 30 ghz processor, 8gb ram, 2tb hard drive, dvd, vga, display port, rj45, windows 10 professional (certified refurbished)',     url: 'https://www.amazon.com/lenovo-thinkcentre-m58-professional-refurbished/dp/b01m4md9c1?subscriptionid=akiajxxnmxu323wlp4sq&tag=creek0a-20&linkcode=xm2&camp=2025&creative=165953&creativeasin=b01m4md9c1',     highlight: { text: [array] } } 

the response user want value of text , value of url.

this whole program ibm https://github.com/watson-developer-cloud/conversation-simple

like example ibm developers: conversation-with-discovery. can follow same logic programming. recommend check out project , video in end of answer.

summary:

you can see in workspace, call discovery 1 action variable inside advanced json (dialog node) called call_discovery.

"action":{"call_discovery: ""},

basically, have 1 intent name out_of_scope, because if user tells doesn't have answer in intents or conditions in conversation, call discovery happen , return 1 object documents according message user.

create 1 context variable inside conversation service:

{   "context": {     "calldiscovery": true   },   "output": {     "text": {       "values": [         "wait response, i'll check out."       ],       "selection_policy": "sequential"     }   } } 

after creates 1 context variable (example: "calldiscovery": true) inside node in chatbot in advanced json call discovery service, need use code identify if arrived @ part need make call discovery. using function updatemessage inside conversation-simple example:

function updatemessage(input, response) {   var calldiscovery ;   if (!response.output) {     response.output = {};      //the context variable calldiscovery   } else if (response.context.calldiscovery === true){       //create 1 new function code       getmybody(url, callback, response); //response parameter send message     } } 

and, in function getmybody (the function returns prints in question[id, text, url, etc]), need send message user, like:

url2 = 'fakeurl'  var request = require("request"); var myjson = require("json"); var body1; function getmybody(url, callback, response) {   request(   {     url: url,     auth: {'user': 'fakeusername','pass': 'fakepassword'},     json: true   },   function (error, response, body) {     if (error || response.statuscode !== 200) {       return callback(error || {statuscode: response.statuscode});     }     else{       callback(null, json.parse(json.stringify(body.results)));     }   }); }  getmybody(url2, function test8(err, body) {     body1 = body[0];     console.log(body1);     var sendmessage = ("i've find results: "+ body1.text + "and can see url: "+ body1.url)// said body1.text , body1.url     response.output.text[0] = sendmessage;     return res.json(response);     });     } 

note: according project conversation-simple, need use response parameter sending message user, then, need set parameter in function calls discovery, , add following code above in function.

  • see official video ibm watson talking project , showing 1 example call discovery service , sends result user.

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -