This is server API (go to client)

Warning: Reason support is experimental. We are looking for beta-tester and contributors.

Module Os_fcm_notif

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.

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

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_empty_response
exception FCM_no_json_response of string
exception FCM_missing_field of string
exception FCM_unauthorized
module Notification : sig..end

This module provides an interface to create the JSON for the notification key.

module Data : sig..end
module Options : sig..end
module Response : sig..end
val send : 
  string ->
  Notification.t ->
  ?data:Data.t ->
  Options.t -> Response.t Lwt.t

send server_key notification options