Class CardService

CardService

CardService を使用すると、Google Workspace アドオンなどのさまざまな Google 拡張プロダクトで使用される汎用カードを作成できます。

アドオンカードのサンプルを以下に示します。

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

Properties

プロパティタイプ説明
BorderTypeBorderTypeBorderType 列挙型。
ComposedEmailTypeComposedEmailTypeComposedEmailType 列挙型。
ContentTypeContentTypeContentType 列挙型。
GridItemLayoutGridItemLayoutGridItemLayout 列挙型。
HorizontalAlignmentHorizontalAlignmentHorizontalAlignment 列挙型。
IconIconIcon 列挙型。
ImageCropTypeImageCropTypeImageCropType 列挙型。
ImageStyleImageStyleImageStyle 列挙型。
LoadIndicatorLoadIndicatorLoadIndicator 列挙型。
OnCloseOnCloseOnClose 列挙型。
OpenAsOpenAsOpenAs 列挙型。
SelectionInputTypeSelectionInputTypeSelectionInputType 列挙型。
TextButtonStyleTextButtonStyleTextButtonStyle 列挙型。
UpdateDraftBodyTypeUpdateDraftBodyTypeUpdateDraftBodyType 列挙型。

Methods

メソッド戻り値の型概要
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 を作成します。
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 - 空の BorderStyle。


newButtonSet()

新しい ButtonSet を作成します。

リターン

ButtonSet - 空の ButtonSet。


newCalendarEventActionResponseBuilder()


newCardAction()

新しい CardAction を作成します。

リターン

CardAction - 空の CardAction。


newCardBuilder()

新しい CardBuilder を作成します。

リターン

CardBuilder - 空のカードビルダー。


newCardHeader()

新しい CardHeader を作成します。

リターン

CardHeader - 空の CardHeader。


newCardSection()

新しい CardSection を作成します。

リターン

CardSection - 空の CardSection。


newCardWithId()

新しい CardWithId を作成します。Google Chat メッセージでカードを送信するために使用されます。カード ID は、複数のカードを送信する場合のメッセージでカードの一意の識別子です。

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

リターン

CardWithId - 空の CardWithId


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

リターン

ChatActionResponse - 空の ChatActionResponse


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。


newComposeActionResponseBuilder()

新しい ComposeActionResponseBuilder を作成します。

リターン

ComposeActionResponseBuilder - 空の ComposeActionResponse ビルダー。


newDatePicker()

新しい DatePicker を作成します。

リターン

DatePicker - 空の DatePicker。


newDateTimePicker()

新しい DateTimePicker を作成します。

リターン

DateTimePicker - 空の DateTimePicker。


newDecoratedText()

新しい DecoratedText を作成します。

リターン

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

リターン

Dialog - 空の Dialog


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)

リターン

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


newFixedFooter()

新しい FixedFooter を作成します。

リターン

FixedFooter - 空の ProtectedFooter。


newGrid()

新しい Grid を作成します。

リターン

Grid - 空のグリッド。


newGridItem()

新しい GridItem を作成します。

リターン

GridItem - 空の GridItem。


newIconImage()

新しい IconImage を作成します。

リターン

IconImage - 空のアイコン画像。


newImage()

新しい Image を作成します。

リターン

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 - 空の Navigation。


newNotification()

新しい Notification を作成します。

リターン

Notification - 空の通知。


新しい OpenLink を作成します。

リターン

OpenLink - 空の OpenLink。


newSelectionInput()

新しい SelectionInput を作成します。

リターン

SelectionInput - 空の SelectionInput。


newSuggestions()

新しい Suggestions を作成します。

リターン

Suggestions - 空の候補。


newSuggestionsResponseBuilder()

新しい SuggestionsResponseBuilder を作成します。

リターン

SuggestionsResponseBuilder - 空の SuggestionsResponse ビルダー。


newSwitch()

新しい Switch を作成します。

リターン

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。