CardService cung cấp khả năng tạo thẻ chung dùng trên các sản phẩm có khả năng mở rộng của Google, chẳng hạn như Tiện ích bổ sung của Google Workspace.
Dưới đây là ví dụ về thẻ tiện ích bổ sung.
return CardService.newCardBuilder() .setHeader(CardService.newCardHeader().setTitle("CardTitle")) .build();
Hoặc bạn có thể trả lại nhiều Thẻ như sau:
return [ CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), CardService.newCardBuilder().build() ]
Phần sau đây cho thấy cách bạn có thể xác định 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(); }
Mẫu cho thẻ Các ứng dụng trong 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
Tài sản | Loại | Nội dung mô tả |
---|---|---|
BorderType | BorderType | Bảng liệt kê BorderType . |
ComposedEmailType | ComposedEmailType | Bảng liệt kê ComposedEmailType . |
ContentType | ContentType | Bảng liệt kê ContentType . |
GridItemLayout | GridItemLayout | Bảng liệt kê GridItemLayout . |
HorizontalAlignment | HorizontalAlignment | Bảng liệt kê HorizontalAlignment . |
Icon | Icon | Bảng liệt kê Icon . |
ImageCropType | ImageCropType | Bảng liệt kê ImageCropType . |
ImageStyle | ImageStyle | Bảng liệt kê ImageStyle . |
LoadIndicator | LoadIndicator | Bảng liệt kê LoadIndicator . |
OnClose | OnClose | Bảng liệt kê OnClose . |
OpenAs | OpenAs | Bảng liệt kê OpenAs . |
SelectionInputType | SelectionInputType | Bảng liệt kê SelectionInputType . |
TextButtonStyle | TextButtonStyle | Bảng liệt kê TextButtonStyle . |
UpdateDraftBodyType | UpdateDraftBodyType | Bảng liệt kê UpdateDraftBodyType . |
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 sử dụng được với 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
– ActionStatus trống.
newAttachment()
newAuthorizationAction()
newAuthorizationException()
Tạo AuthorizationException
mới.
Cầu thủ trả bóng
AuthorizationException
– ActivityException (Exception) bị trống.
newBorderStyle()
newCalendarEventActionResponseBuilder()
Tạo CalendarEventActionResponseBuilder
mới.
Cầu thủ trả bóng
CalendarEventActionResponseBuilder
– CalendarEventActionResponseBuilder
trống.
newCardAction()
newCardBuilder()
newCardHeader()
newCardSection()
newCardWithId()
Tạo CardWithId
mới. Mã thẻ này được dùng để gửi một thẻ trong tin nhắn trên Google Chat. Mã thẻ là giá trị nhận dạng duy nhất của một thẻ trong tin nhắn khi gửi nhiều thẻ.
Chỉ dành cho các ứng dụng Google Chat. Không sử dụng được với 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
– CardWithId
trống.
newChatActionResponse()
Tạo ChatActionResponse
mới.
Chỉ dành cho các ứng dụng Google Chat. Không sử dụng được với 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
– ChatActionResponse
trống.
newChatResponseBuilder()
Tạo ChatResponseBuilder
mới.
Chỉ dành cho các ứng dụng Google Chat. Không sử dụng được với 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
– ChatResponseBuilder trống.
newColumn()
Tạo Column
mới.
Được cung cấp 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
– Cột trống.
newColumns()
Tạo một nhóm Columns
mới.
Được cung cấp 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(column) .addColumn(secondColumn) .setWrapStyle(CardService.WrapStyle.WRAP);
Cầu thủ trả bóng
Columns
— Một tập hợp Cột trống.
newComposeActionResponseBuilder()
Tạo ComposeActionResponseBuilder
mới.
Cầu thủ trả bóng
ComposeActionResponseBuilder
– Trình tạo ComposeActionResponse trống.
newDatePicker()
newDateTimePicker()
newDecoratedText()
newDialog()
Tạo Dialog
mới.
Chỉ dành cho các ứng dụng Google Chat. Không sử dụng được với 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 sử dụng được với 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
– DialogAction
trống.
newDivider()
Tạo Divider
mới. Mẫu sau đây sẽ tạo một thẻ đơn giản có 2 đoạn được phân tách bằng một đường phân chia.
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; }
Cầu thủ trả bóng
Divider
– Một thanh phân cách.
newDriveItemsSelectedActionResponseBuilder()
Tạo DriveItemsSelectedActionResponseBuilder
mới.
Cầu thủ trả bóng
DriveItemsSelectedActionResponseBuilder
– DriveItemsSelectedActionResponseBuilder
trống.
newEditorFileScopeActionResponseBuilder()
Tạo EditorFileScopeActionResponseBuilder
mới.
Cầu thủ trả bóng
EditorFileScopeActionResponseBuilder
– EditorFileScopeActionResponseBuilder
trống.
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(); const linkPreview = CardService.newLinkPreview() .setPreviewCard(card) .setTitle('Smart chip title');
Cầu thủ trả bóng
LinkPreview
– Một LinkPreview trống.
newNotification()
newSelectionInput()
newSuggestions()
newSuggestionsResponseBuilder()
Tạo SuggestionsResponseBuilder
mới.
Cầu thủ trả bóng
SuggestionsResponseBuilder
— Trình tạoSuggestedResponse trống.
newTextButton()
newTextParagraph()
newTimePicker()
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
— Update DraftActionResponseBuilder trống.
newUpdateDraftBccRecipientsAction()
Tạo UpdateDraftBccRecipientsAction
mới;
Cầu thủ trả bóng
UpdateDraftBccRecipientsAction
— Thao tác Cập Nhật BccNgười nhận trống rỗng.
newUpdateDraftBodyAction()
Tạo UpdateDraftBodyAction
mới.
Cầu thủ trả bóng
UpdateDraftBodyAction
— Cập nhậtBản thảoBodyAction trống.
newUpdateDraftCcRecipientsAction()
Tạo UpdateDraftCcRecipientsAction
mới.
Cầu thủ trả bóng
UpdateDraftCcRecipientsAction
— một Update DraftCcReceivesAction không có dữ liệu.
newUpdateDraftSubjectAction()
Tạo UpdateDraftSubjectAction
mới.
Cầu thủ trả bóng
UpdateDraftSubjectAction
— một Update draftSubjectAction trống.
newUpdateDraftToRecipientsAction()
Tạo UpdateDraftToRecipientsAction
mới.
Cầu thủ trả bóng
UpdateDraftToRecipientsAction
— Cập nhật UpdateToRevenuesAction trống.