קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אובייקטים מסוג Action מאפשרים לכם ליצור התנהגות אינטראקטיבית בתוספים ל-Google Workspace. הם מגדירים מה קורה כשמשתמש מבצע אינטראקציה עם ווידג'ט (למשל, לחצן) בממשק המשתמש של התוסף.
הפעולה מצורפת לווידג'ט נתון באמצעות פונקציית טיפול בווידג'ט, שמגדירה גם את התנאי שמפעיל את הפעולה. כשהפעולה מופעלת, היא מבצעת פונקציית קריאה חוזרת שהוגדרה מראש.
לפונקציית ה-callback מועבר אובייקט אירוע שמכיל מידע על האינטראקציות של המשתמש בצד הלקוח. צריך להטמיע את פונקציית ה-callback ולגרום לה להחזיר אובייקט תגובה ספציפי.
לדוגמה, נניח שאתם רוצים ליצור לחצן שיוצר כרטיס חדש ומציג אותו כשלוחצים עליו. לשם כך, צריך ליצור ווידג'ט לחצן חדש ולהשתמש בפונקציית הטיפול בווידג'ט הלחצן setOnClickAction(action) כדי להגדיר Action ליצירת כרטיסים. הערך של Action שצריך להגדיר הוא פונקציית קריאה חוזרת של Apps Script שתתבצע כשהמשתמשים ילחצו על הלחצן. במקרה כזה, צריך להטמיע את פונקציית הקריאה החוזרת כדי ליצור את הכרטיס הרצוי ולהחזיר אובייקט ActionResponse. אובייקט התגובה מורה לתוסף להציג את הכרטיס שפונקציית הקריאה החוזרת יצרה.
בדף הזה מוסבר על פעולות ווידג'ט ספציפיות ל-Gmail שאפשר לכלול בתוסף.
אינטראקציות ב-Gmail
תוספים של Google Workspace שמרחיבים את Gmail יכולים לכלול פעולת ווידג'ט נוספת ספציפית ל-Gmail לכתיבה של טיוטות של הודעות. כדי לבצע את הפעולה הזו, פונקציית הקריאה החוזרת של הפעולה המשויכת צריכה להחזיר אובייקט תגובה מיוחד:
כדי להשתמש באובייקטים של התגובה ובפעולות הווידג'ט האלה, התוסף צריך לכלול את היקףhttps://www.googleapis.com/auth/gmail.addons.current.action.compose במניפסט שלו.
כתיבת הודעה
תוסף ל-Google Workspace שמרחיב את Gmail יכול להגדיר ווידג'ט, שבאמצעותו אפשר ליצור טיוטות של הודעות ב-Gmail (הודעות חדשות או תשובות). כדי לעשות זאת, צריך לשייך את הווידג'ט שמפעיל את האירוע לפונקציית קריאה חוזרת שמחזירה אובייקט ComposeActionResponse. כשפונקציית הקריאה החוזרת מסתיימת, Gmail משתמש באובייקט התגובה הזה כדי לפתוח וליישב חלון כתיבה של טיוטה.
[[["התוכן קל להבנה","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-06 (שעון UTC)."],[[["\u003cp\u003e\u003ccode\u003eAction\u003c/code\u003e objects enable interactive behavior in Google Workspace add-ons by defining responses to user interactions with widgets.\u003c/p\u003e\n"],["\u003cp\u003eActions are linked to widgets via handler functions and trigger callback functions that process user interactions and return response objects to update the add-on UI.\u003c/p\u003e\n"],["\u003cp\u003eGmail add-ons have a specific action for composing draft messages, requiring a \u003ccode\u003eComposeActionResponse\u003c/code\u003e object from the callback function and a specific scope in the add-on's manifest.\u003c/p\u003e\n"],["\u003cp\u003eAdd-ons can generate draft messages in Gmail by associating a widget with a callback function that returns a \u003ccode\u003eComposeActionResponse\u003c/code\u003e object, which Gmail uses to populate a draft compose window.\u003c/p\u003e\n"]]],["`Action` objects in Google Workspace add-ons enable interactive behavior. An action, triggered by a widget interaction, executes a callback function. This function receives an event object with user interaction details and returns a response object. For instance, a button click can trigger a callback to build and display a new card. Gmail add-ons can use `ComposeActionResponse` to generate draft messages, triggered by widget interaction. The add-on must include the `https://www.googleapis.com/auth/gmail.addons.current.action.compose` scope for this.\n"],null,["# Gmail actions\n\n[`Action`](/workspace/add-ons/concepts/actions) objects let you build interactive\nbehavior into Google Workspace add-ons. They define\nwhat happens when a user interacts with a widget (for example, a button) in\nthe add-on UI.\n\nAn action is attached to a given widget using a\n[widget handler function](/workspace/add-ons/concepts/actions#widget_handler_functions),\nwhich also defines the condition that triggers the action. When triggered, the\naction executes a designated\n[callback function](/workspace/add-ons/concepts/actions#callback_functions).\nThe callback function is passed an\n[event object](/workspace/add-ons/concepts/event-objects) that carries\ninformation about the user's client-side interactions. You must implement the\ncallback function and have it return a specific response object.\n\nFor example, say you want a button that builds and displays a new card when\nclicked. For this, you must create a new button widget and use the button widget\nhandler function\n[`setOnClickAction(action)`](/apps-script/reference/card-service/text-button#setOnClickAction(Action))\nto set a card-building [`Action`](/workspace/add-ons/concepts/actions). The\n[`Action`](/workspace/add-ons/concepts/actions) you define specifies an Apps Script\ncallback function that executes when the button is clicked. In this case, you\nimplement the callback function to build the card you want and return an\n[`ActionResponse`](/apps-script/reference/card-service/action-response)\nobject. The response object tells the add-on to display the card the callback\nfunction built.\n\nThis page describes Gmail-specific widget actions you can include in your\nadd-on.\n\nGmail interactions\n------------------\n\nGoogle Workspace add-ons that extend Gmail can include\nan additional Gmail-specific widget action to compose draft messages. This\naction requires the associated action\n[callback function](/workspace/add-ons/concepts/actions#callback_functions)\nto return a specialized response object:\n\n| Action attempted | Callback function should return |\n|------------------------------------------------------------|----------------------------------------------------------------------------------------|\n| [Compose draft messages](/workspace/add-ons/gmail/compose) | [`ComposeActionResponse`](/apps-script/reference/card-service/compose-action-response) |\n\nTo make use of these widget actions and response objects, the add-on must\ninclude the\n`https://www.googleapis.com/auth/gmail.addons.current.action.compose`\n[scope](/workspace/add-ons/concepts/workspace-scopes#gmail_add-on_scopes) in its manifest.\n\n### Compose a message\n\nA Google Workspace add-on that extends Gmail can\ndefine a widget that, when interacted with, generates draft messages in Gmail\n(either new messages or replies). To do this, you must associate the triggering\nwidget with a callback function that returns a\n[`ComposeActionResponse`](/apps-script/reference/card-service/compose-action-response)\nobject. When the callback function finishes executing, Gmail uses this\nresponse object to open and populate a draft compose window.\n\nFor more details and an example, see\n[Compose draft messages](/workspace/add-ons/gmail/compose).\n| **Note:** This behavior is distinct from [extending the compose window UI](/workspace/add-ons/gmail/extending-compose-ui). In that case the add-on is creating a contextual card interface alongside the compose window. Here, a draft is generated in response to a widget interaction."]]