Class CardService

CardService

CardService permet de créer des cartes génériques utilisées dans différents produits d'extensibilité Google, tels que les modules complémentaires Google Workspace.

Vous trouverez ci-dessous un exemple de fiche de modules complémentaires.

return CardService.newCardBuilder()
         .setHeader(CardService.newCardHeader().setTitle("CardTitle"))
         .build();

Vous pouvez également renvoyer plusieurs cartes comme suit:

return [
  CardService.newCardBuilder().build(),
  CardService.newCardBuilder().build(),
  CardService.newCardBuilder().build()
]

Voici comment définir une fiche avec un en-tête, du texte, une image et un élément de menu:

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

Exemple pour une fiche "Applications de 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();

Propriétés

PropriétéTypeDescription
BorderTypeBorderTypeÉnumération BorderType.
ComposedEmailTypeComposedEmailTypeÉnumération ComposedEmailType.
ContentTypeContentTypeÉnumération ContentType.
GridItemLayoutGridItemLayoutÉnumération GridItemLayout.
HorizontalAlignmentHorizontalAlignmentÉnumération HorizontalAlignment.
IconIconÉnumération Icon.
ImageCropTypeImageCropTypeÉnumération ImageCropType.
ImageStyleImageStyleÉnumération ImageStyle.
LoadIndicatorLoadIndicatorÉnumération LoadIndicator.
OnCloseOnCloseÉnumération OnClose.
OpenAsOpenAsÉnumération OpenAs.
SelectionInputTypeSelectionInputTypeÉnumération SelectionInputType.
TextButtonStyleTextButtonStyleÉnumération TextButtonStyle.
UpdateDraftBodyTypeUpdateDraftBodyTypeÉnumération UpdateDraftBodyType.

Méthodes

MéthodeType renvoyéBrève description
newAction()Actioncrée un objet Action ;
newActionResponseBuilder()ActionResponseBuildercrée un objet ActionResponseBuilder ;
newActionStatus()ActionStatuscrée un objet ActionStatus ;
newAttachment()Attachmentcrée un objet Attachment ;
newAuthorizationAction()AuthorizationActioncrée un objet AuthorizationAction ;
newAuthorizationException()AuthorizationExceptioncrée un objet AuthorizationException ;
newBorderStyle()BorderStylecrée un objet BorderStyle ;
newButtonSet()ButtonSetcrée un objet ButtonSet ;
newCalendarEventActionResponseBuilder()CalendarEventActionResponseBuildercrée un objet CalendarEventActionResponseBuilder ;
newCardAction()CardActioncrée un objet CardAction ;
newCardBuilder()CardBuildercrée un objet CardBuilder ;
newCardHeader()CardHeadercrée un objet CardHeader ;
newCardSection()CardSectioncrée un objet CardSection ;
newCardWithId()CardWithIdcrée un objet CardWithId ;
newChatActionResponse()ChatActionResponsecrée un objet ChatActionResponse ;
newChatResponseBuilder()ChatResponseBuildercrée un objet ChatResponseBuilder ;
newComposeActionResponseBuilder()ComposeActionResponseBuildercrée un objet ComposeActionResponseBuilder ;
newDatePicker()DatePickercrée un objet DatePicker ;
newDateTimePicker()DateTimePickercrée un objet DateTimePicker ;
newDecoratedText()DecoratedTextcrée un objet DecoratedText ;
newDialog()Dialogcrée un objet Dialog ;
newDialogAction()DialogActioncrée un objet DialogAction ;
newDivider()Dividercrée un objet Divider ;
newDriveItemsSelectedActionResponseBuilder()DriveItemsSelectedActionResponseBuildercrée un objet DriveItemsSelectedActionResponseBuilder ;
newEditorFileScopeActionResponseBuilder()EditorFileScopeActionResponseBuildercrée un objet EditorFileScopeActionResponseBuilder ;
newFixedFooter()FixedFootercrée un objet FixedFooter ;
newGrid()Gridcrée un objet Grid ;
newGridItem()GridItemcrée un objet GridItem ;
newIconImage()IconImagecrée un objet IconImage ;
newImage()Imagecrée un objet Image ;
newImageButton()ImageButtoncrée un objet ImageButton ;
newImageComponent()ImageComponentcrée un objet ImageComponent ;
newImageCropStyle()ImageCropStylecrée un objet ImageCropStyle ;
newKeyValue()KeyValuecrée un objet KeyValue ;
newLinkPreview()LinkPreviewcrée un objet LinkPreview ;
newNavigation()Navigationcrée un objet Navigation ;
newNotification()Notificationcrée un objet Notification ;
newOpenLink()OpenLinkcrée un objet OpenLink ;
newSelectionInput()SelectionInputcrée un objet SelectionInput ;
newSuggestions()Suggestionscrée un objet Suggestions ;
newSuggestionsResponseBuilder()SuggestionsResponseBuildercrée un objet SuggestionsResponseBuilder ;
newSwitch()Switchcrée un objet Switch ;
newTextButton()TextButtoncrée un objet TextButton ;
newTextInput()TextInputcrée un objet TextInput ;
newTextParagraph()TextParagraphcrée un objet TextParagraph ;
newTimePicker()TimePickercrée un objet TimePicker ;
newUniversalActionResponseBuilder()UniversalActionResponseBuildercrée un objet UniversalActionResponseBuilder ;
newUpdateDraftActionResponseBuilder()UpdateDraftActionResponseBuildercrée un objet UpdateDraftActionResponseBuilder ;
newUpdateDraftBccRecipientsAction()UpdateDraftBccRecipientsActioncrée un objet UpdateDraftBccRecipientsAction ;
newUpdateDraftBodyAction()UpdateDraftBodyActioncrée un objet UpdateDraftBodyAction ;
newUpdateDraftCcRecipientsAction()UpdateDraftCcRecipientsActioncrée un objet UpdateDraftCcRecipientsAction ;
newUpdateDraftSubjectAction()UpdateDraftSubjectActioncrée un objet UpdateDraftSubjectAction ;
newUpdateDraftToRecipientsAction()UpdateDraftToRecipientsActioncrée un objet UpdateDraftToRecipientsAction ;

