CardService memberikan kemampuan untuk membuat kartu generik yang digunakan di berbagai layanan Google produk ekstensibilitas, seperti Add-on Google Workspace.
Berikut adalah contoh kartu add-on.
return CardService.newCardBuilder() .setHeader(CardService.newCardHeader().setTitle("CardTitle")) .build();
Atau, Anda dapat mengembalikan beberapa Kartu seperti berikut:
return [ CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), CardService.newCardBuilder().build() ]
Berikut 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 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 . |
ComposedEmailType | ComposedEmailType | Enumerasi ComposedEmailType . |
ContentType | ContentType | Enumerasi ContentType . |
GridItemLayout | GridItemLayout | Enumerasi GridItemLayout . |
HorizontalAlignment | HorizontalAlignment | Enumerasi HorizontalAlignment . |
Icon | Icon | Enumerasi Icon . |
ImageCropType | ImageCropType | Enumerasi ImageCropType . |
ImageStyle | ImageStyle | Enumerasi ImageStyle . |
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 pengidentifikasi unik untuk sebuah 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.
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);
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(column) .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 sebuah pemisah.
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; }
Pulang pergi
Divider
— Pemisah.
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.
newNotification()
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.