A struct representing a push notification message.
Provides a builder API for constructing notifications with title, body, badge, sound, and custom data.
Examples
# Simple message
message = PushX.Message.new("Hello", "World")
# Builder pattern
message = PushX.Message.new()
|> PushX.Message.title("Order Update")
|> PushX.Message.body("Your order has been shipped!")
|> PushX.Message.badge(1)
|> PushX.Message.sound("default")
|> PushX.Message.data(%{order_id: "12345"})
Summary
Functions
Sets the badge count (iOS).
Sets the body of the message.
Sets the notification category (iOS).
Sets the collapse key for message deduplication.
Sets custom data payload.
Sets the image URL for rich notifications.
Creates a new empty message.
Creates a new message with title and body.
Sets the priority (:high or :normal).
Adds a key-value pair to the data payload.
Sets the notification sound.
Sets the thread ID for notification grouping (iOS).
Sets the title of the message.
Translates the message's delivery fields into APNS send options.
Converts the message to an APNS payload map.
Translates the message's delivery fields into an FCM android block.
Converts the message to an FCM payload map.
Sets the TTL (time to live) in seconds.
Types
@type t() :: %PushX.Message{ badge: non_neg_integer() | nil, body: String.t() | nil, category: String.t() | nil, collapse_key: String.t() | nil, data: map(), image: String.t() | nil, priority: :high | :normal | nil, sound: String.t() | nil, thread_id: String.t() | nil, title: String.t() | nil, ttl: non_neg_integer() | nil }
Functions
@spec badge(t(), non_neg_integer()) :: t()
Sets the badge count (iOS).
Sets the body of the message.
Sets the notification category (iOS).
Sets the collapse key for message deduplication.
Sets custom data payload.
Sets the image URL for rich notifications.
@spec new() :: t()
Creates a new empty message.
Examples
iex> PushX.Message.new()
%PushX.Message{title: nil, body: nil, data: %{}, priority: nil}
Creates a new message with title and body.
Examples
iex> PushX.Message.new("Hello", "World")
%PushX.Message{title: "Hello", body: "World", data: %{}, priority: nil}
Sets the priority (:high or :normal).
Adds a key-value pair to the data payload.
Sets the notification sound.
Sets the thread ID for notification grouping (iOS).
Sets the title of the message.
Translates the message's delivery fields into APNS send options.
Returns a keyword list suitable for merging into the opts of
PushX.APNS.send/3 — explicit call-site options take precedence.
priority: :high→priority: 10,priority: :normal→priority: 5ttl(seconds from now) →expiration(absolute Unix timestamp;ttl: 0maps toexpiration: 0, APNS's "attempt once, don't store")collapse_key→collapse_id
Examples
iex> PushX.Message.new("Hi", "There") |> PushX.Message.priority(:normal) |> PushX.Message.to_apns_options()
[priority: 5]
Converts the message to an APNS payload map.
Note: when the message has a title but no explicit sound, "default" is
injected — a titled notification is assumed to be user-visible. To send a
visible-but-silent notification, build the raw APNS payload map yourself
(omit "sound") instead of using the Message builder.
Translates the message's delivery fields into an FCM android block.
Returns nil when none of priority, ttl, or collapse_key are set.
Examples
iex> PushX.Message.new("Hi", "There") |> PushX.Message.ttl(3600) |> PushX.Message.to_fcm_android()
%{"ttl" => "3600s"}
iex> PushX.Message.new("Hi", "There") |> PushX.Message.to_fcm_android()
nil
Converts the message to an FCM payload map.
@spec ttl(t(), non_neg_integer()) :: t()
Sets the TTL (time to live) in seconds.