Gmail 動作
Action
物件可讓您在 Google Workspace 外掛程式中建立互動行為。這些事件定義了使用者在外掛程式 UI 中與小工具 (例如按鈕) 互動時的情況。
使用 Widget 處理常式函式附加至特定小工具的動作,該函式也會定義觸發動作的條件。觸發時,動作會執行指定的回呼函式。回呼函式會傳遞事件物件,該物件會攜帶使用者用戶端互動資訊。您必須實作回呼函式,並讓回呼函式傳回特定回應物件。
舉例來說,假設您希望按鈕在點選時建立並顯示新卡片。為此,您必須建立新的按鈕小工具,並使用按鈕小工具處理常式函式 setOnClickAction(action)
設定卡片建構 Action
。您定義的 Action
會指定 Apps Script 回呼函式,在按下按鈕時執行。在這種情況下,您可以實作回呼函式來建構所需的資訊卡,並傳回 ActionResponse
物件。回應物件會告知外掛程式顯示回呼函式建立的卡片。
本頁面說明可在外掛程式中加入的 Gmail 專屬小工具動作。
Gmail 互動
擴充 Gmail 功能的 Google Workspace 外掛程式可以包含額外的 Gmail 專屬小工具動作,用於撰寫草稿郵件。這個動作需要相關聯的動作 回呼函式,才能傳回專門的回應物件:
如要使用這些小工具動作和回應物件,外掛程式必須在資訊清單中加入 https://www.googleapis.com/auth/gmail.addons.current.action.compose
範圍。
撰寫訊息
可擴充 Gmail 功能的 Google Workspace 外掛程式可定義小工具,當使用者與小工具互動時,系統就會在 Gmail 中產生草稿郵件 (新郵件或回覆)。為此,您必須將觸發小工具與會傳回 ComposeActionResponse
物件的回呼函式建立關聯。回呼函式執行完畢後,Gmail 會使用這個回應物件開啟並填入草稿撰寫視窗。
如需詳細資訊和範例,請參閱「撰寫草稿訊息」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-12-22 (世界標準時間)。
[null,null,["上次更新時間:2024-12-22 (世界標準時間)。"],[[["`Action` objects enable interactive behavior in Google Workspace add-ons by defining responses to user interactions with widgets."],["Actions 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."],["Gmail add-ons have a specific action for composing draft messages, requiring a `ComposeActionResponse` object from the callback function and a specific scope in the add-on's manifest."],["Add-ons can generate draft messages in Gmail by associating a widget with a callback function that returns a `ComposeActionResponse` object, which Gmail uses to populate a draft compose window."]]],["`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"]]