## File: README.md

# Cloud Functions for Firebase Sample Library

This repository contains a collection of samples showcasing some typical uses of [Cloud Functions for Firebase](https://firebase.google.com/features/functions).

Samples are available for **Node** (1st and 2nd gen) and **Python** (2nd gen).

> Note: Python support in Cloud Functions for Firebase is a public preview. This means that the functionality might change in backward-incompatible ways. A preview release is not subject to any SLA or deprecation policy and may receive limited or no support.

### What's Cloud Functions for Firebase?

Cloud Functions is a hosted, private, and scalable Node.js environment where you can run JavaScript or Python code. [Cloud Functions for Firebase](https://firebase.google.com/features/functions) integrates the Firebase platform by letting you write code that responds to events and invokes functionality exposed by other Firebase features.

## Prerequisites

> All samples require the Blaze pay-as-you-go billing plan to deploy. Learn more about [pricing](https://firebase.google.com/pricing#cloud-functions).

To learn how to get started with Cloud Functions for Firebase by having a look at the [Getting Started Guide](https://firebase.google.com/docs/functions/get-started), trying the [quickstart samples](/Node/quickstarts) and looking at [the documentation](https://firebase.google.com/docs/functions).

<a name="quickstarts"></a>
## Quickstarts

Minimal samples for each Cloud Functions trigger type.

### Quickstart: Uppercaser for Firestore

- [Node 2nd gen](/Node/quickstarts/uppercase-firestore/)
- [Python](/Python/quickstarts/uppercase-firestore/)
- [Node 1st gen](/Node-1st-gen/quickstarts/uppercase-firestore/)

This quickstart sample demonstrates using **Cloud Functions** triggered by **Firestore events**. The function transforms message text written to Firestore to uppercase.

### Quickstart: Add numbers and sanitize text with callable functions

- [Dart](/Dart/quickstarts/callable-functions/)
- [Node 2nd gen](/Node/quickstarts/callable-functions/)
- [Python](/Python/quickstarts/callable-functions)
- [Node 1st gen](/Node-1st-gen/quickstarts/callable-functions/)

### Quickstart: Stream responses with callable functions

- [Dart](/Dart/quickstarts/callable-functions-streaming/)
- [Node 2nd gen](/Node/quickstarts/callable-functions-streaming/)

### HTTPS trigger quickstart: Time Server

- [Dart](/Dart/quickstarts/https-time-server/)
- [Node 2nd gen](/Node/quickstarts/https-time-server/)
- [Python](/Python/quickstarts/https-time-server/)
- [Node 1st gen](/Node-1st-gen/quickstarts/https-time-server/)

This quickstart sample demonstrates using **Cloud Functions** triggered by **HTTPS requests**. The function returns the current server time and allows for date time formatting.

### Quickstart: Uppercaser for Realtime Database

- [Node 2nd gen](/Node/quickstarts/uppercase-rtdb/)
- [Python](/Python/quickstarts/uppercase-rtdb/)
- [Node 1st gen](/Node-1st-gen/quickstarts/uppercase-rtdb/)

This quickstart sample demonstrates using **Cloud Functions** triggered by **Realtime Database events**. The function transforms message text written to Realtime Database to uppercase.

### Hosting triggered HTTPS function quickstart: Big Ben

- [Node 1st gen](/Node-1st-gen/quickstarts/big-ben/)

This quickstart demonstrates using **Cloud Functions** with an HTTPS trigger that's triggered by a Firebase Hosting URL. The function will display a repeated number of "BONG"s depending on the hour of the day.

### Cloud Storage trigger quickstart: Thumbnail generator

- [Node 2nd gen](/Node/quickstarts/thumbnails/)
- [Python](/Python/quickstarts/thumbnails/)
- [Node 1st gen](/Node-1st-gen/quickstarts/thumbnails/)

This quickstart sample demonstrates using **Cloud Functions** triggered by **Firebase Storage events**. The function generates a thumbnail of uploaded images.

### Auth trigger quickstart: Welcome Email

> Auth user create and delete triggers aren't yet supported by 2nd gen functions

- [Node 1st gen](/Node-1st-gen/quickstarts/email-users/)

This quickstart sample demonstrates using **Cloud Functions** triggered by **Firebase Auth events**. The function sends a Welcome Email when user accounts are created (or when users sign-in using an Identity Provider for the first time) and sends a Goodbye Email when user accounts are deleted.

### Auth blocking trigger quickstart: Validate and check user status

- [Node 2nd gen](/Node/quickstarts/auth-blocking-functions/)
- [Python](/Python/quickstarts/auth-blocking-functions/)
- [Node 1st gen](/Node-1st-gen/quickstarts/auth-blocking-functions/)

This quickstart demonstrates using **Auth blocking functions** to validate a user's email before they are allowed to sign in, and to see if a user is part of a list of banned users in Firestore.

### PubSub trigger quickstart: Hello World

- [Node 2nd gen](/Node/quickstarts/pubsub-helloworld/)
- [Python](/Python/quickstarts/pubsub-helloworld/)
- [Node 1st gen](/Node-1st-gen/quickstarts/pubsub-helloworld/)

This quickstart sample demonstrates using **Cloud Functions** triggered by **PubSub events**. The functions log the PubSub payload in a Hello world message.

### Test Lab trigger quickstart: Log when a matrix completes

- [Node 2nd gen](/Node/quickstarts/testlab-matrix-completed/)
- [Python](/Python/quickstarts/testlab-matrix-completed)

### Firebase Alerts trigger quickstart: Send crash reports to Discord

- [Node 2nd gen](/Node/alerts-to-discord/)
- [Python](/Python/alerts-to-discord/)
- Node 1st gen: not supported

Trigger a function based on a Firebase Alert, and send information about the alert to a channel in a Discord server.

### Custom Events: Save image metadata

- [Node 2nd gen](/Node/quickstarts/custom-events/)
- [Python](/Python/quickstarts/custom-events)
- Node 1st gen: not supported

Learn how to trigger a function based on an event sent by an extension

### Unit testing

- [Test with Jest](/Node/test-functions-jest/)
    - [Test with Jest and TypeScript](/Node/test-functions-jest-ts/)
- [Test with Mocha](/Node/test-functions-mocha/)

<a name="environment"></a>
## Development Boilerplates

The Firebase CLI generates sample code for Cloud Functions using JavaScript or TypeScript.

### Server-side generated pages w/ Handlebars templating and user sessions

- [Node (1st gen)](/Node-1st-gen/template-handlebars)

This sample shows how to serve server-side generated HTML pages using the [HandlebarsJs](http://handlebarsjs.com/) templating system and serve user-specific content by always passing the Firebase ID token in a `__session` cookie.

<a name="image"></a>
## Image Processing

Here are a few samples that show how you can process or analyze images using Cloud Functions.

### Image Maker

- [Node (1st gen)](/Node-1st-gen/image-maker)

This sample demonstrates how to create various customized images such as sparkline or sphere charts through Cloud Functions and Hosting and serve it to the client.
Uses an HTTP trigger.

### Convert images after upload

- [Node (1st gen)](/Node-1st-gen/convert-images)

Demonstrates how to automatically convert images that are uploaded to Firebase Storage to JPEG using ImageMagick.
Uses a Firebase Storage trigger.

### Moderate offensive images

- [Node (1st gen)](/Node-1st-gen/moderate-images/)

Demonstrates how to automatically moderate offensive images that are uploaded to Firebase Storage by using the Google Cloud Vision API to detect offensive images and ImageMagick to blur these images.
Uses a Firebase Storage trigger.

### Extract image metadata

- [Node (1st gen)](/Node-1st-gen/exif-images/)

Demonstrates how to automatically extract image's metadata using ImageMagick for images that are uploaded to Firebase Storage.
Uses a Firebase Storage trigger.

### Task Queues: back up images from an API

- [Node 2nd gen](/Node/taskqueues-backup-images/)
- [Python](/Python/taskqueues-backup-images/)

See how to use Task Queues to meter traffic to a rate-limited API.


<a name="rtdb"></a>
## Firebase Realtime Database Data Consistency

These samples show how to implement automatic data consistency such as keeping a count of children, having a max amount of node childs, cleaning up old data etc...

### LastModified Firebase Realtime Database tracking

- [Node (1st gen)](/Node-1st-gen/lastmodified-tracking)

Tracking when the Firebase Database (or a subset) was last modified.
Uses a Realtime Database trigger.

### Firebase Database child nodes count

- [Node (1st gen)](/Node-1st-gen/child-count)

Keeps track of the number of child nodes of a Firebase Database element allowing clients to filter or order results using the child count.
This can be useful to keep track of the number of "likes" or "followers" of something shared through social media.
Uses a Realtime Database trigger.

### Limit number of child nodes

- [Node (1st gen)](/Node-1st-gen/limit-children)

Makes sure that the number of child nodes stays below a certain threshold. This can be useful to limit the number of lines of logs or chat history below a given number.
Uses a Realtime Database trigger.

### Removing old items from a list

- [Node (1st gen)](/Node-1st-gen/delete-old-child-nodes)

This sample shows how to remove child nodes older than 2 hours from a Firebase Database list. This can be useful for removing outdated items from a collection.
Uses a Realtime Database trigger.

<a name="other"></a>
## Solve other common use cases

### Send FCM notifications

- [Node (1st gen)](/Node-1st-gen/fcm-notifications)

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Realtime Database triggered Function when users get new followers. The sample also features a Web UI to experience the FCM notification.
Uses a Realtime Database trigger.

### Google Assistant says ordinal of given number

- [Node (1st gen)](/Node-1st-gen/assistant-say-number)

This sample shows how to create an action for the Google Home/Assistant using the Actions SDK hosted on Cloud Functions. The sample action asks users to say a number and reads out the ordinal of that number.
Uses an HTTP trigger.

### Authenticated JSON API

- [Node (1st gen)](/Node-1st-gen/authenticated-json-api)

This sample shows how to authenticate access to a JSON API to only allow access to data for a specific Firebase user.
Uses an HTTP trigger.

### Authorized HTTP endpoint

- [Node (1st gen)](/Node-1st-gen/authorized-https-endpoint)

This sample shows how to restrict an HTTPS Function to only the Firebase users of your app.
Only users who pass a valid Firebase ID token as a Bearer token in the `Authorization` header of the HTTP request or in a `__session` cookie are authorized to use the function.
Checking the ID token is done with an ExpressJs middleware that also passes the decoded ID token in the Express request object.
Uses an HTTP trigger.

### Authorize with 3rd-party authentication providers

[Okta](/Node-1st-gen/okta-auth), [LinkedIn](/Node-1st-gen/linkedin-auth), [Spotify](/Node-1st-gen/spotify-auth), [Instagram](/Node-1st-gen/instagram-auth), or [Basic Auth](/Node-1st-gen/username-password-auth)

Demonstrates how to authorize with a 3rd party sign-in mechanism, create a Firebase custom auth token, update the user's profile and authorize Firebase.
Uses an HTTP trigger.

### Post GitHub commits to Slack channel

- [Node (1st gen)](/Node-1st-gen/github-to-slack)

Demonstrates how to automatically post GitHub commits to a Slack channel using an HTTPS triggered Function.

### Create and charge customers with [Stripe](/Node-1st-gen/stripe) or [Paypal](/Node-1st-gen/paypal)

Demonstrates hows to integrate Firebase Auth and the Realtime database with Stripe via the Stripe Node.js library and shows how to create HTTP endpoints to charge customers via Paypal.

### Text moderation

- [Node (1st gen)](/Node-1st-gen/text-moderation)

Demonstrates how to moderate user input text for bad words. This can be used to moderate usernames, chat or forum messages.
Uses a Realtime Database trigger.

### Email confirmation

- [Node (1st gen)](/Node-1st-gen/email-confirmation)

Sends email confirmation after users subscribed to a mailing list.
Uses a Realtime Database trigger.

### Automatic message translation

- [Node (1st gen)](/Node-1st-gen/message-translation)

Integrates the Google Translate API to perform automatic text translation across any number of languages. Language codes can be stored in Firebase for on the fly changes.
Uses a Realtime Database trigger.

### Automatic URL shortener

- [Node (1st gen)](/Node-1st-gen/url-shortener)

Integrates the Bit.ly API to shorten URLs automatically as they are added to the database.
Uses a Realtime Database trigger.

### Full-text search for [Realtime Database](/Node-1st-gen/fulltext-search) or [Firestore](/Node-1st-gen/fulltext-search-firestore)

Enable full-text search on Firebase Database data or Firestore documents by using a hosted search service.
Uses a Realtime Database or Firestore trigger.

### User data cleanup

- [Node (1st gen)](/Node-1st-gen/user-data-cleanup)

Deletes all associated user data in the Realtime database when a user deletes his Firebase account.
Uses an Auth trigger.
**This code has moved to its own repo at
https://github.com/firebase/user-data-protection**

### Export your data to a Google Spreadsheet

- [Node (1st gen)](/Node-1st-gen/google-sheet-sync)

This sample demonstrates how to sync new data written to a Firebase database to a Google Sheet. It includes a method for obtaining, storing, and using Oauth2 tokens for Google API access.
Uses HTTPS triggers and Realtime Database triggers.

### Export your data to Big Query

- [Node (1st gen)](/Node-1st-gen/bigquery-import)

Copies Firebase Database elements into BigQuery automatically. This can be useful for instance for further logs analysis.
Uses a Realtime Database trigger.

### Webhook upon Firebase Database writes

- [Node (1st gen)](/Node-1st-gen/minimal-webhook)

Writing to the Firebase Database triggers a request to a callback URL (a Webhook). The content of the modified Data is sent to the Webhook.
Uses a Realtime Database trigger.

### Send a survey when users update your app

- [Node (1st gen)](/Node-1st-gen/survey-app-update)

This sample shows how to send a survey to your users who have updated your app. App Update is detected using a Firebase Analytics event.
Uses an Analytics trigger.

### Send a coupon to user who have completed a purchase

- [Node (1st gen)](/Node-1st-gen/coupon-on-purchase)

This sample shows how to send a coupon to your users who have just purchased something. 10% off on your next purchase!
Uses an Analytics trigger.

### Delete inactive users accounts via cron

- [Node (1st gen)](/Node-1st-gen/delete-unused-accounts-cron)

Periodically deletes the accounts of users who have not signed in in the last month.
Uses an HTTPS trigger.

### Developer Motivator

- [Node (1st gen)](/Node-1st-gen/developer-motivator)

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification to the developer device each time your app gains or loses a user.
Uses an Analytics trigger.

### Audio Files Conversion

- [Node (1st gen)](/Node-1st-gen/ffmpeg-convert-audio)

This sample uses ffmpeg / fluent-ffmpeg and automatically converts audio files that are uploaded to Cloud Storage to FLAC file format with mono-channel audio @ 16000hz.
Uses a Storage trigger.

### Presence for Firestore

- [Node (1st gen)](/Node-1st-gen/presence-firestore)

Build a simple online / offline status indicator for your users by leveraging Firestore and Realtime Database together.
Uses a Realtime Database trigger.

### Publish Models to Firebase ML

- [Node (1st gen)](/Node-1st-gen/publish-model)

Automatically publishes models to Firebase ML for each TensorFlow Lite file that is uploaded to Firebase Storage.

### Get information about a YouTube channel

- [Node (1st gen)](/Node-1st-gen/youtube)

This sample shows how to query the Youtube Data API.
Uses an HTTPS trigger.

## Contributing

We'd love that you contribute to the project. Before doing so please read our [Contributor guide](CONTRIBUTING.md).

## License

© Google, 2015-2023. Licensed under an [Apache-2](LICENSE) license.

## Build Status

[![Actions Status][gh-actions-badge]][gh-actions]

[gh-actions]: https://github.com/firebase/functions-samples/actions
[gh-actions-badge]: https://github.com/firebase/functions-samples/workflows/CI%20Tests/badge.svg

---

## File: Node/instrument-with-opentelemetry/README.md

# Instrumenting Cloud Functions for Firebase with Open Telemetry
This sample demonstrates instrumenting your Cloud Functions for Firebase using [OpenTelemetry](https://opentelemetry.io).

See Firebase Summit 2022 Talk "Observability in Cloud Functions for Firebase" for motivations and context.

Open Telemetry SDK provides both automatic and manual instrumentation, both of which are demonstrated here. See [OpenTelemetry JS documentations](https://opentelemetry.io/docs/instrumentation/js/) for more information about how to use and configure OpenTelemetry for your javascript project.

## Notable Files
* `./tracing.js`: Initializes OpenTelemetry SDK to automatically instrument HTTP/GRPC/Express modules and export the generated traces to Google Cloud Trace.

* `./.env`: Configures `NODE_OPTIONS` to preload the `tracing.js` module. This is important because OpenTelemtry SDK works by monkey-patching instrumented modules and must run first before other module is loaded.

* `./index.js`: Includes sample code for generating custom spans using the OpenTelemetry API. e.g.:
```js
const opentelemetry = require('@opentelemetry/api');

const tracer = opentelemetry.trace.getTracer();
await tracer.startActiveSpan("calculatePrice", async (span) => {
    totalUsd = await calculatePrice(productIds);
    span.end();
});
```

## Deploy and test
1. Deploy your function using firebase deploy --only functions
2. Seed Firestore with mock data.
3. Send callable request to the deployed function, e.g.:
```
$ curl -X POST -H "content-type: application/json" https:// -d '{ "data": ... }'
```

---

## File: Node/fcm-notifications/README.md

# Send Firebase Cloud Messaging notifications for new followers.

This sample demonstrates how to send a Firebase Cloud Messaging (FCM) notification from a Realtime Database triggered Function. The sample also features a Web UI to experience the FCM notification.


## Functions Code

See file [functions/index.js](functions/index.js) for the code.

Sending the notification is done using the [Firebase Admin SDK](https://www.npmjs.com/package/firebase-admin). The Web client writes the individual device tokens to the realtime database which the Function uses to send the notification.

The dependencies are listed in [functions/package.json](functions/package.json).


## Sample Database Structure

Users sign into the app and are requested to enable notifications on their browsers. If they successfully enable notifications the device token is saved into the datastore under `/users/$uid/notificationTokens`.:

```
/functions-project-12345
    /users
        /Uid-12345
            displayName: "Bob Dole"
            /notificationTokens
                1234567890: true
            photoURL: "https://lh3.googleusercontent.com/..."

```

If a user starts following another user we'll write to `/followers/$followedUid/$followerUid`:

```
/functions-project-12345
    /followers
        /followedUid-12345
            followerUid-67890: true
    /users
        /Uid-12345
            displayName: "Bob Dole"
            /notificationTokens
                1234567890: true
            photoURL: "https://lh3.googleusercontent.com/..."

```


## Trigger rules

The function triggers every time the value of a follow flag changes at `/followers/$followedUid/$followerUid`.


## Deploy and test

This sample comes with a web-based UI for testing the function. To test it out:

 1. Set up your Firebase project:
     1. [Create a Firebase project](https://firebase.google.com/docs/web/setup/#create-firebase-project)
     1. [Register your web app with Firebase](https://firebase.google.com/docs/web/setup/#register-app)
 1. Enable **Google Provider** in the [Auth section](https://console.firebase.google.com/project/_/authentication/providers)
 1. Clone or download this repo and open the `fcm-notification` directory.
 1. You must have the Firebase CLI installed. If you don't have it install it with `npm install firebase-tools` and then configure it with `firebase login`.
 1. Configure the CLI locally by using `firebase use --add` and select your project in the list.
 1. Install dependencies locally by running: `cd functions; npm install; cd -`
 1. Deploy your project using `firebase deploy`
 1. Open the app using `firebase open hosting:site`, this will open a browser.
 1. Start following a user, this will send a notification to them.

---

## File: Node/delete-unused-accounts-cron/README.md

# Periodically delete unused accounts

This sample demonstrates how to delete the accounts of users who have not signed-in in the last month.


## Functions Code

See the file [functions/index.js](functions/index.js) for the code.

**Note:** This function uses Cloud Scheduler, which can have associated costs. Your project must be on the Blaze payment plan as these features require billing information. See the [Cloud Scheduler pricing page](https://cloud.google.com/scheduler/pricing) for more information.

The dependencies are listed in [functions/package.json](functions/package.json).

## Deploy and test

To set up the sample:

 - Create a Firebase Project using the [Firebase Developer Console](https://console.firebase.google.com)
 - Download this sample e.g. `git clone https://github.com/firebase/functions-samples`
 - Enter the sample directory `cd functions-samples/2nd-gen/delete-unused-accounts-cron`
 - Setup the sample with your project `firebase use --add` and follow the instructions.
 - Install node dependencies of your Functions `cd functions; npm install; cd -`
 - Deploy your project using `firebase deploy`.
 - The Cloud Scheduler job should then run once a day and delete any inactive users. You can manually run the task by [navigating to Cloud Scheduler in the Google Cloud Platform Console](https://console.cloud.google.com/cloudscheduler).

---

## File: Node/call-vertex-remote-config-server/client/README.md

Test client for call-vertex-remote-config-server
================================================

Introduction
------------

This is a basic web app that calls the `callVertexWithRC` function. The
function uses values stored in Remote Config server templates with
the Firebase Admin SDK to dynamically update Vertex AI Gemini API
parameters. Access is controlled using Firebase App Check.

- [Read more about Remote Config for servers](https://firebase.google.com/docs/remote-config/server).
- [Read more about App Check](https://firebase.google.com/docs/app-check).
- [Read more about the Vertex AI Node.js Client library](https://cloud.google.com/nodejs/docs/reference/aiplatform/latest).

Important:  Vertex AI and Cloud Functions require a billing account. Review
[Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and
[Firebase pricing](https://firebase.google.com/pricing) before running
this function. If you're new to Firebase and Google Cloud, check to see if
you're eligible for a
[$300 credit](https://firebase.google.com/support/faq#pricing-free-trial) and
a Free Trial Cloud Billing account.

Get started
---------------

 1. Create a [Firebase project and register a web app](https://firebase.google.com/docs/web/setup#create-firebase-project-and-app).
 2. [Create a ReCAPTCHA Enterprise key](https://firebase.google.com/docs/app-check/web/recaptcha-enterprise-provider#project-setup)
    in the same project.
 3. [Enable App Check](https://firebase.google.com/docs/app-check/web/recaptcha-enterprise-provider)
    in the Firebase console with the ReCAPTCHA Enterprise site key you created.
 4. Copy your Firebase project config and your ReCAPTCHA Enterprise site key
    into the appropriate places in `config.ts` in this directory.
 5. In this directory, run `npm install`.
 6. Set up and deploy the function as described in [../README.md](../README.md).
 7. In this directory, run `npm run dev` to run the client.

To run this app against the `callVertexWithRC` function running in the Firebase
emulator, ensure that `testMode`in `main.ts` is set to `true`. Before testing
with a deployed (i.e., not emulated) function, set `testMode` to `false`.

TIP: You can build the client and deploy to Firebase Hosting by running
     `npm run build` from the `client` directory. Hosting deliverables are
     generated and saved in `client/dist` and you can then deploy to
     the emulator or Firebase Hosting from the parent directory. We recommend
     deploying to the emulator first--you can use the following command to
     deploy the function and web client simultaneously:
   
     firebase serve --only functions,hosting 

Support
-------

- [Firebase Support](https://firebase.google.com/support/)

License
-------

© Google, 2024. Licensed under an [Apache-2](../../../LICENSE) license.

---

## File: Node/call-vertex-remote-config-server/README.md

Call the Vertex AI Gemini API with Remote Config and App Check
==============================================================

Introduction
------------

This is a sample callable function that authenticates clients with App
Check and then sends queries to Gemini using the Vertex AI Gemini API. Vertex
AI model parameters (including the model itself) are controlled by
Remote Config server features included in the Firebase Admin SDK for
Node.js.

Use the web client provided in `client/` to test the function.

- [Read more about Remote Config for servers](https://firebase.google.com/docs/remote-config/server).
- [Read more about App Check](https://firebase.google.com/docs/app-check).
- [Read more about the Vertex AI Node.js Client library](https://cloud.google.com/nodejs/docs/reference/aiplatform/latest).

Important:  Vertex AI and Cloud Functions require a billing account. Review
[Vertex AI pricing](https://cloud.google.com/vertex-ai/pricing) and
[Firebase pricing](https://firebase.google.com/pricing) before running
this function. If you're new to Firebase and Google Cloud, check to see if
you're eligible for a
[$300 credit](https://firebase.google.com/support/faq#pricing-free-trial) and
a Free Trial Cloud Billing account.

Get Started
---------------

 1. Follow the instructions in client/README.md to create a Firebase project,
    enable ReCAPTCHA Enterprise, enable and enforce Firebase App Check, and add
    your Firebase config and ReCAPTCHA Enterprise key to the client config.
 
 2. Enable [recommended Vertex AI APIs](https://console.cloud.google.com/vertex-ai).
 
 3. Configure a Remote Config server template on the Firebase console. Use the template
    described in
    [Use server side Remote Config with Cloud Functions and Vertex
    AI](https://firebase.google.com/docs/remote-config/solution-server#implementation-create-template),
    which contains all of the parameters used in this function sample.
 
 4. Install dependencies: `cd functions && npm install`
 
 5. If you haven't already done so, install firebase-tools:
  
    `npm i firebase-tools@latest`
 
 6. Log into Firebase:
 
    `firebase login`
 
 7. Deploy the function. We recommend testing in the
    [Firebase emulator](https://firebase.google.com/docs/remote-config/solution-server#implementation-deploy-and-test-in-emulator):
 
    `firebase emulators:start`
 
 8. If testing in the emulator, verify that `testMode` is set to `true` in
     `client/main.ts`, then start the client:

    `cd client && npm run dev`

    TIP: If you're using the emulator, you can deploy both the function and hosting
         to the emulator. From the `client` directory, run `npm run build`.
         Then, from the parent directory, run `firebase server --only functions,hosting`.
         Open http://localhost:5000 to access and test the web client's connection
         to the `callVertexWithRC` function.
    
 0. Open the [client app in a browser](http://localhost:5173) and enter a
    prompt. To access the Vertex AI Gemini API, make sure that you have
    set the `is_vertex_enabled` boolean parameter in your Remote Config
    server template to `true`.

Support
-------

- [Firebase Support](https://firebase.google.com/support/)

License
-------

© Google, 2024. Licensed under an [Apache-2](../../LICENSE) license.

---

## File: Node/app-distribution-feedback-to-jira/README.md

# Send in-app feedback to Jira
 
This [code](functions/index.js) demonstrates how to use a Firebase Cloud Function triggered by an 
[in-app feedback Firebase Alert from App Distribution](https://firebase.google.com/docs/functions/beta/reference/firebase-functions.alerts.appdistribution.inappfeedbackpayload),
and stores the feedback details (including screenshot) in Jira.

You can customize this code to work with your own Jira configuration (eg on-premise support, custom issue types, etc). 

## Quickstart

This sample code uses Jira's built-in APIs to create issues for in-app tester feedback. For simplicity it uses [basic authorization](https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/).

1. [Generate an API token](https://id.atlassian.com/manage-profile/security/api-tokens) via your Jira profile.


   Note: If the tester who files feedback does not have a Jira account, the user who generates this token will be marked as the issue's reporter.
2. This [code](functions/index.js) uses [parameterized configuration](https://firebase.google.com/docs/functions/config-env#params) to prompt for the required configuratio. To start the process, run:
   ```bash
   $ firebase deploy
   ```
   This will store the `API_TOKEN` using [Google Cloud Secret Manager](https://cloud.google.com/secret-manager) and the remaining settings in an `.env` file which will contain the following variables, customized to your Jira project:
    ```bash
    JIRA_URI="<your JIRA instance's URI, e.g. 'https://mysite.atlassian.net'>"
    PROJECT_KEY="<your project's key, e.g. 'DEV'>"
    ISSUE_TYPE_ID=""
    ISSUE_LABEL="<label applied to the Jira issues created; defaults to 'in-app'>"
    API_TOKEN_OWNER="<creator of the token; default reporter of issues>"
    ```

## License
© Google, 2022. Licensed under an [Apache-2 license](../../LICENSE).

---

## File: Node/alerts-to-discord/README.md

# Quickstart: Send Firebase Alerts to Discord

This quickstart demonstrates how to trigger a function based on a Firebase Alert, and send information about the alert to a channel in a Discord server.



## Set up and Deploy

### Discord Webhook URL

The sample uses [Discord Webhooks](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks) to send alerts to a Discord channel. You'll need to create a Webhook and hook it up the function by [creating an environment variable](https://firebase.google.com/docs/functions/config-env#env-variables):

1. Follow the "MAKING A WEBHOOK" instructions in the [Discord docs](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks). 
1. Copy the Webhook URL
1. Create a `.env` file in the `functions` directory
1. Add the `DISCORD_WEBHOOK_URL` variable and set it to your Webhook URL:
    ```bash
    DISCORD_WEBHOOK_URL="<your webhook url>"
    ```

### Deploy
Deploy functions using the Firebase CLI:

```bash
$ firebase deploy
```

## License

© Google, 2022. Licensed under an [Apache-2](../../../LICENSE) license.

---

## File: Node/quickstarts/uppercase-rtdb/README.md

# Firebase SDK for Cloud Functions 2nd Gen Quickstart - Realtime Database

This quickstart demonstrates using **Firebase SDK for Cloud Functions** with **Firebase Realtime Database**.


## Introduction

This sample app does two things:
 - Create messages in the Firebase Realtime Database using a simple HTTPS request which is handled by a v2 HTTPS function. Writing to the Realtime Database is done using the Firebase Admin SDK. 
 - When a message gets added in the Realtime Database, a v2 function triggers and automatically makes these messages all uppercase.

## Deploy and try out

To deploy and try out the sample:

 - Create a Firebase project using the [Firebase console](https://console.firebase.google.com)
 - Install the required dependencies by running `npm install` in the `functions` directory
 - Deploy your project's code using `firebase deploy`
 - Create a message by opening the querying the functions URL from your browser.

 The function executes and redirects the browser to the Firebase console at the database location where the text string was stored. You should see your text value displayed in the console and in uppercase.

## Contributing

We'd love you to contribute to the project. Before doing so please read our [Contributor guide](../../CONTRIBUTING.md).


## License

© Google, 2022. Licensed under an [Apache-2](../../LICENSE) license.

---

## File: Node/quickstarts/uppercase-firestore/README.md

# Firebase SDK for Cloud Functions Quickstart - Firestore

This quickstart demonstrates using the **Firebase SDK for Cloud Functions** with
**Firestore**.

## Introduction

This sample app does two things:

- Creates messages in Firestore using a simple HTTPS request which is
  handled by an HTTP function. Writing to Firestore is done using the
  Firebase Admin SDK.
- When a message gets added in Firestore, a function triggers and
  automatically makes these messages all uppercase.

## Set up the sample

Before you can test the functions locally or deploy to a Firebase project,
you'll need to run `npm install` in the `functions` directory.

## Run locally with the Firebase Emulator suite

The
[Firebase Local Emulator Suite](https://firebase.google.com/docs/emulator-suite)
allows you to build and test apps on your local machine instead of deploying to
a Firebase project.

1. Create a Firebase project in the
   [Firebase Console](https://console.firebase.google.com)
   > _Wondering why this step is needed?_ Even though the emulator will run this
   > sample on your local machine, it needs to interact with a Firebase project
   > to retrieve some configuration values.
1. [Set up or update the Firebase CLI](https://firebase.google.com/docs/cli#setup_update_cli)
1. Run `firebase emulators:start`
1. Open the Emulator Suite UI
   1. Look in the output of the `firebase emulators:start` command for the URL
      of the Emulator Suite UI. It defaults to
      [localhost:4000](http://localhost:4000), but may be hosted on a different
      port on your machine.
   1. Enter that URL in your browser to open the UI.
1. Trigger the functions
   1. Look in the output of the `firebase emulators:start` command for the URL
      of the http function "addmessage". It will look similar to:
      `http://localhost:5001/MY_PROJECT/us-central1/addmessage`
      1. `MY_PROJECT` will be replaced with your project ID
      1. The port may be different on your local machine
   1. Add the query string `?text=uppercaseme` to the end of the function's URL.
      It should now look something like:
      `http://localhost:5001/MY_PROJECT/us-central1/addmessage?text=uppercaseme`
      1. Optionally, you can change the message "uppercaseme" to a custom
         message
   1. Create a new message by opening the URL in a new tab in your browser
1. View the effects of the functions in the Emulator Suite UI

   1. In the "Logs" tab, you should see new logs indicating that the functions
      "addmessage" and "makeuppercase" ran:

      > `functions: Beginning execution of "addmessage"`

      > `functions: Beginning execution of "makeuppercase"`

   1. In the "Firestore" tab, you should see a document containing your original
      message as well as the uppercased version of your message (if it was
      originally "uppercaseme", you'll see "UPPERCASEME")

## Deploy and test on a live Firebase project

To deploy and test the sample:

1. Create a Firebase project on the
   [Firebase Console](https://console.firebase.google.com)
1. Deploy your project's code using `firebase deploy`
1. Create a message by opening the function URL in your browser.

You should see your text value displayed in the console and uppercase.

## Contributing

We'd love that you contribute to the project. Before doing so please read our
[Contributor guide](../../CONTRIBUTING.md).

## License

© Google, 2023. Licensed under an [Apache-2](../../LICENSE) license.