Class CardService

CardService

CardService umożliwia tworzenie ogólnych kart używanych w różnych usługach Google rozszerzalnych, takich jak dodatki do Google Workspace.

Poniżej znajdziesz przykład karty dodatków.

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

Możesz też zwrócić wiele kart, na przykład:

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

Poniżej pokazujemy, jak zdefiniować kartę z nagłówkiem, tekstem, obrazem i pozycją menu:

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();
}

Przykład karty aplikacji do obsługi czatu.

const cardHeader = CardService.newCardHeader()
    .setTitle("Sasha")
    .setSubtitle("Software Engineer")
    .setImageUrl('https://developers.google.com/chat/images/quickstart-app-avatar.png')
    .setImageStyle(CardService.ImageStyle.CIRCLE)
    .setImageAltText("Avatar for Sasha");

const cardSection = CardService.newCardSection()
    .setHeader("Contact Info")
    .setCollapsible(true)
    .setNumUncollapsibleWidgets(1)
    .addWidget(
       CardService.newDecoratedText()
         .setStartIcon(CardService.newIconImage().setIcon(CardService.Icon.EMAIL))
         .setText("sasha@example.com"))
    .addWidget(
       CardService.newDecoratedText()
          .setStartIcon(CardService.newIconImage().setIcon(CardService.Icon.PERSON))
          .setText("<font color=\"#80e27e\">Online</font>"))
    .addWidget(
       CardService.newDecoratedText()
          .setStartIcon(CardService.newIconImage().setIcon(CardService.Icon.PHONE))
          .setText("+1 (555) 555-1234"))
    .addWidget(
       CardService.newButtonSet()
          .addButton(CardService.newTextButton()
           .setText("Share")
           .setOpenLink(CardService.newOpenLink().setUrl("https://example.com/share")))
          .addButton(CardService.newTextButton()
           .setText("Edit")
           .setOnClickAction(
         CardService.newAction().setFunctionName("goToView").setParameters({viewType:"EDIT"}))))

const card = CardService.newCardBuilder()
    .setHeader(cardHeader)
    .addSection(cardSection)
    .build();

Właściwości

WłaściwośćTypOpis
BorderTypeBorderTypeWyliczenie BorderType.
ComposedEmailTypeComposedEmailTypeWyliczenie ComposedEmailType.
ContentTypeContentTypeWyliczenie ContentType.
GridItemLayoutGridItemLayoutWyliczenie GridItemLayout.
HorizontalAlignmentHorizontalAlignmentWyliczenie HorizontalAlignment.
IconIconWyliczenie Icon.
ImageCropTypeImageCropTypeWyliczenie ImageCropType.
ImageStyleImageStyleWyliczenie ImageStyle.
LoadIndicatorLoadIndicatorWyliczenie LoadIndicator.
OnCloseOnCloseWyliczenie OnClose.
OpenAsOpenAsWyliczenie OpenAs.
SelectionInputTypeSelectionInputTypeWyliczenie SelectionInputType.
TextButtonStyleTextButtonStyleWyliczenie TextButtonStyle.
UpdateDraftBodyTypeUpdateDraftBodyTypeWyliczenie UpdateDraftBodyType.

Metody

