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

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

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

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

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

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

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

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

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

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

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

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

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

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