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

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

পূর্বশর্ত

  • অ্যাপস স্ক্রিপ্ট দ্বারা স্বয়ংক্রিয়ভাবে তৈরি ডিফল্ট প্রোজেক্টের পরিবর্তে একটি স্ট্যান্ডার্ড গুগল ক্লাউড প্রোজেক্ট ব্যবহার করে এমন একটি অ্যাপস স্ক্রিপ্ট প্রোজেক্ট।
  • সাবস্ক্রিপশন ইভেন্টগুলি গ্রহণ করার জন্য একই Google ক্লাউড প্রকল্পে একটি পাব/সাব বিষয় তৈরি করা হয়েছে। একটি পাব/সাব বিষয় তৈরি করতে, একটি পাব/সাব বিষয় তৈরি করুন এবং সাবস্ক্রাইব করুন দেখুন।
  • চ্যাট ইভেন্টগুলিতে সাবস্ক্রাইব করতে, আপনার Google ক্লাউড কনসোলের Chat API কনফিগারেশন পৃষ্ঠায় একটি Google Chat অ্যাপ কনফিগার করা থাকতে হবে। একটি Google Chat অ্যাপ তৈরি করতে, "অ্যাপস স্ক্রিপ্ট দিয়ে একটি 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 Events পরিষেবাটি পাবলিক API-এর মতো একই বস্তু, পদ্ধতি এবং পরামিতি ব্যবহার করে।

নমুনা কোড

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

একটি সাবস্ক্রিপশন তৈরি করুন

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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);
  }
}

সাবস্ক্রিপশন তালিকাভুক্ত করুন

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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);
  }
}

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

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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);
  }
}

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

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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);
  }
}

সাবস্ক্রিপশন পুনরায় সক্রিয় করুন

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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);
  }
}

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

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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 Events API পদ্ধতি দীর্ঘমেয়াদী অপারেশন প্রদান করে। অপারেশনের অবস্থা নির্ধারণ করতে, আপনি operations.get() পদ্ধতি ব্যবহার করতে পারেন।

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

উন্নত/ইভেন্টস.জিএস
/**
 * 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 ফিল্ড থেকে প্রাপ্ত মান ব্যবহার করুন।