ChatResponse 物件的建構工具。
僅適用於 Google Chat 擴充應用程式。不適用於 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();
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
add | Chat | 設定訊息的資訊卡欄位。 |
build() | Chat | 建構並驗證目前動作的回覆。 |
set | Chat | 設定訊息的動作回應欄位。 |
set | Chat | 設定 Chat 訊息的文字。 |
內容詳盡的說明文件
addCardsV2(cardWithId)
設定訊息的資訊卡欄位。用於在 Google Chat 訊息中傳送資訊卡。每張卡片都與專屬 ID 相關聯,應建構 CardWithId 物件並搭配這個方法使用。
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();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
card | Card | 要使用的 Card。 |
回攻員
ChatResponseBuilder - 這個物件,用於鏈結。
build()
setActionResponse(actionResponse)
設定訊息的動作回應欄位。
// 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();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
action | Chat | 要使用的 Chat。 |
回攻員
ChatResponseBuilder - 這個物件,用於鏈結。
setText(text)
設定 Chat 訊息的文字。
const chatResponse = CardService.newChatResponseBuilder().setText('Example text').build();
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 要使用的文字。 |
回攻員
ChatResponseBuilder - 這個物件,用於鏈結。