Action 객체를 사용하면 Google Workspace 부가기능에 대화형 동작을 빌드할 수 있습니다. 이러한 핸들러는 사용자가 부가기능 UI에서 위젯 (예: 버튼)과 상호작용할 때 발생하는 작업을 정의합니다.
작업은 위젯 핸들러 함수를 사용하여 지정된 위젯에 연결되며, 이 함수는 작업을 트리거하는 조건도 정의합니다. 트리거되면 작업이 지정된 콜백 함수를 실행합니다.
콜백 함수에는 사용자의 클라이언트 측 상호작용에 관한 정보를 전달하는 이벤트 객체가 전달됩니다. 콜백 함수를 구현하고 특정 응답 객체를 반환하도록 해야 합니다.
예를 들어 클릭하면 새 카드를 빌드하고 표시하는 버튼을 원한다고 가정해 보겠습니다. 이를 위해 새 버튼 위젯을 만들고 버튼 위젯 핸들러 함수 setOnClickAction(action)를 사용하여 카드 빌드 Action를 설정해야 합니다. 정의한 Action은 버튼을 클릭할 때 실행되는 Apps Script 콜백 함수를 지정합니다. 이 경우 콜백 함수를 구현하여 원하는 카드를 빌드하고 ActionResponse 객체를 반환합니다. 응답 객체는 콜백 함수가 빌드한 카드를 표시하도록 부가기능에 지시합니다.
이 페이지에서는 부가기능에 포함할 수 있는 캘린더 전용 위젯 작업을 설명합니다.
캘린더 상호작용
Calendar를 확장하는 Google Workspace 부가기능에는 몇 가지 추가 Calendar 관련 위젯 작업이 포함될 수 있습니다. 이러한 작업에는 연결된 작업 콜백 함수가 전문화된 응답 객체를 반환해야 합니다.
부가기능에는 https://www.googleapis.com/auth/calendar.addons.current.event.write캘린더 범위가 포함됩니다.
또한 작업 콜백 함수에서 변경한 내용은 사용자가 캘린더 일정을 저장할 때까지 저장되지 않습니다.
콜백 함수를 사용하여 참석자 추가
다음 예시에서는 수정 중인 Calendar 이벤트에 특정 참석자를 추가하는 버튼을 만드는 방법을 보여줍니다.
/***Buildasimplecardwithabuttonthatsendsanotification.*ThisfunctioniscalledaspartoftheeventOpenTriggerthatbuilds*aUIwhentheuseropensanevent.**@parameTheeventobjectpassedtoeventOpenTriggerfunction.*@return{Card}*/functionbuildSimpleCard(e){varbuttonAction=CardService.newAction().setFunctionName('onAddAttendeesButtonClicked');varbutton=CardService.newTextButton().setText('Add new attendee').setOnClickAction(buttonAction);//Checktheeventobjecttodetermineiftheusercanadd//attendeesanddisablethebuttonifnot.if(!e.calendar.capabilities.canAddAttendees){button.setDisabled(true);}//...continuecreatingcardsectionsandwidgets,thencreateaCard//objecttoaddthemto.ReturnthebuiltCardobject.}/***Callbackfunctionforabuttonaction.Addsattendeestothe*Calendareventbeingedited.**@param{Object}eTheactioneventobject.*@return{CalendarEventActionResponse}*/functiononAddAttendeesButtonClicked(e){returnCardService.newCalendarEventActionResponseBuilder().addAttendees(["aiko@example.com","malcom@example.com"]).build();}
콜백 함수를 사용하여 회의 데이터 설정
이 작업은 열려 있는 일정에 회의 데이터를 설정합니다. 이 회의 데이터의 경우 사용자가 원하는 솔루션을 선택하여 작업이 트리거되지 않았으므로 회의 솔루션 ID를 지정해야 합니다.
다음 예는 수정 중인 이벤트의 회의 데이터를 설정하는 버튼을 만드는 방법을 보여줍니다.
/***Buildasimplecardwithabuttonthatsendsanotification.*ThisfunctioniscalledaspartoftheeventOpenTriggerthatbuilds*aUIwhentheuseropensaCalendarevent.**@parameTheeventobjectpassedtoeventOpenTriggerfunction.*@return{Card}*/functionbuildSimpleCard(e){varbuttonAction=CardService.newAction().setFunctionName('onSaveConferenceOptionsButtonClicked').setParameters({'phone':"1555123467",'adminEmail':"joyce@example.com"});varbutton=CardService.newTextButton().setText('Add new attendee').setOnClickAction(buttonAction);//Checktheeventobjecttodetermineiftheusercanset//conferencedataanddisablethebuttonifnot.if(!e.calendar.capabilities.canSetConferenceData){button.setDisabled(true);}//...continuecreatingcardsectionsandwidgets,thencreateaCard//objecttoaddthemto.ReturnthebuiltCardobject.}/***Callbackfunctionforabuttonaction.Setsconferencedataforthe*Calendareventbeingedited.**@param{Object}eTheactioneventobject.*@return{CalendarEventActionResponse}*/functiononSaveConferenceOptionsButtonClicked(e){varparameters=e.commonEventObject.parameters;//Createanentrypointandaconferenceparameter.varphoneEntryPoint=ConferenceDataService.newEntryPoint().setEntryPointType(ConferenceDataService.EntryPointType.PHONE).setUri('tel:'+parameters['phone']);varadminEmailParameter=ConferenceDataService.newConferenceParameter().setKey('adminEmail').setValue(parameters['adminEmail']);//CreateaconferencedataobjecttosettothisCalendarevent.varconferenceData=ConferenceDataService.newConferenceDataBuilder().addEntryPoint(phoneEntryPoint).addConferenceParameter(adminEmailParameter).setConferenceSolutionId('myWebScheduledMeeting').build();returnCardService.newCalendarEventActionResponseBuilder().setConferenceData(conferenceData).build();}
콜백 함수를 사용하여 첨부파일 추가
다음 예시에서는 수정 중인 Calendar 일정에 첨부파일을 추가하는 버튼을 만드는 방법을 보여줍니다.
/***Buildasimplecardwithabuttonthatcreatesanewattachment.*ThisfunctioniscalledaspartoftheeventAttachmentTriggerthat*buildsaUIwhentheusergoesthroughtheadd-attachmentsflow.**@parameTheeventobjectpassedtoeventAttachmentTriggerfunction.*@return{Card}*/functionbuildSimpleCard(e){varbuttonAction=CardService.newAction().setFunctionName('onAddAttachmentButtonClicked');varbutton=CardService.newTextButton().setText('Add a custom attachment').setOnClickAction(buttonAction);//Checktheeventobjecttodetermineiftheusercanadd//attachmentsanddisablethebuttonifnot.if(!e.calendar.capabilities.canAddAttachments){button.setDisabled(true);}//...continuecreatingcardsectionsandwidgets,thencreateaCard//objecttoaddthemto.ReturnthebuiltCardobject.}/***Callbackfunctionforabuttonaction.AddsattachmentstotheCalendar*eventbeingedited.**@param{Object}eTheactioneventobject.*@return{CalendarEventActionResponse}*/functiononAddAttachmentButtonClicked(e){returnCardService.newCalendarEventActionResponseBuilder().addAttachments([CardService.newAttachment().setResourceUrl("https://example.com/test").setTitle("Custom attachment").setMimeType("text/html").setIconUrl("https://example.com/test.png")]).build();}
첨부파일 아이콘 설정
첨부파일 아이콘은 Google 인프라에 호스팅되어야 합니다. 자세한 내용은 첨부파일 아이콘 제공을 참고하세요.
[[["이해하기 쉬움","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-08-29(UTC)"],[[["\u003cp\u003eActions enable interactive behavior in Google Workspace add-ons by defining responses to user interactions with UI widgets.\u003c/p\u003e\n"],["\u003cp\u003eActions are linked to widgets using handlers, triggering callback functions with event details for custom logic.\u003c/p\u003e\n"],["\u003cp\u003eCalendar add-ons have specific actions for attendee management, conference data, and attachments, requiring proper setup and permissions.\u003c/p\u003e\n"],["\u003cp\u003eCallback functions for Calendar actions return specialized response objects to manipulate event details like attendees and attachments.\u003c/p\u003e\n"],["\u003cp\u003eChanges made by these actions are only saved when the user saves the Calendar event itself.\u003c/p\u003e\n"]]],["Actions in Google Workspace add-ons define interactive behaviors triggered by widget interactions. Widget handler functions link actions to widgets, invoking callback functions upon user interaction. These callbacks, receiving event object data, return specific response objects. Calendar add-ons offer actions to add attendees, set conference data, and add attachments, requiring `CalendarEventActionResponse` returns and specific permissions. Example code demonstrates creating buttons that, when clicked, modify calendar events by adding attendees, setting conference data, or add an attachement.\n"],null,["# Calendar 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 Calendar-specific widget actions you can include in your\nadd-on.\n\nCalendar interactions\n---------------------\n\nGoogle Workspace add-ons that extend Calendar\ncan include a few additional Calendar-specific widget actions. These actions\nrequire the associated action [callback function](/workspace/add-ons/concepts/actions#callback_functions)\nto return specialized response objects:\n\n| Action attempted | Callback function should return |\n|------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|\n| [Adding attendees](#adding_attendees_with_a_callback_function) | [`CalendarEventActionResponse`](/apps-script/reference/card-service/calendar-event-action-response) |\n| [Setting conference data](#setting_conference_data_with_a_callback_function) | [`CalendarEventActionResponse`](/apps-script/reference/card-service/calendar-event-action-response) |\n| [Adding attachments](#add_attachments_with_a_callback_function) | [`CalendarEventActionResponse`](/apps-script/reference/card-service/calendar-event-action-response) |\n\nTo make use of these widget actions and response objects, all of the following\nmust be true:\n\n- The action is triggered while the user has a Calendar event open.\n- The add-on's [`addOns.calendar.currentEventAccess`](/apps-script/manifest/calendar-addons#Calendar.FIELDS.currentEventAccess) manifest field is set to `WRITE` or `READ_WRITE`.\n- The add-on includes the `https://www.googleapis.com/auth/calendar.addons.current.event.write` [Calendar scope](/workspace/add-ons/concepts/workspace-scopes#calendar_scopes).\n\nIn addition, any changes made by the action callback function aren't saved until\nthe user saves the Calendar event.\n\n### Adding attendees with a callback function\n\nThe following example shows how to create a button that adds a specific\nattendee to a Calendar event being edited: \n\n /**\n * Build a simple card with a button that sends a notification.\n * This function is called as part of the eventOpenTrigger that builds\n * a UI when the user opens an event.\n *\n * @param e The event object passed to eventOpenTrigger function.\n * @return {Card}\n */\n function buildSimpleCard(e) {\n var buttonAction = CardService.newAction()\n .setFunctionName('onAddAttendeesButtonClicked');\n var button = CardService.newTextButton()\n .setText('Add new attendee')\n .setOnClickAction(buttonAction);\n\n // Check the event object to determine if the user can add\n // attendees and disable the button if not.\n if (!e.calendar.capabilities.canAddAttendees) {\n button.setDisabled(true);\n }\n\n // ...continue creating card sections and widgets, then create a Card\n // object to add them to. Return the built Card object.\n }\n\n /**\n * Callback function for a button action. Adds attendees to the\n * Calendar event being edited.\n *\n * @param {Object} e The action event object.\n * @return {CalendarEventActionResponse}\n */\n function onAddAttendeesButtonClicked (e) {\n return CardService.newCalendarEventActionResponseBuilder()\n .addAttendees([\"aiko@example.com\", \"malcom@example.com\"])\n .build();\n }\n\n### Setting conference data with a callback function\n\nThis action sets the conference data on the open event. For this conference data\nthe conference solution ID needs to be specified, because the action was not\ntriggered by the user selecting the desired solution.\n\nThe following example shows how to create a button that sets conference data\nfor an event being edited: \n\n /**\n * Build a simple card with a button that sends a notification.\n * This function is called as part of the eventOpenTrigger that builds\n * a UI when the user opens a Calendar event.\n *\n * @param e The event object passed to eventOpenTrigger function.\n * @return {Card}\n */\n function buildSimpleCard(e) {\n var buttonAction = CardService.newAction()\n .setFunctionName('onSaveConferenceOptionsButtonClicked')\n .setParameters(\n {'phone': \"1555123467\", 'adminEmail': \"joyce@example.com\"});\n var button = CardService.newTextButton()\n .setText('Add new attendee')\n .setOnClickAction(buttonAction);\n\n // Check the event object to determine if the user can set\n // conference data and disable the button if not.\n if (!e.calendar.capabilities.canSetConferenceData) {\n button.setDisabled(true);\n }\n\n // ...continue creating card sections and widgets, then create a Card\n // object to add them to. Return the built Card object.\n }\n\n /**\n * Callback function for a button action. Sets conference data for the\n * Calendar event being edited.\n *\n * @param {Object} e The action event object.\n * @return {CalendarEventActionResponse}\n */\n function onSaveConferenceOptionsButtonClicked(e) {\n var parameters = e.commonEventObject.parameters;\n\n // Create an entry point and a conference parameter.\n var phoneEntryPoint = ConferenceDataService.newEntryPoint()\n .setEntryPointType(ConferenceDataService.EntryPointType.PHONE)\n .setUri('tel:' + parameters['phone']);\n\n var adminEmailParameter = ConferenceDataService.newConferenceParameter()\n .setKey('adminEmail')\n .setValue(parameters['adminEmail']);\n\n // Create a conference data object to set to this Calendar event.\n var conferenceData = ConferenceDataService.newConferenceDataBuilder()\n .addEntryPoint(phoneEntryPoint)\n .addConferenceParameter(adminEmailParameter)\n .setConferenceSolutionId('myWebScheduledMeeting')\n .build();\n\n return CardService.newCalendarEventActionResponseBuilder()\n .setConferenceData(conferenceData)\n .build();\n }\n\n### Add attachments with a callback function\n\nThe following example shows how to create a button that adds an attachment to a\nCalendar event being edited: \n\n /**\n * Build a simple card with a button that creates a new attachment.\n * This function is called as part of the eventAttachmentTrigger that\n * builds a UI when the user goes through the add-attachments flow.\n *\n * @param e The event object passed to eventAttachmentTrigger function.\n * @return {Card}\n */\n function buildSimpleCard(e) {\n var buttonAction = CardService.newAction()\n .setFunctionName('onAddAttachmentButtonClicked');\n var button = CardService.newTextButton()\n .setText('Add a custom attachment')\n .setOnClickAction(buttonAction);\n\n // Check the event object to determine if the user can add\n // attachments and disable the button if not.\n if (!e.calendar.capabilities.canAddAttachments) {\n button.setDisabled(true);\n }\n\n // ...continue creating card sections and widgets, then create a Card\n // object to add them to. Return the built Card object.\n }\n\n /**\n * Callback function for a button action. Adds attachments to the Calendar\n * event being edited.\n *\n * @param {Object} e The action event object.\n * @return {CalendarEventActionResponse}\n */\n function onAddAttachmentButtonClicked(e) {\n return CardService.newCalendarEventActionResponseBuilder()\n .addAttachments([\n CardService.newAttachment()\n .setResourceUrl(\"https://example.com/test\")\n .setTitle(\"Custom attachment\")\n .setMimeType(\"text/html\")\n .setIconUrl(\"https://example.com/test.png\")\n ])\n .build();\n }\n\n#### Setting the attachment icon\n\nThe attachment icon must be hosted on Google's infrastructure. See [Provide\nattachment icons](/workspace/add-ons/calendar/attachment/providing-icons)\nfor details."]]