Class ChatResponseBuilder

ChatResponseBuilder

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

Chỉ dùng được cho các ứng dụng Google Chat. Không dùng được cho các 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()ChatResponseTạo phản hồi hành động hiện tại và xác thực phản hồi đó.
setActionResponse(actionResponse)ChatResponseBuilderĐặt trường phản hồi hành động của thông báo.
setText(text)ChatResponseBuilderĐặt văn bản của tin nhắn trong Chat.

Tài liệu chi tiết

addCardsV2(cardWithId)

Đặt trường thẻ của thông báo. Trường này 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. Bạn nên tạo đối tượng CardWithId và dùng đối tượng này 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ạiMô tả
cardWithIdCardWithIdCardWithId cần dùng.

Cầu thủ trả bóng

ChatResponseBuilder – Đối tượng này dùng để liên kết.


build()

Tạo phản hồi hành động hiện tại và xác thực phản hồi đó.

Cầu thủ trả bóng

ChatResponse – ChatResponse đã 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ạiMô tả
actionResponseChatActionResponseChatActionResponse cần dùng.

Cầu thủ trả bóng

ChatResponseBuilder – Đối tượng này dùng để liên kết.


setText(text)

Đặt văn bản của tin nhắn trong Chat.

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

Tham số

TênLoạiMô tả
textStringVăn bản cần dùng.

Cầu thủ trả bóng

ChatResponseBuilder – Đối tượng này dùng để liên kết.