Documentation détaillée

newAction()

crée un objet Action ;

Renvois

Action : action vide.


newActionResponseBuilder()

crée un objet ActionResponseBuilder ;

Renvois

ActionResponseBuilder : compilateur ActionResponse vide.


newActionStatus()

crée un objet ActionStatus ;

Disponible uniquement pour les applications Google Chat. Non disponible pour les modules complémentaires Google Workspace.

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

Renvois

ActionStatus : un ActionStatus vide.


newAttachment()

crée un objet Attachment ;

Renvois

Attachment : pièce jointe vide


newAuthorizationAction()

crée un objet AuthorizationAction ;

Renvois

AuthorizationAction : une AuthorizationAction vide.


newAuthorizationException()

crée un objet AuthorizationException ;

Renvois

AuthorizationException : une valeur AuthorizationException vide.


newBorderStyle()

crée un objet BorderStyle ;

Renvois

BorderStyle : BorderStyle vide.


newButtonSet()

crée un objet ButtonSet ;

Renvois

ButtonSet : un ButtonSet vide.


newCalendarEventActionResponseBuilder()


newCardAction()

crée un objet CardAction ;

Renvois

CardAction : une CardAction vide.


newCardBuilder()

crée un objet CardBuilder ;

Renvois

CardBuilder : générateur de cartes vide.


newCardHeader()

crée un objet CardHeader ;

Renvois

CardHeader : un CardHeader vide.


newCardSection()

crée un objet CardSection ;

Renvois

CardSection : une CardSection vide.


newCardWithId()

crée un objet CardWithId ; Il permet d'envoyer une carte dans un message Google Chat. L'ID de carte est un identifiant unique associé à une carte dans un message lors de l'envoi de plusieurs cartes.

Disponible uniquement pour les applications Google Chat. Non disponible pour les modules complémentaires 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);

Renvois

CardWithId : CardWithId vide.


newChatActionResponse()

crée un objet ChatActionResponse ;

Disponible uniquement pour les applications Google Chat. Non disponible pour les modules complémentaires 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);

Renvois

ChatActionResponse : ChatActionResponse vide.


newChatResponseBuilder()

crée un objet ChatResponseBuilder ;

Disponible uniquement pour les applications Google Chat. Non disponible pour les modules complémentaires 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();

Renvois

ChatResponseBuilder : ChatResponseBuilder vide.


newComposeActionResponseBuilder()

crée un objet ComposeActionResponseBuilder ;

Renvois

ComposeActionResponseBuilder : compilateur ComposeActionResponse vide.


newDatePicker()

crée un objet DatePicker ;

Renvois

DatePicker : sélecteur de date vide.


newDateTimePicker()

crée un objet DateTimePicker ;

