UCI provides a firebase adapter which sends push notifications to your Mobile or Web based application.
2. How to send firebase notification ?
We need a mobile or web application that will register the FCM tokens on firebase. These tokens can be later used to trigger firebase notification. We can trigger these notification in two ways.
1. Use UCI Internal Apis
We can store these registered tokens in UCI & use UCI fetch api to get these tokens for notification. Follow below steps to do this.
Register FCM tokens on any mobile or web application using the firebase details of UCI. Add this FCM token on UCI using below API:
Create a new service here with the fetch token API in config.
Create a new user segment here with the service created in step 3. Or you can use an already created user segment for this case. cf085492-266f-46d1-841c-1b38e93bce3f.
The ID of the transformer returned by UCI when this particular transformer was created.
data.transformers.meta
object
Yes
An object containing metadata for the transformer.
data.transformers.meta.form
string
Yes
The URL of the form used by the transformer where the form is hosted.
data.transformers.meta.formID
string
Yes
The ID of the ODK form used by the transformer.
data.transformers.meta.title
string
Yes
The title of the transformer.
data.transformers.meta.body
string
Yes
The body of the transformer.
data.transformers.meta.serviceClass
string
Yes
The service class of the transformer. Used for prefilling in ODK responses. Currently only SurveyService is supported as a valid value.
data.transformers.meta.hiddenFields
array
No
An array of hidden fields in the transformer. Hidden fields are used to prefill data in form, for example, mobile name.
data.transformers.meta.hiddenFields.name
string
Yes
Name of the field that is used as a placeholder in the form XML.
data.transformers.meta.hiddenFields.path
string
Yes
Path of the object from which the data needs to be filled in. For example if path is mobilePhone, it would be filled with the data stored in mobilePhone field in the object provided by config field.
data.transformers.meta.hiddenFields.type
string
Yes
Currently the only type supported is param.
data.transformers.meta.hiddenFields.config
object
Yes
An object containing the data that has to be passed for injecting in the prefilled fields. An example value would be user which would make the user object data, present in UCI session, available for use. In our example mobileNumber is extracted from this data.
The name of the data object that needs to be used in config.
data.transformers.meta.templateType
string
Yes
The template type of the transformer. This governs how literals are treated in the template. Possible values include JS_TEMPLATE_LITERALS and PYTHON_TEMPLATE_LITERALS.
data.adapter
string
Yes
The ID of the adapter that is returned by UCI when a particular adapter was created.
Hit the below api using the created bot id to send firebase notification to all registered FCM tokens.
curl --location --request GET 'http://[HOST]:[PORT]/campaign/start?campaignId=1ea5346d-8d98-4cf4-a470-9c234476f3d1'
2. Use your own FCM token api
We can also use third party apis that have registered FCM tokens in a specific format. For this we will also need the firebase project service key to send notifications.
Create an api that provides the FCM tokens in below format.
Note: Param fcmClickActionUrl is being used to mention the url to open on click ot fcm notification. This url should have the same domain as the one on which the fcm tokens are registered, else the url will not work.
Add Firebase service key in vault using below APIs.
Please contact the administrator to get the loginId and password for this API.
This API will give below response. Use the token from the response in "Add secret API".\
This API will create a new adapter and will return the adapter id (Eg. 2a704e82-132e-41f2-9746-83e74550d2ea). We will use this adapter id later in conversation logic.
Create a new service here with the your token API.
Create a new user segment here with the service created in step 4.
Create a new conversation logic with adapter from step 3 and below logic.
Hit the below api using the created bot id to send firebase notification to all registered FCM tokens.
curl --location --request GET 'http://[HOST]:[PORT]/campaign/start?campaignId=1ea5346d-8d98-4cf4-a470-9c234476f3d1'
3. Message Receipts Api
We have two apis that provides the option to add delivery & read receipts for the received message.
When a firebase notification is sent, some extra data required for the receipt apis are also sent in it. externalId (Message ID), destAdd (User ID) & fcmDestAdd (User FCM Token) will be sent in the notification data to be later used in the receipt apis.
3.1. Delivery Receipt
This api stores the delivery receipt against a message. To sent a delivery report use the below curl request with required details.
start & end date: Conversations between start & end date.
curl --location --request GET 'http://[HOST]:[PORT]/xmsg/history/dump?provider=firebase&botId=1ea5346d-8d98-4cf4-a470-9c234476f3d1&endDate=19-07-2022&startDate=05-07-2022'
Limitation: This API can provide conversations for 15 days only.
These APIs will give the response in below format.