首页 > 解决方案 > Dialogflow基本卡与卡

问题描述

为这个幼稚的问题道歉。

在 DialogFlow v2 API 中,有 2 个类似的 RichResponse 选项。基本卡和卡。从对象定义来看,它看起来几乎相似。

有谁知道何时使用一个与另一个?什么时候应该使用基本卡,什么时候应该使用卡?

标签: dialogflow-es

解决方案


大多数 Google Cloud 服务的接口都在Protobuf消息中定义,这些消息发布在Github 上的googleapis 存储库中。因此,您可以直接查看 Dialogflow 的底层,您可以在其中找到Card和的以下两个定义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;
}

唯一的区别似乎是:

  • Card 上的按钮可以将文本发送回您的代理,而 BasicCard 上的按钮始终打开一个外部 URL。
  • BasicCard 可以有格式化的文本而不是图像,尽管我找不到关于它们所指的格式类型的任何信息(HTML?Markdown?)。
  • BasicCard 的图像可以有一个accessibility_text,供某些没有屏幕的设备(例如屏幕阅读器)使用。

从 protobufs 但从 Dialogflow 文档中看不到的一个重要区别是,它Card是一个通用的富消息,可以在 Actions on Google 和其他集成(如 Facebook Messenger、Twitter、Slack 等)上使用。BasicCard是一个 Actions on Google - 在任何其他平台上都不起作用的特定类型。

除非您真的需要格式化文本,否则最好建议您使用更通用的文本,Card因为当您决定将代理与另一个平台集成时它不会中断。请记住,尽管每个平台都有自己的富消息限制,因此您的卡与平台无关的程度取决于您填写的数据。


推荐阅读