Class CardService

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.

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

מאפיינים

נכססוגתיאור
BorderTypeBorderTypeהספירה BorderType.
ComposedEmailTypeComposedEmailTypeהספירה ComposedEmailType.
ContentTypeContentTypeהספירה ContentType.
GridItemLayoutGridItemLayoutהספירה GridItemLayout.
HorizontalAlignmentHorizontalAlignmentהספירה HorizontalAlignment.
IconIconהספירה Icon.
ImageCropTypeImageCropTypeהספירה ImageCropType.
ImageStyleImageStyleהספירה ImageStyle.
LoadIndicatorLoadIndicatorהספירה LoadIndicator.
OnCloseOnCloseהספירה OnClose.
OpenAsOpenAsהספירה OpenAs.
SelectionInputTypeSelectionInputTypeהספירה SelectionInputType.
TextButtonStyleTextButtonStyleהספירה TextButtonStyle.
UpdateDraftBodyTypeUpdateDraftBodyTypeהספירה 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 חדש.
newValidation()Validationיצירת Validation חדש.

מסמכי תיעוד מפורטים

newAction()

יצירת Action חדש.

חזרה

Action – פעולה ריקה.


newActionResponseBuilder()

יצירת ActionResponseBuilder חדש.

חזרה

ActionResponseBuilder — כלי לפיתוח פעולות (ActionResponse) ריק.


newActionStatus()

יצירת ActionStatus חדש.

האפשרות הזו זמינה רק באפליקציות של Google Chat. לא זמינה לתוספים ל-Google Workspace.

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

חזרה

ActionStatus – ערך ActionStatus ריק.


newAttachment()

יצירת Attachment חדש.

חזרה

Attachment – קובץ מצורף ריק.


newAuthorizationAction()

יצירת AuthorizationAction חדש.

חזרה

AuthorizationAction – AuthorizationAction ריק.


newAuthorizationException()

יצירת AuthorizationException חדש.

חזרה

AuthorizationException – אופציה Authorization מפרסמים ריקה.


newBorderStyle()

יצירת BorderStyle חדש.

חזרה

BorderStyle — BorderStyle ריק.


newButtonSet()

יצירת ButtonSet חדש.

חזרה

ButtonSet – buttonSet ריק.


newCalendarEventActionResponseBuilder()


newCardAction()

יצירת CardAction חדש.

חזרה

CardAction – פעולת CardAction ריקה.


newCardBuilder()

יצירת CardBuilder חדש.

חזרה

CardBuilder – הכלי ליצירת כרטיסים ריק.


newCardHeader()

יצירת CardHeader חדש.

חזרה

CardHeader – כותרת כרטיס ריקה.


newCardSection()

יצירת CardSection חדש.

חזרה

CardSection – קטע כרטיס ריק.


newCardWithId()

יצירת CardWithId חדש. הכרטיס הזה משמש לשליחת כרטיס בהודעות ב-Google Chat. מזהה הכרטיס הוא מזהה ייחודי של כרטיס בהודעה כששולחים כמה כרטיסים.

האפשרות הזו זמינה רק באפליקציות של Google Chat. לא זמינה לתוספים ל-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);

חזרה

CardWithIdCardWithId ריק.


newChatActionResponse()

יצירת ChatActionResponse חדש.

האפשרות הזו זמינה רק באפליקציות של Google Chat. לא זמינה לתוספים ל-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);

חזרה

ChatActionResponseChatActionResponse ריק.


newChatResponseBuilder()

יצירת ChatResponseBuilder חדש.

האפשרות הזו זמינה רק באפליקציות של Google Chat. לא זמינה לתוספים ל-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 — בורר התאריך ריק.


newDateTimePicker()

יצירת DateTimePicker חדש.

חזרה

DateTimePicker – השדה DateTimePicker (תאריך היעד) ריק.


newDecoratedText()

יצירת DecoratedText חדש.

חזרה

DecoratedText – טקסט מעוצב ריק.


newDialog()

יצירת Dialog חדש.

האפשרות הזו זמינה רק באפליקציות של Google Chat. לא זמינה לתוספים ל-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);

חזרה

DialogDialog ריק.


newDialogAction()

יצירת DialogAction חדש.

האפשרות הזו זמינה רק באפליקציות של Google Chat. לא זמינה לתוספים ל-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)

חזרה

DialogActionDialogAction ריק.


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


newFixedFooter()

יצירת FixedFooter חדש.

חזרה

FixedFooter — ערך FixedFooter ריק.


newGrid()

יצירת Grid חדש.

חזרה

Grid — רשת ריקה.


newGridItem()

יצירת GridItem חדש.

חזרה

GridItem – פריט רשת ריק.


newIconImage()

יצירת IconImage חדש.

חזרה

IconImage – תמונת סמל ריקה.


newImage()

יצירת Image חדש.

חזרה

Image – תמונה ריקה.


newImageButton()

יצירת ImageButton חדש.

חזרה

ImageButton – לחצן תמונה ריק.


newImageComponent()

יצירת ImageComponent חדש.

חזרה

ImageComponent – רכיב Imageרכיב ריק.


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 – תצוגה מקדימה ריקה של קישור.


newNavigation()

יצירת Navigation חדש.

חזרה

Navigation – ניווט ריק.


newNotification()

יצירת Notification חדש.

חזרה

Notification – התראה ריקה.


יצירת OpenLink חדש.

חזרה

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 — יוצר UniversalActionResponse ריק.


newUpdateDraftActionResponseBuilder()

יצירת UpdateDraftActionResponseBuilder חדש.

חזרה

UpdateDraftActionResponseBuilder — קובץ UpdateActionResponseBuilder ריק.


newUpdateDraftBccRecipientsAction()

יצירת UpdateDraftBccRecipientsAction חדש;

חזרה

UpdateDraftBccRecipientsAction - ערך UpdateBccRecipientsAction ריק.


newUpdateDraftBodyAction()

יצירת UpdateDraftBodyAction חדש.

חזרה

UpdateDraftBodyAction – UpdateDraftBodyAction ריק.


newUpdateDraftCcRecipientsAction()

יצירת UpdateDraftCcRecipientsAction חדש.

חזרה

UpdateDraftCcRecipientsAction — עדכון טיוטה CcRecipientsAction ריק.


newUpdateDraftSubjectAction()

יצירת UpdateDraftSubjectAction חדש.

חזרה

UpdateDraftSubjectAction — השדה UpdateDraftSubjectAction ריק.


newUpdateDraftToRecipientsAction()

יצירת UpdateDraftToRecipientsAction חדש.

חזרה

UpdateDraftToRecipientsAction — ערך UpdateToRecipientsAction ריק.


newValidation()

יצירת Validation חדש.

רק באפליקציות של Google Chat ובתוספים ל-Google Workspace.

const validation = CardService.newValidation()
    .setCharacterLimit(5)
    .setInputType(CardService.InputType.EMAIL);

חזרה

Validation – אימות ריק.