A builder for ChatResponse
objects.
Only available for Google Chat apps. Not available for Google Workspace Add-ons.
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();
Methods
Method | Return type | Brief description |
---|---|---|
ChatResponseBuilder
|
Sets the card field of the message. | |
ChatResponse
|
Builds the current action response and validates it. | |
ChatResponseBuilder
|
Sets the action response field of the message. | |
ChatResponseBuilder
|
Sets 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.
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();
Parameters
Name | Type | Description |
---|---|---|
cardWithId
|
CardWithId
|
The 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. 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();
Parameters
Name | Type | Description |
---|---|---|
actionResponse
|
ChatActionResponse
|
The ChatActionResponse
to use. |
Return
ChatResponseBuilder
— This object, for chaining.
setText(text)
Sets the text of the Chat message.
const chatResponse = CardService.newChatResponseBuilder() .setText('Example text') .build();
Parameters
Name | Type | Description |
---|---|---|
text
|
String
|
The text to use. |
Return
ChatResponseBuilder
— This object, for chaining.