استبدِل MESSAGE بمورد
Message
من Chat API. لمزيد من المعلومات حول طريقة عمل الإجراءات، يمكنك الاطّلاع على إجراءات Chat.
في المثال التالي، ينشئ تطبيق Chat رسالة نصية ويرسلها كلما تمت إضافته إلى مساحة. لإرسال رسالة نصية عندما يضيف مستخدم تطبيق Chat إلى مساحة، يستجيب تطبيق Chat إلى مشغّل تمت الإضافة إلى المساحة من خلال عرض الإجراء DataActions:
Node.js
/** * Sends an onboarding message when the Chat app is added to a space. * * @param {Object} req The request object from Google Workspace add-on. * @param {Object} res The response object from the Chat app. An onboarding message that * introduces the app and helps people get started with it. */exports.cymbalApp=functioncymbalApp(req,res){constchatEvent=req.body.chat;// Send an onboarding message when added to a Chat spaceif(chatEvent.addedToSpacePayload){res.json({hostAppDataAction:{chatDataAction:{createMessageAction:{message:{text:'Hi, Cymbal at your service. I help you manage your calendar'+'from Google Chat. Take a look at your schedule today by typing'+'`/checkCalendar`, or schedule a meeting with `/scheduleMeeting`. To learn'+'what else I can do, type `/help`.'}}}}});}};
برمجة التطبيقات
/** * Sends an onboarding message when the Chat app is added to a space. * * @param {Object} event The event object from Chat API. * @return {Object} Response from the Chat app. An onboarding message that * introduces the app and helps people get started with it. */functiononAddedToSpace(event){return{hostAppDataAction:{chatDataAction:{createMessageAction:{message:{text:'Hi, Cymbal at your service. I help you manage your calendar'+'from Google Chat. Take a look at your schedule today by typing'+'`/checkCalendar`, or schedule a meeting with `/scheduleMeeting`. To learn'+'what else I can do, type `/help`.'}}}}};}
تعرض عيّنة الرمز البرمجي الرسالة النصية التالية:
للاطّلاع على أمثلة إضافية حول كيفية الرد برسالة، يُرجى الرجوع إلى الأدلة التالية:
لمزيد من المعلومات حول طريقة عمل الإجراءات، يمكنك الاطّلاع على إجراءات Chat.
يمكن أيضًا لتطبيقات المحادثات تعديل رسالة من مستخدم لعرض معاينة للرابط الذي أرسله. لمزيد من التفاصيل، يُرجى الاطّلاع على مقالة
معاينة الروابط في رسائل Google Chat.
الردّ على التفاعلات أو إرسال رسائل استباقية باستخدام Google Chat API
بدلاً من عرض إجراء إضافة، قد تحتاج تطبيقات Chat إلى استخدام Google Chat API للرد على تفاعل. على سبيل المثال، يجب أن تستخدم تطبيقات Chat واجهة برمجة تطبيقات Google Chat لتنفيذ أي مما يلي:
إرسال الرسائل وفقًا لجدول زمني أو حول التغييرات في المراجع الخارجية على سبيل المثال، الإشعارات بشأن مشكلة أو طلب دعم جديدَين.
الردّ بعد أكثر من 30 ثانية من التفاعل على سبيل المثال، للرد برسالة بعد إكمال مهمة تستغرق وقتًا طويلاً.
تاريخ التعديل الأخير: 2025-08-04 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-04 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThis guide explains how Google Chat apps can send and update messages in response to user interactions like slash commands, button clicks, or added to space triggers.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Chat apps can include text, cards, and widgets in their messages and can reply using actions or the Google Chat API.\u003c/p\u003e\n"],["\u003cp\u003eYou should use the Google Chat API for tasks such as scheduled messages, responses exceeding 30 seconds, and messaging outside the interaction space.\u003c/p\u003e\n"],["\u003cp\u003eTo build a Google Chat app, you'll need Node.js or Apps Script and a Google Workspace add-on extending Google Chat.\u003c/p\u003e\n"],["\u003cp\u003eThis feature is available as part of the Google Workspace Developer Preview Program for early access.\u003c/p\u003e\n"]]],["Google Chat apps can send messages in response to user interactions like message triggers, being added to a space, or button clicks. These messages can include text, cards, or accessory widgets. Apps can use `CreateMessageAction` or `UpdateMessageAction` to reply or update messages. For scheduled messages, or those outside the interaction space, they can call the Google Chat API's `create()` method. Node.js and Apps Script examples are provided to show a text message response to the \"added to space\" trigger.\n"],null,["# Send Google Chat messages\n\nThis page explains how Google Chat apps can send messages to reply to user\ninteractions.\n\n\n| **Note:** In Google Chat, add-ons appear to users as\n| Google Chat apps. You can also build your Chat app using\n| *Google Chat API interaction events* . To learn more, see the\n| [Extend Google Chat overview](/workspace/add-ons/chat).\n\n\u003cbr /\u003e\n\n- **Figure 1.** A Chat app responds to a slash command with a text message and button.\n- **Figure 2.** A Chat app opens a dialog where users can input information.\n- **Figure 5.** A Chat app sends a message with text and an interactive card.\n\nPrerequisites\n-------------\n\n### Node.js\n\nA Google Workspace add-on that extends Google Chat. To build one,\ncomplete the\n[HTTP quickstart](/workspace/add-ons/chat/quickstart-http).\n| **Note:** The code samples in this guide are written to run as a [Google Cloud Function](https://cloud.google.com/functions/docs/quickstarts) for Node.js.\n\n### Apps Script\n\nA Google Workspace add-on that extends Google Chat. To build one,\ncomplete the\n[Apps Script quickstart](/workspace/add-ons/chat/quickstart-apps-script).\n\nDesign the message\n------------------\n\nChat apps can include any of the following in a message:\n\n- Text that contains hyperlinks, @mentions, and emoji.\n- One or more cards, which can appear in a message or open in a new window as a dialog.\n- One or more accessory widgets, which are buttons that appear after any text or cards in a message.\n\nTo learn about designing messages, see the following\nGoogle Chat API documentation:\n\n- [Messaging overview](/workspace/chat/messages-overview)\n- [Format messages](/workspace/chat/format-messages)\n- [Build cards for Google Chat apps](/workspace/chat/design-components-card-dialog)\n- [Add text and images to cards](/workspace/chat/add-text-image-card-dialog)\n- [Add interactive UI elements to cards](/workspace/chat/design-interactive-card-dialog)\n\nReply with a message\n--------------------\n\nChat apps can respond with a message to any of the following\ntriggers or interactions:\n\n- [**Message** triggers](/workspace/add-ons/chat/build#TRIGGER.MESSAGE), such as when users @mention or direct message a Chat app.\n- [**Added to space** triggers](/workspace/add-ons/chat/build#TRIGGER.ADDED_TO_SPACE), such as when users install the Chat app from the Google Workspace Marketplace or add it to a space.\n- Button clicks from cards in messages or dialogs. For example, when users input information and click submit.\n\nOtherwise, Chat apps can send messages proactively by\n[calling the Google Chat API](#message-api).\n\nTo reply with a message, return the action `DataActions` with a\n[`CreateMessageAction`](/workspace/add-ons/reference/rpc/apps.extensions.markup#apps.extensions.markup.ChatDataActionMarkup.CreateMessageAction) object: \n\n { \"hostAppDataAction\": { \"chatDataAction\": { \"createMessageAction\": {\n \"message\": \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-err\"\u003eMESSAGE\u003c/span\u003e\u003c/var\u003e\n }}}\n\nReplace \u003cvar translate=\"no\"\u003eMESSAGE\u003c/var\u003e with a\n[`Message`](/workspace/chat/api/reference/rest/v1/spaces.messages)\nresource from the Chat API. To learn more about how actions work, see\n[Chat actions](/workspace/add-ons/chat/build#actions).\n\nIn the following example, a Chat app creates and sends\na text message whenever it's added to a space. To send a text message when a\nuser adds your Chat app\nto a space, your Chat app responds to the\n**Added to space** trigger by returning the action `DataActions`: \n\n### Node.js\n\n /**\n * Sends an onboarding message when the Chat app is added to a space.\n *\n * @param {Object} req The request object from Google Workspace add-on.\n * @param {Object} res The response object from the Chat app. An onboarding message that\n * introduces the app and helps people get started with it.\n */\n exports.cymbalApp = function cymbalApp(req, res) {\n const chatEvent = req.body.chat;\n // Send an onboarding message when added to a Chat space\n if (chatEvent.addedToSpacePayload) {\n res.json({ hostAppDataAction: { chatDataAction: { createMessageAction: { message: {\n text: 'Hi, Cymbal at your service. I help you manage your calendar' +\n 'from Google Chat. Take a look at your schedule today by typing' +\n '`/checkCalendar`, or schedule a meeting with `/scheduleMeeting`. To learn' +\n 'what else I can do, type `/help`.'\n }}}}});\n }\n };\n\n### Apps Script\n\n /**\n * Sends an onboarding message when the Chat app is added to a space.\n *\n * @param {Object} event The event object from Chat API.\n * @return {Object} Response from the Chat app. An onboarding message that\n * introduces the app and helps people get started with it.\n */\n function onAddedToSpace(event) {\n return { hostAppDataAction: { chatDataAction: { createMessageAction: { message: {\n text: 'Hi, Cymbal at your service. I help you manage your calendar' +\n 'from Google Chat. Take a look at your schedule today by typing' +\n '`/checkCalendar`, or schedule a meeting with `/scheduleMeeting`. To learn' +\n 'what else I can do, type `/help`.'\n }}}}};\n }\n\nThe code sample returns the following text message:\n\nFor additional examples of how to respond with a message, see the following\nguides:\n\n- [Respond to quick commands](/workspace/add-ons/chat/quick-commands)\n- [Respond to slash commands](/workspace/add-ons/chat/slash-commands)\n- [Open interactive dialogs](/workspace/add-ons/chat/dialogs)\n- [Collect information from Google Chat users](/workspace/add-ons/chat/collect-information)\n\nUpdate a message\n----------------\n\nChat apps can also update messages that they send. For example,\nto update a message after a user has submitted a dialog or clicked a button an\na message.\n\nTo update a Chat app message, return the action\n`DataActions` with a\n[`UpdateMessageAction`](/workspace/add-ons/reference/rpc/apps.extensions.markup#updatemessageaction), as shown in\nthe following example: \n\n { \"hostAppDataAction\": { \"chatDataAction\": { \"updateMessageAction\": {\n \"message\": \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-err\"\u003eMESSAGE\u003c/span\u003e\u003c/var\u003e\n }}}}\n\nReplace \u003cvar translate=\"no\"\u003eMESSAGE\u003c/var\u003e with a\n[`Message`](/workspace/chat/api/reference/rest/v1/spaces.messages)\nresource from the Chat API.\n\nTo learn more about how actions work, see\n[Chat actions](/workspace/add-ons/chat/build#actions).\n\nChat apps can also update a message from a user, to return a\npreview of a link that they sent. For details, see\n[Preview links in Google Chat messages](/workspace/add-ons/chat/preview-links).\n\nReply to interactions or send proactive messages using the Google Chat API\n--------------------------------------------------------------------------\n\nInstead of returning an add-on action,\nChat apps might need to use the Google Chat API respond to an\ninteraction. For example, Chat apps must call the Google Chat API to\ndo any of the following:\n\n- Send messages on a schedule, or about changes to external resources. For example, notifications about a new issue or case.\n- Reply more than 30 seconds after the interaction. For example, to respond with a message after completing a long-running task.\n- Send a message outside of the space where the interaction took place.\n- Send a message on behalf of a Chat user.\n\nTo send a message using the Chat API, you must set up authentication\nand call the `create()` method on the `Message` resource. For steps, see\n[Send a message using the Google Chat API](/workspace/chat/create-messages).\n\nRelated topics\n--------------\n\n- [Build Google Chat interfaces](/workspace/add-ons/chat/build)\n- [Respond to quick commands](/workspace/add-ons/chat/quick-commands)\n- [Respond to slash commands](/workspace/add-ons/chat/slash-commands)\n- [Open interactive dialogs](/workspace/add-ons/chat/dialogs)\n- [Collect information from Google Chat users](/workspace/add-ons/chat/collect-information)\n- [Preview links in Google Chat messages](/workspace/add-ons/chat/preview-links)\n- [Send a message using the Google Chat API](/workspace/chat/create-messages)"]]