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

ตัวอย่างการ์ดแอปแชท

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 ใหม่

เอกสารโดยละเอียด

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 — AuthorizationException


newBorderStyle()

สร้าง BorderStyle ใหม่

รีเทิร์น

BorderStyle — รูปแบบเส้นขอบที่ว่างเปล่า


newButtonSet()

สร้าง ButtonSet ใหม่

รีเทิร์น

ButtonSet — ButtonSet เปล่า


newCalendarEventActionResponseBuilder()

สร้าง CalendarEventActionResponseBuilder ใหม่

รีเทิร์น

CalendarEventActionResponseBuilderCalendarEventActionResponseBuilder ว่างเปล่า


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 — DateTimeChooseer ที่ว่างเปล่า


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

สร้าง DriveItemsSelectedActionResponseBuilder ใหม่

รีเทิร์น

DriveItemsSelectedActionResponseBuilderDriveItemsSelectedActionResponseBuilder ว่างเปล่า


newEditorFileScopeActionResponseBuilder()

สร้าง EditorFileScopeActionResponseBuilder ใหม่

รีเทิร์น

EditorFileScopeActionResponseBuilderEditorFileScopeActionResponseBuilder ว่างเปล่า


newFixedFooter()

สร้าง FixedFooter ใหม่

รีเทิร์น

FixedFooter —FixFooter ที่ไม่มีข้อมูล


newGrid()

สร้าง Grid ใหม่

รีเทิร์น

Grid — ตารางกริดว่างเปล่า


newGridItem()

สร้าง GridItem ใหม่

รีเทิร์น

GridItem — GridItem ที่ว่างเปล่า


newIconImage()

สร้าง IconImage ใหม่

รีเทิร์น

IconImage — รูปภาพไอคอนว่างเปล่า


newImage()

สร้าง Image ใหม่

รีเทิร์น

Image — รูปภาพว่างเปล่า


newImageButton()

สร้าง ImageButton ใหม่

รีเทิร์น

ImageButton — ปุ่มรูปภาพที่ว่างเปล่า


newImageComponent()

สร้าง ImageComponent ใหม่

รีเทิร์น

ImageComponent — คอมโพเนนต์รูปภาพที่ว่างเปล่า


newImageCropStyle()

สร้าง ImageCropStyle ใหม่

รีเทิร์น

ImageCropStyle — ImageCropStyle ที่ว่างเปล่า


newKeyValue()

สร้าง 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 — ค่า SelectionIn ว่างเปล่า


newSuggestions()

สร้าง Suggestions ใหม่

รีเทิร์น

Suggestions — คำแนะนำที่ว่างเปล่า


newSuggestionsResponseBuilder()

สร้าง SuggestionsResponseBuilder ใหม่

รีเทิร์น

SuggestionsResponseBuilder — เครื่องมือสร้าง FAQsResponse ที่ว่างเปล่า


newSwitch()

สร้าง Switch ใหม่

รีเทิร์น

Switch — Switch ที่ว่างเปล่า


newTextButton()

สร้าง TextButton ใหม่

รีเทิร์น

TextButton — ปุ่มข้อความที่ว่างเปล่า


newTextInput()

สร้าง TextInput ใหม่

รีเทิร์น

TextInput — TextInput ที่ว่างเปล่า


newTextParagraph()

สร้าง TextParagraph ใหม่

รีเทิร์น

TextParagraph — ย่อหน้าข้อความที่ว่างเปล่า


newTimePicker()

สร้าง 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 ที่ว่างเปล่า