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ตั้งค่าข้อความในข้อความแชท

เอกสารโดยละเอียด

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)

ตั้งค่าข้อความในข้อความแชท

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

พารามิเตอร์

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

รีเทิร์น

ChatResponseBuilder — ออบเจ็กต์นี้สำหรับการทำเชน