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

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

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

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

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

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

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

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

للاستفادة من إجراءات الأدوات وكائنات الاستجابة هذه، يجب استيفاء جميع الشروط التالية:

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

بالإضافة إلى ذلك، لا يتم حفظ أي تغييرات تجريها وظيفة استدعاء الإجراء حتى يحفظ المستخدم حدث "تقويم 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 الأساسية. راجع تقديم رموز المرفقات لمزيد من التفاصيل.