Class ChatResponseBuilder

ChatResponseBuilder

Un generatore di ChatResponse oggetti.

Disponibile solo per le app Google Chat. Non disponibile per i componenti aggiuntivi di 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();

Metodi

MetodoTipo restituitoBreve descrizione
addCardsV2(cardWithId)ChatResponseBuilderImposta il campo della scheda del messaggio.
build()ChatResponseCrea la risposta dell'azione attuale e la convalida.
setActionResponse(actionResponse)ChatResponseBuilderImposta il campo di risposta dell'azione del messaggio.
setText(text)ChatResponseBuilderImposta il testo del messaggio di Chat.

Documentazione dettagliata

addCardsV2(cardWithId)

Imposta il campo della scheda del messaggio. Viene utilizzato per inviare una scheda in un messaggio di Google Chat. Ogni scheda è associata a un ID univoco. Devi creare l'oggetto CardWithId e utilizzarlo con questo metodo.

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

Parametri

NomeTipoDescrizione
cardWithIdCardWithIdIl CardWithId da utilizzare.

Ritorni

ChatResponseBuilder: questo oggetto per il concatenamento.


build()

Crea la risposta dell'azione attuale e la convalida.

Ritorni

ChatResponse: una ChatResponse convalidata.


setActionResponse(actionResponse)

Imposta il campo di risposta dell'azione del messaggio.

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

Parametri

NomeTipoDescrizione
actionResponseChatActionResponseIl ChatActionResponse da utilizzare.

Ritorni

ChatResponseBuilder: questo oggetto per il concatenamento.


setText(text)

Imposta il testo del messaggio di Chat.

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

Parametri

NomeTipoDescrizione
textStringIl testo da utilizzare.

Ritorni

ChatResponseBuilder: questo oggetto per il concatenamento.