0

I have a QnA bot and a LUIS bot. I would like to make a post request inside my LUIS dialog when the dialog for QnA is triggered to get a response. I have it testing just with the question: Hi which should respond hello.

I am not sure if my port is correct because I got it from another stackoverflow question that is similar so that might be where my error is. I have tried without any port as well.

When I ask questions I get the error: Error: read ECONNRESET

I am running this on Azure Bot Service which I suspect could be a reason for this peticular error.

Here is my code:

var request = require('request');
var http = require('http');

var options = {
  host:'westus.api.cognitive.microsoft.com',
  path:'/qnamaker/v2.0/knowledgebases/<kb-key>/generateAnswer',
  port:443,
  method:'POST',
  headers:{
    'Ocp-Apim-Subscription-Key':<sub-key>,
    'Content-Type':'application/json'
  }
};
//http POST request
var reqPost = http.request(options,function(res){
    res.setEncoding('utf-8');

    var responseString = '';

    res.on('data',function(chunk){
        responseString += chunk;
    });

    res.on('end', function () {
       session.send(responseString); 
    });
});
//LUIS dialog when question is asked. 
bot.dialog('qnaReq', function (session, args) {
    //call QnA Bot and ask that bot the question
    reqPost.write({"question":"hi"}); //Just testing "hi" for now.
    reqPost.end();
    reqPost.on('error',function(e){
        session.send('error: ' + e);
    });
}).triggerAction({
    matches: 'QnA'
});
Brennan Casey
  • 887
  • 2
  • 7
  • 17
  • Is this your complete bot code? If so, it appears that you have not instantiated the `botbuilder` module, and you haven't actually initialized your `bot` object as a UniversalBot and bind it to the connector. – nwxdev Jul 10 '17 at 19:12
  • @NilsW No this is not all my code. botbuilder is imported and everything and normal dialogs work perfectly. I am just having an issue with this specific dialog that has a POST request. I only posted my code that is unique to my application. – Brennan Casey Jul 10 '17 at 19:14
  • Have you tried testing your QnAMaker API call outside the bot application to verify that it's working? Just curious, you appear to have imported the `request` module into your code, but you're not using it to make the API requests. Try using the `request` module instead of `http.request`. – nwxdev Jul 10 '17 at 19:30
  • It was my mistake for including request in my code sample. My code calls another api in a different dialog using that. I am not completely sure how to test the QnAMaker API call outside the application. I don't understand where to put {"question": "hi"} is it a parameter because I tried testing it on hurl.it and I got badArgument as an error so I know im doing something wrong there – Brennan Casey Jul 10 '17 at 19:44
  • @NilsW I have passed {"question" : "hi"} as a body of my POST and got the expected results: {"answers":[{"answer":"hello","questions":["hi","Hello","Hi"],"score":98.814691264718775}]} – Brennan Casey Jul 10 '17 at 19:54
  • Check out this [QnAMaker API Reference](https://westus.dev.cognitive.microsoft.com/docs/services/58994a073d9e04097c7ba6fe/operations/58994a073d9e041ad42d9baa) - It's got code examples in various languages showing how to call the API. – nwxdev Jul 10 '17 at 20:03

0 Answers0