Class CardService

خدمات کارت

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 .

مواد و روش ها

روش نوع برگشت توضیح مختصر
newAction() Action یک Action جدید ایجاد می کند.
newActionResponseBuilder() ActionResponseBuilder یک ActionResponseBuilder جدید ایجاد می کند.
newActionStatus() ActionStatus یک ActionStatus جدید ایجاد می کند.
newAttachment() Attachment یک Attachment جدید ایجاد می کند.
newAuthorizationAction() AuthorizationAction یک AuthorizationAction جدید ایجاد می کند.
newAuthorizationException() AuthorizationException یک AuthorizationException جدید ایجاد می کند.
newBorderStyle() BorderStyle یک BorderStyle جدید ایجاد می کند.
newButtonSet() ButtonSet یک ButtonSet جدید ایجاد می کند.
newCalendarEventActionResponseBuilder() CalendarEventActionResponseBuilder یک CalendarEventActionResponseBuilder جدید ایجاد می کند.
newCardAction() CardAction یک CardAction جدید ایجاد می کند.
newCardBuilder() CardBuilder یک CardBuilder جدید ایجاد می کند.
newCardHeader() CardHeader یک CardHeader جدید ایجاد می کند.
newCardSection() CardSection یک CardSection جدید ایجاد می کند.
newCardWithId() CardWithId یک CardWithId جدید ایجاد می کند.
newChatActionResponse() ChatActionResponse یک ChatActionResponse جدید ایجاد می کند.
newChatResponseBuilder() ChatResponseBuilder یک ChatResponseBuilder جدید ایجاد می کند.
newColumn() Column یک Column جدید ایجاد می کند.
newColumns() Columns مجموعه جدیدی از Columns را ایجاد می کند.
newComposeActionResponseBuilder() ComposeActionResponseBuilder یک ComposeActionResponseBuilder جدید ایجاد می کند.
newDatePicker() DatePicker یک DatePicker جدید ایجاد می کند.
newDateTimePicker() DateTimePicker یک DateTimePicker جدید ایجاد می کند.
newDecoratedText() DecoratedText یک DecoratedText جدید ایجاد می کند.
newDialog() Dialog یک Dialog جدید ایجاد می کند.
newDialogAction() DialogAction یک DialogAction جدید ایجاد می کند.
newDivider() Divider یک Divider جدید ایجاد می کند.
newDriveItemsSelectedActionResponseBuilder() DriveItemsSelectedActionResponseBuilder یک DriveItemsSelectedActionResponseBuilder جدید ایجاد می کند.
newEditorFileScopeActionResponseBuilder() EditorFileScopeActionResponseBuilder یک EditorFileScopeActionResponseBuilder جدید ایجاد می کند.
newFixedFooter() FixedFooter یک FixedFooter جدید ایجاد می کند.
newGrid() Grid یک Grid جدید ایجاد می کند.
newGridItem() GridItem یک GridItem جدید ایجاد می کند.
newIconImage() IconImage یک IconImage جدید ایجاد می کند.
newImage() Image یک Image جدید ایجاد می کند.
newImageButton() ImageButton یک ImageButton جدید ایجاد می کند.
newImageComponent() ImageComponent یک ImageComponent جدید ایجاد می کند.
newImageCropStyle() ImageCropStyle یک ImageCropStyle جدید ایجاد می کند.
newKeyValue() KeyValue یک KeyValue جدید ایجاد می کند.
newLinkPreview() LinkPreview یک LinkPreview جدید ایجاد می کند.
newNavigation() Navigation یک Navigation جدید ایجاد می کند.
newNotification() Notification یک Notification جدید ایجاد می کند.
newOpenLink() OpenLink یک OpenLink جدید ایجاد می کند.
newSelectionInput() SelectionInput یک SelectionInput جدید ایجاد می کند.
newSuggestions() Suggestions یک Suggestions جدید ایجاد می کند.
newSuggestionsResponseBuilder() SuggestionsResponseBuilder یک SuggestionsResponseBuilder جدید ایجاد می کند.
newSwitch() Switch یک Switch جدید ایجاد می کند.
newTextButton() TextButton یک TextButton جدید ایجاد می کند.
newTextInput() TextInput یک TextInput جدید ایجاد می کند.
newTextParagraph() TextParagraph یک TextParagraph جدید ایجاد می کند.
newTimePicker() TimePicker یک TimePicker جدید ایجاد می کند.
newUniversalActionResponseBuilder() UniversalActionResponseBuilder یک UniversalActionResponseBuilder جدید ایجاد می کند.
newUpdateDraftActionResponseBuilder() UpdateDraftActionResponseBuilder یک UpdateDraftActionResponseBuilder جدید ایجاد می کند.
newUpdateDraftBccRecipientsAction() UpdateDraftBccRecipientsAction یک UpdateDraftBccRecipientsAction جدید ایجاد می کند.
newUpdateDraftBodyAction() UpdateDraftBodyAction یک UpdateDraftBodyAction جدید ایجاد می کند.
newUpdateDraftCcRecipientsAction() UpdateDraftCcRecipientsAction یک UpdateDraftCcRecipientsAction جدید ایجاد می کند.
newUpdateDraftSubjectAction() UpdateDraftSubjectAction یک UpdateDraftSubjectAction جدید ایجاد می کند.
newUpdateDraftToRecipientsAction() UpdateDraftToRecipientsAction یک UpdateDraftToRecipientsAction جدید ایجاد می کند.

