Class ChatResponseBuilder

ChatResponseBuilder

Trình tạo cho các đối tượng ChatResponse.

Chỉ dành cho các ứng dụng Google Chat. Không sử dụng được với tiện ích bổ sung của 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();

Phương thức

Phương thứcKiểu dữ liệu trả vềMô tả ngắn
addCardsV2(cardWithId)ChatResponseBuilderĐặt trường thẻ của thông báo.
build()ChatResponseXây dựng phản hồi cho hành động hiện tại và xác thực hành động đó.
setActionResponse(actionResponse)ChatResponseBuilderĐặt trường phản hồi hành động của thông báo.
setText(text)ChatResponseBuilderĐặt nội dung của tin nhắn trên Chat.

Tài liệu chi tiết

addCardsV2(cardWithId)

Đặt trường thẻ của thông báo. Mã này được dùng để gửi thẻ trong tin nhắn trên Google Chat. Mỗi thẻ được liên kết với một mã nhận dạng duy nhất, đối tượng CardWithId sẽ được tạo và sử dụng với phương thức này.

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

Tham số

TênLoạiNội dung mô tả
cardWithIdCardWithIdCardWithId để sử dụng.

Cầu thủ trả bóng

ChatResponseBuilder – Đối tượng này để tạo chuỗi.


build()

Xây dựng phản hồi cho hành động hiện tại và xác thực hành động đó.

Cầu thủ trả bóng

ChatResponse — Câu trả lời Chat đã được xác thực.


setActionResponse(actionResponse)

Đặt trường phản hồi hành động của thông báo.

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

Tham số

TênLoạiNội dung mô tả
actionResponseChatActionResponseChatActionResponse để sử dụng.

Cầu thủ trả bóng

ChatResponseBuilder – Đối tượng này để tạo chuỗi.


setText(text)

Đặt nội dung của tin nhắn trên Chat.

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

Tham số

TênLoạiNội dung mô tả
textStringVăn bản cần sử dụng.

Cầu thủ trả bóng

ChatResponseBuilder – Đối tượng này để tạo chuỗi.