我已经在Dialogflow控制台中成功测试了我的代理意图,其中我的履行webhook给出了响应,例如:
{
speech: 'You have 4 items, aaaa, bbbb, cccc, dddd ',
displayText: 'You have 4 items, aaaa, bbbb, cccc, dddd ',
data: {},
contextOut: [],
source: 'xxx:'
}
现在我已经设置了Dialogflow V2 API(我认为是v2beta1)。
我收到回复:
“Webhook调用失败。错误:无法解析webhook JSON响应:无法找到字段:消息中的语音google.cloud.dialogflow.v2beta1.WebhookResponse”。
我需要使用什么JSON响应结构/格式?关于这方面的文件一点也不清楚。有人能指出我正确的页面 - 或在此描述。
如果我搜索“dialogflow v2beta1履行json响应格式”,一个条目似乎很有希望:Dialog Flow WebhookResponse
但我似乎无法找到任何名为“语音”的字段的引用(根据错误消息)。
查看此API的the reference documentation会很有帮助。
{
"fulfillmentText": string,
"fulfillmentMessages": [
{
object(Message)
}
],
"source": string,
"payload": {
object
},
"outputContexts": [
{
object(Context)
}
],
"followupEventInput": {
object(EventInput)
},
}
而不是“演讲”,你可能正在寻找fulfillmentText
。您的响应中的其他字段似乎也不匹配,因此您应该参考上面的参考文档来确定如何重新构建有效负载以匹配所需的API。
嗨所以我在尝试为我的dialogflow v2 beta设置webhook时遇到了类似的问题。我用了几个小时的谷歌搜索才能理解错误。该错误表示您发送的字段不匹配您可以在fullfillment消息中传递的可能消息字段。
这是我用于webhook的云功能,它适用于v2。请按照以下链接获取可以作为fulfillmentMessages数组一部分的消息格式
Message Format for fulfillmentMessages
app.post('/v2/Hello',(req,res)=>{
let response = "This is a sample response from your webhook!";//Default response from the webhook to show it’s working
let responseObj={
"fulfillmentText":response
,"fulfillmentMessages":[
{
"text": {
"text": [
"Hello I m Responding to intent"
]
}
}
]
,"source":""
}
return res.json(responseObj);});
下面的代码适用于v1
app.post('/Hello',(req,res)=>{
let response = 'This is a sample response from your webhook!' //Default response from the webhook to show it’s working
res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
return res.send(JSON.stringify({ "speech": response, "displayText": response}));});
这适用于v1
v2有些事情发生了变化,他们对返回对话框流的格式非常讲究,因为他们接受并将其插入RAW API响应json中。我遇到了这个问题,发现文档here中的模板响应非常有用。
V1
var chat="success response";
response.setHeader('Content-Type','application/json');
response.send(JSON.stringify({"speech":chat,"displayText":chat}));
V2
var chat="success response";
response.setHeader('Content-Type','application/json');
response.send(JSON.stringify({"fulfillmentText":chat}));
演讲----> fulfillmentText
displayText ---> fulfillmentMessages
对话框流响应已从v1更改为v2请参阅Dialog流文档以获取更多详细信息click here