캘린더 작업

Action 객체를 사용하면 Google Workspace 부가기능에서 대화형 동작을 빌드할 수 있습니다. 사용자가 부가기능 UI에서 위젯 (예: 버튼)과 상호작용할 때 발생하는 작업을 정의합니다.

작업은 작업을 트리거하는 조건을 정의하는 위젯 핸들러 함수를 사용하여 지정된 위젯에 연결됩니다. 이 작업이 트리거되면 지정된 콜백 함수를 실행합니다. 콜백 함수에는 사용자의 클라이언트 측 상호작용에 대한 정보를 전달하는 이벤트 객체가 전달됩니다. 콜백 함수를 구현하고 특정 응답 객체를 반환하도록 해야 합니다.

예를 들어 클릭 시 새 카드가 빌드되어 표시되는 버튼을 원한다고 가정해 보겠습니다. 이를 위해 새 버튼 위젯을 만들고 버튼 위젯 핸들러 함수 setOnClickAction(action)를 사용하여 카드 빌드 Action를 설정해야 합니다. 정의한 Action는 버튼을 클릭할 때 실행되는 Apps Script 콜백 함수를 지정합니다. 이 경우 콜백 함수를 구현하여 원하는 카드를 빌드하고 ActionResponse 객체를 반환합니다. 응답 객체는 빌드한 콜백 함수가 빌드한 카드를 표시하도록 부가기능에 지시합니다.

이 페이지에서는 부가기능에 포함할 수 있는 캘린더 관련 위젯 작업을 설명합니다.

캘린더 상호작용

Calendar를 확장하는 Google Workspace 부가기능에는 몇 가지 Calendar 관련 위젯 작업이 추가로 포함될 수 있습니다. 이러한 작업을 수행하려면 연결된 작업 콜백 함수가 특수 응답 객체를 반환해야 합니다.

시도한 작업 콜백 함수가 반환해야 함
참석자 추가하기 CalendarEventActionResponse
회의 데이터 설정 CalendarEventActionResponse
첨부파일 추가하기 CalendarEventActionResponse

이러한 위젯 작업과 응답 객체를 사용하려면 다음 조건을 모두 충족해야 합니다.

  • 사용자가 Calendar 일정을 열어둔 상태에서 작업이 트리거됩니다.
  • 부가기능의 addOns.calendar.currentEventAccess 매니페스트 필드는 WRITE 또는 READ_WRITE로 설정됩니다.
  • 부가기능에는 https://www.googleapis.com/auth/calendar.addons.current.event.write 캘린더 범위가 포함됩니다.

또한 작업 콜백 함수의 변경사항은 사용자가 캘린더 이벤트를 저장할 때까지 저장되지 않습니다.

콜백 함수를 사용하여 참석자 추가

다음 예는 수정 중인 캘린더 일정에 특정 참석자를 추가하는 버튼을 만드는 방법을 보여줍니다.

  /**
   * Build a simple card with a button that sends a notification.
   * This function is called as part of the eventOpenTrigger that builds
   * a UI when the user opens an event.
   *
   * @param e The event object passed to eventOpenTrigger function.
   * @return {Card}
   */
  function buildSimpleCard(e) {
    var buttonAction = CardService.newAction()
        .setFunctionName('onAddAttendeesButtonClicked');
    var button = CardService.newTextButton()
        .setText('Add new attendee')
        .setOnClickAction(buttonAction);

    // Check the event object to determine if the user can add
    // attendees and disable the button if not.
    if (!e.calendar.capabilities.canAddAttendees) {
      button.setDisabled(true);
    }

    // ...continue creating card sections and widgets, then create a Card
    // object to add them to. Return the built Card object.
  }

  /**
   * Callback function for a button action. Adds attendees to the
   * Calendar event being edited.
   *
   * @param {Object} e The action event object.
   * @return {CalendarEventActionResponse}
   */
  function onAddAttendeesButtonClicked (e) {
    return CardService.newCalendarEventActionResponseBuilder()
        .addAttendees(["aiko@example.com", "malcom@example.com"])
        .build();
  }

콜백 함수를 사용하여 회의 데이터 설정

