Can WebhookResponse send a Basic Card?

社会主义新天地 提交于 2020-08-09 19:32:17

问题


I'm developing an action and I want to return a basic card with information from a fullfilment webhook. I can return plain text with no problem, using WebhookResponse class for preparing the data before sending it. I did also create the basic card using BasicCard class.

I noticed the response the WebhookResponse creates is diferent from the example responses available on google documentation. I was wandering if there's a new version I missed? Or if this isn't at all possible using this class? "Rich responses" are the kind of response I want to return, but I can't figure out where that locks in with the WebhookResponse class.

Here is the code I'm using:

webhookResp = new WebhookResponse
{
    FulfillmentText = @"Fullfilment Phrase. ",
    FulfillmentMessages = 
    { new Intent.Types.Message
        { SimpleResponses = new Intent.Types.Message.Types.SimpleResponses
            { SimpleResponses_ =
                { new Intent.Types.Message.Types.SimpleResponse
                    {
                        DisplayText = @"Text",
                        TextToSpeech = @"The speech",
                        Ssml = $"<speak>The speech</speak>"
                    }
                }
            }
        },
      new Intent.Types.Message
        { BasicCard = new Intent.Types.Message.Types.BasicCard
            {
                Title = @"Card Title",
                Subtitle = @"Card Subtitle",
                FormattedText = @"Card Information",
                Buttons =
                { new Button
                    {
                        Title = @"Url",
                        OpenUriAction = new OpenUriAction
                        {
                            Uri = "url"
                        }
                    }
                }
            }
        }
    },
    Source = "my-app"
};

And the json received by the Assistant:

{
  "fulfillmentText": "Fullfilment Phrase. ",
  "fulfillmentMessages": [
    {
      "messageCase": 7,
      "text": null,
      "image": null,
      "quickReplies": null,
      "card": null,
      "payload": null,
      "simpleResponses": {
        "simpleResponses_": [
          {
            "textToSpeech": "The speech",
            "ssml": "<speak>The speech</speak>",
            "displayText": "Text"
          }
        ]
      },
      "basicCard": null,
      "suggestions": null,
      "linkOutSuggestion": null,
      "listSelect": null,
      "carouselSelect": null,
      "browseCarouselCard": null,
      "tableCard": null,
      "mediaContent": null,
      "platform": 0
    },
    {
      "messageCase": 8,
      "text": null,
      "image": null,
      "quickReplies": null,
      "card": null,
      "payload": null,
      "simpleResponses": null,
      "basicCard": {
        "title": "Card Title",
        "subtitle": "Card Subtitle",
        "formattedText": "Card Information",
        "image": null,
        "buttons": [
          {
            "title": "Url",
            "openUriAction": {
              "uri": "url"
            }
          }
        ]
      },
      "suggestions": null,
      "linkOutSuggestion": null,
      "listSelect": null,
      "carouselSelect": null,
      "browseCarouselCard": null,
      "tableCard": null,
      "mediaContent": null,
      "platform": 0
    }
  ],
  "source": "my-app",
  "payload": null,
  "outputContexts": [],
  "followupEven
  "sessionEntityTypes": []
}

Thank you in advance for trying to help. If any information more needed please say :)

páris


回答1:


The problem is that the Google.Cloud.Dialogflow.V2 package is to use Dialogflow as a client - not to use for Dialogflow fulfillment. So the WebhookResponse is usually created for you based on the response that comes from the server. You're not expected to create it yourself.

To send a response from your webhook, you will need to generate the JSON and return it as the reply from your webhook.

In addition, the BasicCard that Dialogflow refers to is not the same as the Card that is used by Actions on Google. Dialogflow has a generic "Card" that it represents, but it does not translate this into the Actions on Google "Card".



来源:https://stackoverflow.com/questions/63078459/can-webhookresponse-send-a-basic-card

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