إجراءات التقويم

تتيح لك كائنات Action إنشاء سلوك تفاعلي في إضافات Google Workspace. وهي تحدد ما يحدث عندما يتفاعل المستخدم مع أداة (على سبيل المثال، زر) في واجهة مستخدم الإضافة.

يتم إرفاق إجراء بأداة معيّنة باستخدام دالة معالج الأدوات، التي تحدد أيضًا الشرط الذي يؤدي إلى تنفيذ الإجراء. عند التشغيل، ينفّذ الإجراء دالة استدعاء معيّنة. تمرر دالة الاستدعاء كائن حدث يحمل معلومات عن تفاعلات المستخدم من جهة العميل. يجب عليك تنفيذ دالة معاودة الاتصال وجعلها تعرض كائن استجابة محددًا.

على سبيل المثال، لنفترض أنّك تريد زرًا لإنشاء بطاقة جديدة وعرضها عند النقر عليها. لإجراء ذلك، عليك إنشاء تطبيق مصغّر جديد للأزرار واستخدام وظيفة المعالج المصغّر للأزرار setOnClickAction(action) لضبط Action لإنشاء البطاقات. تحدّد Action التي تحدّدها دالة استدعاء "برمجة تطبيقات Google" التي يتم تنفيذها عند النقر على الزر. في هذه الحالة، يمكنك تنفيذ دالة معاودة الاتصال لإنشاء البطاقة المطلوبة وعرض عنصر ActionResponse. يطلب كائن الاستجابة من الإضافة عرض البطاقة التي تم إنشاؤها في دالة رد الاتصال.

تصف هذه الصفحة إجراءات الأداة الخاصة بالتقويم والتي يمكنك تضمينها في إضافتك.

تفاعلات التقويم

يمكن أن تتضمن "إضافات Google Workspace" التي تُكمِّل "تقويم Google" بعض الإجراءات الإضافية الخاصة بالأداة الخاصة بالتقويم. تتطلب هذه الإجراءات الإجراء المرتبط دالة معاودة الاتصال لعرض كائنات استجابة متخصصة:

تمت محاولة تنفيذ الإجراء يجب أن تعرض دالة معاودة الاتصال
إضافة الضيوف CalendarEventActionResponse
ضبط بيانات مكالمة الفيديو CalendarEventActionResponse
إضافة مرفقات CalendarEventActionResponse

للاستفادة من هذه الإجراءات وكائنات الاستجابة للأدوات المصغّرة، يجب استيفاء كل ما يلي:

  • يتم تشغيل الإجراء عندما يكون لدى المستخدم حدث في "تقويم Google" مفتوح.
  • تم ضبط حقل بيان addOns.calendar.currentEventAccess للإضافة على WRITE أو READ_WRITE.
  • تتضمن الإضافة https://www.googleapis.com/auth/calendar.addons.current.event.write نطاق "تقويم Google".

بالإضافة إلى ذلك، لا يتم حفظ أي تغييرات تجريها وظيفة استدعاء الإجراء حتى يحفظ المستخدم حدث "تقويم Google".

إضافة ضيوف باستخدام دالة معاودة الاتصال

يوضح المثال التالي كيفية إنشاء زر يضيف ضيفًا محددًا إلى حدث تقويم يتم تعديله:

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

إعداد بيانات مكالمة الفيديو باستخدام دالة معاودة الاتصال

يُحدِّد هذا الإجراء بيانات مكالمة الفيديو على الحدث المفتوح. بالنسبة إلى بيانات مكالمة الفيديو هذه، يجب تحديد معرّف حل مكالمة الفيديو هذه، لأنّ الإجراء لم يتم تشغيله بواسطة المستخدم الذي يختار الحل المطلوب.

يوضح المثال التالي كيفية إنشاء زر يحدّد بيانات مكالمة الفيديو لحدث يتم تعديله:

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

إضافة مرفقات باستخدام وظيفة معاودة الاتصال

يوضح المثال التالي كيفية إنشاء زر يضيف مرفقًا إلى حدث في "تقويم Google" يتم تعديله:

  /**
   * 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 الأساسية. راجِع توفير رموز المرفقات لمعرفة التفاصيل.