ภาพรวมของผู้เผยแพร่ส่วนขยาย
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ส่วนขยาย Firebase จะทำงานเฉพาะอย่างหรือชุดงานเพื่อตอบสนองต่อ
คำขอ HTTP หรือเหตุการณ์ที่ทริกเกอร์จากผลิตภัณฑ์อื่นๆ ของ Firebase และ Google เช่น
Firebase Cloud Messaging, Cloud Firestore หรือ Pub/Sub
คุณสามารถสร้างส่วนขยายของคุณเองเพื่อใช้ส่วนตัวหรือแชร์กับผู้คนทั่วโลกใน
ฮับส่วนขยาย Firebase ตัวอย่างเช่น ส่วนขยายสามารถทำงานเฉพาะ
อย่างที่แอปของคุณต้องใช้เป็นประจำ หรือช่วยให้เข้าถึง API ของบริษัทได้ง่ายขึ้น
หลังจากสร้างส่วนขยายแล้ว คุณจะแชร์กับผู้อื่นได้ ผู้ใช้เหล่านั้นจะติดตั้งและกำหนดค่าส่วนขยายเพื่อใช้ในโปรเจ็กต์ Firebase ของตนเองได้
โครงสร้างของส่วนขยาย
คุณอาจคิดว่าส่วนขยายมีองค์ประกอบหลัก 3 อย่างดังนี้
- โค้ด Cloud Functions ใน JavaScript หรือ TypeScript
- ข้อมูลเมตาที่อธิบายส่วนขยาย
- เอกสารประกอบที่จะช่วยผู้ใช้กำหนดค่าและใช้ส่วนขยายของคุณ
หากต้องการพัฒนาส่วนขยาย คุณต้องประกอบคอมโพเนนต์เหล่านี้เป็นโครงสร้างต่อไปนี้
example-extension
├── functions
│ ├── integration-tests
│ │ ├── extensions
│ │ │ └── example-extension.env
│ │ ├── firebase.json
│ │ └── integration-test.spec.js
│ ├── index.js
│ └── package.json
├── README.md
├── PREINSTALL.md
├── POSTINSTALL.md
├── CHANGELOG.md
├── icon.png
└── extension.yaml
- ไดเรกทอรี
functions
มีโค้ด Cloud Functions ใน JavaScript
หรือ TypeScript นี่คือโค้ดที่ทํางานของส่วนขยายเพื่อตอบสนองต่อเหตุการณ์ที่ทริกเกอร์โดย Firebase และบริการของ Google
extension.yaml
ไฟล์ประกอบด้วยข้อมูลเมตาเกี่ยวกับส่วนขยาย เช่น
ทริกเกอร์และบทบาทการเข้าถึง IAM รวมถึงพารามิเตอร์ที่คุณต้องการให้
ผู้ใช้กำหนดค่าได้
- ไฟล์
PREINSTALL
, POSTINSTALL
และ CHANGELOG
คือเอกสารขั้นต่ำที่ส่วนขยายของคุณต้องมี ไฟล์เหล่านี้ช่วยให้ผู้ใช้ทราบ
สิ่งที่ส่วนขยายของคุณทำ วิธีใช้ และการอัปเดตที่คุณทำ นอกจากนี้ คุณควรระบุไอคอนเพื่อช่วยให้ผู้ใช้จดจำส่วนขยายของคุณได้ คอนโซล Firebase, Firebase CLI และฮับส่วนขยายจะแสดงเนื้อหาของไฟล์เหล่านี้เมื่อผู้ใช้สำรวจ ติดตั้ง และจัดการส่วนขยาย
หลังจากสร้างส่วนขยายแล้ว คุณจะใช้ Firebase CLI เพื่อติดตั้งส่วนขยายในโปรเจ็กต์หรือเผยแพร่ไปยังฮับส่วนขยายได้ ซึ่งทุกคนจะค้นพบและติดตั้งส่วนขยายในโปรเจ็กต์ของตนเองได้
ส่วนขยายของฉันโต้ตอบกับผลิตภัณฑ์ใดได้บ้าง
เนื่องจากส่วนขยาย Firebase ทำงานโดยใช้ Cloud Functions คุณจึงพิจารณาคำถามเกี่ยวกับการผสานรวมที่เป็นไปได้ได้ 2 วิธี ได้แก่ ผลิตภัณฑ์ใดบ้างที่เรียกใช้ฟังก์ชันของส่วนขยายได้ และเมื่อเรียกใช้แล้ว ฟังก์ชันของส่วนขยายจะโต้ตอบกับผลิตภัณฑ์ใดได้บ้าง
ทริกเกอร์ฟังก์ชันที่รองรับ
ทริกเกอร์ด้วยตนเอง
ก่อนอื่น คุณสามารถเรียกใช้ฟังก์ชันด้วยตนเองได้ ส่วนขยาย Firebase และ Cloud
Functions รองรับ 2 วิธีในการทริกเกอร์ฟังก์ชันด้วยตนเอง ดังนี้
- ทริกเกอร์ HTTP: ทำให้ฟังก์ชันใช้งานได้ที่ปลายทาง HTTP
- ฟังก์ชันที่เรียกใช้ได้: เรียกใช้ Cloud Functions โดยตรงจากโค้ดไคลเอ็นต์ iOS, Android หรือเว็บโดยใช้ Firebase Client SDK
การเปิดเผยปลายทาง HTTP จากส่วนขยายจะช่วยให้ส่วนขยายของคุณอาจผสานรวมกับบริการเว็บใดก็ได้ที่รองรับ Webhook ฟังก์ชันที่เรียกใช้ได้ช่วยให้ผู้ใช้ที่ติดตั้งส่วนขยายสามารถใช้ Firebase SDK เป็นไลบรารีไคลเอ็นต์
เพื่อเข้าถึง API ที่ส่วนขยายของคุณใช้ได้
ทริกเกอร์บริการ Firebase
ผลิตภัณฑ์ Firebase ส่วนใหญ่จะปล่อยเหตุการณ์ที่ทริกเกอร์ Cloud
Functions ของส่วนขยายได้
- Analytics: เรียกใช้ฟังก์ชันเมื่อ Analytics บันทึกเหตุการณ์
- App Distribution: เรียกใช้ฟังก์ชันเมื่อ App Distribution เรียกใช้การแจ้งเตือน
- การตรวจสอบสิทธิ์: เรียกใช้ฟังก์ชันเมื่อผู้ใช้สร้างและลบบัญชี
- Cloud Firestore: เรียกใช้ฟังก์ชันเมื่อมีการสร้าง อัปเดต หรือลบหน้าเว็บ
- Cloud Storage: ทริกเกอร์ฟังก์ชันเมื่อมีการอัปโหลด เก็บถาวร หรือ
ลบออบเจ็กต์จากที่เก็บข้อมูล
- Crashlytics: ทริกเกอร์ฟังก์ชันเมื่อ Crashlytics ทริกเกอร์การแจ้งเตือน
- การตรวจสอบประสิทธิภาพ: เรียกใช้ฟังก์ชันเมื่อการตรวจสอบประสิทธิภาพ
ทริกเกอร์การแจ้งเตือน
- Realtime Database: เรียกใช้ฟังก์ชันเมื่อมีการสร้าง อัปเดต หรือ
ลบข้อมูล
- การกำหนดค่าระยะไกล: เรียกใช้ฟังก์ชันเมื่อมีการอัปเดตพารามิเตอร์
- Test Lab: เรียกใช้ฟังก์ชันเมื่อ Test Lab เรียกใช้การแจ้งเตือน
ทริกเกอร์บริการ Google Cloud
นอกจากนี้ ส่วนขยายยังอาจมีฟังก์ชันที่ทริกเกอร์จากบริการ Google Cloud ที่ไม่ใช่ Firebase หลายรายการด้วย ดังนี้
- Cloud Pub/Sub: ส่วนขยายสามารถมีฟังก์ชันที่ทริกเกอร์เมื่อมีการโพสต์เหตุการณ์ไปยังหัวข้อ Pub/Sub ที่กำหนดค่าได้
- Cloud Scheduler: ส่วนขยายสามารถมีฟังก์ชันที่ทำงานตามกำหนดเวลาที่ตั้งไว้
- Cloud Tasks: ส่วนขยายสามารถมีฟังก์ชันที่จัดคิวได้โดยใช้
Cloud Tasks ส่วนขยาย Firebase ใช้ความสามารถนี้เพื่อให้คุณในฐานะผู้เขียนส่วนขยายเขียนฟังก์ชันที่ตอบสนองต่อเหตุการณ์ "วงจร" ของส่วนขยายได้ เช่น การติดตั้งในโปรเจ็กต์เป็นครั้งแรก การอัปเกรดเป็นเวอร์ชันใหม่ และการกำหนดค่าใหม่
- Eventarc: ส่วนขยายสามารถมีฟังก์ชันที่ทริกเกอร์เมื่อมีการเผยแพร่เหตุการณ์ไปยังช่อง Eventarc ที่กำหนดค่าได้ ในทางกลับกัน ส่วนขยายสามารถเผยแพร่เหตุการณ์ของตัวเองไปยังช่อง Eventarc เพื่อให้ผู้ใช้กำหนดฟังก์ชันของตนเองที่ทริกเกอร์จากเหตุการณ์ของส่วนขยายได้
รองรับจากฟังก์ชัน
เมื่อทริกเกอร์ Cloud Function ของส่วนขยายแล้ว โดยทั่วไปแล้วช่วงของการผสานรวมที่เป็นไปได้จะไม่มีที่สิ้นสุด
ความสามารถบางส่วนของ Cloud Functions มีดังนี้
- อ่าน เขียน และโต้ตอบกับบริการ Firebase หรือ Google Cloud
ที่ใช้บทบาท IAM ที่รองรับ
- ทำงานร่วมกับบริการของบุคคลที่สามที่ให้บริการ Web API
- ทำงานร่วมกับบริการที่กำหนดเองหากคุณให้บริการ Web API
- เรียกใช้ไลบรารี JavaScript ส่วนใหญ่ รวมถึง TensorFlow.js, Express.js
และอื่นๆ
วิธีสร้างส่วนขยาย
บทแนะนำเริ่มต้นใช้งานจะอธิบายขั้นตอนการสร้าง ทดสอบ และเผยแพร่ส่วนขยายที่สมบูรณ์ และเป็นวิธีที่แนะนำในการเรียนรู้วิธีสร้างส่วนขยาย
เริ่มต้นใช้งาน
หลังจากอ่านคู่มือการเริ่มต้นใช้งานแล้ว คุณสามารถดูคู่มือหัวข้อแต่ละหัวข้อ ซึ่งอธิบายงานแต่ละอย่างที่เกี่ยวข้องกับการสร้างส่วนขยายของคุณเองได้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],null,["# Extension publisher overview\n\n\u003cbr /\u003e\n\nA Firebase Extension performs a specific task or set of tasks in response to\nHTTP requests or triggering events from other Firebase and Google products, like\nFirebase Cloud Messaging, Cloud Firestore, or Pub/Sub.\n\nYou can build your own extension for personal use or to share with the world in\nthe Firebase Extensions Hub. For example, your extension can perform a specific\ntask that your app regularly needs, or it can make it easier to access one of\nyour company's APIs. After you build your extension, you can share it with\nothers. Those users can install and configure the extension for use in their own\nFirebase projects.\n\nStructure of an extension\n-------------------------\n\nYou can think of an extension as having three main components:\n\n- Cloud Functions code, in JavaScript or TypeScript\n- Metadata that describes your extension\n- Documentation to help your users configure and use your extension\n\nTo develop an extension, you assemble these components into the following\nstructure: \n\n example-extension\n ├── functions\n │ ├── integration-tests\n │ │ ├── extensions\n │ │ │ └── example-extension.env\n │ │ ├── firebase.json\n │ │ └── integration-test.spec.js\n │ ├── index.js\n │ └── package.json\n ├── README.md\n ├── PREINSTALL.md\n ├── POSTINSTALL.md\n ├── CHANGELOG.md\n ├── icon.png\n └── extension.yaml\n\n- The `functions` directory contains your Cloud Functions code in JavaScript or TypeScript. This is the code that performs the extension's tasks in response to events triggered by Firebase and Google services.\n- The `extension.yaml` file contains metadata about your extension, such as its triggers and IAM access roles, as well as any parameters you want to be user-configurable.\n- The `PREINSTALL`, `POSTINSTALL`, and `CHANGELOG` files are the minimum documentation your extension must have. These files help your users learn what your extension does, how to use it, and what updates you've made. You should also provide an icon to help users recognize your extension. The Firebase console, Firebase CLI, and Extensions Hub display the contents of these files when users explore, install, and manage your extension.\n\nAfter you have created your extension, you can use the Firebase CLI to install\nit into a project or publish it to the Extensions Hub, where anyone can discover\nand install it into their projects.\n\nWhat products can my extension interact with?\n---------------------------------------------\n\nBecause a Firebase extension does its work using Cloud Functions, you can think\nof the question of possible integrations in two ways: *What products can trigger\nmy extension's functions?* and *Once triggered, what products can my extension's\nfunctions interact with?*\n\n### Supported function triggers\n\n#### Manual triggers\n\nFirst of all, you can manually trigger a function. Firebase Extensions and Cloud\nFunctions support two ways of manually triggering functions:\n\n- HTTP triggers: deploy a function to an HTTP endpoint\n- Callable functions: call your Cloud Functions directly from your iOS, Android, or web client code, using the Firebase client SDKs.\n\nBy exposing HTTP endpoints from your extension, your extension can potentially\nintegrate with any web service that supports webhooks. With callable functions,\nusers who install your extension can use the Firebase SDKs as a client library\nfor accessing the API your extension implements.\n\n#### Firebase service triggers\n\nMost Firebase products emit events that can trigger an extension's Cloud\nFunctions.\n\n- **Analytics:** trigger functions when Analytics logs an event\n- **App Distribution:** trigger functions when App Distribution triggers an alert\n- **Authentication:** trigger functions when users create and delete accounts\n- **Cloud Firestore:** trigger functions when pages are created, updated, or deleted\n- **Cloud Storage**: trigger functions when objects are uploaded, archived, or deleted from buckets\n- **Crashlytics:** trigger functions when Crashlytics triggers an alert\n- **Performance Monitoring:** trigger functions when Performance Monitoring triggers an alert\n- **Realtime Database:** trigger functions when data is created, updated, or deleted\n- **Remote Config:** trigger functions when a parameter is updated\n- **Test Lab:** trigger functions when Test Lab triggers an alert\n\n#### Google Cloud service triggers\n\nAn extension can also include functions that trigger off several non-Firebase\nGoogle Cloud services:\n\n- **Cloud Pub/Sub**: an extension can include functions that trigger when events are posted to a configurable Pub/Sub topic.\n- **Cloud Scheduler**: an extension can include functions that run on a set schedule\n- **Cloud Tasks**: an extension can include functions that can be queued using Cloud Tasks. Firebase Extensions uses this capability to let you, as an extension author, write functions that respond to an extension's \"lifecycle\" events: being installed in a project for the first time, being upgraded to a new version, and being reconfigured.\n- **Eventarc** : an extension can include functions that trigger when events are published to a configurable Eventarc channel; conversely, an extension can publish its own events to an Eventarc channel in order to enable users to define their own functions that trigger from an *extension's* events.\n\n### Supported from functions\n\nOnce an extension's Cloud Function has been triggered, the range of possible\nintegrations is generally open ended. Here are some highlights of what you can\ndo from a Cloud Function:\n\n- Read, write, and otherwise interact with any **Firebase** or **Google Cloud** service that uses a [supported IAM role](/docs/extensions/publishers/access#supported-roles).\n- Work with any **third-party service** that provides a web API.\n- Work with your **custom services** if you provide a web API.\n- Run most JavaScript libraries, including **TensorFlow.js** , **Express.js,** and so on.\n\nHow to build an extension\n-------------------------\n\nThe [Get Started](/docs/extensions/publishers/get-started) tutorial walks you through\nthe process of building, testing, and publishing a complete extension, and is\nthe recommended way to learn how to build one.\n\n[Get Started](/docs/extensions/publishers/get-started)\n\nAfter you've gone through the getting started guide once, you can refer to the\nindividual topic guides, which explain each of the tasks involved in building\nyour own extension:\n\n- [Write functions for an extension](/docs/extensions/publishers/functions)\n- [Use parameters in an extension](/docs/extensions/publishers/parameters)\n- [Set up appropriate access for an extension](/docs/extensions/publishers/access)\n- [Respond to extension lifecycle events](/docs/extensions/publishers/lifecycle-events)\n- [Add user hooks to an extension](/docs/extensions/publishers/user-hooks)\n- [Create user documentation for your extension](/docs/extensions/publishers/user-documentation)\n- [Publish an extension on Extensions Hub](/docs/extensions/publishers/upload-and-publish)\n- [Complete extension.yaml reference](/docs/extensions/reference/extension-yaml)"]]