Class ChatResponseBuilder
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
سازنده پاسخ چت سازنده برای اشیاء Chat Response
.
فقط برای برنامههای گپ Google در دسترس است. برای افزونه های 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();
مستندات دقیق
add Cards V2(cardWithId)
فیلد کارت پیام را تنظیم می کند. این برای ارسال کارت در پیام Google Chat استفاده می شود. هر کارت با یک شناسه منحصر به فرد همراه است، شی Card With Id
باید ساخته شود و با این روش استفاده شود.
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();
پارامترها
بازگشت
Chat Response Builder
- این شیء، برای زنجیره زدن.
build()
پاسخ اقدام فعلی را می سازد و آن را تأیید می کند.
بازگشت
Chat Response
- یک ChatResponse معتبر.
set Action Response(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();
پارامترها
بازگشت
Chat Response Builder
- این شیء، برای زنجیره زدن.
set Text(text)
متن پیام چت را تنظیم می کند.
const chatResponse =
CardService.newChatResponseBuilder().setText('Example text').build();
پارامترها
نام | تایپ کنید | توضیحات |
---|
text | String | متن مورد استفاده |
بازگشت
Chat Response Builder
- این شیء، برای زنجیره زدن.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003e\u003ccode\u003eChatResponseBuilder\u003c/code\u003e constructs responses for Google Chat apps, enabling the inclusion of cards, text, and actions within messages.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods like \u003ccode\u003eaddCardsV2\u003c/code\u003e, \u003ccode\u003esetText\u003c/code\u003e, and \u003ccode\u003esetActionResponse\u003c/code\u003e to build comprehensive responses.\u003c/p\u003e\n"],["\u003cp\u003eEach method allows for chaining, facilitating a fluent and concise approach to building responses.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ebuild()\u003c/code\u003e finalizes the response and returns a \u003ccode\u003eChatResponse\u003c/code\u003e object ready for delivery.\u003c/p\u003e\n"],["\u003cp\u003eThis builder is exclusively available for Google Chat apps and not for Google Workspace Add-ons.\u003c/p\u003e\n"]]],["The `ChatResponseBuilder` constructs `ChatResponse` objects for Google Chat apps. Key actions include: `addCardsV2(cardWithId)` to send cards with unique IDs, `build()` to finalize and validate the response, `setActionResponse(actionResponse)` to handle dialog actions, and `setText(text)` to include message text. Each method returns the `ChatResponseBuilder` object to enable chaining. It is crucial to notice that the object built is for chat applications only.\n"],null,["# Class ChatResponseBuilder\n\nChatResponseBuilder\n\nA builder for [ChatResponse](/apps-script/reference/card-service/chat-response) objects.\n\nOnly available for Google Chat apps. Not available for Google Workspace add-ons.\n\n```javascript\nconst cardSection = CardService.newCardSection();\ncardSection.addWidget(\n CardService.newTextParagraph().setText('This is a text paragraph widget.'),\n);\n\nconst card = CardService.newCardBuilder()\n .setName('Card name')\n .setHeader(CardService.newCardHeader().setTitle('Card title'))\n .addSection(cardSection)\n .build();\n\nconst cardWithId =\n CardService.newCardWithId().setCardId('card_id').setCard(card);\n\nconst chatResponse = CardService.newChatResponseBuilder()\n .addCardsV2(cardWithId)\n .setText('Example text')\n .build();\n``` \n\n### Methods\n\n| Method | Return type | Brief description |\n|-----------------------------------------------------------------------------|-------------------------------------------------------------------|------------------------------------------------------|\n| [addCardsV2(cardWithId)](#addCardsV2(CardWithId)) | [ChatResponseBuilder](#) | Sets the card field of the message. |\n| [build()](#build()) | [ChatResponse](/apps-script/reference/card-service/chat-response) | Builds the current action response and validates it. |\n| [setActionResponse(actionResponse)](#setActionResponse(ChatActionResponse)) | [ChatResponseBuilder](#) | Sets the action response field of the message. |\n| [setText(text)](#setText(String)) | [ChatResponseBuilder](#) | Sets the text of the Chat message. |\n\nDetailed documentation\n----------------------\n\n### `add``Cards``V2(cardWithId)`\n\nSets the card field of the message. This is used to send a card in a Google Chat message. Each\ncard is associated with a unique id, [CardWithId](/apps-script/reference/card-service/card-with-id) object should be built and be used with\nthis method.\n\n```javascript\nconst cardSection = CardService.newCardSection();\ncardSection.addWidget(\n CardService.newTextParagraph().setText('This is a text paragraph widget.'),\n);\n\nconst card = CardService.newCardBuilder()\n .setHeader(CardService.newCardHeader().setTitle('Card title'))\n .addSection(cardSection)\n .build();\n\nconst cardWithId =\n CardService.newCardWithId().setCardId('card_id').setCard(card);\n\nconst chatResponse =\n CardService.newChatResponseBuilder().addCardsV2(cardWithId).build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|------------------|----------------------------------------------------------------|----------------------------------------------------------------------------|\n| `card``With``Id` | [CardWithId](/apps-script/reference/card-service/card-with-id) | The [CardWithId](/apps-script/reference/card-service/card-with-id) to use. |\n\n#### Return\n\n\n[ChatResponseBuilder](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `build()`\n\nBuilds the current action response and validates it.\n\n#### Return\n\n\n[ChatResponse](/apps-script/reference/card-service/chat-response) --- A validated ChatResponse.\n\n*** ** * ** ***\n\n### `set``Action``Response(actionResponse)`\n\nSets the action response field of the message.\n\n```javascript\n// Build the card.\nconst card = CardService.newCardBuilder()\n .setHeader(CardService.newCardHeader().setTitle('card title'))\n .build();\n\n// Creates the dialog.\nconst dialog = CardService.newDialog().setBody(card);\n\n// Creates the dialog action.\nconst dialogAction = CardService.newDialogAction().setDialog(dialog);\n\n// Creates the action response and sets the type to DIALOG.\nconst actionResponse = CardService.newChatActionResponse()\n .setDialogAction(dialogAction)\n .setResponseType(CardService.Type.DIALOG);\n\n// Creates the Chat response and sets the action response.\nconst chatResponse = CardService.newChatResponseBuilder()\n .setActionResponse(actionResponse)\n .build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------------------|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|\n| `action``Response` | [ChatActionResponse](/apps-script/reference/card-service/chat-action-response) | The [ChatActionResponse](/apps-script/reference/card-service/chat-action-response) to use. |\n\n#### Return\n\n\n[ChatResponseBuilder](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Text(text)`\n\nSets the text of the Chat message.\n\n```javascript\nconst chatResponse =\n CardService.newChatResponseBuilder().setText('Example text').build();\n```\n\n#### Parameters\n\n| Name | Type | Description |\n|--------|----------|------------------|\n| `text` | `String` | The text to use. |\n\n#### Return\n\n\n[ChatResponseBuilder](#) --- This object, for chaining."]]