이 작업으로 공개 이벤트에 관한 회의 데이터가 설정됩니다. 이 회의 데이터의 경우 회의 솔루션 ID를 지정해야 합니다. 원하는 솔루션을 선택한 사용자에 의해 작업이 트리거되지 않았기 때문입니다.

다음 예에서는 수정 중인 이벤트의 회의 데이터를 설정하는 버튼을 만드는 방법을 보여줍니다.

  /**
   * Build a simple card with a button that sends a notification.
   * This function is called as part of the eventOpenTrigger that builds
   * a UI when the user opens a Calendar event.
   *
   * @param e The event object passed to eventOpenTrigger function.
   * @return {Card}
   */
  function buildSimpleCard(e) {
    var buttonAction = CardService.newAction()
        .setFunctionName('onSaveConferenceOptionsButtonClicked')
        .setParameters(
          {'phone': "1555123467", 'adminEmail': "joyce@example.com"});
    var button = CardService.newTextButton()
        .setText('Add new attendee')
        .setOnClickAction(buttonAction);

    // Check the event object to determine if the user can set
    // conference data and disable the button if not.
    if (!e.calendar.capabilities.canSetConferenceData) {
      button.setDisabled(true);
    }

    // ...continue creating card sections and widgets, then create a Card
    // object to add them to. Return the built Card object.
  }

  /**
   * Callback function for a button action. Sets conference data for the
   * Calendar event being edited.
   *
   * @param {Object} e The action event object.
   * @return {CalendarEventActionResponse}
   */
  function onSaveConferenceOptionsButtonClicked(e) {
    var parameters = e.commonEventObject.parameters;

    // Create an entry point and a conference parameter.
    var phoneEntryPoint = ConferenceDataService.newEntryPoint()
      .setEntryPointType(ConferenceDataService.EntryPointType.PHONE)
      .setUri('tel:' + parameters['phone']);

    var adminEmailParameter = ConferenceDataService.newConferenceParameter()
        .setKey('adminEmail')
        .setValue(parameters['adminEmail']);

    // Create a conference data object to set to this Calendar event.
    var conferenceData = ConferenceDataService.newConferenceDataBuilder()
        .addEntryPoint(phoneEntryPoint)
        .addConferenceParameter(adminEmailParameter)
        .setConferenceSolutionId('myWebScheduledMeeting')
        .build();

    return CardService.newCalendarEventActionResponseBuilder()
        .setConferenceData(conferenceData)
        .build();
  }

콜백 함수를 사용하여 연결 추가

다음 예는 수정 중인 캘린더 일정에 첨부파일을 추가하는 버튼을 만드는 방법을 보여줍니다.

  /**
   * Build a simple card with a button that creates a new attachment.
   * This function is called as part of the eventAttachmentTrigger that
   * builds a UI when the user goes through the add-attachments flow.
   *
   * @param e The event object passed to eventAttachmentTrigger function.
   * @return {Card}
   */
  function buildSimpleCard(e) {
    var buttonAction = CardService.newAction()
        .setFunctionName('onAddAttachmentButtonClicked');
    var button = CardService.newTextButton()
        .setText('Add a custom attachment')
        .setOnClickAction(buttonAction);

    // Check the event object to determine if the user can add
    // attachments and disable the button if not.
    if (!e.calendar.capabilities.canAddAttachments) {
      button.setDisabled(true);
    }

    // ...continue creating card sections and widgets, then create a Card
    // object to add them to. Return the built Card object.
  }

  /**
   * Callback function for a button action. Adds attachments to the Calendar
   * event being edited.
   *
   * @param {Object} e The action event object.
   * @return {CalendarEventActionResponse}
   */
  function onAddAttachmentButtonClicked(e) {
    return CardService.newCalendarEventActionResponseBuilder()
             .addAttachments([
               CardService.newAttachment()
                 .setResourceUrl("https://example.com/test")
                 .setTitle("Custom attachment")
                 .setMimeType("text/html")
                 .setIconUrl("https://example.com/test.png")
             ])
        .build();
  }

첨부파일 아이콘 설정

첨부파일 아이콘은 Google 인프라에서 호스팅되어야 합니다. 자세한 내용은 첨부파일 아이콘 제공을 참조하세요.