Class CardService

CardService

CardService 让您能够创建用于各种 Google 扩展产品(例如 Google Workspace 插件)的通用卡片。

return CardService.newCardBuilder()
         .setHeader(CardService.newCardHeader().setTitle("CardTitle"))
         .build();

或者,您也可以按如下方式返回多张卡片:

return [
  CardService.newCardBuilder().build(),
  CardService.newCardBuilder().build(),
  CardService.newCardBuilder().build()
]

下面展示了如何定义包含标题、文本、图片和菜单项的卡片:

function createWidgetDemoCard() {
  return CardService
     .newCardBuilder()
     .setHeader(
         CardService.newCardHeader()
             .setTitle('Widget demonstration')
             .setSubtitle('Check out these widgets')
             .setImageStyle(CardService.ImageStyle.SQUARE)
             .setImageUrl(
                 'https://www.example.com/images/headerImage.png'))
     .addSection(
          CardService.newCardSection()
              .setHeader('Simple widgets')  // optional
              .addWidget(CardService.newTextParagraph().setText(
                  'These widgets are display-only. ' +
                  'A text paragraph can have multiple lines and ' +
                  'formatting.'))
              .addWidget(CardService.newImage().setImageUrl(
                  'https://www.example.com/images/mapsImage.png')))
     .addCardAction(CardService.newCardAction().setText('Gmail').setOpenLink(
         CardService.newOpenLink().setUrl('https://mail.google.com/mail')))
     .build();
}

属性

属性类型说明
BorderTypeBorderTypeBorderType 枚举。
ComposedEmailTypeComposedEmailTypeComposedEmailType 枚举。
ContentTypeContentTypeContentType 枚举。
GridItemLayoutGridItemLayoutGridItemLayout 枚举。
HorizontalAlignmentHorizontalAlignmentHorizontalAlignment 枚举。
IconIconIcon 枚举。
ImageCropTypeImageCropTypeImageCropType 枚举。
ImageStyleImageStyleImageStyle 枚举。
LoadIndicatorLoadIndicatorLoadIndicator 枚举。
OnCloseOnCloseOnClose 枚举。
OpenAsOpenAsOpenAs 枚举。
SelectionInputTypeSelectionInputTypeSelectionInputType 枚举。
TextButtonStyleTextButtonStyleTextButtonStyle 枚举。
UpdateDraftBodyTypeUpdateDraftBodyTypeUpdateDraftBodyType 枚举。

方法

