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

Образец карточки приложения 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();

Характеристики

Свойство Тип Описание
BorderType BorderType Перечисление BorderType .
ComposedEmailType ComposedEmailType Перечисление ComposedEmailType .
ContentType ContentType Перечисление ContentType .
GridItemLayout GridItemLayout Перечисление GridItemLayout .
HorizontalAlignment HorizontalAlignment Перечисление HorizontalAlignment .
Icon Icon Перечисление Icon .
ImageCropType ImageCropType Перечисление ImageCropType .
ImageStyle ImageStyle Перечисление ImageStyle .
LoadIndicator LoadIndicator Перечисление LoadIndicator .
OnClose OnClose Перечисление OnClose .
OpenAs OpenAs Перечисление OpenAs .
SelectionInputType SelectionInputType Перечисление SelectionInputType .
TextButtonStyle TextButtonStyle Перечисление TextButtonStyle .
UpdateDraftBodyType UpdateDraftBodyType Перечисление UpdateDraftBodyType .

Методы

Метод Тип возврата Краткое описание
newAction() Action Создает новое Action .
newActionResponseBuilder() ActionResponseBuilder Создает новый ActionResponseBuilder .
newActionStatus() ActionStatus Создает новый ActionStatus .
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 .
newCardWithId() CardWithId Создает новый CardWithId .
newChatActionResponse() ChatActionResponse Создает новый ChatActionResponse .
newChatResponseBuilder() ChatResponseBuilder Создает новый ChatResponseBuilder .
newColumn() Column Создает новый Column .
newColumns() Columns Создает новый набор Columns .
newComposeActionResponseBuilder() ComposeActionResponseBuilder Создает новый ComposeActionResponseBuilder .
newDatePicker() DatePicker Создает новый DatePicker .
newDateTimePicker() DateTimePicker Создает новый DateTimePicker .
newDecoratedText() DecoratedText Создает новый DecoratedText .
newDialog() Dialog Создает новый Dialog .
newDialogAction() DialogAction Создает новый DialogAction .
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 .
newLinkPreview() LinkPreview Создает новый LinkPreview .
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 — пустое действие.


newActionResponseBuilder()

Создает новый ActionResponseBuilder .

Возвращаться

ActionResponseBuilder — пустой построитель ActionResponse.


newActionStatus()

Создает новый ActionStatus .

Доступно только для приложений Google Chat. Недоступно для дополнений Google Workspace.

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

Возвращаться

ActionStatus — пустой ActionStatus.


newAttachment()

Создает новое Attachment .

Возвращаться

Attachment — пустое вложение.


newAuthorizationAction()

Создает новое AuthorizationAction .

Возвращаться

AuthorizationAction — пустое AuthorizationAction.


newAuthorizationException()

Создает новое AuthorizationException .

Возвращаться

AuthorizationException — пустое исключение AuthorizationException.


newBorderStyle()

Создает новый BorderStyle .

Возвращаться

BorderStyle — пустой BorderStyle.


newButtonSet()

Создает новый ButtonSet .

Возвращаться

ButtonSet — пустой ButtonSet.


newCalendarEventActionResponseBuilder()

Создает новый CalendarEventActionResponseBuilder .

Возвращаться

CalendarEventActionResponseBuilder — пустой CalendarEventActionResponseBuilder .


newCardAction()

Создает новое CardAction .

Возвращаться

CardAction — пустое CardAction.


newCardBuilder()

Создает новый CardBuilder .

Возвращаться

CardBuilder — пустой конструктор карт.


newCardHeader()

Создает новый CardHeader .

Возвращаться

CardHeader — пустой CardHeader.


newCardSection()

Создает новый CardSection .

Возвращаться

CardSection — Пустой CardSection.


newCardWithId()

Создает новый CardWithId . Используется для отправки карточки в сообщении Google Chat. ID карты — уникальный идентификатор карты в сообщении при отправке нескольких карт.

Доступно только для приложений Google Chat. Недоступно для дополнений 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);

Возвращаться

CardWithId — Пустой CardWithId .


newChatActionResponse()

Создает новый ChatActionResponse .

Доступно только для приложений Google Chat. Недоступно для дополнений 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);

Возвращаться

ChatActionResponse — пустой ChatActionResponse .


newChatResponseBuilder()

Создает новый ChatResponseBuilder .

Доступно только для приложений Google Chat. Недоступно для дополнений 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();

Возвращаться

