উন্নত Google Workspace ইভেন্ট পরিষেবা

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

পূর্বশর্ত

  • অ্যাপস স্ক্রিপ্ট দ্বারা স্বয়ংক্রিয়ভাবে তৈরি ডিফল্টের পরিবর্তে একটি আদর্শ Google ক্লাউড প্রকল্প ব্যবহার করে একটি Apps স্ক্রিপ্ট প্রকল্প৷
  • সাবস্ক্রিপশন ইভেন্টগুলি পাওয়ার জন্য একই Google ক্লাউড প্রকল্পে একটি পাব/সাব বিষয় তৈরি করা হয়েছে। একটি পাব/সাব বিষয় তৈরি করতে, একটি পাব/সাব বিষয় তৈরি করুন এবং সদস্যতা নিন দেখুন।
  • চ্যাট ইভেন্টগুলিতে সদস্যতা নিতে, আপনার অবশ্যই Google ক্লাউড কনসোলে চ্যাট API কনফিগারেশন পৃষ্ঠায় একটি Google চ্যাট অ্যাপ কনফিগার করা থাকতে হবে। একটি Google Chat অ্যাপ তৈরি করতে, Apps Script দিয়ে Google Chat অ্যাপ তৈরি করুন দেখুন।
  • Apps Script প্রকল্পের appsscript.json ফাইলে প্রয়োজনীয় অনুমোদনের সুযোগ যোগ করা হয়েছে। প্রয়োজনীয় সুযোগগুলি সাবস্ক্রিপশনের লক্ষ্য সংস্থান এবং ইভেন্টগুলির প্রকারের উপর নির্ভর করে৷ বিস্তারিত জানতে, Google Workspace Events API স্কোপ বেছে নিন দেখুন। উদাহরণ স্বরূপ:

    "oauthScopes": [
      "https://www.googleapis.com/auth/chat.messages.readonly"
    ]
    

রেফারেন্স

এই পরিষেবা সম্পর্কে আরও তথ্যের জন্য, Google Workspace Events API রেফারেন্স ডকুমেন্টেশন দেখুন। Apps Script-এর সমস্ত উন্নত পরিষেবার মতো, Google Workspace ইভেন্ট পরিষেবা পাবলিক API-এর মতো একই অবজেক্ট, পদ্ধতি এবং প্যারামিটার ব্যবহার করে।

কোডের উদাহরণ

এই নমুনাগুলি আপনাকে কীভাবে উন্নত পরিষেবা ব্যবহার করে সাধারণ Google Workspace ইভেন্ট API অ্যাকশনগুলি সম্পাদন করতে হয় তা দেখায়।

একটি সদস্যতা তৈরি করুন

Google Workspace রিসোর্সে সাবস্ক্রিপশন তৈরি করতে, Apps Script প্রোজেক্টের কোডে নিম্নলিখিত ফাংশন যোগ করুন:

advanced/events.gs
/**
 * Creates a subscription to receive events about a Google Workspace resource.
 * For a list of supported resources and event types, see the
 * [Google Workspace Events API Overview](https://developers.google.com/workspace/events#supported-events).
 * For additional information, see the
 * [subscriptions.create](https://developers.google.com/workspace/events/reference/rest/v1/subscriptions/create)
 * method reference.
 * @param {!string} targetResource The full resource name of the Google Workspace resource to subscribe to.
 * @param {!string|!Array<string>} eventTypes The types of events to receive about the resource.
 * @param {!string} pubsubTopic The resource name of the Pub/Sub topic that receives events from the subscription.
 */
function createSubscription(targetResource, eventTypes, pubsubTopic) {
  try {
    const operation = WorkspaceEvents.Subscriptions.create({
      targetResource: targetResource,
      eventTypes: eventTypes,
      notificationEndpoint: {
        pubsubTopic: pubsubTopic,
      },
    });
    console.log(operation);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to create subscription with error %s', err.message);
  }
}

তালিকা সদস্যতা

ইভেন্টের ধরন এবং টার্গেট রিসোর্স দ্বারা ফিল্টার করা সাবস্ক্রিপশন তালিকাভুক্ত করতে, অ্যাপস স্ক্রিপ্ট প্রকল্পের কোডে নিম্নলিখিত ফাংশনটি যোগ করুন:

advanced/events.gs
/**
 * Lists subscriptions created by the calling app filtered by one or more event types and optionally by a target resource.
 * For additional information, see the
 * [subscriptions.list](https://developers.google.com/workspace/events/reference/rest/v1/subscriptions/list)
 * method reference.
 * @param {!string} filter The query filter.
 */