Renvois

DateTimePicker : sélecteur de date et heure vide.


newDecoratedText()

crée un objet DecoratedText ;

Renvois

DecoratedText : Élément DecoratedText vide.


newDialog()

crée un objet Dialog ;

Disponible uniquement pour les applications Google Chat. Non disponible pour les modules complémentaires 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);

Renvois

Dialog : Dialog vide.


newDialogAction()

crée un objet DialogAction ;

Disponible uniquement pour les applications Google Chat. Non disponible pour les modules complémentaires 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)

Renvois

DialogAction : DialogAction vide.


newDivider()

crée un objet Divider ; L'exemple suivant crée une fiche simple avec deux paragraphes séparés par un séparateur.

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

Renvois

Divider : séparateur.


newDriveItemsSelectedActionResponseBuilder()


newEditorFileScopeActionResponseBuilder()


newFixedFooter()

crée un objet FixedFooter ;

Renvois

FixedFooter : un pied de page statique vide.


newGrid()

crée un objet Grid ;

Renvois

Grid : grille vide.


newGridItem()

crée un objet GridItem ;

Renvois

GridItem : un élément GridItem vide.


newIconImage()

crée un objet IconImage ;

Renvois

IconImage : image d'icône vide.


newImage()

crée un objet Image ;

Renvois

Image : image vide.


newImageButton()

crée un objet ImageButton ;

Renvois

ImageButton : un élément ImageButton vide.


newImageComponent()

crée un objet ImageComponent ;

Renvois

ImageComponent : ImageComponent vide.


newImageCropStyle()

crée un objet ImageCropStyle ;

Renvois

ImageCropStyle : Imagecadre de style de recadrage vide.


newKeyValue()

crée un objet KeyValue ;

Renvois

KeyValue : clé-valeur vide.


newLinkPreview()

crée un objet 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');

Renvois

LinkPreview : un LinkPreview vide.


newNavigation()

crée un objet Navigation ;

Renvois

Navigation : navigation vide.


newNotification()

crée un objet Notification ;

Renvois

Notification : notification vide.


crée un objet OpenLink ;

Renvois

OpenLink : un OpenLink vide.


newSelectionInput()

crée un objet SelectionInput ;

Renvois

SelectionInput : SelectionInput vide.


newSuggestions()

crée un objet Suggestions ;

Renvois

Suggestions : suggestion vide.


newSuggestionsResponseBuilder()

crée un objet SuggestionsResponseBuilder ;

Renvois

SuggestionsResponseBuilder : compilateur SuggestionsResponse vide.


newSwitch()

crée un objet Switch ;

Renvois

Switch : commutateur vide.


newTextButton()

crée un objet TextButton ;

Renvois

TextButton : un TextButton vide.


newTextInput()

crée un objet TextInput ;

Renvois

TextInput : TextInput vide.


newTextParagraph()

crée un objet TextParagraph ;

Renvois

TextParagraph : un TextParagraph vide.


newTimePicker()

crée un objet TimePicker ;

Renvois

TimePicker : sélecteur de temps vide.


newUniversalActionResponseBuilder()

crée un objet UniversalActionResponseBuilder ;

Renvois

UniversalActionResponseBuilder : compilateur UniversalActionResponse vide.


newUpdateDraftActionResponseBuilder()

crée un objet UpdateDraftActionResponseBuilder ;

Renvois

UpdateDraftActionResponseBuilder : UpdateBrouillonActionResponseBuilder vide.


newUpdateDraftBccRecipientsAction()

crée un objet UpdateDraftBccRecipientsAction ;

Renvois

UpdateDraftBccRecipientsAction : une UpdateBrouillonBccRecipientsAction vide.


newUpdateDraftBodyAction()

crée un objet UpdateDraftBodyAction ;

Renvois

UpdateDraftBodyAction : UpdateBrouillonBodyAction vide.


newUpdateDraftCcRecipientsAction()

crée un objet UpdateDraftCcRecipientsAction ;

Renvois

UpdateDraftCcRecipientsAction : une action UpdateBrouillonCCRecipients vide.


newUpdateDraftSubjectAction()

crée un objet UpdateDraftSubjectAction ;

Renvois

UpdateDraftSubjectAction : UpdateBrouillonSubjectAction vide.


newUpdateDraftToRecipientsAction()

crée un objet UpdateDraftToRecipientsAction ;

Renvois

UpdateDraftToRecipientsAction : une UpdateBrouillonToRecipientsAction vide.