캘린더 작업

Action 객체를 사용하면 양방향 빌드가 가능합니다. Google Workspace 부가기능에 적용될 예정입니다. 특성은 사용자가 홈 화면의 위젯 (예: 버튼)과 설정할 수 있습니다

작업은 위젯 핸들러 함수 작업을 트리거하는 조건도 정의합니다. 트리거되면 작업은 지정된 콜백 함수입니다. 콜백 함수는 이벤트 객체 클라이언트 측 상호작용에 대한 정보 이때 콜백 함수를 호출하고 특정 응답 객체를 반환하도록 합니다.

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

이 페이지에서는 부가기능

캘린더 상호작용

Calendar를 확장하는 Google Workspace 부가기능 몇 가지 캘린더 관련 위젯 작업을 추가로 포함할 수 있습니다. 이러한 작업 연결된 작업 콜백 함수가 필요합니다. 특수 응답 객체를 반환합니다.

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

이러한 위젯 작업 및 응답 객체를 활용하려면 다음을 모두 충족해야 합니다. 가 true여야 합니다.

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

또한 작업 콜백 함수에 의한 변경사항은 사용자가 Calendar 일정을 저장합니다.

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

다음 예는 특정 수정 중인 Calendar 일정의 참석자:

  /**
   * 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 인프라에서 호스팅되어야 합니다. 제공을 참조하세요. 첨부파일 아이콘 참조하세요.