Class ChatResponseBuilder

ChatResponseBuilder

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

方法

方法傳回類型簡短說明
addCardsV2(cardWithId)ChatResponseBuilder設定訊息的卡片欄位。
build()ChatResponse建構目前的動作回應並加以驗證。
setActionResponse(actionResponse)ChatResponseBuilder設定訊息的動作回應欄位。
setText(text)ChatResponseBuilder設定 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();

參數

名稱類型說明
cardWithIdCardWithId要使用的 CardWithId

回攻員

ChatResponseBuilder:這個物件用於鏈結。


build()

建構目前的動作回應並加以驗證。

回攻員

ChatResponse — 經過驗證的 ChatResponse。


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

參數

名稱類型說明
actionResponseChatActionResponse要使用的 ChatActionResponse

回攻員

ChatResponseBuilder:這個物件用於鏈結。


setText(text)

設定 Chat 訊息的文字。

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

參數

名稱類型說明
textString要使用的文字。

回攻員

ChatResponseBuilder:這個物件用於鏈結。