A Fn Project function for sending mobile push notifications through third party integrations.
Currently, push notifications can be sent to Androind and iOS devices using Firebase Cloud Messaging (FCM).
For sending push notifications, a Firebase Admin SDK service account is required.
Of course, also an OCI tenancy where deploy the function is required.
Currently the most recent Firebase Admin Go SDK supported version is 4.9.0
, because Go Fn FDK doesn't support go
versions >1.15
.
The function supports the following configuration variables:
Variable | Description | Required | Notes |
---|---|---|---|
GOOGLE_APPLICATION_CREDENTIALS |
The Firebase Admin SDK service account private key file, in JSON format. The variable should be base64 encoded | If GOOGLE_APPLICATION_CREDENTIALS_SECRET_ID is not specified |
Configuration variables are stored in plain text, please consider using GOOGLE_APPLICATION_CREDENTIALS_SECRET_ID instead |
GOOGLE_APPLICATION_CREDENTIALS_SECRET_ID |
The OCID of the secret that contains the Firebase Admin SDK service account private key file, in JSON format | If GOOGLE_APPLICATION_CREDENTIALS is not specified |
The function payload is a JSON with the following attributes:
Name | Description | Notes |
---|---|---|
recipients |
The registration tokens of push notification recipients | |
data |
A custom set of key-value pairs | Only strings are allowed, both for keys and values |
message |
The message to push to recipients | |
message.title |
The title of the message | |
message.body |
The body of the message |
An example of function's payload is the following:
{
"recipients": [
"00000000"
],
"data": {
"description": "Use the data element for sending custom key-value pairs",
"note": "Only strings are allowed, both for keys and values"
},
"message": {
"title": "Hello",
"body": "A message for you !!!"
}
}
- Configure your tenancy and your development environment to use OCI Functions
- A Firebase Admin SDK service account
For deploying the function:
- Clone the oci-fn-push-notification repo
git clone https://github.com/cdivita/oci-fn-push-notification.git
- Create the application in OCI Functions
fn create app <app-name> --annotation oracle.com/oci/subnetIds='["<subnet-ocid>"]'
- Deploy the function
fn -v deploy --app <app-name> --no-bump
- Configure the function
fn config function <app-name> fn-push-notification GOOGLE_APPLICATION_CREDENTIALS <Firebase Admin SDK service account private key>
If you stored the Google Application Credentials OCI Vault, the configuration activities are slightly different:
- Use
GOOGLE_APPLICATION_CREDENTIALS_SECRET_ID
rather thanGOOGLE_APPLICATION_CREDENTIALS
as configuration variablefn config function <app-name> fn-push-notification GOOGLE_APPLICATION_CREDENTIALS_SECRET_ID <The OCID of your Twilio Auth Token secret>
- Create a dynamic group that includes your function resources. A matching rule that can be used is:
all {resource.type = 'fnfunc'}
- Create a policy for such dynamic group that allows the access to keys resources
allow dynamic-group <dynamic-group-name> to read secret-bundles in compartment <keys-compartment>