MetodaTyp zwracanej wartościKrótki opis
newAction()ActionTworzy nowy element: Action.
newActionResponseBuilder()ActionResponseBuilderTworzy nowy element: ActionResponseBuilder.
newActionStatus()ActionStatusTworzy nowy element: ActionStatus.
newAttachment()AttachmentTworzy nowy element: Attachment.
newAuthorizationAction()AuthorizationActionTworzy nowy element: AuthorizationAction.
newAuthorizationException()AuthorizationExceptionTworzy nowy element: AuthorizationException.
newBorderStyle()BorderStyleTworzy nowy element: BorderStyle.
newButtonSet()ButtonSetTworzy nowy element: ButtonSet.
newCalendarEventActionResponseBuilder()CalendarEventActionResponseBuilderTworzy nowy element: CalendarEventActionResponseBuilder.
newCardAction()CardActionTworzy nowy element: CardAction.
newCardBuilder()CardBuilderTworzy nowy element: CardBuilder.
newCardHeader()CardHeaderTworzy nowy element: CardHeader.
newCardSection()CardSectionTworzy nowy element: CardSection.
newCardWithId()CardWithIdTworzy nowy element: CardWithId.
newChatActionResponse()ChatActionResponseTworzy nowy element: ChatActionResponse.
newChatResponseBuilder()ChatResponseBuilderTworzy nowy element: ChatResponseBuilder.
newColumn()ColumnTworzy nowy element: Column.
newColumns()ColumnsTworzy nowy zbiór elementów Columns.
newComposeActionResponseBuilder()ComposeActionResponseBuilderTworzy nowy element: ComposeActionResponseBuilder.
newDatePicker()DatePickerTworzy nowy element: DatePicker.
newDateTimePicker()DateTimePickerTworzy nowy element: DateTimePicker.
newDecoratedText()DecoratedTextTworzy nowy element: DecoratedText.
newDialog()DialogTworzy nowy element: Dialog.
newDialogAction()DialogActionTworzy nowy element: DialogAction.
newDivider()DividerTworzy nowy element: Divider.
newDriveItemsSelectedActionResponseBuilder()DriveItemsSelectedActionResponseBuilderTworzy nowy element: DriveItemsSelectedActionResponseBuilder.
newEditorFileScopeActionResponseBuilder()EditorFileScopeActionResponseBuilderTworzy nowy element: EditorFileScopeActionResponseBuilder.
newFixedFooter()FixedFooterTworzy nowy element: FixedFooter.
newGrid()GridTworzy nowy element: Grid.
newGridItem()GridItemTworzy nowy element: GridItem.
newIconImage()IconImageTworzy nowy element: IconImage.
newImage()ImageTworzy nowy element: Image.
newImageButton()ImageButtonTworzy nowy element: ImageButton.
newImageComponent()ImageComponentTworzy nowy element: ImageComponent.
newImageCropStyle()ImageCropStyleTworzy nowy element: ImageCropStyle.
newKeyValue()KeyValueTworzy nowy element: KeyValue.
newLinkPreview()LinkPreviewTworzy nowy element: LinkPreview.
newNavigation()NavigationTworzy nowy element: Navigation.
newNotification()NotificationTworzy nowy element: Notification.
newOpenLink()OpenLinkTworzy nowy element: OpenLink.
newSelectionInput()SelectionInputTworzy nowy element: SelectionInput.
newSuggestions()SuggestionsTworzy nowy element: Suggestions.
newSuggestionsResponseBuilder()SuggestionsResponseBuilderTworzy nowy element: SuggestionsResponseBuilder.
newSwitch()SwitchTworzy nowy element: Switch.
newTextButton()TextButtonTworzy nowy element: TextButton.
newTextInput()TextInputTworzy nowy element: TextInput.
newTextParagraph()TextParagraphTworzy nowy element: TextParagraph.
newTimePicker()TimePickerTworzy nowy element: TimePicker.
newUniversalActionResponseBuilder()UniversalActionResponseBuilderTworzy nowy element: UniversalActionResponseBuilder.
newUpdateDraftActionResponseBuilder()UpdateDraftActionResponseBuilderTworzy nowy element: UpdateDraftActionResponseBuilder.
newUpdateDraftBccRecipientsAction()UpdateDraftBccRecipientsActionTworzy nowy element: UpdateDraftBccRecipientsAction;
newUpdateDraftBodyAction()UpdateDraftBodyActionTworzy nowy element: UpdateDraftBodyAction.
newUpdateDraftCcRecipientsAction()UpdateDraftCcRecipientsActionTworzy nowy element: UpdateDraftCcRecipientsAction.
newUpdateDraftSubjectAction()UpdateDraftSubjectActionTworzy nowy element: UpdateDraftSubjectAction.
newUpdateDraftToRecipientsAction()UpdateDraftToRecipientsActionTworzy nowy element: UpdateDraftToRecipientsAction.

