اقدامات تقویم

اشیاء Action به شما امکان می دهند رفتار تعاملی را در افزونه های Google Workspace ایجاد کنید. آنها تعریف می کنند که چه اتفاقی می افتد زمانی که کاربر با یک ویجت (به عنوان مثال، یک دکمه) در رابط کاربری افزونه تعامل می کند.

یک عملکرد با استفاده از یک تابع کنترل کننده ویجت به یک ویجت معین متصل می‌شود، که همچنین شرایطی را که اقدام را آغاز می‌کند، تعریف می‌کند. وقتی فعال می‌شود، عملکرد یک تابع بازخوانی تعیین‌شده را اجرا می‌کند. تابع callback به یک شی رویداد ارسال می شود که اطلاعات مربوط به تعاملات سمت مشتری کاربر را حمل می کند. شما باید تابع callback را پیاده سازی کنید و از آن بخواهید یک شی پاسخ خاص را برگرداند.

به عنوان مثال، می‌خواهید دکمه‌ای را می‌خواهید که با کلیک کردن، یک کارت جدید بسازد و نمایش دهد. برای این کار، باید یک ویجت دکمه جدید ایجاد کنید و از تابع کنترل کننده ابزارک دکمه setOnClickAction(action) برای تنظیم یک Action ساخت کارت استفاده کنید. Action که شما تعریف می‌کنید، یک تابع فراخوانی Apps Script را مشخص می‌کند که با کلیک روی دکمه اجرا می‌شود. در این حالت، تابع callback را برای ساخت کارت مورد نظر و برگرداندن یک شی ActionResponse پیاده سازی می کنید. شیء پاسخ به افزونه می‌گوید که کارتی را که تابع پاسخ به تماس ساخته شده است نمایش دهد.

این صفحه اقدامات ویجت ویژه تقویم را که می توانید در برافزای خود قرار دهید، توضیح می دهد.

تعاملات تقویم

افزونه‌های Google Workspace که تقویم را گسترش می‌دهند، می‌توانند شامل چند اقدام ویجت ویژه تقویم باشند. این کنش‌ها برای برگرداندن اشیاء پاسخ تخصصی ، به تابع مربوط به تماس نیاز دارند:

اقدامی انجام شد تابع Callback باید برگردد
اضافه کردن شرکت کنندگان CalendarEventActionResponse
تنظیم داده های کنفرانس CalendarEventActionResponse
افزودن پیوست ها CalendarEventActionResponse

برای استفاده از این اقدامات ویجت و اشیاء پاسخ، همه موارد زیر باید درست باشد:

  • زمانی که کاربر یک رویداد Calendar را باز کرده است، این اقدام فعال می شود.
  • فیلد مانیفست addOns.calendar.currentEventAccess افزونه روی WRITE یا READ_WRITE تنظیم شده است.
  • این افزونه شامل https://www.googleapis.com/auth/calendar.addons.current.event.write محدوده تقویم است.

علاوه بر این، هر تغییری که توسط عملکرد پاسخ به تماس عملی ایجاد شده است تا زمانی که کاربر رویداد Calendar را ذخیره نکند، ذخیره نمی شود.

اضافه کردن شرکت کنندگان با عملکرد پاسخ به تماس

مثال زیر نحوه ایجاد دکمه ای را نشان می دهد که یک شرکت کننده خاص را به رویداد تقویم در حال ویرایش اضافه می کند:

  /**
   * 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 میزبانی شود. برای جزئیات بیشتر به ارائه نمادهای پیوست مراجعه کنید.