CardService menyediakan kemampuan untuk membuat kartu generik yang digunakan di berbagai produk ekstensi Google, seperti Add-on Google Workspace.
Berikut adalah contoh kartu add-on.
function createCard() { return CardService.newCardBuilder() .setHeader(CardService.newCardHeader().setTitle('CardTitle')) .build(); }
Atau, Anda dapat menampilkan beberapa Kartu seperti ini:
function createCards() { return [ CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), ]; }
Berikut ini cara menentukan kartu dengan header, teks, gambar, dan item 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(); }
Contoh untuk kartu Aplikasi 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();
Properti
Properti | Jenis | Deskripsi |
---|---|---|
BorderType | BorderType | Enumerasi BorderType . |
ChipListLayout | ChipListLayout | Enumerasi ChipListLayout . |
ComposedEmailType | ComposedEmailType | Enumerasi ComposedEmailType . |
ContentType | ContentType | Enumerasi ContentType . |
GridItemLayout | GridItemLayout | Enumerasi GridItemLayout . |
HorizontalAlignment | HorizontalAlignment | Enumerasi HorizontalAlignment . |
Icon | Icon | Enumerasi Icon . |
ImageButtonStyle | ImageButtonStyle | Enumerasi ImageButtonStyle . |
ImageCropType | ImageCropType | Enumerasi ImageCropType . |
ImageStyle | ImageStyle | Enumerasi ImageStyle . |
InputType | InputType | Enumerasi InputType . |
LoadIndicator | LoadIndicator | Enumerasi LoadIndicator . |
OnClose | OnClose | Enumerasi OnClose . |
OpenAs | OpenAs | Enumerasi OpenAs . |
SelectionInputType | SelectionInputType | Enumerasi SelectionInputType . |
TextButtonStyle | TextButtonStyle | Enumerasi TextButtonStyle . |
UpdateDraftBodyType | UpdateDraftBodyType | Enumerasi UpdateDraftBodyType . |
Metode
Dokumentasi mendetail
newActionResponseBuilder()
Membuat ActionResponseBuilder
baru.
Pulang pergi
ActionResponseBuilder
— Builder ActionResponse kosong.
newActionStatus()
Membuat ActionStatus
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on Google Workspace.
const actionStatus = CardService.newActionStatus() .setStatusCode(CardService.Status.OK) .setUserFacingMessage('Success');
Pulang pergi
ActionStatus
— ActionStatus kosong.
newAttachment()
newAuthorizationAction()
newAuthorizationException()
Membuat AuthorizationException
baru.
Pulang pergi
AuthorizationException
— AuthorizationException kosong.
newBorderStyle()
newCalendarEventActionResponseBuilder()
Membuat CalendarEventActionResponseBuilder
baru.
Pulang pergi
CalendarEventActionResponseBuilder
— CalendarEventActionResponseBuilder
kosong.
newCardAction()
newCardBuilder()
newCardHeader()
newCardSection()
newCardWithId()
Membuat CardWithId
baru. Ini digunakan untuk mengirim kartu dalam pesan Google Chat. ID kartu
adalah ID unik untuk kartu dalam pesan saat mengirim beberapa kartu.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on 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);
Pulang pergi
CardWithId
— CardWithId
kosong.
newChatActionResponse()
Membuat ChatActionResponse
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on 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);
Pulang pergi
ChatActionResponse
— ChatActionResponse
kosong.
newChatResponseBuilder()
Membuat ChatResponseBuilder
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on 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();
Pulang pergi
ChatResponseBuilder
— ChatResponseBuilder kosong.
newChip()
newChipList()
Membuat ChipList
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on Google Workspace.
const chip = CardService.newChip(); // Finish building the text chip... const chipList = CardService.newChipList() .setLayout(CardService.ChipListLayout.WRAPPED) .addChip(chip);
Pulang pergi
ChipList
— ChipList kosong.
newCollapseControl()
Membuat CollapseControl
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on Google Workspace.
const collapseControl = CardService.newCollapseControl() .setHorizontalAlign(CardService.HorizontalAlignment.START) .setExpandButton(CardService.newTextButton().setText('Expand')) .setCollapseButton(CardService.newTextButton().setText('Collapse'));
Pulang pergi
CollapseControl
— CollapseControl kosong.
newColumn()
Membuat Column
baru.
Tersedia untuk aplikasi Google Chat dan Add-on 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);
Pulang pergi
Column
— Kolom kosong.
newColumns()
Membuat kumpulan Columns
baru.
Tersedia untuk aplikasi Google Chat dan Add-on 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);
Pulang pergi
Columns
— Kumpulan Kolom kosong.
newComposeActionResponseBuilder()
Membuat ComposeActionResponseBuilder
baru.
Pulang pergi
ComposeActionResponseBuilder
— Builder ComposeActionResponse kosong.
newDatePicker()
newDateTimePicker()
newDecoratedText()
newDialog()
Membuat Dialog
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on 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);
Pulang pergi
newDialogAction()
Membuat DialogAction
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on 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);
Pulang pergi
DialogAction
— DialogAction
kosong.
newDivider()
Membuat Divider
baru. Contoh berikut membuat kartu sederhana dengan 2 paragraf
yang dipisahkan oleh pemisah.
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; }
Pulang pergi
Divider
— Pembagi.
newDriveItemsSelectedActionResponseBuilder()
Membuat DriveItemsSelectedActionResponseBuilder
baru.
Pulang pergi
DriveItemsSelectedActionResponseBuilder
— DriveItemsSelectedActionResponseBuilder
kosong.
newEditorFileScopeActionResponseBuilder()
Membuat EditorFileScopeActionResponseBuilder
baru.
Pulang pergi
EditorFileScopeActionResponseBuilder
— EditorFileScopeActionResponseBuilder
kosong.
newImageButton()
newImageComponent()
newImageCropStyle()
newLinkPreview()
Membuat LinkPreview
baru.
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');
Pulang pergi
LinkPreview
— LinkPreview kosong.
newMaterialIcon()
Membuat MaterialIcon
baru.
Tersedia untuk aplikasi Google Chat dan Add-on 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();
Pulang pergi
MaterialIcon
— MaterialIcon kosong.
newNotification()
newOverflowMenu()
Membuat OverflowMenu
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on Google Workspace.
const overflowMenuItem = CardService.newOverflowMenuItem(); // Finish building the overflow menu item... const overflowMenu = CardService.newOverflowMenu().addMenuItem(overflowMenuItem);
Pulang pergi
OverflowMenu
— OverflowMenu kosong.
newOverflowMenuItem()
Membuat OverflowMenuItem
baru.
Hanya tersedia untuk aplikasi Google Chat. Tidak tersedia untuk Add-on 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'));
Pulang pergi
OverflowMenuItem
— OverflowMenuItem kosong.
newSelectionInput()
newSuggestions()
newSuggestionsResponseBuilder()
Membuat SuggestionsResponseBuilder
baru.
Pulang pergi
SuggestionsResponseBuilder
— Builder SuggestionsResponse kosong.
newTextButton()
newTextParagraph()
newTimePicker()
newUniversalActionResponseBuilder()
Membuat UniversalActionResponseBuilder
baru.
Pulang pergi
UniversalActionResponseBuilder
— Builder UniversalActionResponse kosong.
newUpdateDraftActionResponseBuilder()
Membuat UpdateDraftActionResponseBuilder
baru.
Pulang pergi
UpdateDraftActionResponseBuilder
— UpdateDraftActionResponseBuilder kosong.
newUpdateDraftBccRecipientsAction()
Membuat UpdateDraftBccRecipientsAction
baru;
Pulang pergi
UpdateDraftBccRecipientsAction
— UpdateDraftBccRecipientsAction kosong.
newUpdateDraftBodyAction()
Membuat UpdateDraftBodyAction
baru.
Pulang pergi
UpdateDraftBodyAction
— UpdateDraftBodyAction kosong.
newUpdateDraftCcRecipientsAction()
Membuat UpdateDraftCcRecipientsAction
baru.
Pulang pergi
UpdateDraftCcRecipientsAction
— UpdateDraftCcRecipientsAction Kosong.
newUpdateDraftSubjectAction()
Membuat UpdateDraftSubjectAction
baru.
Pulang pergi
UpdateDraftSubjectAction
— UpdateDraftSubjectAction kosong.
newUpdateDraftToRecipientsAction()
Membuat UpdateDraftToRecipientsAction
baru.
Pulang pergi
UpdateDraftToRecipientsAction
— UpdateDraftToRecipientsAction kosong.
newValidation()
Membuat Validation
baru.
Tersedia untuk aplikasi Google Chat dan Add-on Google Workspace.
const validation = CardService.newValidation().setCharacterLimit(5).setInputType( CardService.InputType.EMAIL);
Pulang pergi
Validation
— Validasi kosong.