Class CardService

CardService

CardService umożliwia tworzenie ogólnych kart używanych w różnych usługach Google usługi rozszerzania zasięgu, takie jak dodatki do Google Workspace.

Poniżej znajduje się przykładowa karta dodatków.

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

Możesz też zwrócić kilka kart w następujący sposób:

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

Poniżej pokazujemy, jak można 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 Aplikacje Google Chat.

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

MetodaZwracany typKró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.
newValidation()ValidationTworzy nowy element Validation.

Szczegółowa dokumentacja

newAction()

Tworzy nowy element Action.

Powrót

Action – puste akcje.


newActionResponseBuilder()

Tworzy nowy element ActionResponseBuilder.

Powrót

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');

Powrót

ActionStatus – pusta wartość ActionStatus.


newAttachment()

Tworzy nowy element Attachment.

Powrót

Attachment – pusty załącznik.


newAuthorizationAction()

Tworzy nowy element AuthorizationAction.

Powrót

AuthorizationAction – puste pole AuthorizationAction.


newAuthorizationException()

Tworzy nowy element AuthorizationException.

Powrót

AuthorizationException – pusty wyjątek AuthorizationException.


newBorderStyle()

Tworzy nowy element BorderStyle.

Powrót

BorderStyle – pusty styl BorderStyle.


newButtonSet()

Tworzy nowy element ButtonSet.

Powrót

ButtonSet – pusty ButtonSet.


newCalendarEventActionResponseBuilder()


newCardAction()

Tworzy nowy element CardAction.

Powrót

CardAction – puste pole CardAction.


newCardBuilder()

Tworzy nowy element CardBuilder.

Powrót

CardBuilder – pusty kreator kart.


newCardHeader()

Tworzy nowy element CardHeader.

Powrót

CardHeader – pusty nagłówek CardHeader.


newCardSection()

Tworzy nowy element CardSection.

Powrót

CardSection – pusta sekcja CardSection.


newCardWithId()

Tworzy nowy element CardWithId. Służą one do wysyłania kart w wiadomości w Google Chat. identyfikator karty to unikalny identyfikator karty w wiadomości wysyłanej podczas wysyłania wielu 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);

Powrót

CardWithId – puste pole 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);

Powrót

ChatActionResponse – puste pole 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();

Powrót

ChatResponseBuilder – pusty ChatResponseBuilder.


newColumn()

Tworzy nowy element Column.

Dostępny 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);

Column – pusta kolumna.


newColumns()

Tworzy nowy zbiór elementów Columns.

Dostępny 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);

Powrót

Columns – pusty zbiór kolumn.


newComposeActionResponseBuilder()

Tworzy nowy element ComposeActionResponseBuilder.

Powrót

ComposeActionResponseBuilder – pusty kreator ComposeActionResponse.


newDatePicker()

Tworzy nowy element DatePicker.

Powrót

DatePicker – pusty DatePicker.


newDateTimePicker()

Tworzy nowy element DateTimePicker.

Powrót

DateTimePicker – pusty element DateTimePicker.


newDecoratedText()

Tworzy nowy element DecoratedText.

Powrót

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

Powrót

Dialog – puste pole 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)

Powrót

DialogAction – puste pole DialogAction.


newDivider()

Tworzy nowy element Divider. Ten przykład pozwala utworzyć prostą kartę złożoną z 2 akapitów oddzielone separatorem.

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

Powrót

Divider – separator.


newDriveItemsSelectedActionResponseBuilder()


newEditorFileScopeActionResponseBuilder()


newFixedFooter()

Tworzy nowy element FixedFooter.

Powrót

FixedFooter – pusta stopka ze stałą stopką.


newGrid()

Tworzy nowy element Grid.

Powrót

Grid – pusta siatka.


newGridItem()

Tworzy nowy element GridItem.

Powrót

GridItem – pusty element GridItem.


newIconImage()

Tworzy nowy element IconImage.

Powrót

IconImage – pusty obraz ikony.


newImage()

Tworzy nowy element Image.

Powrót

Image – pusty obraz.


newImageButton()

Tworzy nowy element ImageButton.

Powrót

ImageButton – pusty ImageButton.


newImageComponent()

Tworzy nowy element ImageComponent.

Powrót

ImageComponent – pusty komponent ImageKomponent.


newImageCropStyle()

Tworzy nowy element ImageCropStyle.

Powrót

ImageCropStyle – pusty ImageCropStyle.


newKeyValue()

Tworzy nowy element KeyValue.

Powrót

KeyValue – pusta wartość klucza.


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');

Powrót

LinkPreview – pusty podgląd linku.


newNavigation()

Tworzy nowy element Navigation.

Powrót

Navigation – pusta karta Nawigacja.


newNotification()

Tworzy nowy element Notification.

Powrót

Notification – puste powiadomienie.


Tworzy nowy element OpenLink.

Powrót

OpenLink – pusty link OpenLink.


newSelectionInput()

Tworzy nowy element SelectionInput.

Powrót

SelectionInput – puste pole wyboru.


newSuggestions()

Tworzy nowy element Suggestions.

Powrót

Suggestions – puste sugestie.


newSuggestionsResponseBuilder()

Tworzy nowy element SuggestionsResponseBuilder.

Powrót

SuggestionsResponseBuilder – pusty kreator SuggestionsResponse.


newSwitch()

Tworzy nowy element Switch.

Powrót

Switch – pusty przełącznik.


newTextButton()

Tworzy nowy element TextButton.

Powrót

TextButton – pusty element TextButton.


newTextInput()

Tworzy nowy element TextInput.

Powrót

TextInput – puste pole TextInput.


newTextParagraph()

Tworzy nowy element TextParagraph.

Powrót

TextParagraph – pusty tekst akapitu.


newTimePicker()

Tworzy nowy element TimePicker.

Powrót

TimePicker – pusty selektor TimePicker.


newUniversalActionResponseBuilder()

Tworzy nowy element UniversalActionResponseBuilder.

Powrót

UniversalActionResponseBuilder – pusty kreator UniversalActionResponse.


newUpdateDraftActionResponseBuilder()

Tworzy nowy element UpdateDraftActionResponseBuilder.

Powrót

UpdateDraftActionResponseBuilder – pusty element UpdateDraftActionResponseBuilder.


newUpdateDraftBccRecipientsAction()

Tworzy nowy element UpdateDraftBccRecipientsAction;

Powrót

UpdateDraftBccRecipientsAction – pusta wartość UpdateDraftBccRecipientsAction.


newUpdateDraftBodyAction()

Tworzy nowy element UpdateDraftBodyAction.

Powrót

UpdateDraftBodyAction – pusta wartość UpdateDraftBodyAction.


newUpdateDraftCcRecipientsAction()

Tworzy nowy element UpdateDraftCcRecipientsAction.

Powrót

UpdateDraftCcRecipientsAction – pusta wartość UpdateDraftCcRecipientsAction.


newUpdateDraftSubjectAction()

Tworzy nowy element UpdateDraftSubjectAction.

Powrót

UpdateDraftSubjectAction – puste pole UpdateDraftSubjectAction.


newUpdateDraftToRecipientsAction()

Tworzy nowy element UpdateDraftToRecipientsAction.

Powrót

UpdateDraftToRecipientsAction – pusta wartość UpdateDraftToRecipientsAction.


newValidation()

Tworzy nowy element Validation.

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

const validation = CardService.newValidation()
    .setCharacterLimit(5)
    .setInputType(CardService.InputType.EMAIL);

Powrót

Validation – pusta weryfikacja.