CardService cung cấp khả năng tạo các thẻ chung được dùng trên nhiều sản phẩm có khả năng mở rộng của Google, chẳng hạn như tiện ích bổ sung Google Workspace.
Dưới đây là một mẫu cho thẻ tiện ích bổ sung.
function createCard() { return CardService.newCardBuilder() .setHeader(CardService.newCardHeader().setTitle('CardTitle')) .build(); }
Hoặc bạn có thể trả về nhiều Thẻ như sau:
function createCards() { return [ CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), ]; }
Sau đây là cách bạn có thể xác định một thẻ có tiêu đề, văn bản, hình ảnh và một mục trong trình đơn:
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(); }
Ví dụ về thẻ Ứng dụng 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();
Thuộc tính
| Thuộc tính | Loại | Mô tả |
|---|---|---|
Border | Border | Bảng liệt kê Border. |
Chip | Chip | Bảng liệt kê Chip. |
Common | Common | Bảng liệt kê Common. |
Composed | Composed | Bảng liệt kê Composed. |
Content | Content | Bảng liệt kê Content. |
Drive | Drive | Bảng liệt kê Drive. |
Expression | Expression | Bảng liệt kê Expression. |
Expression | Expression | Bảng liệt kê Expression. |
Grid | Grid | Bảng liệt kê Grid. |
Horizontal | Horizontal | Bảng liệt kê Horizontal. |
Icon | Icon | Bảng liệt kê Icon. |
Image | Image | Bảng liệt kê Image. |
Image | Image | Bảng liệt kê Image. |
Image | Image | Bảng liệt kê Image. |
Input | Input | Bảng liệt kê Input. |
Load | Load | Bảng liệt kê Load. |
On | On | Bảng liệt kê On. |
Open | Open | Bảng liệt kê Open. |
Selection | Selection | Bảng liệt kê Selection. |
Text | Text | Bảng liệt kê Text. |
Text | Text | Bảng liệt kê Text. |
Update | Update | Bảng liệt kê Update. |
Variable | Variable | Bảng liệt kê Variable. |
Visibility | Visibility | Bảng liệt kê Visibility. |
Workflow | Workflow | Bảng liệt kê Workflow. |
Phương thức
Tài liệu chi tiết
newActionResponseBuilder()
Tạo ActionResponseBuilder mới.
Cầu thủ trả bóng
ActionResponseBuilder – Trình tạo ActionResponse trống.
newActionStatus()
Tạo ActionStatus mới.
Chỉ dành cho các ứng dụng Google Chat. Không dùng được cho các tiện ích bổ sung của Google Workspace.
const actionStatus = CardService.newActionStatus() .setStatusCode(CardService.Status.OK) .setUserFacingMessage('Success');
Cầu thủ trả bóng
ActionStatus – Một ActionStatus trống.
newAttachment()
newAuthorizationAction()
newAuthorizationException()
Tạo AuthorizationException mới.
Cầu thủ trả bóng
AuthorizationException – Một AuthorizationException trống.
newBorderStyle()
newCalendarEventActionResponseBuilder()
Tạo CalendarEventActionResponseBuilder mới.
Cầu thủ trả bóng
CalendarEventActionResponseBuilder – Một CalendarEventActionResponseBuilder trống.
newCardAction()
newCardBuilder()
newCardHeader()
newCardSection()
newCardWithId()
Tạo CardWithId mới. Tham số này dùng để gửi thẻ trong tin nhắn Google Chat. card ID là giá trị nhận dạng duy nhất cho thẻ trong tin nhắn khi gửi nhiều thẻ.
Chỉ dành cho các ứng dụng Google Chat. Không dùng được cho các tiện ích bổ sung của 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);
Cầu thủ trả bóng
CardWithId – Một CardWithId trống.
newCarousel()
Tạo Carousel.
const carousel = 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')))
Cầu thủ trả bóng
Carousel – Băng chuyền trống.
newCarouselCard()
Tạo CarouselCard mới.
const carouselCard = CardService.newCarouselCard().addWidget( CardService.newTextParagraph().setText('Text paragraph in carousel'));
Cầu thủ trả bóng
CarouselCard – Một Khối trống.
newChatActionResponse()
Tạo ChatActionResponse mới.
Chỉ dành cho các ứng dụng Google Chat. Không dùng được cho các tiện ích bổ sung của 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);
Cầu thủ trả bóng
ChatActionResponse – Một ChatActionResponse trống.
newChatResponseBuilder()
Tạo ChatResponseBuilder mới.
Chỉ dành cho các ứng dụng Google Chat. Không dùng được cho các tiện ích bổ sung của 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();
Cầu thủ trả bóng
ChatResponseBuilder – Một ChatResponseBuilder trống.
newChip()
newChipList()
Tạo ChipList mới.
Có trong các ứng dụng Google Chat. Trong bản dùng thử cho nhà phát triển của tiện ích bổ sung Google Workspace.
const chip = CardService.newChip(); // Finish building the text chip... const chipList = CardService.newChipList() .setLayout(CardService.ChipListLayout.WRAPPED) .addChip(chip);
Cầu thủ trả bóng
ChipList – Một ChipList trống.
newCollapseControl()
Tạo CollapseControl mới.
Có trong các ứng dụng Google Chat. Trong bản dùng thử cho nhà phát triển của tiện ích bổ sung Google Workspace.
const collapseControl = CardService.newCollapseControl() .setHorizontalAlign(CardService.HorizontalAlignment.START) .setExpandButton(CardService.newTextButton().setText('Expand')) .setCollapseButton(CardService.newTextButton().setText('Collapse'));
Cầu thủ trả bóng
CollapseControl – Một CollapseControl trống.
newColumn()
Tạo Column mới.
Dành cho các ứng dụng Google Chat và tiện ích bổ sung của 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);
Cầu thủ trả bóng
Column – Một cột trống.
newColumns()
Tạo một tập hợp Columns mới.
Dành cho các ứng dụng Google Chat và tiện ích bổ sung của 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(firstColumn) .addColumn(secondColumn) .setWrapStyle(CardService.WrapStyle.WRAP);
Cầu thủ trả bóng
Columns – Một tập hợp các cột trống.
newCommonWidgetAction()
newComposeActionResponseBuilder()
Tạo ComposeActionResponseBuilder mới.
Cầu thủ trả bóng
ComposeActionResponseBuilder – Trình tạo ComposeActionResponse trống.
newCondition()
newDataSourceConfig()
newDatePicker()
newDateTimePicker()
newDecoratedText()
newDialog()
Tạo Dialog mới.
Chỉ dành cho các ứng dụng Google Chat. Không dùng được cho các tiện ích bổ sung của 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);
Cầu thủ trả bóng
newDialogAction()
Tạo DialogAction mới.
Chỉ dành cho các ứng dụng Google Chat. Không dùng được cho các tiện ích bổ sung của 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);
Cầu thủ trả bóng
DialogAction – Một DialogAction trống.
newDivider()
Tạo Divider mới. Mẫu sau đây tạo một thẻ đơn giản có 2 đoạn văn được phân tách bằng một đường phân chia.
function buildCard() { const cardSection1TextParagraph1 = CardService.newTextParagraph().setText('Hello world!'); const cardSection1Divider1 = CardService.newDivider(); const cardSection1TextParagraph2 = CardService.newTextParagraph().setText('Hello world!'); const cardSection1 = CardService.newCardSection() .addWidget(cardSection1TextParagraph1) .addWidget(cardSection1Divider1) .addWidget(cardSection1TextParagraph2); const card = CardService.newCardBuilder().addSection(cardSection1).build(); return card; }
Cầu thủ trả bóng
Divider – Đường phân cách.
newDriveDataSourceSpec()
newDriveItemsSelectedActionResponseBuilder()
Tạo DriveItemsSelectedActionResponseBuilder mới.
Cầu thủ trả bóng
DriveItemsSelectedActionResponseBuilder – Một DriveItemsSelectedActionResponseBuilder trống.
newEditorFileScopeActionResponseBuilder()
Tạo EditorFileScopeActionResponseBuilder mới.
Cầu thủ trả bóng
EditorFileScopeActionResponseBuilder – Một EditorFileScopeActionResponseBuilder trống.
newEventAction()
Tạo một EventAction mới dùng để xác thực phía máy khách.
Cầu thủ trả bóng
EventAction – Một EventAction trống.
newExpressionData()
Tạo một ExpressionData mới dùng để xác thực phía máy khách.
Cầu thủ trả bóng
ExpressionData – Một ExpressionData trống.
newExpressionDataAction()
Tạo một ExpressionDataAction mới dùng để xác thực phía máy khách.
Cầu thủ trả bóng
ExpressionDataAction – Một ExpressionDataAction trống.
newExpressionDataCondition()
Tạo một ExpressionDataCondition mới dùng để xác thực phía máy khách.
Cầu thủ trả bóng
ExpressionDataCondition – Một ExpressionDataCondition trống.
newHostAppDataSource()
newImageButton()
newImageComponent()
newImageCropStyle()
newLinkPreview()
Tạo LinkPreview mới.
const decoratedText = CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!'); const cardSection = CardService.newCardSection().addWidget(decoratedText); const card = CardService.newCardBuilder().addSection(cardSection).build(); return CardService.newLinkPreview().setPreviewCard(card).setTitle( 'Smart chip title');
Cầu thủ trả bóng
LinkPreview – Một LinkPreview trống.
newMaterialIcon()
Tạo MaterialIcon mới.
Dành cho các ứng dụng Google Chat và tiện ích bổ sung của Google Workspace.
const materialIcon = CardService.newMaterialIcon().setName('check_box').setFill(true); const cardSection = CardService.newCardSection(); cardSection.addWidget( CardService.newDecoratedText() .setStartIcon(CardService.newIconImage().setMaterialIcon(materialIcon)) .setText('sasha@example.com'), ); const card = CardService.newCardBuilder() .setHeader(CardService.newCardHeader().setTitle('Card Title')) .addSection(cardSection) .build();
Cầu thủ trả bóng
MaterialIcon – Một MaterialIcon trống.
newNotification()
newOverflowMenu()
Tạo OverflowMenu mới.
Có trong các ứng dụng Google Chat. Trong bản dùng thử cho nhà phát triển của tiện ích bổ sung Google Workspace.
const overflowMenuItem = CardService.newOverflowMenuItem(); // Finish building the overflow menu item... const overflowMenu = CardService.newOverflowMenu().addMenuItem(overflowMenuItem);
Cầu thủ trả bóng
OverflowMenu – Một OverflowMenu trống.
newOverflowMenuItem()
Tạo OverflowMenuItem mới.
Có trong các ứng dụng Google Chat. Trong bản dùng thử cho nhà phát triển của tiện ích bổ sung Google Workspace.
const overflowMenuItem = 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'));
Cầu thủ trả bóng
OverflowMenuItem – Một OverflowMenuItem trống.
newPlatformDataSource()
newSelectionInput()
newSuggestions()
newSuggestionsResponseBuilder()
Tạo SuggestionsResponseBuilder mới.
Cầu thủ trả bóng
SuggestionsResponseBuilder – Trình tạo SuggestionsResponse trống.
newTextButton()
newTextParagraph()
newTimePicker()
newTrigger()
newUniversalActionResponseBuilder()
Tạo UniversalActionResponseBuilder mới.
Cầu thủ trả bóng
UniversalActionResponseBuilder – Trình tạo UniversalActionResponse trống.
newUpdateDraftActionResponseBuilder()
Tạo UpdateDraftActionResponseBuilder mới.
Cầu thủ trả bóng
UpdateDraftActionResponseBuilder – Một UpdateDraftActionResponseBuilder trống.
newUpdateDraftBccRecipientsAction()
Tạo một UpdateDraftBccRecipientsAction mới;
Cầu thủ trả bóng
UpdateDraftBccRecipientsAction – Một UpdateDraftBccRecipientsAction trống.
newUpdateDraftBodyAction()
Tạo UpdateDraftBodyAction mới.
Cầu thủ trả bóng
UpdateDraftBodyAction – Một UpdateDraftBodyAction trống.
newUpdateDraftCcRecipientsAction()
Tạo UpdateDraftCcRecipientsAction mới.
Cầu thủ trả bóng
UpdateDraftCcRecipientsAction – Một UpdateDraftCcRecipientsAction trống.
newUpdateDraftSubjectAction()
Tạo UpdateDraftSubjectAction mới.
Cầu thủ trả bóng
UpdateDraftSubjectAction – Một UpdateDraftSubjectAction trống.
newUpdateDraftToRecipientsAction()
Tạo UpdateDraftToRecipientsAction mới.
Cầu thủ trả bóng
UpdateDraftToRecipientsAction – Một UpdateDraftToRecipientsAction trống.
newUpdateVisibilityAction()
Tạo UpdateVisibilityAction mới.
Cầu thủ trả bóng
UpdateVisibilityAction – Một UpdateVisibilityAction trống.
newValidation()
Tạo Validation mới.
Dành cho các ứng dụng Google Chat và tiện ích bổ sung của Google Workspace.
const validation = CardService.newValidation().setCharacterLimit(5).setInputType( CardService.InputType.EMAIL);
Cầu thủ trả bóng
Validation – Một quy trình xác thực trống.