कैलेंडर कॉन्फ़्रेंस के बदलाव सिंक किए जा रहे हैं

उपयोगकर्ता अपने Google Calendar इवेंट को आसानी से अपडेट कर सकते हैं या मिटा सकते हैं. अगर कोई उपयोगकर्ता इवेंट बनाने के बाद उसे अपडेट करता है, तो ऐड-ऑन के लिए कॉन्फ़्रेंस का डेटा अपडेट करके, बदलाव के बारे में जवाब दें. अगर आपके तीसरे पक्ष का कॉन्फ़्रेंसिंग सिस्टम इवेंट डेटा को ट्रैक करने, इवेंट में बदलाव करने के बारे में कॉन्फ़्रेंस को अपडेट न करने पर, कॉन्फ़्रेंस रेंडर हो सकता है इसकी वजह से उपयोगकर्ताओं को खराब अनुभव मिलता है.

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

सिंक करने की सामान्य प्रोसेस नीचे दी गई है:

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

सिंक करना शुरू करें

ऐड-ऑन के तीसरे पक्ष के सिस्टम पर कॉन्फ़्रेंस बनाने के बाद, तो एक इंस्टॉल किया जा सकने वाला ट्रिगर बन जाएगा. जो जवाब देती है इवेंट में हुए बदलाव इस कैलेंडर में, अगर ट्रिगर पहले से मौजूद नहीं है.

ट्रिगर बनाने के बाद, शुरुआत में शुरू करना चाहिए सिंक टोकन. ऐसा सीधे तौर पर ट्रिगर फ़ंक्शन को एक्ज़ीक्यूट करके किया जाता है.

कैलेंडर के लिए ट्रिगर बनाएं

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

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

सिंक ट्रिगर फ़ंक्शन लागू करना

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

आपको अपने ऐड-ऑन के इस्तेमाल किए जाने वाले ट्रिगर फ़ंक्शन को लागू करना होगा. यह ट्रिगर फ़ंक्शन को ये काम करने होंगे:

  1. Calendar की बेहतर सेवा के लिए Calendar.Events.list() कॉल करें. इसके लिए, इसका इस्तेमाल करें: पिछले इवेंट के बाद से बदले गए इवेंट की सूची फिर से पाने के लिए syncToken सिंक. सिंक टोकन का इस्तेमाल करके, ऐड-ऑन के इवेंट की संख्या कम की जा सकती है को जांचना होगा.

    जब ट्रिगर फ़ंक्शन मान्य सिंक टोकन के बिना काम करता है, तो यह बैक अप लेता है फ़ुल सिंक पर स्विच करें. पूरी तरह से सिंक करने पर, सभी इवेंट वापस पाने की कोशिश की जाती है तय समयसीमा में नया, मान्य सिंक जनरेट करने में मदद मिलती है टोकन.

  2. बदलाव किए गए हर इवेंट की जांच करके यह पता लगाया जाता है कि इवेंट से तीसरे पक्ष की कॉन्फ़्रेंस.
  3. अगर किसी इवेंट में कॉन्फ़्रेंस होती है, तो इसकी जांच की जाती है कि क्या बदलाव हुए हैं. इस बदलाव के आधार पर, इससे जुड़े कॉन्फ़्रेंस में ज़रूरी हो. उदाहरण के लिए, अगर कोई इवेंट मिटा दिया गया था, तो ऐड-ऑन को साथ ही, वे कॉन्फ़्रेंस को मिटा भी सकते हैं.
  4. कॉन्फ़्रेंस में कोई भी ज़रूरी बदलाव करने के लिए, तीसरे पक्ष का सिस्टम.
  5. सभी ज़रूरी बदलाव करने के बाद, इस तारीख तक लौटाए गए nextSyncToken को सेव करें: Calendar.Events.list() तरीका. यह सिंक टोकन सबसे आखिर में मिला है Calendar.Events.list() कॉल के बाद नतीजे दिखाने वाला पेज.

Google Calendar इवेंट अपडेट किया जा रहा है

कुछ मामलों में हो सकता है कि आप परफ़ॉर्म करते समय Google Calendar इवेंट को अपडेट करना चाहें सिंक करते हैं. अगर आपको ऐसा करना है, तो इवेंट को इवेंट के हिसाब से अपडेट करें Google Calendar की बेहतर सेवा अनुरोध. कृपया शर्त के साथ अपडेट करना If-Match हेडर के साथ. यह आपके बदलावों को अनजाने में होने से रोकता है किसी दूसरे क्लाइंट में उपयोगकर्ता की ओर से एक साथ किए जाने वाले बदलावों को ओवरराइट करना.

उदाहरण

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

/**
 *  Initializes syncing of conference data by creating a sync trigger and
 *  sync token if either does not exist yet.
 *
 *  @param {String} calendarId The ID of the Google Calendar.
 */
function initializeSyncing(calendarId) {
  // Create a syncing trigger if it doesn't exist yet.
  createSyncTrigger(calendarId);

  // Perform an event sync to create the initial sync token.
  syncEvents({'calendarId': calendarId});
}

