Class ChatResponseBuilder

ChatResponseBuilder

אובייקט builder של 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();

Methods

שיטהסוג הערך שמוחזרתיאור קצר
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();

פרמטרים

שםסוגתיאור
cardWithIdCardWithIdה-CardWithId שבו רוצים להשתמש.

חזרה

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

פרמטרים

שםסוגתיאור
actionResponseChatActionResponseה-ChatActionResponse שבו רוצים להשתמש.

חזרה

ChatResponseBuilder – האובייקט הזה, לשרשור.


setText(text)

הגדרת הטקסט של ההודעה ב-Chat.

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

פרמטרים

שםסוגתיאור
textStringהטקסט שבו רוצים להשתמש.

חזרה

ChatResponseBuilder – האובייקט הזה, לשרשור.