Dialogflow basic card vs card

爷,独闯天下 提交于 2019-12-11 10:47:24

问题


Apologies for the naive question.

In DialogFlow v2 APIs, there are 2 similar RichResponse options. Basic card and card. From the object definitions, it looks almost similar.

Does anyone know when to use one vs the other? When should I use Basic card and When should I use Card?


回答1:


The interfaces of most Google Cloud services are defined in Protobuf messages, which are published in the googleapis repo on Github. You can thus peek directly under the hood of Dialogflow, where you find these two definitions for Card and BasicCard:

// The card response message.
message Card {
  // Optional. Contains information about a button.
  message Button {
    // Optional. The text to show on the button.
    string text = 1;

    // Optional. The text to send back to the Dialogflow API or a URI to
    // open.
    string postback = 2;
  }

  // Optional. The title of the card.
  string title = 1;

  // Optional. The subtitle of the card.
  string subtitle = 2;

  // Optional. The public URI to an image file for the card.
  string image_uri = 3;

  // Optional. The collection of card buttons.
  repeated Button buttons = 4;
}

// The basic card message. Useful for displaying information.
message BasicCard {
  // The button object that appears at the bottom of a card.
  message Button {
    // Opens the given URI.
    message OpenUriAction {
      // Required. The HTTP or HTTPS scheme URI.
      string uri = 1;
    }

    // Required. The title of the button.
    string title = 1;

    // Required. Action to take when a user taps on the button.
    OpenUriAction open_uri_action = 2;
  }

  // Optional. The title of the card.
  string title = 1;

  // Optional. The subtitle of the card.
  string subtitle = 2;

  // Required, unless image is present. The body text of the card.
  string formatted_text = 3;

  // Optional. The image for the card.
  Image image = 4;

  // Optional. The collection of card buttons.
  repeated Button buttons = 5;
}

The only differences seem to be:

  • The buttons on a Card can send a text back to your agent, while on a BasicCard they always open an external URL.
  • A BasicCard can have formatted text instead of an image, although I can't find any information about what kind of formatting they are referring to (HTML? Markdown?).
  • The image of a BasicCard can have an accessibility_text, which is used by certain devices without a screen (e.g. screen readers).

An important difference that is not apparent from the protobufs, but from the Dialogflow documentation is that Card is a generic Rich Message that can be used both on Actions on Google and other integrations such as Facebook Messenger, Twitter, Slack etc. BasicCard is an Actions on Google-specific type that does not work on any other platform.

Unless you really need the formatted text you would probably be better advised to use the more generic Card because it doesn't break when you decide to integrate your agent with another platform. Keep in mind though that each platform has it's own limitations for Rich Messages, so how platform-agnostic your card really is depends on the data you fill it with.



来源:https://stackoverflow.com/questions/51004493/dialogflow-basic-card-vs-card

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