Class ChatResponseBuilder

ChatResponseBuilder

Compilateur pour les objets ChatResponse.

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()
                 .setName('Card name')
                 .setHeader(CardService.newCardHeader().setTitle('Card title'))
                 .addSection(cardSection)
                 .build();

const cardWithId =
    CardService.newCardWithId().setCardId('card_id').setCard(card);

const chatResponse = CardService.newChatResponseBuilder()
                         .addCardsV2(cardWithId)
                         .setText('Example text')
                         .build();

Méthodes

MéthodeType renvoyéBrève description
addCardsV2(cardWithId)ChatResponseBuilderDéfinit le champ de carte du message.
build()ChatResponseCrée la réponse d'action actuelle et la valide.
setActionResponse(actionResponse)ChatResponseBuilderDéfinit le champ de réponse d'action du message.
setText(text)ChatResponseBuilderDéfinit le texte du message Chat.

Documentation détaillée

addCardsV2(cardWithId)

Définit le champ de carte du message. Cette méthode permet d'envoyer une carte dans un message Google Chat. Chaque carte est associée à un ID unique. L'objet CardWithId doit être créé et utilisé avec cette méthode.

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

Paramètres

NomTypeDescription
cardWithIdCardWithIdLe CardWithId à utiliser.

Renvois

ChatResponseBuilder : cet objet, pour l'association en chaîne.


build()

Crée la réponse d'action actuelle et la valide.

Renvois

ChatResponse : réponse Chat validée.


setActionResponse(actionResponse)

Définit le champ de réponse d'action du message.

// Build the card.
const card = CardService.newCardBuilder()
                 .setHeader(CardService.newCardHeader().setTitle('card title'))
                 .build();

// Creates the dialog.
const dialog = CardService.newDialog().setBody(card);

// Creates the dialog action.
const dialogAction = CardService.newDialogAction().setDialog(dialog);

// Creates the action response and sets the type to DIALOG.
const actionResponse = CardService.newChatActionResponse()
                           .setDialogAction(dialogAction)
                           .setResponseType(CardService.Type.DIALOG);

// Creates the Chat response and sets the action response.
const chatResponse = CardService.newChatResponseBuilder()
                         .setActionResponse(actionResponse)
                         .build();

Paramètres

NomTypeDescription
actionResponseChatActionResponseLe ChatActionResponse à utiliser.

Renvois

ChatResponseBuilder : cet objet, pour l'association en chaîne.


setText(text)

Définit le texte du message Chat.

const chatResponse =
    CardService.newChatResponseBuilder().setText('Example text').build();

Paramètres

NomTypeDescription
textStringLe texte à utiliser.

Renvois

ChatResponseBuilder : cet objet, pour l'association en chaîne.