Class 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 การ์ดแต่ละใบจะเชื่อมโยงกับรหัสที่ไม่ซ้ำกัน คุณควรสร้างออบเจ็กต์ 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();

พารามิเตอร์

ชื่อประเภทคำอธิบาย
cardWithIdCardWithIdCardWithId ที่จะใช้

รีเทิร์น

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
actionResponseChatActionResponseChatActionResponse ที่จะใช้

รีเทิร์น

ChatResponseBuilder — ออบเจ็กต์นี้สําหรับการต่อเชื่อม


setText(text)

ตั้งค่าข้อความของข้อความ Chat

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

พารามิเตอร์

ชื่อประเภทคำอธิบาย
textStringข้อความที่จะใช้

รีเทิร์น

ChatResponseBuilder — ออบเจ็กต์นี้สําหรับการต่อเชื่อม