تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يمكن أن توفّر إضافات Google Workspace التي تُوسّع نطاق Gmail
واجهة مستخدم عندما يقرأ المستخدم الرسائل. يتيح ذلك لإضافة Google Workspace تنفيذ المهام تلقائيًا التي تستجيب
لمحتوى الرسالة، مثل عرض أو استرداد أو إرسال
معلومات إضافية ذات صلة بالرسالة.
الوصول إلى واجهة مستخدم الرسالة الإضافية
هناك طريقتان لعرض واجهة مستخدم الرسائل في إحدى الإضافات. الطريقة الأولى هي فتح
رسالة عندما تكون الإضافة مفتوحة (على سبيل المثال، عند عرض
الصفحة الرئيسية للإضافة في نافذة البريد الوارد في Gmail). الطريقة الثانية هي
بدء الإضافة أثناء عرض رسالة.
يؤدي أيّ من الحالتَين إلى تنفيذ الإضافة لمحاولة تنفيذ
دالة التفعيل السياقي ذات الصلة، والتي تم تحديدها في
بيان الإضافة.
يتم تنفيذ العامل المشغِّل أيضًا إذا غيّر المستخدم إلى رسالة مختلفة بينما كانت الإضافة مفتوحة. تعمل وظيفة العنصر المشغِّل السياقي على إنشاء واجهة مستخدم الرسالة
لهذه الرسالة، والتي يعرضها Gmail بعد ذلك للمستخدم.
إنشاء إضافة رسالة
يمكنك إضافة وظيفة الرسائل إلى إضافة باتّباع الخطوات العامة التالية:
أضِف الحقول المناسبة إلى بيان مشروع نص الإضافة البرمجي، بما في ذلك النطاقات المطلوبة لوظائف الرسائل. احرص على إضافة
حقل مشغّل شَرطي
إلى البيان، مع تحديد قيمة {} لملف
unconditional.
نفِّذ دالة تشغيل سياقية تُنشئ واجهة مستخدم للرسالة
عندما يختار المستخدم الإضافة في رسالة.
تنفيذ الدوالّ المرتبطة اللازمة للردّ على تفاعلات واجهة مستخدم
المشغّلات السياقية
لتوفير مساعدة للمستخدمين عند قراءة الرسائل، يمكن أن تحدِّد إضافات Google Workspace عامل تشغيل سياقيًا في ملفات البيان الخاصة بها. عندما يفتح المستخدم
رسالة Gmail (مع فتح الإضافة) تستوفي معايير* التفعيل، يتم تشغيل التفعيل. ينفِّذ عامل التشغيل الذي تم تشغيله دالة عامل تشغيل سياقي تُنشئ واجهة مستخدم الإضافة وتُعيدها إلى Gmail لعرضها. وفي هذه المرحلة، يمكن
للمستخدم البدء في التفاعل معه.
يتم تحديد عوامل التفعيل السياقية في ملف
بيان مشروع الإضافة.
يُخبر تعريف العامل المشغِّل Gmail بدالة العامل المشغِّل التي سيتم تفعيلها في ظل ظروف معيّنة. على سبيل المثال، يضبط مقتطف البيان هذا عامل تشغيل غير مشروط
يستدعي دالة العامل التشغيلي onGmailMessageOpen() عند فتح رسالة:
يجب أن يكون لكل عامل تشغيل سياقي دالة تشغيل
مقابلة له تنشئ واجهة مستخدم الإضافة. يمكنك تحديد هذه الدالة في حقل onTriggerFunction
ملف البيان. يمكنك تنفيذ هذه الدالة لقبول مَعلمة كائن حدث إجراء وعرض إما كائن Card واحد أو صفيف من كائنات Card.
عند بدء تشغيل عامل تشغيل سياقي لرسالة Gmail معيّنة، يُطلِق هذا العامل التشغيلي
هذه الدالة ويمرّر إليها
عنصر حدث إجراء.
غالبًا ما تستخدِم دوالّ التفعيل رقم تعريف الرسالة المقدَّم من عنصر الحدث هذا
للحصول على نص الرسالة وتفاصيل أخرى باستخدام خدمة Gmail في Apps Script. على سبيل المثال، يمكن أن تستخرج دالة البدء
محتوى الرسالة باستخدام الدوالّ التالية:
يمكن بعد ذلك لدالة التفعيل التصرّف استنادًا إلى هذه البيانات، واستخراج المعلومات التي تحتاجها للواجهة. على سبيل المثال، يمكن أن تجمع إحدى الإضافات التي تلخّص أرقام المبيعات أرقام المبيعات من نص الرسالة وتنظمها لعرضها في بطاقة.
يجب أن تنشئ دالة العنصر المشغِّل صفيفًا من عناصر
Card
المنشأة وتُعرِضها. على سبيل المثال، تنشئ الإضافة التالية بطاقة واحدة تُدرج
فقط موضوع الرسالة ومُرسِلها:
تاريخ التعديل الأخير: 2025-06-05 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-06-05 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eGoogle Workspace add-ons can extend Gmail functionality by providing a user interface within messages, enabling automation of tasks like retrieving or sending information.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons utilize contextual triggers, defined in their manifest, to execute functions that build the message UI when a user interacts with an email.\u003c/p\u003e\n"],["\u003cp\u003eThese triggers fire when a user opens a message while the add-on is active, prompting a trigger function to create and display the add-on's interface using cards.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can build message add-ons by defining triggers, implementing a contextual trigger function that builds the UI using card objects and accessing message data via the Gmail service with appropriate scopes.\u003c/p\u003e\n"]]],["Google Workspace add-ons enhance Gmail by providing a user interface that automates tasks related to message content. Accessing the add-on's UI triggers a contextual function defined in the add-on's manifest. This trigger function, when fired, constructs the UI using message details fetched via the message ID. The function must then build and return `Card` objects for display. The add-on can define `unconditional` triggers to operate on any message, requiring proper manifest setup and scope activation.\n"],null,["# Extending the message UI\n\nGoogle Workspace add-ons that extend Gmail can provide\na user interface when the user is reading messages. This allows\nGoogle Workspace add-ons to automate tasks that respond\nto message content, such as displaying, retrieving, or sending out\nadditional information related to the message.\n\nAccessing the add-on message UI\n-------------------------------\n\nThere are two ways to view an add-on's message UI. The first way is to open\na message while the add-on is already open (for example, when viewing\nthe add-on homepage in the Gmail inbox window). The second way is to\nstart the add-on while viewing a message.\n\nEither case causes the add-on to execute the corresponding\n[*contextual trigger function*](#contextual_trigger_function), defined in the\nadd-on [manifest](/workspace/add-ons/concepts/workspace-manifests#manifest_structure_for_g_suite_add-ons).\nThe trigger also executes if the user switches to a different message while the\nadd-on is still open. The contextual trigger function builds the message UI for\nthat message, which Gmail then displays to the user.\n\nBuilding a message add-on\n-------------------------\n\nYou can add message functionality to an add-on by following these general steps:\n\n1. Add the appropriate fields to the add-on script project [manifest](/workspace/add-ons/concepts/workspace-manifests#manifest_structure_for_g_suite_add-ons), including the [scopes](/workspace/add-ons/concepts/workspace-scopes#gmail_add-on_scopes) required for message functionality. Be sure to add a [conditional trigger field](/apps-script/manifest/gmail-addons#contextualtrigger) to the manifest, with a [`unconditional`](/apps-script/manifest/gmail-addons#ContextualTrigger.FIELDS.unconditional) value of `{}`.\n2. Implement a contextual trigger function that builds a message UI when the user selects the add-on in a message.\n3. Implement associated functions needed to respond to the user's UI interactions.\n\n### Contextual triggers\n\nTo provide users assistance when reading messages,\nGoogle Workspace add-ons can define\na *contextual trigger* in their manifests. When the user\nopens a Gmail message (with the add-on open) that meets the trigger\ncriteria[\\*](#note1) the trigger fires. A fired trigger executes a\n[contextual trigger function](#contextual_trigger_function) that constructs the\nadd-on user interface and returns it for Gmail to display. At that point the\nuser can begin interacting with it.\n\nContextual triggers are defined in your add-on's project\n[manifest](/workspace/add-ons/concepts/workspace-manifests#manifest_structure_for_g_suite_add-ons).\nThe trigger definition tells Gmail which trigger function to fire under which\nconditions. For example, this manifest snippet sets an unconditional trigger\nthat calls the trigger function `onGmailMessageOpen()` when a message is opened: \n\n```text\n{\n ...\n \"addOns\": {\n\n \"common\": {\n ...\n },\n \"gmail\": {\n \"contextualTriggers\": [\n {\n \"unconditional\": {},\n \"onTriggerFunction\": \"onGmailMessageOpen\"\n }\n ],\n ...\n },\n ...\n }\n ...\n}\n```\n\n\n| Currently, the only contextual trigger type available is `unconditional`, which triggers for all emails regardless of content.\n\n\u003cbr /\u003e\n\n### Contextual trigger function\n\nEvery contextual trigger must have a corresponding *trigger function*\nthat constructs your add-on's user interface. You specify this function in your\nmanifest's [`onTriggerFunction`](/apps-script/manifest/gmail#ContextualTrigger.FIELDS.onTriggerFunction)\nfield. You implement this function to accept an\n[action event object](/workspace/add-ons/concepts/actions#action_event_objects)\nargument and return either a single\n[`Card`](/apps-script/reference/card-service/card) object or an array of\n[`Card`](/apps-script/reference/card-service/card) objects.\n\nWhen a contextual trigger fires for a given Gmail message, it calls this\nfunction and passes it an\n[action event object](/workspace/add-ons/concepts/actions#action_event_objects).\nOften trigger functions use the message ID provided by this event object\nto get the message text and other details using Apps Script's\n[Gmail service](/apps-script/reference/gmail). For example, your trigger\nfunction could extract message content using these functions: \n\n // Activate temporary Gmail scopes, in this case to allow\n // the add-on to read message metadata and content.\n var accessToken = e.gmail.accessToken;\n GmailApp.setCurrentMessageAccessToken(accessToken);\n\n // Read message metadata and content. This requires the Gmail scope\n // https://www.googleapis.com/auth/gmail.addons.current.message.readonly.\n var messageId = e.gmail.messageId;\n var message = GmailApp.getMessageById(messageId);\n var subject = message.getSubject();\n var sender = message.getFrom();\n var body = message.getPlainBody();\n var messageDate = message.getDate();\n\n // Setting the access token with a gmail.addons.current.message.readonly\n // scope also allows read access to the other messages in the thread.\n var thread = message.getThread();\n var threadMessages = thread.getMessages();\n\n // Using this link can avoid the need to copy message or thread content\n var threadLink = thread.getPermalink();\n\n| **Note:** In most cases you must activate [Gmail scopes](/workspace/add-ons/concepts/workspace-scopes#gmail_add-on_scopes) using the access token provided by the event object and the [`GmailApp.setCurrentMessageAccessToken(accessToken)`](/apps-script/reference/gmail/gmail-app#setcurrentmessageaccesstokenaccesstoken) function before using other [Gmail service](/apps-script/reference/gmail) functions.\n\nThe trigger function can then act on this data, extracting the information that\nit needs for the interface. For example, an add-on that summarizes sales\nnumbers can collect sales figures from the message body and organize them for\ndisplay in a [card](/workspace/add-ons/concepts/cards).\n\nThe trigger function must build and return an array of built\n[`Card`](/apps-script/reference/card-service/card)\nobjects. For example, the following builds an add-on with a single card that\njust lists the subject and sender of the message: \n\n function onGmailMessageOpen(e) {\n // Activate temporary Gmail scopes, in this case to allow\n // message metadata to be read.\n var accessToken = e.gmail.accessToken;\n GmailApp.setCurrentMessageAccessToken(accessToken);\n\n var messageId = e.gmail.messageId;\n var message = GmailApp.getMessageById(messageId);\n var subject = message.getSubject();\n var sender = message.getFrom();\n\n // Create a card with a single card section and two widgets.\n // Be sure to execute build() to finalize the card construction.\n var exampleCard = CardService.newCardBuilder()\n .setHeader(CardService.newCardHeader()\n .setTitle('Example card'))\n .addSection(CardService.newCardSection()\n .addWidget(CardService.newKeyValue()\n .setTopLabel('Subject')\n .setContent(subject))\n .addWidget(CardService.newKeyValue()\n .setTopLabel('From')\n .setContent(sender)))\n .build(); // Don't forget to build the Card!\n return [exampleCard];\n }"]]