Szczegółowa dokumentacja

newAction()

Tworzy nowy element: Action.

Powroty

Action – pusta akcja.


newActionResponseBuilder()

Tworzy nowy element: ActionResponseBuilder.

Powroty

ActionResponseBuilder – pusty kreator ActionResponse.


newActionStatus()

Tworzy nowy element: ActionStatus.

Dostępne tylko w aplikacjach Google Chat. Opcja niedostępna w przypadku dodatków do Google Workspace.

const actionStatus = CardService.newActionStatus()
    .setStatusCode(CardService.Status.OK)
    .setUserFacingMessage('Success');

Powroty

ActionStatus – pusty ActionStatus.


newAttachment()

Tworzy nowy element: Attachment.

Powroty

Attachment – pusty załącznik.


newAuthorizationAction()

Tworzy nowy element: AuthorizationAction.

Powroty

AuthorizationAction – pusta wartość AuthorizationAction.


newAuthorizationException()

Tworzy nowy element: AuthorizationException.

Powroty

AuthorizationException – pusty wyjątek AuthorizationException.


newBorderStyle()

Tworzy nowy element: BorderStyle.

Powroty

BorderStyle – pusty styl obramowania.


newButtonSet()

Tworzy nowy element: ButtonSet.

Powroty

ButtonSet – pusty zestaw przycisków.


newCalendarEventActionResponseBuilder()


newCardAction()

Tworzy nowy element: CardAction.

Powroty

CardAction – pusta wartość CardAction.


newCardBuilder()

Tworzy nowy element: CardBuilder.

Powroty

CardBuilder – pusty kreator kart.


newCardHeader()

Tworzy nowy element: CardHeader.

Powroty

CardHeader – pusty nagłówek CardHeader.


newCardSection()

Tworzy nowy element: CardSection.

Powroty

CardSection – pusta sekcja karty.


newCardWithId()

Tworzy nowy element: CardWithId. Służy do wysyłania karty w wiadomości w Google Chat. Identyfikator karty to unikalny identyfikator karty w wiadomości, gdy wysyłasz kilka kart.

Dostępne tylko w aplikacjach Google Chat. Opcja niedostępna w przypadku dodatków do Google Workspace.

const cardSection = CardService.newCardSection();
cardSection.addWidget(
    CardService.newTextParagraph().setText('This is a text paragraph widget.'));

const card = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader().setTitle('Card title'))
    .addSection(cardSection)
    .build();

const cardWithId = CardService.newCardWithId()
    .setCardId('card_id')
    .setCard(card);

Powroty

CardWithId – pusty element CardWithId.


newChatActionResponse()

Tworzy nowy element: ChatActionResponse.

Dostępne tylko w aplikacjach Google Chat. Opcja niedostępna w przypadku dodatków do Google Workspace.

const card = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader().setTitle('Card title')).build();
const dialog = CardService.newDialog()
    .setBody(card);

const dialogAction = CardService.newDialogAction()
    .setDialog(dialog)

const chatActionResponse = CardService.newChatActionResponse()
    .setResponseType(CardService.ResponseType.DIALOG)
    .setDialogAction(dialogAction);

Powroty

ChatActionResponse – pusty element ChatActionResponse.


newChatResponseBuilder()

Tworzy nowy element: ChatResponseBuilder.

Dostępne tylko w aplikacjach Google Chat. Opcja niedostępna w przypadku dodatków do Google Workspace.

const cardSection = CardService.newCardSection();
cardSection.addWidget(
    CardService.newTextParagraph().setText('This is a text paragraph widget.'));

const card = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader().setTitle('Card title'))
    .addSection(cardSection)
    .build();

