Gmail을 확장하는 Google Workspace 부가기능은 사용자가 메일을 읽을 때 사용자 인터페이스를 제공할 수 있습니다. 이를 통해 Google Workspace 부가기능은 메시지와 관련된 추가 정보를 표시, 검색 또는 전송하는 등 메시지 콘텐츠에 응답하는 작업을 자동화할 수 있습니다.
부가기능 메시지 UI에 액세스
부가기능의 메시지 UI를 보는 방법에는 두 가지가 있습니다. 첫 번째 방법은 부가기능이 이미 열려 있는 동안 메시지를 여는 것입니다 (예: Gmail 받은편지함 창에서 부가기능 홈페이지를 볼 때). 두 번째 방법은 메시지를 보는 동안 부가기능을 시작하는 것입니다.
어느 경우든 부가기능 매니페스트에 정의된 상응하는 문맥 트리거 함수가 실행됩니다.
또한 부가기능이 열려 있는 동안 사용자가 다른 메시지로 전환하면 트리거가 실행됩니다. 문맥 트리거 함수는 해당 메시지의 메시지 UI를 빌드하고 Gmail은 이를 사용자에게 표시합니다.
사용자가 메시지에서 부가기능을 선택할 때 메시지 UI를 빌드하는 문맥 트리거 함수를 구현합니다.
사용자의 UI 상호작용에 응답하는 데 필요한 연결된 함수를 구현합니다.
문맥 트리거
메시지를 읽을 때 사용자에게 도움을 제공하기 위해 Google Workspace 부가기능은 매니페스트에서 문맥 트리거를 정의할 수 있습니다. 사용자가 트리거 기준을 충족하는 Gmail 메일을 열면 (부가기능이 열려 있는 상태에서)* 트리거가 실행됩니다. 실행된 트리거는 부가기능 사용자 인터페이스를 생성하고 Gmail에 표시되도록 반환하는 문맥 트리거 함수를 실행합니다. 이 시점에서 사용자는 앱과 상호작용을 시작할 수 있습니다.
문맥 트리거는 부가기능의 프로젝트 매니페스트에 정의됩니다.
트리거 정의는 Gmail에 어떤 조건에서 어떤 트리거 함수를 실행할지 알려줍니다. 예를 들어 이 매니페스트 스니펫은 메시지가 열릴 때 트리거 함수 onGmailMessageOpen()를 호출하는 무조건 트리거를 설정합니다.
모든 문맥 트리거에는 부가기능의 사용자 인터페이스를 구성하는 상응하는 트리거 함수가 있어야 합니다. 이 함수는 매니페스트의 onTriggerFunction 필드에 지정합니다. 이 함수를 구현하여 작업 이벤트 객체 인수를 수락하고 단일 Card 객체 또는 Card 객체 배열을 반환합니다.
특정 Gmail 메일에 대해 문맥 트리거가 실행되면 이 함수를 호출하고 작업 이벤트 객체를 전달합니다.
트리거 함수는 이 이벤트 객체에서 제공된 메시지 ID를 사용하여 Apps Script의 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-05(UTC)"],[[["\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 }"]]