问题
I'm using DialogFlow's webhook thing and when I send my JSON response as follows:
{
"fulfillmentText": "This is a text response",
"source": "example.com",
"payload": {
"google": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "this is a simple response"
}
}
]
}
}
}
}
but I get the error MalformedResponse 'final_response' must be set.
after the webserver responds.
回答1:
That JSON response is valid for V2 of the Dialogflow webhook fulfillment protocol. Make sure you've done the following:
Make sure you have the V2 API turned on. Click the settings gear in the upper left and click the V2 API button.
Make sure you have Fulfillment set for the URL for your webhook, and that you have it turned on for the Intent you're testing with.
回答2:
If you have Webhook enabled for your intent,Please make sure you add the line 'WebhookClient.add('This is a sample response') because when Webhooks are enabled for an intent,it expects that the user has set some response inside the webhook intent handler.Also make sure that the add() is not inside any condition statements like if
or while
etc.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({request, response});
function webhookIntent(agent)
{
//All your custom logics.
//Ensure the below line is not inside any conditional statements
agent.add(`You should hear this response without any error!`);
}
}
Or
If you're not using webhooks in your intent,Make sure you have default response set in your intent.
I hope this helps!
来源:https://stackoverflow.com/questions/51004983/malformed-response-final-response-must-be-set