Action using web-fulfillment with firebase throwing MalformedResponse 'final_response' must be set

懵懂的女人 提交于 2019-12-02 04:26:07

In most cases involving the MalformedResponse and an asynchronous call using something like request, the problem is that you're sending the response outside of the callback. Frequently this is because the library is expecting a Promise and you are handling things in a non-promise like way.

My usual practice is:

  • use the request-promise library (or the request-promise-native library)
  • in one of the then sections where you get the results, make sure you call conv.ask()
  • make sure you return the promise itself.

So (very roughly)

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?` );
  });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!