/**
 *  Creates a sync trigger if it does not exist yet.
 *
 *  @param {String} calendarId The ID of the Google Calendar.
 */
function createSyncTrigger(calendarId) {
  // Check to see if the trigger already exists; if does, return.
  var allTriggers = ScriptApp.getProjectTriggers();
  for (var i = 0; i < allTriggers.length; i++) {
    var trigger = allTriggers[i];
    if (trigger.getTriggerSourceId() == calendarId) {
      return;
    }
  }

  // Trigger does not exist, so create it. The trigger calls the
  // 'syncEvents()' trigger function when it fires.
  var trigger = ScriptApp.newTrigger('syncEvents')
      .forUserCalendar(calendarId)
      .onEventUpdated()
      .create();
}

/**
 *  Sync events for the given calendar; this is the syncing trigger
 *  function. If a sync token already exists, this retrieves all events
 *  that have been modified since the last sync, then checks each to see
 *  if an associated conference needs to be updated and makes any required
 *  changes. If the sync token does not exist or is invalid, this
 *  retrieves future events modified in the last 24 hours instead. In
 *  either case, a new sync token is created and stored.
 *
 *  @param {Object} e If called by a event updated trigger, this object
 *      contains the Google Calendar ID, authorization mode, and
 *      calling trigger ID. Only the calendar ID is actually used here,
 *      however.
 */
function syncEvents(e) {
  var calendarId = e.calendarId;
  var properties = PropertiesService.getUserProperties();
  var syncToken = properties.getProperty('syncToken');

  var options;
  if (syncToken) {
    // There's an existing sync token, so configure the following event
    // retrieval request to only get events that have been modified
    // since the last sync.
    options = {
      syncToken: syncToken
    };
  } else {
    // No sync token, so configure to do a 'full' sync instead. In this
    // example only recently updated events are retrieved in a full sync.
    // A larger time window can be examined during a full sync, but this
    // slows down the script execution. Consider the trade-offs while
    // designing your add-on.
    var now = new Date();
    var yesterday = new Date();
    yesterday.setDate(now.getDate() - 1);
    options = {
      timeMin: now.toISOString(),          // Events that start after now...
      updatedMin: yesterday.toISOString(), // ...and were modified recently
      maxResults: 50,   // Max. number of results per page of responses
      orderBy: 'updated'
    }
  }

  // Examine the list of updated events since last sync (or all events
  // modified after yesterday if the sync token is missing or invalid), and
  // update any associated conferences as required.
  var events;
  var pageToken;
  do {
    try {
      options.pageToken = pageToken;
      events = Calendar.Events.list(calendarId, options);
    } catch (err) {
      // Check to see if the sync token was invalidated by the server;
      // if so, perform a full sync instead.
      if (err.message ===
            "Sync token is no longer valid, a full sync is required.") {
        properties.deleteProperty('syncToken');
        syncEvents(e);
        return;
      } else {
        throw new Error(err.message);
      }
    }

    // Read through the list of returned events looking for conferences
    // to update.
    if (events.items && events.items.length > 0) {
      for (var i = 0; i < events.items.length; i++) {
         var calEvent = events.items[i];
         // Check to see if there is a record of this event has a
         // conference that needs updating.
         if (eventHasConference(calEvent)) {
           updateConference(calEvent, calEvent.conferenceData.conferenceId);
         }
      }
    }

    pageToken = events.nextPageToken;
  } while (pageToken);

  // Record the new sync token.
  if (events.nextSyncToken) {
    properties.setProperty('syncToken', events.nextSyncToken);
  }
}

/**
 *  Returns true if the specified event has an associated conference
 *  of the type managed by this add-on; retuns false otherwise.
 *
 *  @param {Object} calEvent The Google Calendar event object, as defined by
 *      the Calendar API.
 *  @return {boolean}
 */
function eventHasConference(calEvent) {
  var name = calEvent.conferenceData.conferenceSolution.name || null;

  // This version checks if the conference data solution name matches the
  // one of the solution names used by the add-on. Alternatively you could
  // check the solution's entry point URIs or other solution-specific
  // information.
  if (name) {
    if (name === "My Web Conference" ||
        name === "My Recorded Web Conference") {
      return true;
    }
  }
  return false;
}

/**
 *  Update a conference based on new Google Calendar event information.
 *  The exact implementation of this function is highly dependant on the
 *  details of the third-party conferencing system, so only a rough outline
 *  is shown here.
 *
 *  @param {Object} calEvent The Google Calendar event object, as defined by
 *      the Calendar API.
 *  @param {String} conferenceId The ID used to identify the conference on
 *      the third-party conferencing system.
 */
function updateConference(calEvent, conferenceId) {
  // Check edge case: the event was cancelled
  if (calEvent.status === 'cancelled' || eventHasConference(calEvent)) {
    // Use the third-party API to delete the conference too.


  } else {
    // Extract any necessary information from the event object, then
    // make the appropriate third-party API requests to update the
    // conference with that information.

  }
}