CardService امکان ایجاد کارتهای عمومی مورد استفاده در محصولات مختلف توسعهپذیری Google، مانند افزونههای Google Workspace را فراهم میکند.
در زیر یک نمونه برای کارت افزودنی است.
return CardService.newCardBuilder() .setHeader(CardService.newCardHeader().setTitle("CardTitle")) .build();
یا می توانید چندین کارت مانند این را برگردانید:
return [ CardService.newCardBuilder().build(), CardService.newCardBuilder().build(), CardService.newCardBuilder().build() ]
موارد زیر نشان می دهد که چگونه می توانید یک کارت را با سربرگ، متن، تصویر و آیتم منو تعریف کنید:
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(); }
نمونه کارت Chat Apps.
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();
خواص
ویژگی | تایپ کنید | شرح |
---|---|---|
BorderType | BorderType | شمارش BorderType . |
ComposedEmailType | ComposedEmailType | شمارش ComposedEmailType . |
ContentType | ContentType | شمارش ContentType . |
GridItemLayout | GridItemLayout | شمارش GridItemLayout . |
HorizontalAlignment | HorizontalAlignment | شمارش HorizontalAlignment . |
Icon | Icon | شمارش Icon |
ImageCropType | ImageCropType | شمارش ImageCropType . |
ImageStyle | ImageStyle | شمارش ImageStyle . |
LoadIndicator | LoadIndicator | شمارش LoadIndicator . |
OnClose | OnClose | شمارش OnClose . |
OpenAs | OpenAs | شمارش OpenAs . |
SelectionInputType | SelectionInputType | شمارش SelectionInputType . |
TextButtonStyle | TextButtonStyle | شمارش TextButtonStyle . |
UpdateDraftBodyType | UpdateDraftBodyType | شمارش UpdateDraftBodyType . |
مواد و روش ها
مستندات دقیق
newActionResponseBuilder()
یک ActionResponseBuilder
جدید ایجاد می کند.
برگشت
ActionResponseBuilder
- سازنده ActionResponse خالی.
newActionStatus()
یک ActionStatus
جدید ایجاد می کند.
فقط برای برنامههای گپ Google در دسترس است. برای افزونههای Google Workspace در دسترس نیست.
const actionStatus = CardService.newActionStatus() .setStatusCode(CardService.Status.OK) .setUserFacingMessage('Success');
برگشت
ActionStatus
- یک ActionStatus خالی.
newAttachment()
newAuthorizationAction()
newAuthorizationException()
یک AuthorizationException
جدید ایجاد می کند.
برگشت
AuthorizationException
- یک AuthorizationException خالی.
newBorderStyle()
newCalendarEventActionResponseBuilder()
یک CalendarEventActionResponseBuilder
جدید ایجاد می کند.
برگشت
CalendarEventActionResponseBuilder
— یک CalendarEventActionResponseBuilder
خالی.
newCardAction()
newCardBuilder()
newCardHeader()
newCardSection()
newCardWithId()
یک CardWithId
جدید ایجاد می کند. این برای ارسال کارت در پیام Google Chat استفاده می شود. شناسه کارت یک شناسه منحصر به فرد برای یک کارت در پیام هنگام ارسال چند کارت است.
فقط برای برنامههای گپ Google در دسترس است. برای افزونههای 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);
برگشت
CardWithId
- یک CardWithId
خالی.
newChatActionResponse()
یک ChatActionResponse
جدید ایجاد می کند.
فقط برای برنامههای گپ Google در دسترس است. برای افزونههای 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);
برگشت
ChatActionResponse
- یک ChatActionResponse
خالی.
newChatResponseBuilder()
یک ChatResponseBuilder
جدید ایجاد می کند.
فقط برای برنامههای گپ Google در دسترس است. برای افزونههای 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();
برگشت
ChatResponseBuilder
- یک ChatResponseBuilder خالی.
newColumn()
یک Column
جدید ایجاد می کند.
برای برنامههای Google Chat و افزونههای 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
- یک ستون خالی.
newColumns()
مجموعه جدیدی از Columns
را ایجاد می کند.
برای برنامههای Google Chat و افزونههای 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);
برگشت
Columns
- مجموعه ای خالی از ستون ها.
newComposeActionResponseBuilder()
یک ComposeActionResponseBuilder
جدید ایجاد می کند.
برگشت
ComposeActionResponseBuilder
- سازنده ComposeActionResponse خالی.
newDatePicker()
newDateTimePicker()
newDecoratedText()
newDialog()
یک Dialog
جدید ایجاد می کند.
فقط برای برنامههای گپ Google در دسترس است. برای افزونههای 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);
برگشت
newDialogAction()
یک DialogAction
جدید ایجاد می کند.
فقط برای برنامههای گپ Google در دسترس است. برای افزونههای 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)
برگشت
DialogAction
- یک DialogAction
خالی.
newDivider()
یک Divider
جدید ایجاد می کند. نمونه زیر یک کارت ساده با 2 پاراگراف جدا شده توسط یک تقسیم کننده می سازد.
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; }
برگشت
Divider
- تقسیم کننده.
newDriveItemsSelectedActionResponseBuilder()
یک DriveItemsSelectedActionResponseBuilder
جدید ایجاد می کند.
برگشت
DriveItemsSelectedActionResponseBuilder
— DriveItemsSelectedActionResponseBuilder
خالی.
newEditorFileScopeActionResponseBuilder()
یک EditorFileScopeActionResponseBuilder
جدید ایجاد می کند.
برگشت
EditorFileScopeActionResponseBuilder
— یک EditorFileScopeActionResponseBuilder
خالی.
newImageButton()
newImageComponent()
newImageCropStyle()
newLinkPreview()
یک LinkPreview
جدید ایجاد می کند.
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');
برگشت
LinkPreview
- یک LinkPreview خالی.
newNotification()
newSelectionInput()
newSuggestions()
newSuggestionsResponseBuilder()
یک SuggestionsResponseBuilder
جدید ایجاد می کند.
برگشت
SuggestionsResponseBuilder
- سازنده SuggestionsResponse خالی.
newTextButton()
newTextParagraph()
newTimePicker()
newUniversalActionResponseBuilder()
یک UniversalActionResponseBuilder
جدید ایجاد می کند.
برگشت
UniversalActionResponseBuilder
- سازنده خالی UniversalActionResponse.
newUpdateDraftActionResponseBuilder()
یک UpdateDraftActionResponseBuilder
جدید ایجاد می کند.
برگشت
UpdateDraftActionResponseBuilder
— یک UpdateDraftActionResponseBuilder خالی.
newUpdateDraftBccRecipientsAction()
یک UpdateDraftBccRecipientsAction
جدید ایجاد می کند.
برگشت
UpdateDraftBccRecipientsAction
— یک UpdateDraftBccRecipientsAction خالی.
newUpdateDraftBodyAction()
یک UpdateDraftBodyAction
جدید ایجاد می کند.
برگشت
UpdateDraftBodyAction
- یک UpdateDraftBodyAction خالی.
newUpdateDraftCcRecipientsAction()
یک UpdateDraftCcRecipientsAction
جدید ایجاد می کند.
برگشت
UpdateDraftCcRecipientsAction
— یک UpdateDraftCcRecipientsAction خالی.
newUpdateDraftSubjectAction()
یک UpdateDraftSubjectAction
جدید ایجاد می کند.
برگشت
UpdateDraftSubjectAction
— یک UpdateDraftSubjectAction خالی.
newUpdateDraftToRecipientsAction()
یک UpdateDraftToRecipientsAction
جدید ایجاد می کند.
برگشت
UpdateDraftToRecipientsAction
— یک UpdateDraftToRecipientsAction خالی.