ChatResponseBuilder — пустой ChatResponseBuilder.


newColumn()

Создает новый Column .

Доступно для приложений Google Chat и дополнений 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 — пустой столбец.


newColumns()

Создает новый набор Columns .

Доступно для приложений Google Chat и дополнений 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);

Возвращаться

Columns — пустой набор столбцов.


newComposeActionResponseBuilder()

Создает новый ComposeActionResponseBuilder .

Возвращаться

ComposeActionResponseBuilder — пустой построитель ComposeActionResponse.


newDatePicker()

Создает новый DatePicker .

Возвращаться

DatePicker — пустой DatePicker.


newDateTimePicker()

Создает новый DateTimePicker .

Возвращаться

DateTimePicker — пустой DateTimePicker.


newDecoratedText()

Создает новый DecoratedText .

Возвращаться

DecoratedText — пустой декорированныйтекст.


newDialog()

Создает новый Dialog .

Доступно только для приложений Google Chat. Недоступно для дополнений 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);

Возвращаться

Dialog — пустой Dialog .


newDialogAction()

Создает новый DialogAction .

Доступно только для приложений Google Chat. Недоступно для дополнений 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)

Возвращаться

DialogAction — Пустой DialogAction .


newDivider()

Создает новый Divider . В следующем примере создается простая карточка с двумя абзацами, разделенными разделителем.

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

Создает новый EditorFileScopeActionResponseBuilder .

Возвращаться

EditorFileScopeActionResponseBuilder — Пустой EditorFileScopeActionResponseBuilder .


newFixedFooter()

Создает новый FixedFooter .

Возвращаться

FixedFooter — пустой фиксированный нижний колонтитул.


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 — пустое значение KeyValue.


newLinkPreview()

Создает новый 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');

Возвращаться

LinkPreview — пустой LinkPreview.


newNavigation()

Создает новую Navigation .

Возвращаться

Navigation — пустая навигация.


newNotification()

Создает новое Notification .

Возвращаться

Notification — пустое уведомление.


Создает новый OpenLink .

Возвращаться

OpenLink — пустая OpenLink.


newSelectionInput()

Создает новый SelectionInput .

Возвращаться

SelectionInput — пустой SelectionInput.


newSuggestions()

Создает новые Suggestions .

Возвращаться

Suggestions — пустое поле «Предложения».


newSuggestionsResponseBuilder()

Создает новый SuggestionsResponseBuilder .

Возвращаться

SuggestionsResponseBuilder — пустой конструктор OffersResponseBuilder.


newSwitch()

Создает новый Switch .

Возвращаться

Switch — пустой переключатель.


newTextButton()

Создает новый TextButton .

Возвращаться

TextButton — Пустой TextButton.


newTextInput()

Создает новый TextInput .

Возвращаться

TextInput — пустой TextInput.


newTextParagraph()

Создает новый TextParagraph .

Возвращаться

TextParagraph — пустой TextParagraph.


newTimePicker()

Создает новый TimePicker .

Возвращаться

TimePicker — пустой TimePicker.


newUniversalActionResponseBuilder()

Создает новый UniversalActionResponseBuilder .

Возвращаться

UniversalActionResponseBuilder — пустой построитель UniversalActionResponse.


newUpdateDraftActionResponseBuilder()

Создает новый UpdateDraftActionResponseBuilder .

Возвращаться

UpdateDraftActionResponseBuilder — пустой UpdateDraftActionResponseBuilder.


newUpdateDraftBccRecipientsAction()

Создает новое UpdateDraftBccRecipientsAction ;

Возвращаться

UpdateDraftBccRecipientsAction — пустое UpdateDraftBccRecipientsAction.


newUpdateDraftBodyAction()

Создает новый UpdateDraftBodyAction .

Возвращаться

UpdateDraftBodyAction — пустое UpdateDraftBodyAction.


newUpdateDraftCcRecipientsAction()

Создает новый UpdateDraftCcRecipientsAction .

Возвращаться

UpdateDraftCcRecipientsAction — пустое UpdateDraftCcRecipientsAction.


newUpdateDraftSubjectAction()

Создает новый UpdateDraftSubjectAction .

Возвращаться

UpdateDraftSubjectAction — пустое UpdateDraftSubjectAction.


newUpdateDraftToRecipientsAction()

Создает новое UpdateDraftToRecipientsAction .

Возвращаться

UpdateDraftToRecipientsAction — пустое UpdateDraftToRecipientsAction.