مستندات دقیق

newAction()

یک Action جدید ایجاد می کند.

برگشت

Action - یک عمل خالی.


newActionResponseBuilder()

یک ActionResponseBuilder جدید ایجاد می کند.

برگشت

ActionResponseBuilder - سازنده ActionResponse خالی.


newActionStatus()

یک ActionStatus جدید ایجاد می کند.

فقط برای برنامه‌های گپ Google در دسترس است. برای افزونه‌های Google Workspace در دسترس نیست.

const actionStatus = CardService.newActionStatus()
    .setStatusCode(CardService.Status.OK)
    .setUserFacingMessage('Success');

برگشت

ActionStatus - یک ActionStatus خالی.


newAttachment()

یک Attachment جدید ایجاد می کند.

برگشت

Attachment - یک پیوست خالی.


newAuthorizationAction()

یک AuthorizationAction جدید ایجاد می کند.

برگشت

AuthorizationAction - یک AuthorizationAction خالی.


newAuthorizationException()

یک AuthorizationException جدید ایجاد می کند.

برگشت

AuthorizationException - یک AuthorizationException خالی.


newBorderStyle()

یک BorderStyle جدید ایجاد می کند.

برگشت

BorderStyle - یک BorderStyle خالی.


newButtonSet()

یک ButtonSet جدید ایجاد می کند.

برگشت

ButtonSet - یک ButtonSet خالی.


newCalendarEventActionResponseBuilder()

یک CalendarEventActionResponseBuilder جدید ایجاد می کند.

برگشت

CalendarEventActionResponseBuilder — یک CalendarEventActionResponseBuilder خالی.


newCardAction()

یک CardAction جدید ایجاد می کند.

برگشت

CardAction - یک CardAction خالی.


newCardBuilder()

یک CardBuilder جدید ایجاد می کند.

برگشت

CardBuilder - یک سازنده کارت خالی.


newCardHeader()

یک CardHeader جدید ایجاد می کند.

برگشت

CardHeader - یک CardHeader خالی.


newCardSection()

یک CardSection جدید ایجاد می کند.

برگشت

CardSection - یک CardSection خالی.


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()

یک DatePicker جدید ایجاد می کند.

برگشت

DatePicker - یک DatePicker خالی.


newDateTimePicker()

یک DateTimePicker جدید ایجاد می کند.

برگشت

DateTimePicker - یک DateTimePicker خالی.


newDecoratedText()

یک DecoratedText جدید ایجاد می کند.

برگشت

DecoratedText - یک DecoratedText خالی.


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);

برگشت

Dialog - یک Dialog خالی.


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()


newEditorFileScopeActionResponseBuilder()

یک EditorFileScopeActionResponseBuilder جدید ایجاد می کند.

برگشت

EditorFileScopeActionResponseBuilder — یک EditorFileScopeActionResponseBuilder خالی.


newFixedFooter()

یک FixedFooter جدید ایجاد می کند.

برگشت

FixedFooter - یک FixedFooter خالی.


newGrid()

یک Grid جدید ایجاد می کند.

برگشت

Grid - یک شبکه خالی.


newGridItem()

یک GridItem جدید ایجاد می کند.

برگشت

GridItem - یک GridItem خالی.


newIconImage()

یک IconImage جدید ایجاد می کند.

برگشت

IconImage - یک تصویر آیکون خالی.


newImage()

یک Image جدید ایجاد می کند.

برگشت

Image - یک تصویر خالی


newImageButton()

یک ImageButton جدید ایجاد می کند.

برگشت

ImageButton - یک ImageButton خالی.


newImageComponent()

یک ImageComponent جدید ایجاد می کند.

برگشت

ImageComponent - یک ImageComponent خالی.


newImageCropStyle()

یک ImageCropStyle جدید ایجاد می کند.

برگشت

ImageCropStyle - یک ImageCropStyle خالی.


newKeyValue()

یک KeyValue جدید ایجاد می کند.

برگشت

KeyValue - یک KeyValue خالی.


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 خالی.


newNavigation()

یک Navigation جدید ایجاد می کند.

برگشت

Navigation - یک ناوبری خالی.


newNotification()

یک Notification جدید ایجاد می کند.

برگشت

Notification - یک اعلان خالی.


یک OpenLink جدید ایجاد می کند.

برگشت

OpenLink - یک OpenLink خالی.


newSelectionInput()

یک SelectionInput جدید ایجاد می کند.

برگشت

SelectionInput - یک SelectionInput خالی.


newSuggestions()

یک Suggestions جدید ایجاد می کند.

برگشت

Suggestions - یک پیشنهاد خالی.


newSuggestionsResponseBuilder()

یک SuggestionsResponseBuilder جدید ایجاد می کند.

برگشت

SuggestionsResponseBuilder - سازنده SuggestionsResponse خالی.


newSwitch()

یک Switch جدید ایجاد می کند.

برگشت

Switch - یک سوئیچ خالی.


newTextButton()

یک TextButton جدید ایجاد می کند.

برگشت

TextButton - یک TextButton خالی.


newTextInput()

یک TextInput جدید ایجاد می کند.

برگشت

TextInput - یک TextInput خالی.


newTextParagraph()

یک TextParagraph جدید ایجاد می کند.

برگشت

TextParagraph - یک TextParagraph خالی.


newTimePicker()

یک TimePicker جدید ایجاد می کند.

برگشت

TimePicker - یک TimePicker خالی.


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 خالی.