module Os_fcm_notif : sig..end
Send push notifications to Android and iOS mobile devices.
This module provides a simple OCaml interface to Firebase Cloud Messaging (FCM) to send push notifications to Android and iOS mobile devices by using downstream HTTP messages in JSON.
You can find all informations abou FCM at this address: https://firebase.google.com/docs/cloud-messaging/
Before using this module, you need to register your mobile application in FCM and save the server key FCM will give you. You need to pass this key to Os_fcm_notif.send when you want to send a notification.
On the client, you will need first to register the device on FCM. See
- for iOS: https://firebase.google.com/docs/cloud-messaging/ios/client
- for Android: https://firebase.google.com/docs/cloud-messaging/android/client
If you use this module to send push notifications to mobile devices created with ocsigen-start, you can use one of these plugins.
- cordova-plugin-fcm (binding ocaml-cordova-plugin-fcm).
- phonegap-plugin-push (binding ocaml-cordova-plugin-push-notifications). If you use one of them and if you want to add extra data, you need to use Os_fcm_notif.Data.add_raw_string or Os_fcm_notif.Data.add_raw_json depending on the type of the value.
FCM works with tokens which represents a device. This token is used to target the device when you send a notification. The token is retrieved client-side.
To send a notification, you need to use send server_key notification ?data options where
- notification is of type Os_fcm_notif.Notification.t and represents the notification payload in the JSON sent to FCM.
- data is an optional value of type Os_fcm_notif.Data.t and represents the data payload in the JSON sent to FCM. By default, it's empty.
- options is of type Os_fcm_notif.Options.t and represents options in the FCM documentation.
The type Os_fcm_notif.Options.t contains the list of registered ID you want to send the notification notification to. You can create a value of type Os_fcm_notif.Options.t with Os_fcm_notif.Options.create which needs a list of client ID. These ID's are the devices you want to send the notification to. You can add some parameters like priorities, restricted package name, condition, etc.
The type Os_fcm_notif.Notification.t contains the notification payloads. The description is given here: https://firebase.google.com/docs/cloud-messaging/http-server-ref
You can create an empty value of type Os_fcm_notif.Notification.t with Os_fcm_notif.Notification.empty. As described in the link given above, you can add a title, a body, etc to the notification. In general, to add the payload payload, you can use the function add_(payload). The notification value is at the end to be able to use the pipe. For example, to add a title and a message, you can use:
Notification.empty () |> add_title "Hello, World!" |> add_body "Message to the world!"
exception FCM_no_json_response of string
exception FCM_missing_field of string
module Notification : sig..end
This module provides an interface to create the JSON for the notification key.
val send :
Options.t -> Response.t Lwt.t
send server_key notification options