פעולות ביומן

Action אובייקטים מאפשרים ליצור אובייקטים אינטראקטיביים ההתנהגות של המשתמשים בתוספים של Google Workspace. הם מגדירים מה קורה כשמשתמש יוצר אינטראקציה עם ווידג'ט (לדוגמה, לחצן) בממשק המשתמש של התוסף.

הפעולה מצורפת לווידג'ט נתון באמצעות את פונקציית ה-handler של הווידג'טים, שמגדיר גם את התנאי שמפעיל את הפעולה. כשהיא מופעלת, הפרמטר הפעולה מבצעת פונקציית קריאה חוזרת. פונקציית הקריאה החוזרת מועברת אובייקט אירוע שנושא מידע על האינטראקציות של המשתמש בצד הלקוח. עליך ליישם את פונקציית הקריאה החוזרת כדי להחזיר אובייקט תגובה ספציפי.

לדוגמה, נניח שאתם רוצים לחצן ליצירה ולהצגה של כרטיס חדש בוצעה לחיצה. לשם כך, צריך ליצור ווידג'ט חדש של לחצנים ולהשתמש בווידג'ט הלחצנים פונקציית handler setOnClickAction(action) כדי להגדיר בניית כרטיסים Action. Action שמגדירים מציין את Apps Script פונקציית קריאה חוזרת (callback) שמופעלת כשלוחצים על הלחצן. במקרה הזה, להטמיע את פונקציית הקריאה החוזרת כדי ליצור את הכרטיס הרצוי ולהחזיר ActionResponse לאובייקט. אובייקט התשובה מורה לתוסף להציג את הכרטיס שהקריאה אליו חוזרת גנרטיבית.

בדף הזה מתוארות פעולות בווידג'ט ספציפיות ליומן שאפשר לכלול

אינטראקציות ביומן

תוספים ל-Google Workspace שמרחיבים את יומן Google יכולים לכלול עוד כמה פעולות בווידג'ט שספציפיות ליומן Google. הפעולות האלה נדרשת הפעולה המשויכת פונקציית קריאה חוזרת כדי להחזיר אובייקטים מיוחדים של תגובה:

בוצע ניסיון לפעולה פונקציית הקריאה החוזרת אמורה לחזור
הוספת משתתפים CalendarEventActionResponse
הגדרת הנתונים של שיחת הוועידה CalendarEventActionResponse
הוספת קבצים מצורפים CalendarEventActionResponse

כדי להשתמש בפעולות הווידג'ט ובאובייקטים של התשובות, צריך לבצע את כל חייב להיות True:

  • הפעולה מופעלת בזמן שאירוע ביומן של המשתמש פתוח.
  • 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. ראו הוספת סמלים של קבצים מצורפים לקבלת פרטים.