如何使用Google.Cloud.Dialogflow.V2 Carousel进行对话流制作轮播?

时间:2018-11-14 14:32:13

标签: dialogflow actions-on-google

我试图在nuget包Google.Cloud.Dialogflow.V2的帮助下为dialogflow构建一个Webhook。 我使用.Net Core 2.1运行代码。 我得到了fullfilmentText显示在dialogflow中,但是无法显示旋转木马。 我在做什么错了?

这是我的方法:

  [HttpPost]
  public ContentResult Post([FromBody] WebhookRequest webhookRequest)
  {
      var dialogflowResponse = new WebhookResponse { FulfillmentText = "FulfillmentText" };

      var carousel = new Intent.Types.Message.Types.CarouselSelect.Types.Item
      {
        Title = "My title",
          Description = "This is a description",
          Image = new Intent.Types.Message.Types.Image
          {
              ImageUri = "https://placekitten.com/200/300",
              AccessibilityText = "cat"
          },
          Info = new Intent.Types.Message.Types.SelectItemInfo
          {
              Key = "Cats"
           }
      };

      carousel.Info.Synonyms.Add("Synonym 1");
      carousel.Info.Synonyms.Add("Synonym 1");

      dialogflowResponse.FulfillmentMessages.Add(new Intent.Types.Message {
          CarouselSelect = new Intent.Types.Message.Types.CarouselSelect()
      });

      dialogflowResponse.FulfillmentMessages.First().CarouselSelect.Items.Add(carousel);

      return dialogflowResponse;
    }

产生跟随Json的人

{
    "fulfillmentText": "FulfillmentText",
    "fulfillmentMessages": [
        {
            "carouselSelect": {
                "items": [
                    {
                        "info": {
                            "key": "Cats",
                            "synonyms": [
                                "Synonym 1",
                                "Synonym 1"
                            ]
                        },
                        "title": "My title",
                        "description": "This is a description",
                        "image": {
                            "imageUri": "https://placekitten.com/200/300",
                            "accessibilityText": "cat"
                        }
                    }
                ]
            }
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

我在使用Java api时遇到了同样的问题。只有基本的丰富消息(卡片,快速回复等)有效。基本卡,建议,轮播...都不会出现在任何频道中。

如果我向Skype频道添加了以下一些自定义有效负载,我就可以正常工作

{
"skype": {
    "type": "message",
    "attachmentLayout": "carousel",
    "text": "Please select your food.",
    "attachments": [{
            "contentType": "application/vnd.microsoft.card.hero",
            "content": {
                "title": "Sushi",
                "subtitle": "Very fresh shrimp or tuna.",
                "images": [{
                        "url": "https://i.ibb.co/87LmvT3/mdi.png"
                    }
                ],
                "buttons": [{
                        "type": "imBack",
                        "title": "1 piece",
                        "value": "sushi,1"
                    }, {
                        "type": "imBack",
                        "title": "2 piece",
                        "value": "sushi,2"
                    }, {
                        "type": "imBack",
                        "title": "more",
                        "value": "sushi,3+"
                    }
                ]
            }
        }, {
            "contentType": "application/vnd.microsoft.card.hero",
            "content": {
                "title": "Tenpura",
                "subtitle": "Japanese first-class vegitables.",
                "images": [{
                        "url": "https://i.ibb.co/87LmvT3/mdi.png"
                    }
                ],
                "buttons": [{
                        "type": "imBack",
                        "title": "1 piece",
                        "value": "tenpura,1"
                    }, {
                        "type": "imBack",
                        "title": "2 piece",
                        "value": "tenpura,2"
                    }, {
                        "type": "imBack",
                        "title": "more",
                        "value": "tenpura,3+"
                    }
                ]
            }
        }
    ]
}}

希望对您有帮助!