कैलेंडर कार्रवाइयां

Action ऑब्जेक्ट की मदद से, Google Workspace ऐड-ऑन में इंटरैक्टिव व्यवहार की सुविधा दी जा सकती है. इनसे यह तय होता है कि जब कोई उपयोगकर्ता ऐड-ऑन यूज़र इंटरफ़ेस (यूआई) में किसी विजेट (जैसे कि बटन) से इंटरैक्ट करता है, तो क्या होता है.

विजेट हैंडलर फ़ंक्शन का इस्तेमाल करके, किसी दिए गए विजेट से कोई कार्रवाई अटैच की जाती है. यह फ़ंक्शन उस स्थिति के बारे में भी बताता है जो कार्रवाई को ट्रिगर करती है. ट्रिगर होने पर, वह कार्रवाई तय किया गया कॉलबैक फ़ंक्शन लागू करती है. कॉलबैक फ़ंक्शन को एक इवेंट ऑब्जेक्ट पास किया जाता है. इसमें उपयोगकर्ता के क्लाइंट-साइड इंटरैक्शन के बारे में जानकारी होती है. आपको कॉलबैक फ़ंक्शन लागू करना होगा और इससे कोई खास रिस्पॉन्स ऑब्जेक्ट दिखाना होगा.

उदाहरण के लिए, मान लें कि आपको ऐसा बटन चाहिए जिस पर क्लिक करने पर नया कार्ड बने और दिखता हो. इसके लिए, आपको एक नया बटन विजेट बनाना होगा और कार्ड-बिल्डिंग Action सेट करने के लिए, बटन विजेट हैंडलर फ़ंक्शन setOnClickAction(action) का इस्तेमाल करना होगा. आपने जो Action तय किया है उससे Apps Script कॉलबैक फ़ंक्शन के बारे में पता चलता है. यह फ़ंक्शन, बटन पर क्लिक किए जाने पर काम करता है. इस मामले में, आपकी पसंद का कार्ड बनाने के लिए, कॉलबैक फ़ंक्शन लागू किया जाता है और ActionResponse ऑब्जेक्ट दिखाया जाता है. रिस्पॉन्स ऑब्जेक्ट, ऐड-ऑन को कॉलबैक फ़ंक्शन दिखाने के लिए बताता है.

इस पेज पर कैलेंडर से जुड़ी खास विजेट कार्रवाइयों के बारे में बताया गया है, जिन्हें आप अपने ऐड-ऑन में शामिल कर सकते हैं.

Calendar के साथ इंटरैक्शन

Calendar को बढ़ाने वाले Google Workspace ऐड-ऑन में, कैलेंडर के लिए खास विजेट की कुछ और कार्रवाइयां शामिल हो सकती हैं. इन कार्रवाइयों के लिए, खास तरह के रिस्पॉन्स ऑब्जेक्ट देने के लिए, इनसे जुड़े कार्रवाई कॉलबैक फ़ंक्शन की ज़रूरत होती है:

कार्रवाई की कोशिश की गई कॉलबैक फ़ंक्शन को वापस आना चाहिए
मेहमानों को जोड़ना 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();
  }

कॉलबैक फ़ंक्शन की मदद से अटैचमेंट जोड़ना

नीचे दिए गए उदाहरण में, ऐसे बटन को बनाने का तरीका बताया गया है जो बदले जा रहे Calendar इवेंट में अटैचमेंट जोड़ता है:

  /**
   * 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 के इंफ़्रास्ट्रक्चर पर होस्ट होना चाहिए. ज़्यादा जानकारी के लिए, अटैचमेंट वाले आइकॉन दें देखें.