Tindakan kalender

Objek Action memungkinkan Anda membuat aplikasi perilaku pengguna yang berbeda ke Add-on Google Workspace. {i>Sprint<i} menentukan apa yang terjadi ketika pengguna berinteraksi dengan widget (misalnya, tombol) di UI add-on.

Suatu tindakan dilampirkan ke widget tertentu menggunakan fungsi pengendali widget, yang juga menentukan kondisi yang memicu tindakan. Saat dipicu, tindakan menjalankan tindakan fungsi callback. Fungsi callback diberi objek peristiwa yang membawa informasi tentang interaksi {i>client-side<i} pengguna. Anda harus menerapkan fungsi callback dan membuatnya menampilkan objek respons tertentu.

Misalnya, Anda menginginkan tombol yang membuat dan menampilkan kartu baru saat diklik. Untuk melakukannya, Anda harus membuat widget tombol baru dan menggunakan widget tombol tersebut fungsi pengendali setOnClickAction(action) untuk menetapkan Action pembuatan kartu. Tujuan Action yang Anda tentukan menentukan Apps Script fungsi callback yang dieksekusi saat tombol diklik. Dalam hal ini, Anda mengimplementasikan fungsi callback untuk membangun kartu yang Anda inginkan dan menampilkan ActionResponse . Objek respons memberi tahu add-on untuk menampilkan kartu yang akan menampilkan callback fungsi build.

Halaman ini menjelaskan tindakan widget khusus Kalender yang dapat Anda sertakan dalam {i>add-on<i}.

Interaksi kalender

Add-on Google Workspace yang memperluas Kalender dapat menyertakan beberapa tindakan widget khusus Kalender tambahan. Tindakan ini memerlukan tindakan terkait fungsi callback untuk menampilkan objek respons khusus:

Tindakan dicoba Fungsi callback akan ditampilkan
Menambahkan tamu CalendarEventActionResponse
Menetapkan data konferensi CalendarEventActionResponse
Menambahkan lampiran CalendarEventActionResponse

Untuk memanfaatkan tindakan widget dan objek respons ini, semua hal harus benar:

  • Tindakan ini dipicu saat pengguna membuka acara Kalender.
  • addOns.calendar.currentEventAccess add-on kolom manifes disetel ke WRITE atau READ_WRITE.
  • Add-on ini menyertakan https://www.googleapis.com/auth/calendar.addons.current.event.write Cakupan kalender.

Selain itu, perubahan apa pun yang dibuat oleh fungsi callback tindakan tidak disimpan hingga pengguna menyimpan acara Kalender.

Menambahkan peserta dengan fungsi callback

Contoh berikut menampilkan cara membuat tombol yang menambahkan elemen tamu acara Kalender yang sedang diedit:

  /**
   * 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();
  }

Menetapkan data konferensi dengan fungsi callback

Tindakan ini akan menetapkan data konferensi pada acara terbuka. Untuk data konferensi ini ID solusi konferensi harus ditentukan, karena tindakannya dipicu oleh pengguna yang memilih solusi yang diinginkan.

Contoh berikut menunjukkan cara membuat tombol yang menetapkan data konferensi untuk acara yang sedang diedit:

  /**
   * 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();
  }

Menambahkan lampiran dengan fungsi callback

Contoh berikut menampilkan cara membuat tombol yang menambahkan lampiran ke Acara kalender yang sedang diedit:

  /**
   * 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();
  }

Menyetel ikon lampiran

Ikon lampiran harus dihosting di infrastruktur Google. Lihat Menyediakan ikon lampiran untuk mengetahui detailnya.