একটি এক্সটেনশন ব্যবহারকারী হুক যোগ করুন
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
আপনি আপনার এক্সটেনশন ইনস্টল করার ব্যবহারকারীদের তাদের নিজস্ব কাস্টম লজিক আপনার এক্সটেনশন কার্যকর করার ক্ষমতা প্রদান করতে পারেন৷ এটি সম্পন্ন করার দুটি উপায় আছে:
Eventarc ইভেন্ট : ব্যবহারকারীদের ইভেন্টে অ্যাসিঙ্ক্রোনাসভাবে প্রতিক্রিয়া জানাতে, আপনি Eventarc-এ প্রকাশ করতে পারেন। ব্যবহারকারীরা ইভেন্ট হ্যান্ডলার ফাংশন স্থাপন করতে পারে যেগুলি, উদাহরণস্বরূপ, দীর্ঘ-চলমান কাজগুলি সম্পূর্ণ হওয়ার পরে বিজ্ঞপ্তি পাঠায়, অথবা তারা তাদের নিজস্ব পোস্ট-প্রসেসিং ফাংশনগুলি সংজ্ঞায়িত করতে পারে।
সিঙ্ক্রোনাস হুক : ব্যবহারকারীদের আপনার এক্সটেনশনে ব্লকিং লজিক যোগ করার উপায় দিতে, আপনি এক্সটেনশনের অপারেশনে পূর্বনির্ধারিত পয়েন্টে সিঙ্ক্রোনাস হুক যোগ করতে পারেন। এই পয়েন্টগুলিতে, আপনি একটি ব্যবহারকারী-প্রদানকারী ফাংশন চালান এবং এটি সম্পূর্ণ হওয়ার পরেই এগিয়ে যান। প্রাক-প্রক্রিয়াকরণ কাজগুলি প্রায়শই এই বিভাগের অধীনে পড়ে।
একটি এক্সটেনশন উভয় বা উভয় পদ্ধতি ব্যবহার করতে পারে।
ইভেন্টর্ক ইভেন্ট
একটি এক্সটেনশন থেকে ইভেন্ট প্রকাশ করতে:
আপনি extension.yaml
ফাইলে প্রকাশ করবেন এমন ইভেন্টের ধরন ঘোষণা করুন:
events:
- type: publisher-id.extension-name.version.event-name
description: event-description
- type: publisher-id.extension-name.version.another-event-name
description: another-event-description
type
আইডেন্টিফায়ারটি বিভিন্ন ডট-ডিলিমিটেড ফিল্ড দিয়ে তৈরি। প্রকাশক আইডি , এক্সটেনশনের নাম এবং ইভেন্টের নাম ক্ষেত্র প্রয়োজন। সংস্করণ ক্ষেত্র সুপারিশ করা হয়. আপনার প্রকাশ করা প্রতিটি ইভেন্টের জন্য একটি অনন্য এবং বর্ণনামূলক ইভেন্টের নাম চয়ন করুন।
উদাহরণস্বরূপ, storage-resize-images
এক্সটেনশন একটি একক ইভেন্ট টাইপ ঘোষণা করে:
events:
- type: firebase.extensions.storage-resize-images.v1.complete
description: |
Occurs when image resizing completes. The event will contain further
details about specific formats and sizes.
ব্যবহারকারীরা এক্সটেনশন ইনস্টল করার সময় কোন ইভেন্টগুলিতে সদস্যতা নেবেন তা চয়ন করতে সক্ষম হবেন৷
আপনার এক্সটেনশন ফাংশনে, Admin SDK থেকে Eventarc API আমদানি করুন এবং ব্যবহারকারীর ইনস্টলেশন সেটিংস ব্যবহার করে একটি ইভেন্ট চ্যানেল শুরু করুন। এই সেটিংস নিম্নলিখিত পরিবেশ ভেরিয়েবল ব্যবহার করে উন্মুক্ত করা হয়:
-
EVENTARC_CHANNEL
: Eventarc চ্যানেলের সম্পূর্ণ-যোগ্য নাম যেখানে ব্যবহারকারী ইভেন্ট প্রকাশ করতে বেছে নিয়েছে। -
EXT_SELECTED_EVENTS
: ব্যবহারকারী প্রকাশ করতে বেছে নেওয়া ইভেন্ট প্রকারের একটি কমা-বিভক্ত তালিকা৷ আপনি যখন এই মান সহ একটি চ্যানেল শুরু করেন, তখন অ্যাডমিন SDK স্বয়ংক্রিয়ভাবে ইভেন্ট ফিল্টার করে দেয় যা ব্যবহারকারী নির্বাচন করেননি। -
EVENTARC_CLOUD_EVENT_SOURCE
: ক্লাউড ইভেন্ট উৎস শনাক্তকারী। অ্যাডমিন SDK স্বয়ংক্রিয়ভাবে প্রকাশিত ইভেন্টের source
ক্ষেত্রে এই মানটি পাস করে। আপনি সাধারণত স্পষ্টভাবে এই পরিবর্তনশীল ব্যবহার করার প্রয়োজন নেই.
যদি ইভেন্টগুলি ইনস্টলেশনের সময় সক্ষম না করা হয় তবে এই ভেরিয়েবলগুলি অনির্ধারিত হবে। ইভেন্টগুলি সক্ষম হলেই আপনি একটি ইভেন্ট চ্যানেল শুরু করতে এই সত্যটি ব্যবহার করতে পারেন:
import * as admin from "firebase-admin";
import {getEventarc} from 'firebase-admin/eventarc';
admin.initializeApp();
// Set eventChannel to a newly-initialized channel, or `undefined` if events
// aren't enabled.
const eventChannel =
process.env.EVENTARC_CHANNEL &&
getEventarc().channel(process.env.EVENTARC_CHANNEL, {
allowedEventTypes: process.env.EXT_SELECTED_EVENTS,
});
আপনার এক্সটেনশনের পয়েন্টগুলিতে চ্যানেলে ইভেন্টগুলি প্রকাশ করুন যা আপনি ব্যবহারকারীদের কাছে প্রকাশ করতে চান৷ যেমন:
// If events are enabled, publish a `complete` event to the configured
// channel.
eventChannel && eventChannel.publish({
type: 'firebase.extensions.storage-resize-images.v1.complete',
subject: filename, // the name of the original file
data: {
// ...
}
});
প্রিইনস্টল বা পোস্টিনস্টল ফাইলে আপনার প্রকাশিত ইভেন্টগুলি নথিভুক্ত করুন৷
প্রতিটি ইভেন্টের জন্য, নিম্নলিখিত নথিভুক্ত করুন:
- এর উদ্দিষ্ট উদ্দেশ্য
- আপনার এক্সটেনশনের যুক্তিতে বিন্দু এটি চলে
- আউটপুট তথ্য এটি অন্তর্ভুক্ত
- এর বাস্তবায়নের শর্ত
অতিরিক্তভাবে, ব্যবহারকারীদের সতর্ক করুন যে তাদের ইভেন্ট হ্যান্ডলারে এমন কোনো কাজ না করার জন্য যা একই এক্সটেনশন ট্রিগার করতে পারে, যার ফলে একটি অসীম লুপ হতে পারে।
আপনি যখন একটি এক্সটেনশন থেকে ইভেন্ট প্রকাশ করেন, ব্যবহারকারীরা কাস্টম যুক্তি দিয়ে প্রতিক্রিয়া জানাতে ইভেন্ট হ্যান্ডলার স্থাপন করতে পারেন।
উদাহরণস্বরূপ, নিম্নলিখিত উদাহরণটি মূল চিত্রটি পুনরায় আকার দেওয়ার পরে মুছে দেয়। মনে রাখবেন যে এই উদাহরণ হ্যান্ডলারটি ইভেন্টের subject
সম্পত্তি ব্যবহার করে, যা এই ক্ষেত্রে চিত্রের আসল ফাইলের নাম।
exports.onimageresized = onCustomEventPublished(
"firebase.extensions.storage-resize-images.v1.complete",
(event) => {
logger.info("Received image resize completed event", event);
// For example, delete the original.
return admin.storage()
.bucket("my-project.firebasestorage.app")
.file(event.subject)
.delete();
});
আরও তথ্যের জন্য কাস্টম ইভেন্ট ট্রিগার দেখুন।
উদাহরণ
অফিসিয়াল রিসাইজ ইমেজ এক্সটেনশন একটি ইমেজ রিসাইজ করার পরে Eventarc-এ প্রকাশ করে একটি অ্যাসিঙ্ক্রোনাস হুক প্রদান করে।
সিঙ্ক্রোনাস হুক
যখন আপনি ব্যবহারকারীদেরকে এমন একটি হুক প্রদান করতে চান যা আপনার এক্সটেনশন ফাংশনগুলির একটিকে পরিচালনা করার জন্য সফলভাবে সম্পূর্ণ করতে হবে, সিঙ্ক্রোনাস হুকগুলি ব্যবহার করুন৷
একটি সিঙ্ক্রোনাস হুক একটি ব্যবহারকারী-সংজ্ঞায়িত HTTPS কলযোগ্য ক্লাউড ফাংশনকে কল করে এবং চালিয়ে যাওয়ার আগে সমাপ্তির জন্য অপেক্ষা করে (সম্ভবত একটি ফেরত মান সহ)। ব্যবহারকারী-প্রদত্ত ফাংশনে একটি ত্রুটির ফলে এক্সটেনশন ফাংশনে একটি ত্রুটি দেখা দেয়।
একটি সিঙ্ক্রোনাস হুক প্রকাশ করতে:
আপনার এক্সটেনশনে একটি প্যারামিটার যোগ করুন যা ব্যবহারকারীদের তাদের কাস্টম ক্লাউড ফাংশনে URL সহ এক্সটেনশন কনফিগার করতে দেয়। যেমন:
- param: PREPROCESSING_FUNCTION
label: Pre-processing function URL
description: >
An HTTPS callable function that will be called to transform the input data
before it is processed by this function.
type: string
example: https://us-west1-my-project-id.cloudfunctions.net/preprocessData
required: false
আপনার এক্সটেনশনের বিন্দুতে যেখানে আপনি হুকটি প্রকাশ করতে চান, তার URL ব্যবহার করে ফাংশনটিকে কল করুন। যেমন:
const functions = require('firebase-functions/v1');
const fetch = require('node-fetch');
const preprocessFunctionURL = process.env.PREPROCESSING_FUNCTION;
exports.yourFunctionName = functions.firestore.document("collection/{doc_id}")
.onWrite((change, context) => {
// PREPROCESSING_FUNCTION hook begins here.
// If a preprocessing function is defined, call it before continuing.
if (preprocessFunctionURL) {
try {
await fetch(preprocessFunctionURL); // Could also be a POST request if you want to send data.
} catch (e) {
// Preprocessing failure causes the function to fail.
functions.logger.error("Preprocessor error:", e);
return;
}
}
// End of PREPROCESSING_FUNCTION hook.
// Main function logic follows.
// ...
});
প্রিইনস্টল বা পোস্টিনস্টল ফাইলে আপনি উপলব্ধ যে কোনো হুক নথিভুক্ত করুন।
প্রতিটি হুকের জন্য, নিম্নলিখিত নথিভুক্ত করুন:
- এর উদ্দিষ্ট উদ্দেশ্য
- আপনার এক্সটেনশনের যুক্তিতে বিন্দু এটি চলে
- এর প্রত্যাশিত ইনপুট এবং আউটপুট
- এটি কার্যকর করার জন্য শর্ত (বা বিকল্প)
অতিরিক্তভাবে, ব্যবহারকারীদের হুক ফাংশনে এমন কোনো কাজ না করার জন্য সতর্ক করুন যা একই এক্সটেনশনকে ট্রিগার করতে পারে, যার ফলে একটি অসীম লুপ হতে পারে।
উদাহরণ
অ্যালগোলিয়া সার্চ এক্সটেনশনটি অ্যালগোলিয়াতে লেখার আগে ব্যবহারকারীর সরবরাহকৃত ট্রান্সফর্ম ফাংশনকে কল করার জন্য একটি সিঙ্ক্রোনাস হুক প্রদান করে।
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2025-07-25 UTC-তে শেষবার আপডেট করা হয়েছে।
[null,null,["2025-07-25 UTC-তে শেষবার আপডেট করা হয়েছে।"],[],[],null,["\u003cbr /\u003e\n\nYou can provide users who install your extension the ability to insert their own\ncustom logic into the execution of your extension. There are two ways to\naccomplish this:\n\n- **Eventarc events**: to give users a way to asynchronously react to\n events, you can publish to Eventarc. Users can deploy event handler\n functions that, for example, send notifications after long-running\n tasks complete, or they can define their own post-processing functions.\n\n- **Synchronous hooks**: to give users a way to add blocking logic to your\n extension, you can add synchronous hooks at predefined points in the\n extension's operation. At these points, you run a user-provider function\n and proceed only after it completes. Pre-processing tasks often fall under\n this category.\n\nAn extension can use either or both methods.\n\nEventarc events\n\nTo publish events from an extension:\n\n1. Declare the event types you will publish in the `extension.yaml` file:\n\n events:\n - type: publisher-id.extension-name.version.event-name\n description: event-description\n - type: publisher-id.extension-name.version.another-event-name\n description: another-event-description\n\n The `type` identifier is made of several dot-delimited fields. The\n [publisher ID](/docs/extensions/publishers/register), extension name, and event name fields are\n required. The version field is recommended. Choose a unique and descriptive\n event name for each event type you publish.\n\n For example, the [`storage-resize-images` extension](https://github.com/firebase/extensions/blob/next/storage-resize-images/extension.yaml)\n declares a single event type: \n\n events:\n - type: firebase.extensions.storage-resize-images.v1.complete\n description: |\n Occurs when image resizing completes. The event will contain further\n details about specific formats and sizes.\n\n Users will be able to choose which events to subscribe to when they\n install the extension.\n2. In your extension functions, import the Eventarc API from the Admin SDK\n and initialize an event channel using the user's installation settings.\n These settings are exposed using the following environment variables:\n\n - `EVENTARC_CHANNEL`: the fully-qualified name of the Eventarc channel to which the user chose to publish events.\n - `EXT_SELECTED_EVENTS`: a comma-separated list of event types the user chose to publish. When you initialize a channel with this value, the Admin SDK automatically filters out events user did not select.\n - `EVENTARC_CLOUD_EVENT_SOURCE`: the Cloud Event source identifier. The Admin SDK automatically passes this value in the `source` field of published events. You typically don't need to explicitly use this variable.\n\n If events weren't enabled at installation, these variables will be\n undefined. You can use this fact to initialize an event channel only when\n events are enabled: \n\n import * as admin from \"firebase-admin\";\n import {getEventarc} from 'firebase-admin/eventarc';\n\n admin.initializeApp();\n\n // Set eventChannel to a newly-initialized channel, or `undefined` if events\n // aren't enabled.\n const eventChannel =\n process.env.EVENTARC_CHANNEL &&\n getEventarc().channel(process.env.EVENTARC_CHANNEL, {\n allowedEventTypes: process.env.EXT_SELECTED_EVENTS,\n });\n\n3. Publish events to the channel at the points in your extension you want to\n expose to users. For example:\n\n // If events are enabled, publish a `complete` event to the configured\n // channel.\n eventChannel && eventChannel.publish({\n type: 'firebase.extensions.storage-resize-images.v1.complete',\n subject: filename, // the name of the original file\n data: {\n // ...\n }\n });\n\n4. Document the events you publish, in either the PREINSTALL or POSTINSTALL\n file.\n\n For each event, document the following:\n - Its intended purpose\n - The point in your extension's logic it runs\n - The output data it includes\n - The conditions for its execution\n\n Additionally, warn users not to perform any actions in their event\n handlers that might trigger the same extension, resulting in an infinite\n loop.\n\nWhen you publish events from an extension, users can deploy event handlers\nto respond with custom logic.\n\nFor example, the following example deletes the original image after it has been\nresized. Note that this example handler makes use of the `subject` property of\nthe event, which in this case is the image's original filename. \n\n exports.onimageresized = onCustomEventPublished(\n \"firebase.extensions.storage-resize-images.v1.complete\",\n (event) =\u003e {\n logger.info(\"Received image resize completed event\", event);\n // For example, delete the original.\n return admin.storage()\n .bucket(\"my-project.firebasestorage.app\")\n .file(event.subject)\n .delete();\n });\n\nSee [Custom event triggers](/docs/functions/custom-events#handle-events) for more\ninformation.\n\nExample\n\nThe official [Resize Images extension](https://github.com/firebase/extensions/tree/next/storage-resize-images)\nprovides an asynchronous hook by [publishing to Eventarc](https://github.com/firebase/extensions/blob/c29781c7e67c004e2491e4ce3c43b25b05bd3de6/storage-resize-images/functions/src/index.ts#L109-L117)\nafter resizing an image.\n\nSynchronous hooks\n\nWhen you want to provide users with a hook that must complete successfully\nfor one of your extension functions to operate, use *synchronous hooks*.\n\nA synchronous hook calls a user-defined [HTTPS callable Cloud\nFunction](/docs/functions/http-events) and awaits completion (possibly with a\nreturned value) before continuing. An error in the user-provided function\nresults in an error in the extension function.\n\nTo expose a synchronous hook:\n\n1. Add a parameter to your extension that allows users to configure the\n extension with the URL to their custom Cloud Function. For example:\n\n - param: PREPROCESSING_FUNCTION\n label: Pre-processing function URL\n description: \u003e\n An HTTPS callable function that will be called to transform the input data\n before it is processed by this function.\n type: string\n example: https://us-west1-my-project-id.cloudfunctions.net/preprocessData\n required: false\n\n2. At the point in your extension where you want to expose the hook, call the\n function using its URL. For example:\n\n const functions = require('firebase-functions/v1');\n const fetch = require('node-fetch');\n\n const preprocessFunctionURL = process.env.PREPROCESSING_FUNCTION;\n\n exports.yourFunctionName = functions.firestore.document(\"collection/{doc_id}\")\n .onWrite((change, context) =\u003e {\n // PREPROCESSING_FUNCTION hook begins here.\n // If a preprocessing function is defined, call it before continuing.\n if (preprocessFunctionURL) {\n try {\n await fetch(preprocessFunctionURL); // Could also be a POST request if you want to send data.\n } catch (e) {\n // Preprocessing failure causes the function to fail.\n functions.logger.error(\"Preprocessor error:\", e);\n return;\n }\n }\n // End of PREPROCESSING_FUNCTION hook.\n\n // Main function logic follows.\n // ...\n });\n\n3. Document any hooks you make available in either the PREINSTALL or\n POSTINSTALL file.\n\n For each hook, document the following:\n - Its intended purpose\n - The point in your extension's logic it runs\n - Its expected inputs and outputs\n - The conditions (or options) for its execution\n\n Additionally, warn users not to perform any actions in the hook\n function that might trigger the same extension, resulting in an infinite\n loop.\n\nExample\n\nThe [Algolia Search extension](https://github.com/algolia/firestore-algolia-search/)\nprovides a synchronous hook to [call a user-supplied transform function](https://github.com/algolia/firestore-algolia-search/blob/34592d513eac22691d76917874a6466032976f67/functions/src/transform.ts)\nprior to writing to Algolia."]]