日历操作

Action 对象可让您构建交互式 Google Workspace 插件的行为。它们定义了 当用户在 Google Play 中 插件界面

使用 widget 处理程序函数, 这也定义了触发操作的条件。触发后, 执行指定的 回调函数。 系统会向该回调函数传递 事件对象,它包含 有关用户客户端互动情况的信息您必须实现 回调函数并使其返回特定的响应对象。

例如,假设您想要一个按钮,它可以在 。为此,您必须创建新的按钮 widget 并使用按钮 widget 处理程序函数 setOnClickAction(action) 设置卡片构建功能 Action。通过 您定义的 Action 指定了 Apps 脚本 点击按钮时执行的回调函数。在这种情况下, 实现回调函数以构建您所需的卡片,并返回 ActionResponse 对象。响应对象会告知插件向卡片显示回调 函数。

本页面介绍了您可以添加到 插件。

日历互动次数

可对日历进行扩展的 Google Workspace 插件 可包含一些其他特定于 Google 日历的 widget 操作。这些操作 需要关联的操作回调函数 返回专用响应对象:

已尝试执行操作 回调函数应返回
添加参加者 CalendarEventActionResponse
设置会议数据 CalendarEventActionResponse
添加附件 CalendarEventActionResponse

要使用这些 widget 操作和响应对象,必须设置以下 必须为 true:

  • 当用户打开日历活动时,会触发操作。
  • 插件的 addOns.calendar.currentEventAccess 设置为 WRITEREAD_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 的基础架构上。请参阅提供 附件图标 了解详情。