必须设置使用 web-fulfillment 和 firebase 抛出 MalformedResponse 'final_response' 的操作
Action using web-fulfillment with firebase throwing MalformedResponse 'final_response' must be set
Env:使用 firebase 云部署 google 操作。
Action 使用 webhook 从函数中获取结果。
我正在使用 Blaze 计划,因此调用外部 URL 应该是合法的。
我正在使用 dialogflow V2.
我的部分职能是执行以下操作:
我使用以下(屏蔽代码详细信息)发出外部 API 请求:
var requestObj = require('request');
var options = {
url: 'my url',
headers: {
'User-Agent': 'request'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
result = JSON.parse(body).element;
console.log('Title 0 ' + result);
}
}
requestObj(options, callback);
得到结果后,我会解析并使用它。
以下是我从堆栈溢出解决方案中尝试的参考点:
感谢社区的任何帮助。
在大多数涉及 MalformedResponse 和使用 request
之类的异步调用的情况下,问题是您在回调之外发送响应。这通常是因为库期待一个 Promise,而你正在以一种非 Promise 的方式处理事情。
我平时的做法是:
- 使用 request-promise library (or the request-promise-native 库)
- 在获得结果的
then
部分之一中,确保调用 conv.ask()
- 确保你return承诺本身。
所以(非常粗略)
var request = require('request-promise-native');
var options = {
uri: 'https://example.com/api',
json: true // Automatically parses the JSON string in the response
};
return request(options)
.then( response => {
// The response will be a JSON object already. Do whatever with it.
var value = response.whatever.you.want;
return conv.ask( `The value is ${value}. What now?` );
});
Env:使用 firebase 云部署 google 操作。 Action 使用 webhook 从函数中获取结果。 我正在使用 Blaze 计划,因此调用外部 URL 应该是合法的。 我正在使用 dialogflow V2.
我的部分职能是执行以下操作: 我使用以下(屏蔽代码详细信息)发出外部 API 请求:
var requestObj = require('request');
var options = {
url: 'my url',
headers: {
'User-Agent': 'request'
}
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
result = JSON.parse(body).element;
console.log('Title 0 ' + result);
}
}
requestObj(options, callback);
得到结果后,我会解析并使用它。
以下是我从堆栈溢出解决方案中尝试的参考点:
感谢社区的任何帮助。
在大多数涉及 MalformedResponse 和使用 request
之类的异步调用的情况下,问题是您在回调之外发送响应。这通常是因为库期待一个 Promise,而你正在以一种非 Promise 的方式处理事情。
我平时的做法是:
- 使用 request-promise library (or the request-promise-native 库)
- 在获得结果的
then
部分之一中,确保调用conv.ask()
- 确保你return承诺本身。
所以(非常粗略)
var request = require('request-promise-native');
var options = {
uri: 'https://example.com/api',
json: true // Automatically parses the JSON string in the response
};
return request(options)
.then( response => {
// The response will be a JSON object already. Do whatever with it.
var value = response.whatever.you.want;
return conv.ask( `The value is ${value}. What now?` );
});