A builder for Chat
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
Method | Return type | Brief description |
---|---|---|
add | Chat | Sets the card field of the message. |
build() | Chat | Builds the current action response and validates it. |
set | Chat | Sets the action response field of the message. |
set | Chat | 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, Card
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
Name | Type | Description |
---|---|---|
card | Card | The Card to use. |
Return
Chat
— This object, for chaining.
build()
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
Name | Type | Description |
---|---|---|
action | Chat | The Chat to use. |
Return
Chat
— This object, for chaining.
setText(text)
Sets the text of the Chat message.
constchatResponse=CardService.newChatResponseBuilder().setText('Example text').build();
Parameters
Name | Type | Description |
---|---|---|
text | String | The text to use. |
Return
Chat
— This object, for chaining.