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

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

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

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

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

कैलेंडर इंटरैक्शन

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

कार्रवाई की कोशिश की गई कॉलबैक फ़ंक्शन वापस आना चाहिए
मीटिंग में शामिल होने वाले लोगों को जोड़ा जा रहा है CalendarEventActionResponse
कॉन्फ़्रेंस डेटा सेट करना CalendarEventActionResponse
अटैचमेंट जोड़ना CalendarEventActionResponse

विजेट की इन कार्रवाइयों और रिस्पॉन्स ऑब्जेक्ट का इस्तेमाल करने के लिए, इन चीज़ों का सही होना चाहिए:

  • यह कार्रवाई तब ट्रिगर होती है, जब उपयोगकर्ता के पास Calendar इवेंट खुला होता है.
  • ऐड-ऑन का addOns.calendar.currentEventAccess मेनिफ़ेस्ट फ़ील्ड WRITE या READ_WRITE पर सेट है.
  • ऐड-ऑन में https://www.googleapis.com/auth/calendar.addons.current.event.write Calendar का स्कोप शामिल होता है.

इसके अलावा, कार्रवाई के कॉलबैक फ़ंक्शन से किए गए बदलाव तब तक सेव नहीं किए जाते, जब तक उपयोगकर्ता कैलेंडर इवेंट को सेव नहीं करता.

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

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