在Dialogflow中,我使用免费版(V2)和Firebase的大火计划 . 我有一个Intent,它适用于“test”这个词 . 当我在模拟器中输入“test”时,聊天机器人会给出无响应并离开聊天室 . 假设调用我的API并检索信息 .
奇怪的是,有一个console.log打印出正文并从API返回JSON . 这意味着API调用工作正常,但机器人内部仍然存在错误 .
我发现了这个问题:Dialogflow v2 error “MalformedResponse 'final_response' must be set”
它看起来很像我的问题,但我似乎无法弄清楚我应该改变什么使我的工作 .
在此先感谢您的时间 .
富裕:
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: ');
});
});
}
控制台中的响应:
{
"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\"}"
}
]
}
}
}
控制台中的错误:
MalformedResponse
'final_response' must be set.
1 回答
是的,这是同样的问题 .
问题是你从
callNPApi()
返回一个Promise,但你的事件处理程序(我假设是testcommand()
)也没有返回Promise . 如果您在处理程序中的任何位置进行异步调用,则必须使用Promise,如果使用Promise,则还必须从处理程序返回该Promise .在您的情况下,这应该是一个简单的改变 . 只需在处理程序中添加“return”即可 . 所以它可能看起来像这样