v2beta1实现Webhook使用哪种Json响应格式? [英] What Json response format to use for v2beta1 fulfillment webhook?

查看:116
本文介绍了v2beta1实现Webhook使用哪种Json响应格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Dialogflow控制台中成功测试了代理意图,在该控制台中,实现Webhook会给出以下响应:

I have successfully tested my agent intents in the Dialogflow console where my fulfillment webhook gives responses such as:

{
  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)。

Now I have set Dialogflow V2 API (v2beta1, I think).

我得到一个响应:


Webhook调用失败。错误:无法解析Webhook JSON响应:找不到字段:消息google.cloud.dialogflow.v2beta1.WebhookResponse中的语音。

"Webhook call failed. Error: Failed to parse webhook JSON response: Cannot find field: speech in message google.cloud.dialogflow.v2beta1.WebhookResponse".

我需要使用哪种JSON响应结构/格式?对此的文档还不清楚。有人可以将我指向正确的页面-或在此处进行描述。

What JSON response structure/format do I need to use? The documentation on this is not at all clear. Can someone point me to the correct page - or describe it here.

如果我搜索 dialogflow v2beta1实现json响应格式,那么似乎有一个条目很有希望:对话流WebhookResponse

If I do a search for "dialogflow v2beta1 fulfillment json response format", one entry seems to be promising: Dialog Flow WebhookResponse

但是我似乎找不到对名为语音的字段的任何引用(根据错误消息)。

But I cannot seem to find any reference to the field named "speech" (as per the error message).

推荐答案

我在尝试为我的dialogflow v2 beta设置一个Webhook时遇到了类似的问题。 Google用了数小时的Google搜索来了解该错误。该错误意味着您发送的字段与您可以在填充邮件中传递的可能的消息字段不匹配。

Hi So I was facing a similar problem while trying to setup a webhook for my dialogueflow v2 beta . It took me hours of google search to understand the error. The error means that the field you have sent donot match the possible Message Fields you can pass inside fullfillment messages.

这是我用于webhook的云函数,它非常适合v2。按照下面的链接获取可以作为fulfillmentMessages数组一部分的消息的格式

This is my cloud function that I m using for webhook and it works perfectly for v2. Follow the below link for the format of messages that can be part of the fulfillmentMessages array

履行邮件的邮件格式

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

这篇关于v2beta1实现Webhook使用哪种Json响应格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