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 - 此对象,用于链接。