MongoosePush v2.1.0 MongoosePush View Source

MongoosePush is simple (seriously) service providing ability to send push notification to FCM (Firebase Cloud Messaging) and/or APNS (Apple Push Notification Service). What makes it cool is not only simplicity but also support for newest and fastest HTTP/2 based APIs for both services.

At this moment only those two services are supported but in future MongoosePush may and probably will support even more Push Notification Services.

Link to this section Summary

Types

Available keys in request map

Raw push request. The keys: :service and at least one of :alert or :body are required

Functions

Push notification defined by request to device with device_id. request has to define at least :service type (:fcm or :apns) and at least one of :alert or :data. If alert is not present, the notification will be send as 'silent'. Please refer to yours push notification service provider's documentation for more details on silent notifications.

Link to this section Types

Specs

alert() :: %{optional(alert_key()) => atom() | String.t() | integer()}

Specs

alert_key() :: :title | :body | :tag | :badge | :click_action | :sound

Specs

data() :: %{optional(data_key()) => term()}

Specs

data_key() :: atom() | String.t()

Specs

error() ::
  {:generic, :no_matching_pool | :unable_to_connect | :connection_lost | atom()}

Specs

mode() :: :dev | :prod

Specs

req_key() ::
  :service
  | :mode
  | :alert
  | :data
  | :topic
  | :priority
  | :time_to_live
  | :mutable_content
  | :tags

Available keys in request map

Specs

request() :: %{
  optional(req_key()) => atom() | String.t() | integer() | alert() | data()
}

Raw push request. The keys: :service and at least one of :alert or :body are required

Specs

service() :: :fcm | :apns

Link to this section Functions

Link to this function

push(device_id, request)

View Source

Specs

push(String.t(), request()) ::
  :ok | {:error, MongoosePush.Service.error()} | {:error, MongoosePush.error()}

Push notification defined by request to device with device_id. request has to define at least :service type (:fcm or :apns) and at least one of :alert or :data. If alert is not present, the notification will be send as 'silent'. Please refer to yours push notification service provider's documentation for more details on silent notifications.

Field :data may contain any custom data that have to be delivered to the target device, while field :alert, if present, must contain at least :title and :body. The :alert field may also contain: :sound, :tag (option specific to FCM service), :topic and :bagde (specific to APNS). Please consult push notification service provider's documentation for more informations on those optional fields.

Field :priority may be used to set priority for message on both FCM and APNS. The values are native for FCM and for APNS - :normal is "5" and :high is 10.

:mode option is also specific to APNS but it only selects appropriate worker pool (with :mode set to either :prod or :dev). Default value to :mode is :prod.

Field :mutable_content (specific to APNS) can be set to true (by default false) to enable this feature (please consult APNS documentation for more information).