Module notifier_event

The notification event: one schema shared by the REST API (POST /v1/events) and the RabbitMQ consumer.

Description

The notification event: one schema shared by the REST API (POST /v1/events) and the RabbitMQ consumer.

   {
     "id":       "optional correlation id (generated when absent)",
     "type":     "notification" | "data" | "voip",      default notification
     "user_ids": ["alice", "bob"],    recipients, resolved via the token store
     "user_id":  "alice",             shorthand for a single recipient
     "tokens":   [{"token": "...", "provider": "fcm" | "apns_voip",
                   "platform": "ios" | "android" | "web" | "unknown"}],
     "notification": {"title": "...", "body": "...", "image": "https://...",
                      "sound": "default", "badge": 3},
     "data":     {"any": "key/value pairs"},
     "priority": "high" | "normal",   default high
     "ttl":      3600,                seconds; default 0 for voip, unset otherwise
     "collapse_key": "optional",
     "providers": ["fcm", "apns_voip"],   restrict which providers are used
     "exclude_device_ids": ["..."]        skip these devices (token store only)
   }

At least one of user_ids/user_id/tokens is required.

Routing by type: parse/1 validates and normalises the decoded JSON into the internal event() map with atom keys; it never crashes on bad input.

Data Types

event()

event() = #{id := binary(), type := event_type(), user_ids := [binary()], tokens := [target()], notification := map(), data := map(), priority := high | normal, ttl := non_neg_integer() | undefined, collapse_key := binary() | undefined, providers := [provider()], exclude_device_ids := [binary()]}

event_type()

event_type() = notification | data | voip

provider()

provider() = fcm | apns_voip

target()

target() = #{token := binary(), provider := provider(), platform := binary(), device_id => binary() | undefined}

Function Index

allowed_providers/1Providers an event of this type may use when none are given.
new_id/0A random 128-bit hex correlation id.
parse/1Validate and normalise a decoded JSON object.

Function Details

allowed_providers/1

allowed_providers(X1::event_type()) -> [provider()]

Providers an event of this type may use when none are given.

new_id/0

new_id() -> binary()

A random 128-bit hex correlation id.

parse/1

parse(Json::term()) -> {ok, event()} | {error, binary()}

Validate and normalise a decoded JSON object.


Generated by EDoc