方法返回类型简介
newAction()Action创建新的 Action
newActionResponseBuilder()ActionResponseBuilder创建新的 ActionResponseBuilder
newAttachment()Attachment创建新的 Attachment
newAuthorizationAction()AuthorizationAction创建新的 AuthorizationAction
newAuthorizationException()AuthorizationException创建新的 AuthorizationException
newBorderStyle()BorderStyle创建新的 BorderStyle
newButtonSet()ButtonSet创建新的 ButtonSet
newCalendarEventActionResponseBuilder()CalendarEventActionResponseBuilder创建新的 CalendarEventActionResponseBuilder
newCardAction()CardAction创建新的 CardAction
newCardBuilder()CardBuilder创建新的 CardBuilder
newCardHeader()CardHeader创建新的 CardHeader
newCardSection()CardSection创建新的 CardSection
newComposeActionResponseBuilder()ComposeActionResponseBuilder创建新的 ComposeActionResponseBuilder
newDatePicker()DatePicker创建新的 DatePicker
newDateTimePicker()DateTimePicker创建新的 DateTimePicker
newDecoratedText()DecoratedText创建新的 DecoratedText
newDivider()Divider创建新的 Divider
newDriveItemsSelectedActionResponseBuilder()DriveItemsSelectedActionResponseBuilder创建新的 DriveItemsSelectedActionResponseBuilder
newEditorFileScopeActionResponseBuilder()EditorFileScopeActionResponseBuilder创建新的 EditorFileScopeActionResponseBuilder
newFixedFooter()FixedFooter创建新的 FixedFooter
newGrid()Grid创建新的 Grid
newGridItem()GridItem创建新的 GridItem
newIconImage()IconImage创建新的 IconImage
newImage()Image创建新的 Image
newImageButton()ImageButton创建新的 ImageButton
newImageComponent()ImageComponent创建新的 ImageComponent
newImageCropStyle()ImageCropStyle创建新的 ImageCropStyle
newKeyValue()KeyValue创建新的 KeyValue
newNavigation()Navigation创建新的 Navigation
newNotification()Notification创建新的 Notification
newOpenLink()OpenLink创建新的 OpenLink
newSelectionInput()SelectionInput创建新的 SelectionInput
newSuggestions()Suggestions创建新的 Suggestions
newSuggestionsResponseBuilder()SuggestionsResponseBuilder创建新的 SuggestionsResponseBuilder
newSwitch()Switch创建新的 Switch
newTextButton()TextButton创建新的 TextButton
newTextInput()TextInput创建新的 TextInput
newTextParagraph()TextParagraph创建新的 TextParagraph
newTimePicker()TimePicker创建新的 TimePicker
newUniversalActionResponseBuilder()UniversalActionResponseBuilder创建新的 UniversalActionResponseBuilder
newUpdateDraftActionResponseBuilder()UpdateDraftActionResponseBuilder创建新的 UpdateDraftActionResponseBuilder
newUpdateDraftBccRecipientsAction()UpdateDraftBccRecipientsAction创建新的 UpdateDraftBccRecipientsAction
newUpdateDraftBodyAction()UpdateDraftBodyAction创建新的 UpdateDraftBodyAction
newUpdateDraftCcRecipientsAction()UpdateDraftCcRecipientsAction创建新的 UpdateDraftCcRecipientsAction
newUpdateDraftSubjectAction()UpdateDraftSubjectAction创建新的 UpdateDraftSubjectAction
newUpdateDraftToRecipientsAction()UpdateDraftToRecipientsAction创建新的 UpdateDraftToRecipientsAction

详细文档

newAction()

创建新的 Action

返回

Action - 空 Action。


newActionResponseBuilder()

创建新的 ActionResponseBuilder

返回

ActionResponseBuilder - 空 ActionResponse 构建器。


newAttachment()

创建新的 Attachment

返回

Attachment - 附件为空。


newAuthorizationAction()

创建新的 AuthorizationAction

返回

AuthorizationAction - 空的 Action。


newAuthorizationException()

创建新的 AuthorizationException

返回

AuthorizationException - 空 AuthorizationException。


newBorderStyle()

创建新的 BorderStyle

返回

BorderStyle - 空的 BorderStyle。


newButtonSet()

创建新的 ButtonSet

返回

ButtonSet - 空 ButtonSet。


newCalendarEventActionResponseBuilder()


newCardAction()

创建新的 CardAction

返回

CardAction - 空的 CardAction。


newCardBuilder()

创建新的 CardBuilder

返回

CardBuilder - 卡片构建器为空。


newCardHeader()

创建新的 CardHeader

返回

CardHeader - 卡片为空。


newCardSection()

创建新的 CardSection

返回

CardSection - 空 CardSection。


newComposeActionResponseBuilder()

创建新的 ComposeActionResponseBuilder

返回

ComposeActionResponseBuilder - 空 ComposeActionResponse 构建器。


newDatePicker()

创建新的 DatePicker

返回

DatePicker - 日期选择器为空。


newDateTimePicker()

创建新的 DateTimePicker

返回

DateTimePicker - 日期时间选择器为空。


newDecoratedText()

创建新的 DecoratedText

返回

DecoratedText - 空的 DecoratedText。


newDivider()

创建新 Divider。以下示例构建了一个简单的卡片,其中包含 2 个段落,并以分隔线隔开。

