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

Action ऑब्जेक्ट से इंटरैक्टिव बनाया जा सकता है के लिए इस्तेमाल किया जा सकता है. उनकी परिभाषा जब कोई उपयोगकर्ता किसी विजेट (उदाहरण के लिए, बटन) से इंटरैक्ट करता है, तब क्या होता है पर क्लिक करें.

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

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

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

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

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

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