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

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

পূর্বশর্ত

  • অ্যাপস স্ক্রিপ্ট দ্বারা স্বয়ংক্রিয়ভাবে তৈরি ডিফল্ট প্রজেক্টের পরিবর্তে একটি স্ট্যান্ডার্ড গুগল ক্লাউড প্রজেক্ট ব্যবহার করে তৈরি একটি অ্যাপস স্ক্রিপ্ট প্রজেক্ট।
  • সাবস্ক্রিপশন ইভেন্ট গ্রহণ করার জন্য একই গুগল ক্লাউড প্রজেক্টে একটি পাব/সাব টপিক তৈরি করা হয়। পাব/সাব টপিক তৈরি করতে, “পাব/সাব টপিক তৈরি করুন এবং সাবস্ক্রাইব করুন” দেখুন।
  • চ্যাট ইভেন্টগুলিতে সাবস্ক্রাইব করতে হলে, গুগল ক্লাউড কনসোলের চ্যাট এপিআই কনফিগারেশন পৃষ্ঠায় আপনার একটি গুগল চ্যাট অ্যাপ কনফিগার করা থাকতে হবে। গুগল চ্যাট অ্যাপ তৈরি করতে, ‘অ্যাপস স্ক্রিপ্ট দিয়ে একটি গুগল চ্যাট অ্যাপ তৈরি করুন’ দেখুন।
  • অ্যাপস স্ক্রিপ্ট প্রজেক্টের appsscript.json ফাইলে প্রয়োজনীয় অথরাইজেশন স্কোপগুলো যোগ করা হয়েছে। প্রয়োজনীয় স্কোপগুলো সাবস্ক্রিপশনের টার্গেট রিসোর্স এবং ইভেন্টের ধরনের উপর নির্ভর করে। বিস্তারিত জানতে, ‘গুগল ওয়ার্কস্পেস ইভেন্টস এপিআই স্কোপ নির্বাচন করুন ’ দেখুন। উদাহরণস্বরূপ:

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

এটি একটি উন্নত পরিষেবা যা ব্যবহারের আগে আপনাকে অবশ্যই চালু করতে হবে।

রেফারেন্স

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

নমুনা কোড

এই নমুনাগুলো আপনাকে দেখাবে কীভাবে অ্যাডভান্সড সার্ভিস ব্যবহার করে গুগল ওয়ার্কস্পেস ইভেন্টস এপিআই-এর সাধারণ কাজগুলো সম্পাদন করতে হয়।

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

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

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

অপারেশন পান

গুগল ওয়ার্কস্পেস ইভেন্টস এপিআই-এর বেশিরভাগ মেথড একটি দীর্ঘ-চলমান অপারেশন রিটার্ন করে। অপারেশনটির স্ট্যাটাস জানতে, আপনি 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);
  }
}

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