Class CardService Stay organized with collections Save and categorize content based on your preferences.
Page Summary
CardService allows you to create generic cards for use in various Google extensibility products like Google Workspace add-ons.
You can return single or multiple cards using the CardService.
Cards can be built with headers, text, images, and interactive elements like menu items.
CardService provides numerous methods for creating different card components such as buttons, sections, and input fields.
Card
Below is a sample for an add-ons card.
functioncreateCard(){returnCardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('CardTitle')).build();}
Or you can return multiple Cards like so:
functioncreateCards(){return[CardService.newCardBuilder().build(),CardService.newCardBuilder().build(),CardService.newCardBuilder().build(),];}
The following shows how you could define a card with a header, text, an image and a menu item:
functioncreateWidgetDemoCard(){returnCardService.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();}
Sample for a Chat Apps card.
constcardHeader=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');constcardSection=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'}),),),);constcard=CardService.newCardBuilder().setHeader(cardHeader).addSection(cardSection).build();
Properties
| Property | Type | Description |
|---|---|---|
Border | Border | TheBorder enumeration. |
Chip | Chip | TheChip enumeration. |
Common | Common | TheCommon enumeration. |
Composed | Composed | TheComposed enumeration. |
Content | Content | TheContent enumeration. |
Drive | Drive | TheDrive enumeration. |
Expression | Expression | TheExpression enumeration. |
Expression | Expression | TheExpression enumeration. |
Grid | Grid | TheGrid enumeration. |
Horizontal | Horizontal | TheHorizontal enumeration. |
Icon | Icon | TheIcon enumeration. |
Image | Image | TheImage enumeration. |
Image | Image | TheImage enumeration. |
Image | Image | TheImage enumeration. |
Input | Input | TheInput enumeration. |
Load | Load | TheLoad enumeration. |
On | On | TheOn enumeration. |
Open | Open | TheOpen enumeration. |
Selection | Selection | TheSelection enumeration. |
Text | Text | TheText enumeration. |
Text | Text | TheText enumeration. |
Update | Update | TheUpdate enumeration. |
Variable | Variable | TheVariable enumeration. |
Visibility | Visibility | TheVisibility enumeration. |
Workflow | Workflow | TheWorkflow enumeration. |
Methods
Detailed documentation
newActionResponseBuilder()
newActionStatus()
Creates a newAction.
Only available for Google Chat apps. Not available for Google Workspace add-ons.
constactionStatus=CardService.newActionStatus().setStatusCode(CardService.Status.OK).setUserFacingMessage('Success');
Return
Action — An empty ActionStatus.
newAttachment()
newAuthorizationAction()
newAuthorizationException()
newBorderStyle()
newCalendarEventActionResponseBuilder()
Creates a newCalendar.
Return
Calendar — An emptyCalendar.
newCardAction()
newCardBuilder()
newCardHeader()
newCardSection()
newCardWithId()
Creates a newCard. This is used to send a card in a Google Chat message. card IDis a unique identifier for a card in a message when sending multiple cards.
Only available for Google Chat apps. Not available for Google Workspace add-ons.
constcardSection=CardService.newCardSection();cardSection.addWidget(CardService.newTextParagraph().setText('This is a text paragraph widget.'),);constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card title')).addSection(cardSection).build();constcardWithId=CardService.newCardWithId().setCardId('card_id').setCard(card);
Return
Card — An emptyCard.
newCarousel()
Creates aCarousel.
constcarousel=CardService.newCarousel().addCarouselCard(CardService.newCarouselCard().addWidget(CardService.newTextParagraph().setText('The first text paragraph in carousel'))).addCarouselCard(CardService.newCarouselCard().addWidget(CardService.newTextParagraph().setText('The second text paragraph in carousel'))).addCarouselCard(CardService.newCarouselCard().addWidget(CardService.newTextParagraph().setText('The third text paragraph in carousel')))
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
Return
Carousel — An empty Carousel.
newCarouselCard()
Creates a newCarousel.
constcarouselCard=CardService.newCarouselCard().addWidget(CardService.newTextParagraph().setText('Text paragraph in carousel'));
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
Return
Carousel — An empty Chip.
newChatActionResponse()
Creates a newChat.
Only available for Google Chat apps. Not available for Google Workspace add-ons.
constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card title')).build();constdialog=CardService.newDialog().setBody(card);constdialogAction=CardService.newDialogAction().setDialog(dialog);constchatActionResponse=CardService.newChatActionResponse().setResponseType(CardService.ResponseType.DIALOG).setDialogAction(dialogAction);
Return
Chat — An emptyChat.
newChatResponseBuilder()
Creates a newChat.
Only available for Google Chat apps. Not available for Google Workspace add-ons.
constcardSection=CardService.newCardSection();cardSection.addWidget(CardService.newTextParagraph().setText('This is a text paragraph widget.'),);constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card title')).addSection(cardSection).build();constcardWithId=CardService.newCardWithId().setCardId('card_id').setCard(card);constchatResponse=CardService.newChatResponseBuilder().addCardsV2(cardWithId).build();
Return
Chat — An empty ChatResponseBuilder.
newChip()
Creates a newChip.
Available for Google Chat apps. In developer preview for Google Workspace add-ons.
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
constchip=CardService.newChip().setLabel('Open Link').setOpenLink(CardService.newOpenLink().setUrl('https://www.google.com'));
Return
Chip — An empty Chip.
newChipList()
Creates a newChip.
Available for Google Chat apps. In developer preview for Google Workspace add-ons.
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
constchip=CardService.newChip();// Finish building the text chip...constchipList=CardService.newChipList().setLayout(CardService.ChipListLayout.WRAPPED).addChip(chip);
Return
Chip — An empty ChipList.
newCollapseControl()
Creates a newCollapse.
Available for Google Chat apps. In developer preview for Google Workspace add-ons.
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
constcollapseControl=CardService.newCollapseControl().setHorizontalAlign(CardService.HorizontalAlignment.START).setExpandButton(CardService.newTextButton().setText('Expand')).setCollapseButton(CardService.newTextButton().setText('Collapse'));
Return
Collapse — An empty CollapseControl.
newColumn()
Creates a newColumn.
Available for Google Chat apps and Google Workspace add-ons.
constcolumnWidget=CardService.newTextParagraph();constcolumn=CardService.newColumn().setHorizontalSizeStyle(CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE).setHorizontalAlignment(CardService.HorizontalAlignment.CENTER).setVerticalAlignment(CardService.VerticalAlignment.CENTER).addWidget(columnWidget);
Return
Column — An empty Column.
newColumns()
Creates a new set ofColumns.
Available for Google Chat apps and Google Workspace add-ons.
constfirstColumn=CardService.newColumn().setHorizontalSizeStyle(CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE).setHorizontalAlignment(CardService.HorizontalAlignment.CENTER).setVerticalAlignment(CardService.VerticalAlignment.CENTER);constsecondColumn=CardService.newColumn().setHorizontalSizeStyle(CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE).setHorizontalAlignment(CardService.HorizontalAlignment.CENTER).setVerticalAlignment(CardService.VerticalAlignment.CENTER);constcolumns=CardService.newColumns().addColumn(firstColumn).addColumn(secondColumn).setWrapStyle(CardService.WrapStyle.WRAP);
Return
Columns — An empty set of Columns.
newCommonWidgetAction()
newComposeActionResponseBuilder()
Creates a newCompose.
Return
Compose — An empty ComposeActionResponse builder.
newCondition()
newDataSourceConfig()
newDatePicker()
newDateTimePicker()
newDecoratedText()
newDialog()
Creates a newDialog.
Only available for Google Chat apps. Not available for Google Workspace add-ons.
constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card title')).build();// Sets the card of the dialog.constdialog=CardService.newDialog().setBody(card);
Return
newDialogAction()
Creates a newDialog.
Only available for Google Chat apps. Not available for Google Workspace add-ons.
constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card title')).build();constdialog=CardService.newDialog().setBody(card);constdialogAction=CardService.newDialogAction().setDialog(dialog);
Return
Dialog — An emptyDialog.
newDivider()
Creates a newDivider. The following sample builds a simple card with 2 paragraphsseparated by a divider.
functionbuildCard(){constcardSection1TextParagraph1=CardService.newTextParagraph().setText('Hello world!');constcardSection1Divider1=CardService.newDivider();constcardSection1TextParagraph2=CardService.newTextParagraph().setText('Hello world!');constcardSection1=CardService.newCardSection().addWidget(cardSection1TextParagraph1).addWidget(cardSection1Divider1).addWidget(cardSection1TextParagraph2);constcard=CardService.newCardBuilder().addSection(cardSection1).build();returncard;}
Return
Divider — A divider.
newDriveDataSourceSpec()
newDriveItemsSelectedActionResponseBuilder()
Creates a newDrive.
Return
Drive — An emptyDrive.
newEditorFileScopeActionResponseBuilder()
Creates a newEditor.
Return
Editor — An emptyEditor.
newEventAction()
newExpressionData()
Creates a newExpression used for client-side validation.
Return
Expression — An emptyExpression.
newExpressionDataAction()
Creates a newExpression used for client-side validation.
Return
Expression — An emptyExpression.
newExpressionDataCondition()
Creates a newExpression used for client-side validation.
Return
Expression — An emptyExpression.
newFixedFooter()
newHostAppDataSource()
newImageButton()
newImageComponent()
newImageCropStyle()
newLinkPreview()
Creates a newLink.
constdecoratedText=CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');constcardSection=CardService.newCardSection().addWidget(decoratedText);constcard=CardService.newCardBuilder().addSection(cardSection).build();constlinkPreview=CardService.newLinkPreview().setPreviewCard(card).setTitle('Smart chip title');
Return
Link — An empty LinkPreview.
newMaterialIcon()
Creates a newMaterial.
Available for Google Chat apps and Google Workspace add-ons.
constmaterialIcon=CardService.newMaterialIcon().setName('check_box').setFill(true);constcardSection=CardService.newCardSection();cardSection.addWidget(CardService.newDecoratedText().setStartIcon(CardService.newIconImage().setMaterialIcon(materialIcon)).setText('sasha@example.com'),);constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card Title')).addSection(cardSection).build();
Return
Material — An empty MaterialIcon.
newNavigation()
newNotification()
newOverflowMenu()
Creates a newOverflow.
Available for Google Chat apps. In developer preview for Google Workspace add-ons.
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
constoverflowMenuItem=CardService.newOverflowMenuItem();// Finish building the overflow menu item...constoverflowMenu=CardService.newOverflowMenu().addMenuItem(overflowMenuItem);
Return
Overflow — An empty OverflowMenu.
newOverflowMenuItem()
Creates a newOverflow.
Available for Google Chat apps. In developer preview for Google Workspace add-ons.
Developer Preview: Available as part of theGoogle Workspace Developer Preview Program, which grants early access to certain features.
constoverflowMenuItem=CardService.newOverflowMenuItem().setStartIcon(CardService.newIconImage().setIconUrl('https://www.google.com/images/branding/googleg/1x/googleg_standard_color_64dp.png',),).setText('Open Link').setOpenLink(CardService.newOpenLink().setUrl('https://www.google.com'));
Return
Overflow — An empty OverflowMenuItem.
newPlatformDataSource()
newSelectionInput()
newSuggestions()
newSuggestionsResponseBuilder()
Creates a newSuggestions.
Return
Suggestions — An empty SuggestionsResponse builder.
newTextButton()
newTextParagraph()
newTimePicker()
newTrigger()
newUniversalActionResponseBuilder()
Creates a newUniversal.
Return
Universal — An empty UniversalActionResponse builder.
newUpdateDraftActionResponseBuilder()
Creates a newUpdate.
Return
Update — An empty UpdateDraftActionResponseBuilder.
newUpdateDraftBccRecipientsAction()
Creates a newUpdate;
Return
Update — An empty UpdateDraftBccRecipientsAction.
newUpdateDraftBodyAction()
newUpdateDraftCcRecipientsAction()
Creates a newUpdate.
Return
Update — An Empty UpdateDraftCcRecipientsAction.
newUpdateDraftSubjectAction()
Creates a newUpdate.
Return
Update — An empty UpdateDraftSubjectAction.
newUpdateDraftToRecipientsAction()
Creates a newUpdate.
Return
Update — An empty UpdateDraftToRecipientsAction.
newUpdateVisibilityAction()
newValidation()
Creates a newValidation.
Available for Google Chat apps and Google Workspace add-ons.
constvalidation=CardService.newValidation().setCharacterLimit(5).setInputType(CardService.InputType.EMAIL);
Return
Validation — An empty validation.
newWorkflowDataSource()
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-03 UTC.