Installing a function
This guide walks you through the steps to install a function to send a welcome email when customers sign up. You can use this example as a starting point for installing and managing functions.
Last updated
This guide walks you through the steps to install a function to send a welcome email when customers sign up. You can use this example as a starting point for installing and managing functions.
Last updated
Make sure that you have the required setup for this exercise:
An active Google account.
A project in Firebase or GCP where:
you have to assign the following roles to a service account:
Cloud Function Admin
Firebase Authentication Admin
Secret Manager Admin
Service Account User
Service Usage Admin
you linked your project to a Billing account on GCP
you enabled the APIs: Cloud Functions API, Cloud Build API, and Secret Manager API on the GCP. Also, you must enable Firebase Authentication for this specific type of function.
The above list has the basic requirements to install a function, but some functions have other requirements that involve knowledge about other tools and apps.
In case you want to deploy your function without granting your GCP project permissions directly in Function Store, you can do it by uploading a ZIP file.
The function selected for this example is sendSignUpWelcomeEmail. This is a free, reusable function that also requires:
Previous knowledge about SendGrid and Firebase.
A SendGrid account.
A welcome email is one of the first impressions your brand makes. It sets the foundation for the kind of cooperation you will have with your subscribers. The sendSignUpWelcomeEmail function will allow you to send a welcome email when users sign up via a SendGrid template.
Now you know the function, follow these steps to install it.
Let's say that you already have a SendGrid account: open the SendGrid page and sign in.
Once you logged in to your SendGrid account, you'll need to obtain the following information to complete the installation form:
Find the API key to authenticate access to SendGrid services. On the rest of this page, this API key is referred to as SENDGRID_API_KEY.
Create a sender identity before sending an email. It’s required that you provide the identity information about where the emails are coming from in each email you send. On the rest of this page, this sender identity is referred to as SENDGRID_SENDER_EMAIL.
Select the template ID from a blank template, a custom template that you have already created, or a predefined SendGrid Email Design. On the rest of this page, this template ID is referred to as SENDGRID_TEMPLATE_ID.
Notice that the SendGrid template might receive the following variables depending on the provider used to signUp:
provider: The providerId used for signUp (google.com, facebook.com, phone, password, etc.).
displayName: The name of the new user created. It will be received if it's available from the provider.
phoneNumber: The user phone number. It will be received if it's available from the provider.
photoURL: The URL of the new user created. It will be received if it's available from the provider.
These variables can be used in the template as follow:
Notice that if the user doesn't have an email associated with its account, the welcome email will not be sent.
For more information, check the SendGrid documentation.
In the Marketplace section, you'll find all the functions we created for you. Just type the name of the function in the search, scroll, or select the Free filter to easily locate the sendSignUpWelcomeEmail.
Now that you find it, click on the Install button. This opens a drawer with a selectable menu to choose the project where you want to install the function. Keep in mind that you must have previously set up the project.
Once you select the project, you'll need to fill out a form with the following environment variables from your SendGrid account:
SENDGRID_API_KEY: The API to authenticate access to SendGrid services.
SENDGRID_SENDER_EMAIL: Email corresponding to SendGrid sender correctly verified.
SENDGRID_TEMPLATE_ID: Id of SendGrid dynamic template that will be used to generate the welcome email.
Proceed to click Install, and in a few seconds, you will see the function appears in the Installed Functions section.
Great! The sendSignUpWelcomeEmail function is installed into your project and you can programmatically send welcome emails to all users who will be signing up for your project.
Find out more about our functions.
For more information about SendGrid, see: