Class ChatResponseBuilder

ChatResponseBuilder

A builder for ChatResponse objects.

Only available for Google Chat apps. Not available for Google Workspace add-ons.

constcardSection=CardService.newCardSection();cardSection.addWidget(CardService.newTextParagraph().setText('This is a text paragraph widget.'),);constcard=CardService.newCardBuilder().setName('Card name').setHeader(CardService.newCardHeader().setTitle('Card title')).addSection(cardSection).build();constcardWithId=CardService.newCardWithId().setCardId('card_id').setCard(card);constchatResponse=CardService.newChatResponseBuilder().addCardsV2(cardWithId).setText('Example text').build();

Methods

MethodReturn typeBrief description
addCardsV2(cardWithId)ChatResponseBuilderSets the card field of the message.
build()ChatResponseBuilds the current action response and validates it.
setActionResponse(actionResponse)ChatResponseBuilderSets the action response field of the message.
setText(text)ChatResponseBuilderSets the text of the Chat message.

Detailed documentation

addCardsV2(cardWithId)

Sets the card field of the message. This is used to send a card in a Google Chat message. Each card is associated with a unique id, CardWithId object should be built and be used with this method.

constcardSection=CardService.newCardSection();cardSection.addWidget(CardService.newTextParagraph().setText('This is a text paragraph widget.'),);constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('Card title')).addSection(cardSection).build();constcardWithId=CardService.newCardWithId().setCardId('card_id').setCard(card);constchatResponse=CardService.newChatResponseBuilder().addCardsV2(cardWithId).build();

Parameters

NameTypeDescription
cardWithIdCardWithIdThe CardWithId to use.

Return

ChatResponseBuilder — This object, for chaining.


build()

Builds the current action response and validates it.

Return

ChatResponse — A validated ChatResponse.


setActionResponse(actionResponse)

Sets the action response field of the message.

// Build the card.constcard=CardService.newCardBuilder().setHeader(CardService.newCardHeader().setTitle('card title')).build();// Creates the dialog.constdialog=CardService.newDialog().setBody(card);// Creates the dialog action.constdialogAction=CardService.newDialogAction().setDialog(dialog);// Creates the action response and sets the type to DIALOG.constactionResponse=CardService.newChatActionResponse().setDialogAction(dialogAction).setResponseType(CardService.Type.DIALOG);// Creates the Chat response and sets the action response.constchatResponse=CardService.newChatResponseBuilder().setActionResponse(actionResponse).build();

Parameters

NameTypeDescription
actionResponseChatActionResponseThe ChatActionResponse to use.

Return

ChatResponseBuilder — This object, for chaining.


setText(text)

Sets the text of the Chat message.

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

Parameters

NameTypeDescription
textStringThe text to use.

Return

ChatResponseBuilder — This object, for chaining.