Layanan
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 |
---|---|---|
Border | Border | Enumerasi Border . |
Chip | Chip | Enumerasi Chip . |
Composed | Composed | Enumerasi Composed . |
Content | Content | Enumerasi Content . |
Grid | Grid | Enumerasi Grid . |
Horizontal | Horizontal | Enumerasi Horizontal . |
Icon | Icon | Enumerasi Icon . |
Image | Image | Enumerasi Image . |
Image | Image | Enumerasi Image . |
Image | Image | Enumerasi Image . |
Input | Input | Enumerasi Input . |
Load | Load | Enumerasi Load . |
On | On | Enumerasi On . |
Open | Open | Enumerasi Open . |
Selection | Selection | Enumerasi Selection . |
Text | Text | Enumerasi Text . |
Update | Update | Enumerasi Update . |
Metode
Dokumentasi mendetail
new Action Response Builder()
Membuat Action
baru.
Pulang pergi
Action
— Builder ActionResponse kosong.
new Action Status()
Membuat Action
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
Action
— ActionStatus kosong.
new Attachment()
new Authorization Action()
new Authorization Exception()
Membuat Authorization
baru.
Pulang pergi
Authorization
— AuthorizationException kosong.
new Border Style()
new Calendar Event Action Response Builder()
Membuat Calendar
baru.
Pulang pergi
Calendar
— Calendar
kosong.
new Card Action()
new Card Builder()
new Card Header()
new Card Section()
new Card With Id()
Membuat Card
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
Card
— Card
kosong.
new Chat Action Response()
Membuat Chat
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
Chat
— Chat
kosong.
new Chat Response Builder()
Membuat Chat
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
Chat
— ChatResponseBuilder kosong.
new Chip()
new Chip List()
Membuat Chip
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
Chip
— ChipList kosong.
new Collapse Control()
Membuat Collapse
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
Collapse
— CollapseControl kosong.
new Column()
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.
new Columns()
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.
new Compose Action Response Builder()
Membuat Compose
baru.
Pulang pergi
Compose
— Builder ComposeActionResponse kosong.
new Date Picker()
new Date Time Picker()
new Decorated Text()
new Dialog()
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
new Dialog Action()
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(); const dialog = CardService.newDialog().setBody(card); const dialogAction = CardService.newDialogAction().setDialog(dialog);
Pulang pergi
Dialog
— Dialog
kosong.
new Divider()
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.
new Drive Items Selected Action Response Builder()
Membuat Drive
baru.
Pulang pergi
Drive
— Drive
kosong.
new Editor File Scope Action Response Builder()
Membuat Editor
baru.
Pulang pergi
Editor
— Editor
kosong.
new Image Button()
new Image Component()
new Image Crop Style()
new Link Preview()
Membuat Link
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
Link
— LinkPreview kosong.
new Material Icon()
Membuat Material
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
Material
— MaterialIcon kosong.
new Notification()
new Overflow Menu()
Membuat Overflow
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
Overflow
— OverflowMenu kosong.
new Overflow Menu Item()
Membuat Overflow
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
Overflow
— OverflowMenuItem kosong.
new Selection Input()
new Suggestions()
new Suggestions Response Builder()
Membuat Suggestions
baru.
Pulang pergi
Suggestions
— Builder SuggestionsResponse kosong.
new Text Button()
new Text Paragraph()
new Time Picker()
new Universal Action Response Builder()
Membuat Universal
baru.
Pulang pergi
Universal
— Builder UniversalActionResponse kosong.
new Update Draft Action Response Builder()
Membuat Update
baru.
Pulang pergi
Update
— UpdateDraftActionResponseBuilder kosong.
new Update Draft Bcc Recipients Action()
Membuat Update
baru;
Pulang pergi
Update
— UpdateDraftBccRecipientsAction kosong.
new Update Draft Body Action()
Membuat Update
baru.
Pulang pergi
Update
— UpdateDraftBodyAction kosong.
new Update Draft Cc Recipients Action()
Membuat Update
baru.
Pulang pergi
Update
— UpdateDraftCcRecipientsAction Kosong.
new Update Draft Subject Action()
Membuat Update
baru.
Pulang pergi
Update
— UpdateDraftSubjectAction kosong.
new Update Draft To Recipients Action()
Membuat Update
baru.
Pulang pergi
Update
— UpdateDraftToRecipientsAction kosong.
new Validation()
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.