function listSubscriptions(filter) {
  try {
    const response = WorkspaceEvents.Subscriptions.list({ filter });
    console.log(response);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to list subscriptions with error %s', err.message);
  }
}

সাবস্ক্রিপশন পান

একটি সদস্যতা সম্পর্কে তথ্য পেতে, Apps স্ক্রিপ্ট প্রকল্পের কোডে নিম্নলিখিত ফাংশন যোগ করুন:

advanced/events.gs
/**
 * Gets details about a subscription.
 * For additional information, see the
 * [subscriptions.get](https://developers.google.com/workspace/events/reference/rest/v1/subscriptions/get)
 * method reference.
 * @param {!string} name The resource name of the subscription.
 */
function getSubscription(name) {
  try {
    const subscription = WorkspaceEvents.Subscriptions.get(name);
    console.log(subscription);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to get subscription with error %s', err.message);
  }
}

সাবস্ক্রিপশন আপডেট করুন

একটি সাবস্ক্রিপশন আপডেট বা পুনর্নবীকরণ করতে, অ্যাপস স্ক্রিপ্ট প্রকল্পের কোডে নিম্নলিখিত ফাংশনটি যোগ করুন:

advanced/events.gs
/**
 * Updates an existing subscription.
 * This can be used to renew a subscription that is about to expire.
 * For additional information, see the
 * [subscriptions.patch](https://developers.google.com/workspace/events/reference/rest/v1/subscriptions/patch)
 * method reference.
 * @param {!string} name The resource name of the subscription.
 */
function patchSubscription(name) {
  try {
    const operation = WorkspaceEvents.Subscriptions.patch({
      // Setting the TTL to 0 seconds extends the subscription to its maximum expiration time.
      ttl: '0s',
    }, name);
    console.log(operation);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to update subscription with error %s', err.message);
  }
}

সদস্যতা পুনরায় সক্রিয় করুন

একটি সদস্যতা পুনরায় সক্রিয় করতে, Apps স্ক্রিপ্ট প্রকল্পের কোডে নিম্নলিখিত ফাংশন যোগ করুন:

advanced/events.gs
/**
 * Reactivates a suspended subscription.
 * Before reactivating, you must resolve any errors with the subscription.
 * For additional information, see the
 * [subscriptions.reactivate](https://developers.google.com/workspace/events/reference/rest/v1/subscriptions/reactivate)
 * method reference.
 * @param {!string} name The resource name of the subscription.
 */
function reactivateSubscription(name) {
  try {
    const operation = WorkspaceEvents.Subscriptions.reactivate({}, name);
    console.log(operation);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to reactivate subscription with error %s', err.message);
  }
}

সাবস্ক্রিপশন মুছুন

একটি সাবস্ক্রিপশন মুছে ফেলতে, অ্যাপস স্ক্রিপ্ট প্রকল্পের কোডে নিম্নলিখিত ফাংশন যোগ করুন:

advanced/events.gs
/**
 * Deletes a subscription.
 * For additional information, see the
 * [subscriptions.delete](https://developers.google.com/workspace/events/reference/rest/v1/subscriptions/delete)
 * method reference.
 * @param {!string} name The resource name of the subscription.
 */
function deleteSubscription(name) {
  try {
    const operation = WorkspaceEvents.Subscriptions.remove(name);
    console.log(operation);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to delete subscription with error %s', err.message);
  }
}

অপারেশন করান

বেশিরভাগ Google Workspace ইভেন্ট এপিআই পদ্ধতি একটি দীর্ঘস্থায়ী অপারেশন ফিরিয়ে দেয়। অপারেশনের অবস্থা নির্ধারণ করতে, আপনি operations.get() পদ্ধতি ব্যবহার করতে পারেন।

একটি অপারেশন সম্পর্কে তথ্য পেতে, অ্যাপস স্ক্রিপ্ট প্রকল্পের কোডে নিম্নলিখিত ফাংশন যোগ করুন:

advanced/events.gs
/**
 * Gets details about an operation returned by one of the methods on the subscription
 * resource of the Google Workspace Events API.
 * For additional information, see the
 * [operations.get](https://developers.google.com/workspace/events/reference/rest/v1/operations/get)
 * method reference.
 * @param {!string} name The resource name of the operation.
 */
function getOperation(name) {
  try {
    const operation = WorkspaceEvents.Operations.get(name);
    console.log(operation);
  } catch (err) {
    // TODO (developer) - Handle exception
    console.log('Failed to get operation with error %s', err.message);
  }
}

একটি অপারেশনের নাম পেতে, subscriptions.create() বা subscriptions.patch() এর মতো Google Workspace Events API পদ্ধতিগুলির একটি থেকে ফেরত name ফিল্ড থেকে মানটি ব্যবহার করুন।