const cardWithId = CardService.newCardWithId()
    .setCardId('card_id')
    .setCard(card);

const chatResponse = CardService.newChatResponseBuilder()
    .addCardsV2(cardWithId)
    .build();

Powroty

ChatResponseBuilder – pusty obiekt ChatResponseBuilder.


newColumn()

Tworzy nowy element: Column.

Dostępne w przypadku aplikacji Google Chat i dodatków do Google Workspace.

const columnWidget = CardService.newTextParagraph();
const column = CardService.newColumn()
    .setHorizontalSizeStyle(CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE)
    .setHorizontalAlignment(CardService.HorizontalAlignment.CENTER)
    .setVerticalAlignment(CardService.VerticalAlignment.CENTER)
    .addWidget(columnWidget);

Powroty

Column – pusta kolumna.


newColumns()

Tworzy nowy zbiór elementów Columns.

Dostępne w przypadku aplikacji Google Chat i dodatków do Google Workspace.

const firstColumn = CardService.newColumn()
    .setHorizontalSizeStyle(CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE)
    .setHorizontalAlignment(CardService.HorizontalAlignment.CENTER)
    .setVerticalAlignment(CardService.VerticalAlignment.CENTER);
const secondColumn = CardService.newColumn()
    .setHorizontalSizeStyle(CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE)
    .setHorizontalAlignment(CardService.HorizontalAlignment.CENTER)
    .setVerticalAlignment(CardService.VerticalAlignment.CENTER);
const columns = CardService.newColumns()
    .addColumn(column)
    .addColumn(secondColumn)
    .setWrapStyle(CardService.WrapStyle.WRAP);

Powroty

Columns – pusty zestaw kolumn.


newComposeActionResponseBuilder()

Tworzy nowy element: ComposeActionResponseBuilder.

Powroty

ComposeActionResponseBuilder – pusty kreator ComposeActionResponse.


newDatePicker()

Tworzy nowy element: DatePicker.

Powroty

DatePicker – pusty element DatePicker.


newDateTimePicker()

Tworzy nowy element: DateTimePicker.

Powroty

DateTimePicker – pusty element DateTimePicker.


newDecoratedText()

Tworzy nowy element: DecoratedText.

Powroty

DecoratedText – pusty element decorationedText.


newDialog()

Tworzy nowy element: Dialog.

Dostępne tylko w aplikacjach Google Chat. Opcja niedostępna w przypadku dodatków do Google Workspace.

const card = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader().setTitle('Card title')).build();

// Sets the card of the dialog.
const dialog = CardService.newDialog()
    .setBody(card);

Powroty

Dialog – pusty element Dialog.


newDialogAction()

Tworzy nowy element: DialogAction.

Dostępne tylko w aplikacjach Google Chat. Opcja niedostępna w przypadku dodatków do Google Workspace.

const card = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader().setTitle('Card title')).build();
const dialog = CardService.newDialog()
    .setBody(card);

const dialogAction = CardService.newDialogAction()
    .setDialog(dialog)

Powroty

DialogAction – pusty element DialogAction.


newDivider()

Tworzy nowy element: Divider. Z poniższego przykładu dowiesz się, jak utworzyć prostą kartę z 2 akapitymi rozdzielonymi separatorami.

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;
}

Powroty

Divider – rozgraniczenie.


newDriveItemsSelectedActionResponseBuilder()


newEditorFileScopeActionResponseBuilder()


newFixedFooter()

Tworzy nowy element: FixedFooter.

Powroty

FixedFooter – pusta stopka o stałej stopce.


newGrid()

Tworzy nowy element: Grid.

Powroty

Grid – pusta siatka.


newGridItem()

Tworzy nowy element: GridItem.

Powroty

GridItem – pusty element GridItem.


newIconImage()

Tworzy nowy element: IconImage.

Powroty

IconImage – pusty obraz ikony.


newImage()

Tworzy nowy element: Image.