function buildCard() {
    let cardSection1TextParagraph1 = CardService.newTextParagraph()
        .setText('Hello world!');

    let cardSection1Divider1 = CardService.newDivider();

    let cardSection1TextParagraph2 = CardService.newTextParagraph()
        .setText('Hello world!');

    let cardSection1 = CardService.newCardSection()
        .addWidget(cardSection1TextParagraph1)
        .addWidget(cardSection1Divider1)
        .addWidget(cardSection1TextParagraph2);

    let card = CardService.newCardBuilder()
        .addSection(cardSection1)
        .build();

   return card;
}

返回

Divider - 分隔线。


newDriveItemsSelectedActionResponseBuilder()


newEditorFileScopeActionResponseBuilder()


newFixedFooter()

创建新的 FixedFooter

返回

FixedFooter - 一个固定的 Footer。


newGrid()

创建新的 Grid

返回

Grid - 空网格。


newGridItem()

创建新的 GridItem

返回

GridItem - 空的 GridItem。


newIconImage()

创建新的 IconImage

返回

IconImage - 空白图标图片。


newImage()

创建新的 Image

返回

Image - 空图片。


newImageButton()

创建新的 ImageButton

返回

ImageButton - 空 ImageButton。


newImageComponent()

创建新的 ImageComponent

返回

ImageComponent - 空 ImageComponent。


newImageCropStyle()

创建新的 ImageCropStyle

返回

ImageCropStyle - 空 ImageCropStyle。


newKeyValue()

创建新的 KeyValue

返回

KeyValue - 空键值对。


newNavigation()

创建新的 Navigation

返回

Navigation - 空 Navigation。


newNotification()

创建新的 Notification

返回

Notification - 空通知。


创建新的 OpenLink

返回

OpenLink - 空 OpenLink。


newSelectionInput()

创建新的 SelectionInput

返回

SelectionInput - 空的 SelectionInput。


newSuggestions()

创建新的 Suggestions

返回

Suggestions - 空建议。


newSuggestionsResponseBuilder()

创建新的 SuggestionsResponseBuilder

返回

SuggestionsResponseBuilder - 空的 SuggestionResponse 构建器。


newSwitch()

创建新的 Switch

返回

Switch - 空的开关。


newTextButton()

创建新的 TextButton

返回

TextButton - 空 TextButton。


newTextInput()

创建新的 TextInput

返回

TextInput - 一个空的 TextInput。


newTextParagraph()

创建新的 TextParagraph

返回

TextParagraph - 空 TextParagraph。


newTimePicker()

创建新的 TimePicker

返回

TimePicker - 空的时间选择器。


newUniversalActionResponseBuilder()

创建新的 UniversalActionResponseBuilder

返回

UniversalActionResponseBuilder - 空的 UniversalActionResponse 构建器。


newUpdateDraftActionResponseBuilder()

创建新的 UpdateDraftActionResponseBuilder

返回

UpdateDraftActionResponseBuilder - 一个 UpdateUpdateActionResponseBuilder 为空。


newUpdateDraftBccRecipientsAction()

创建新的 UpdateDraftBccRecipientsAction

返回

UpdateDraftBccRecipientsAction - 一个空的草稿草稿 BCCRECIPIENTsAction。


newUpdateDraftBodyAction()

创建新的 UpdateDraftBodyAction

返回

UpdateDraftBodyAction - 一个空的 UpdateDraftBodyAction。


newUpdateDraftCcRecipientsAction()

创建新的 UpdateDraftCcRecipientsAction

返回

UpdateDraftCcRecipientsAction - 一个更新草稿草稿为空的 ActionAction。


newUpdateDraftSubjectAction()

创建新的 UpdateDraftSubjectAction

返回

UpdateDraftSubjectAction - 空 UpdateDraftSubjectAction。


newUpdateDraftToRecipientsAction()

创建新的 UpdateDraftToRecipientsAction

返回

UpdateDraftToRecipientsAction - 一个空的草稿草稿收件人。