简体   繁体   English

Dialogflow api调用有效,但是chatbot关闭

[英]Dialogflow api call works, but chatbot shuts off

In Dialogflow, i use the free edition (V2) with the blaze plan from Firebase. 在Dialogflow中,我将免费版本(V2)与Firebase的出色计划配合使用。 I have an Intent that works on the word "test". 我有一个意图适用于“测试”一词。 When i enter "test" in the simulator, the chatbot gives an non response and leaves the chat. 当我在模拟器中输入“测试”时,聊天机器人会给出无响应并退出聊天。 It is suppose to make an call to my API and retrieves information. 假设要调用我的API并检索信息。

The weird part is, there is a console.log that prints out the body and that returns the JSON from the API. 奇怪的是,有一个console.log可以打印出主体并从API返回JSON。 So that means the API call works fine, but there is still an error somewhere within the bot. 因此,这意味着API调用可以正常运行,但漫游器内部仍存在错误。

I found this question: Dialogflow v2 error “MalformedResponse 'final_response' must be set” 我发现了这个问题: Dialogflow v2错误“必须设置MalformedResponse'final_response'”

It looks alot like my problem, yet i cant seem to figure out what i should change to make mine work. 它看起来很像我的问题,但我似乎无法弄清楚为使我的工作我应该改变的东西。

Thanks in advance for your time. 在此先感谢您的时间。

The Fulfullment: 成就感:

function testcommand(agent) {
  callNPApi().then((output) => {
    agent.add(output);
  }).catch(() => {
    agent.add("That went wrong!");
  });
}

function callNPApi() {
  return new Promise((resolve, reject) => {
    request2(url, function (error, response2, body){
      //The substring is too ensure it doesnt crash for the character limit yet
      body = body.substring(1,10);
      console.log('Api errors: ' + JSON.stringify(error));
      console.log('Api body: ' + JSON.stringify(body));

      if (error) {
        reject();
      }
      resolve('api call returned: ');
    });
  });
}

The Response in the console: 控制台中的响应:

{
  "responseMetadata": {
    "status": {
      "code": 10,
      "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
      "details": [
        {
          "@type": "type.googleapis.com/google.protobuf.Value",
          "value": "{\"id\":\"bca7bd81-58f1-40e7-a5d5-e36b60986b66\",\"timestamp\":\"2018-09-06T12:45:26.718Z\",\"lang\":\"nl\",\"result\":{},\"alternateResult\":{},\"status\":{\"code\":200,\"errorType\":\"success\"},\"sessionId\":\"ABwppHFav_2zx7FWHNQn7d0uw8B_I06cY91SKfn1eJnVNFa3q_Y6CrE_OAJPV-ajaZXl7o2ZHfdlVAZwXw\"}"
        }
      ]
    }
  }
}

The Error in the console: 控制台中的错误:

MalformedResponse
'final_response' must be set.

Yup, this is the same problem. 是的,这是同样的问题。

The issue is that you're returning a Promise from callNPApi() , but your event handler (which I assume is testcommand() ) isn't also returning a Promise. 问题是您从callNPApi()返回了Promise,但是事件处理程序(我认为是testcommand()也没有返回Promise。 If you are doing async calls anywhere in your handler, you must use a Promise, and if you are using a Promise you must also return that Promise from the handler. 如果要在处理程序中的任何位置进行异步调用,则必须使用Promise,如果使用的是Promise,则还必须从处理程序中返回该Promise。

In your case, this should be a simple change. 就您而言,这应该是一个简单的更改。 Simply add "return" to your handler. 只需在您的处理程序中添加“返回”即可。 So it might look something like this 所以看起来可能像这样

function testcommand(agent) {
  return callNPApi().then((output) => {
    agent.add(output);
  }).catch(() => {
    agent.add("That went wrong!");
  });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM