ক্যালেন্ডার সম্মেলনের পরিবর্তনগুলি সিঙ্ক করা হচ্ছে৷

ব্যবহারকারীরা তাদের Google ক্যালেন্ডার ইভেন্টগুলি অবাধে আপডেট করতে বা মুছে ফেলতে পারেন। যদি একজন ব্যবহারকারী এটির জন্য একটি সম্মেলন তৈরি করার পরে একটি ইভেন্ট আপডেট করে, তাহলে আপনার অ্যাড-অনকে কনফারেন্স ডেটা আপডেট করে পরিবর্তনের প্রতিক্রিয়া জানাতে হতে পারে। যদি আপনার তৃতীয়-পক্ষের কনফারেন্সিং সিস্টেম ইভেন্ট ডেটার ট্র্যাক রাখার উপর নির্ভর করে, তাহলে ইভেন্ট পরিবর্তনে কনফারেন্স আপডেট করতে ব্যর্থ হলে কনফারেন্সটি অব্যবহারযোগ্য হতে পারে এবং এর ফলে ব্যবহারকারীর অভিজ্ঞতা খারাপ হতে পারে।

Google ক্যালেন্ডার ইভেন্টে পরিবর্তনের সাথে কনফারেন্স ডেটা আপডেট রাখার প্রক্রিয়াটিকে সিঙ্কিং বলা হয়। আপনি একটি Apps স্ক্রিপ্ট ইনস্টলযোগ্য ট্রিগার তৈরি করে ইভেন্ট পরিবর্তনগুলি সিঙ্ক করতে পারেন যা প্রদত্ত ক্যালেন্ডারে ইভেন্টগুলি পরিবর্তিত হলেই ফায়ার হয়৷ দুর্ভাগ্যবশত, ট্রিগার কোন ইভেন্টগুলি পরিবর্তিত হয়েছে তা রিপোর্ট করে না এবং আপনি এটি শুধুমাত্র আপনার তৈরি করা কনফারেন্সগুলির সাথে ইভেন্টগুলিতে সীমাবদ্ধ করতে পারবেন না। পরিবর্তে, আপনাকে অবশ্যই শেষ সিঙ্কের পর থেকে একটি ক্যালেন্ডারে করা সমস্ত পরিবর্তনের একটি তালিকার অনুরোধ করতে হবে, ইভেন্ট তালিকার মাধ্যমে ফিল্টার করতে হবে এবং সেই অনুযায়ী আপডেটগুলি করতে হবে৷

সাধারণ সিঙ্কিং পদ্ধতিটি নিম্নরূপ:

  1. প্রথমবার যখন একজন ব্যবহারকারী একটি সম্মেলন তৈরি করে, সিঙ্ক প্রক্রিয়াটি শুরু হয়।
  2. যখনই ব্যবহারকারী তাদের ক্যালেন্ডার ইভেন্টগুলির একটি তৈরি করে, আপডেট করে বা মুছে দেয় তখনই ট্রিগারটি আপনার অ্যাড-অন প্রকল্পে একটি ট্রিগার ফাংশন চালায়।
  3. ট্রিগার ফাংশন শেষ সিঙ্কের পর থেকে ইভেন্টের পরিবর্তনের সেট পরীক্ষা করে এবং কোনো সংশ্লিষ্ট তৃতীয় পক্ষের কনফারেন্স আপডেট করার প্রয়োজন কিনা তা নির্ধারণ করে।
  4. তৃতীয় পক্ষের API অনুরোধ করে কনফারেন্সে যেকোন প্রয়োজনীয় আপডেট করা হয়।
  5. একটি নতুন সিঙ্ক টোকেন সংরক্ষণ করা হয় যাতে পরবর্তী ট্রিগার সম্পাদনের জন্য শুধুমাত্র ক্যালেন্ডারে সাম্প্রতিক পরিবর্তনগুলি পরীক্ষা করা প্রয়োজন৷

সিঙ্কিং শুরু করুন

একবার অ্যাড-অন সফলভাবে একটি তৃতীয়-পক্ষের সিস্টেমে একটি সম্মেলন তৈরি করলে, এটি একটি ইনস্টলযোগ্য ট্রিগার তৈরি করা উচিত যা এই ক্যালেন্ডারে ইভেন্ট পরিবর্তনের প্রতিক্রিয়া জানায়, যদি ট্রিগারটি ইতিমধ্যেই বিদ্যমান না থাকে।

ট্রিগার তৈরি করার পরে, প্রারম্ভিক সিঙ্ক টোকেন তৈরি করে প্রাথমিককরণ শেষ করা উচিত। এটি সরাসরি ট্রিগার ফাংশন কার্যকর করার মাধ্যমে করা হয়।

একটি ক্যালেন্ডার ট্রিগার তৈরি করুন

সিঙ্ক করার জন্য, আপনার অ্যাড-অন শনাক্ত করতে হবে যখন একটি ক্যালেন্ডার ইভেন্ট যেখানে একটি সংযুক্ত কনফারেন্স আছে পরিবর্তন করা হয়। এটি একটি EventUpdated ইনস্টলযোগ্য ট্রিগার তৈরি করে সম্পন্ন করা হয়। আপনার অ্যাড-অন প্রতিটি ক্যালেন্ডারের জন্য শুধুমাত্র একটি ট্রিগার প্রয়োজন, এবং সেগুলি প্রোগ্রাম্যাটিকভাবে তৈরি করতে পারে।

একটি ট্রিগার তৈরি করার একটি ভাল সময় হল যখন ব্যবহারকারী তাদের প্রথম সম্মেলন তৈরি করে, যেহেতু সেই সময়ে ব্যবহারকারী অ্যাড-অন ব্যবহার করা শুরু করে। একটি কনফারেন্স তৈরি করার পরে এবং কোনও ত্রুটি নেই তা যাচাই করার পরে, আপনার অ্যাড-অনটি এই ব্যবহারকারীর জন্য ট্রিগার বিদ্যমান কিনা এবং এটি তৈরি না করলে তা দেখতে হবে।

একটি সিঙ্ক ট্রিগার ফাংশন প্রয়োগ করুন

ট্রিগার ফাংশনগুলি চালানো হয় যখন অ্যাপস স্ক্রিপ্ট এমন একটি অবস্থা শনাক্ত করে যা একটি ট্রিগার ফায়ার করে। EventUpdated ক্যালেন্ডার যখন একটি নির্দিষ্ট ক্যালেন্ডারে কোনো ইভেন্ট তৈরি করে, পরিবর্তন করে বা মুছে দেয় তখন আগুন ট্রিগার করে

আপনার অ্যাড-অন ব্যবহার করা ট্রিগার ফাংশনটি আপনাকে অবশ্যই বাস্তবায়ন করতে হবে। এই ট্রিগার ফাংশন নিম্নলিখিত কাজ করা উচিত:

  1. একটি ক্যালেন্ডার উন্নত পরিষেবা Calendar.Events.list() কল করুন একটি syncToken ব্যবহার করে শেষ সিঙ্কের পর থেকে পরিবর্তিত ঘটনাগুলির একটি তালিকা পুনরুদ্ধার করতে৷ একটি সিঙ্ক টোকেন ব্যবহার করে আপনি আপনার অ্যাড-অন পরীক্ষা করা আবশ্যক ইভেন্টের সংখ্যা হ্রাস করুন৷

    যখন ট্রিগার ফাংশনটি একটি বৈধ সিঙ্ক টোকেন ছাড়াই কার্যকর হয়, তখন এটি সম্পূর্ণ সিঙ্কে ফিরে আসে। সম্পূর্ণ সিঙ্কগুলি একটি নতুন, বৈধ সিঙ্ক টোকেন তৈরি করার জন্য নির্ধারিত সময়ের মধ্যে সমস্ত ইভেন্ট পুনরুদ্ধার করার চেষ্টা করে।

  2. প্রতিটি পরিবর্তিত ইভেন্টের সাথে সংশ্লিষ্ট তৃতীয় পক্ষের সম্মেলন আছে কিনা তা নির্ধারণ করতে পরীক্ষা করা হয়।
  3. যদি একটি ইভেন্টের একটি সম্মেলন থাকে, তাহলে এটি পরীক্ষা করা হয় যে কী পরিবর্তন করা হয়েছে। পরিবর্তনের উপর নির্ভর করে, সংশ্লিষ্ট সম্মেলনের একটি পরিবর্তন প্রয়োজন হতে পারে। উদাহরণস্বরূপ, যদি একটি ইভেন্ট মুছে ফেলা হয় তবে অ্যাড-অনটি সম্ভবত সম্মেলনটিও মুছে ফেলা উচিত।
  4. কনফারেন্সে যেকোনো প্রয়োজনীয় পরিবর্তন তৃতীয় পক্ষের সিস্টেমে API কল করার মাধ্যমে করা হয়।
  5. সমস্ত প্রয়োজনীয় পরিবর্তন করার পরে, Calendar.Events.list() পদ্ধতির মাধ্যমে ফেরত দেওয়া nextSyncToken সংরক্ষণ করুন। এই সিঙ্ক টোকেনটি Calendar.Events.list() কল দ্বারা ফেরত ফলাফলের শেষ পৃষ্ঠায় পাওয়া যায়।

Google ক্যালেন্ডার ইভেন্ট আপডেট করা হচ্ছে

কিছু ক্ষেত্রে আপনি একটি সিঙ্ক করার সময় Google ক্যালেন্ডার ইভেন্ট আপডেট করতে চাইতে পারেন। আপনি যদি এটি করতে চান তবে উপযুক্ত Google ক্যালেন্ডার উন্নত পরিষেবার অনুরোধের সাথে ইভেন্ট আপডেট করুন৷ একটি 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.

  }
}