Powroty

Image – pusty obraz.


newImageButton()

Tworzy nowy element: ImageButton.

Powroty

ImageButton – pusty przycisk ImageButton.


newImageComponent()

Tworzy nowy element: ImageComponent.

Powroty

ImageComponent – pusty komponent obrazu.


newImageCropStyle()

Tworzy nowy element: ImageCropStyle.

Powroty

ImageCropStyle – pusty obiekt ImageCropStyle.


newKeyValue()

Tworzy nowy element: KeyValue.

Powroty

KeyValue – pusta para klucz-wartość.


newLinkPreview()

Tworzy nowy element: LinkPreview.

const decoratedText = CardService.newDecoratedText()
    .setTopLabel('Hello')
    .setText('Hi!');

const cardSection = CardService.newCardSection()
    .addWidget(decoratedText);

const card = CardService.newCardBuilder()
    .addSection(cardSection)
    .build();

const linkPreview = CardService.newLinkPreview()
    .setPreviewCard(card)
    .setTitle('Smart chip title');

Powroty

LinkPreview – pusty podgląd linków.


newNavigation()

Tworzy nowy element: Navigation.

Powroty

Navigation – pusta nawigacja.


newNotification()

Tworzy nowy element: Notification.

Powroty

Notification – puste powiadomienie.


Tworzy nowy element: OpenLink.

Powroty

OpenLink – pusty link OpenLink.


newSelectionInput()

Tworzy nowy element: SelectionInput.

Powroty

SelectionInput – puste pole wyboru.


newSuggestions()

Tworzy nowy element: Suggestions.

Powroty

Suggestions – pusta sugestia.


newSuggestionsResponseBuilder()

Tworzy nowy element: SuggestionsResponseBuilder.

Powroty

SuggestionsResponseBuilder – pusty kreator SuggestionsResponse.


newSwitch()

Tworzy nowy element: Switch.

Powroty

Switch – pusty przełącznik.


newTextButton()

Tworzy nowy element: TextButton.

Powroty

TextButton – pusty przycisk TextButton.


newTextInput()

Tworzy nowy element: TextInput.

Powroty

TextInput – puste pole tekstowe.


newTextParagraph()

Tworzy nowy element: TextParagraph.

Powroty

TextParagraph – pusty akapit tekstu.


newTimePicker()

Tworzy nowy element: TimePicker.

Powroty

TimePicker – pusty element TimePicker.


newUniversalActionResponseBuilder()

Tworzy nowy element: UniversalActionResponseBuilder.

Powroty

UniversalActionResponseBuilder – pusty kreator UniversalActionResponse.


newUpdateDraftActionResponseBuilder()

Tworzy nowy element: UpdateDraftActionResponseBuilder.

Powroty

UpdateDraftActionResponseBuilder – pusta wartość UpdateDraftActionResponseBuilder.


newUpdateDraftBccRecipientsAction()

Tworzy nowy element: UpdateDraftBccRecipientsAction;

Powroty

UpdateDraftBccRecipientsAction – pusta wartość UpdateDraftBccRecipientsAction.


newUpdateDraftBodyAction()

Tworzy nowy element: UpdateDraftBodyAction.

Powroty

UpdateDraftBodyAction – pusta wartość UpdateDraftBodyAction.


newUpdateDraftCcRecipientsAction()

Tworzy nowy element: UpdateDraftCcRecipientsAction.

Powroty

UpdateDraftCcRecipientsAction – pusta wartość UpdateDraftCcRecipientsAction.


newUpdateDraftSubjectAction()

Tworzy nowy element: UpdateDraftSubjectAction.

Powroty

UpdateDraftSubjectAction – pusta wartość UpdateDraftSubjectAction.


newUpdateDraftToRecipientsAction()

Tworzy nowy element: UpdateDraftToRecipientsAction.

Powroty

UpdateDraftToRecipientsAction – pusta wartość UpdateDraftToRecipientsAction.