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

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

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

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

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

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

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

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

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

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

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

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

يوضّح المثال التالي كيفية إنشاء زر يضيف مدعوين معيّنين إلى حدث في "تقويم 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();
  }

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

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

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