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ức | Kiểu dữ liệu trả về | Mô tả ngắn |
---|---|---|
addCardsV2(cardWithId) | ChatResponseBuilder | Đặt trường thẻ của thông báo. |
build() | ChatResponse | Xâ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ên | Loại | Nội dung mô tả |
---|---|---|
cardWithId | CardWithId | CardWithId để 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ên | Loại | Nội dung mô tả |
---|---|---|
actionResponse | ChatActionResponse | ChatActionResponse để 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ên | Loại | Nội dung mô tả |
---|---|---|
text | String | Văn bản cần sử dụng. |
Cầu thủ trả bóng
ChatResponseBuilder
– Đối tượng này để tạo chuỗi.