Takvim işlemleri

Action nesneleri Google Workspace Eklentileri'nde etkileşimli davranışlar geliştirmenizi sağlar. Bunlar, bir kullanıcı eklenti kullanıcı arayüzündeki bir widget'la (örneğin, bir düğme) etkileşimde bulunduğunda ne olacağını tanımlar.

İşlem, işlemi tetikleyen koşulu da tanımlayan bir widget işleyici işlevi kullanılarak belirli bir widget'a eklenir. Tetiklendiğinde, özel bir geri çağırma işlevi yürütür. Geri çağırma işlevi, kullanıcının istemci tarafı etkileşimleri hakkında bilgi taşıyan bir etkinlik nesnesi geçirilir. Geri çağırma işlevini uygulamanız ve belirli bir yanıt nesnesi döndürmesini sağlamanız gerekir.

Örneğin, tıklandığında yeni bir kart oluşturan ve görüntüleyen bir düğme istediğinizi varsayalım. Bunun için yeni bir düğme widget'ı oluşturmanız ve bir kart oluşturma Action ayarlamak için düğme widget işleyici işlevini setOnClickAction(action) kullanmanız gerekir. Tanımladığınız Action, düğme tıklandığında yürütülecek bir Apps Komut Dosyası geri çağırma işlevini belirtir. Bu durumda, istediğiniz kartı derlemek ve bir ActionResponse nesnesi döndürmek için geri çağırma işlevini uygularsınız. Yanıt nesnesi, eklentiye geri çağırma işlevinin oluşturduğu kartı görüntülemesini bildirir.

Bu sayfada, eklentinize ekleyebileceğiniz Takvim'e özel widget işlemleri açıklanmaktadır.

Takvim etkileşimleri

Takvim'i genişleten Google Workspace Eklentileri, Takvim'e özel birkaç ek widget işlemi içerebilir. Bu işlemler, özel yanıt nesneleri döndürmek için ilişkili geri çağırma işlevi gerektirir:

İşlem yapılmaya çalışıldı Geri çağırma işlevi şu sonucu döndürmelidir:
Katılımcı ekleme CalendarEventActionResponse
Konferans verilerini ayarlama CalendarEventActionResponse
Dosya ekleme CalendarEventActionResponse

Bu widget eylemlerinden ve yanıt nesnelerinden yararlanmak için aşağıdakilerin tümünün doğru olması gerekir:

  • İşlem, kullanıcının Takvim etkinliği açıkken tetiklenir.
  • Eklentinin addOns.calendar.currentEventAccess manifest alanı WRITE veya READ_WRITE olarak ayarlanmıştır.
  • Eklenti, https://www.googleapis.com/auth/calendar.addons.current.event.write Takvim kapsamını içerir.

Ayrıca, işlem geri çağırma işlevi tarafından yapılan değişiklikler kullanıcı Takvim etkinliğini kaydedene kadar kaydedilmez.

Geri çağırma işleviyle katılımcı ekleme

Aşağıdaki örnekte, düzenlenen Takvim etkinliğine belirli bir katılımcı ekleyen bir düğmenin nasıl oluşturulacağı gösterilmektedir:

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

Geri arama işleviyle konferans verilerini ayarlama

Bu işlem, açık etkinlikte konferans verilerini ayarlar. İşlem, kullanıcı istenen çözümü seçerek tetiklemediğinden, bu konferans verileri için konferans çözümü kimliğinin belirtilmesi gerekir.

Aşağıdaki örnekte, düzenlenen bir etkinlik için konferans verilerini ayarlayan bir düğmenin nasıl oluşturulacağı gösterilmektedir:

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

Geri çağırma işleviyle ekler ekleme

Aşağıdaki örnekte, düzenlenen Takvim etkinliğine dosya ekleyen bir düğmenin nasıl oluşturulacağı gösterilmektedir:

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

Ek simgesini ayarlama

Ek simgesi, Google'ın altyapısında barındırılmalıdır. Ayrıntılar için Ek simgeleri sağlama bölümüne bakın.