PushX.Message (PushX v0.5.0)

Copy Markdown View Source

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.

Converts the message to an APNS payload map.

Converts the message to an FCM payload map.

Sets the TTL (time to live) in seconds.

Types

t()

@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,
  sound: String.t() | nil,
  thread_id: String.t() | nil,
  title: String.t() | nil,
  ttl: non_neg_integer() | nil
}

Functions

badge(message, badge)

@spec badge(t(), non_neg_integer()) :: t()

Sets the badge count (iOS).

body(message, body)

@spec body(t(), String.t()) :: t()

Sets the body of the message.

category(message, category)

@spec category(t(), String.t()) :: t()

Sets the notification category (iOS).

collapse_key(message, key)

@spec collapse_key(t(), String.t()) :: t()

Sets the collapse key for message deduplication.

data(message, data)

@spec data(t(), map()) :: t()

Sets custom data payload.

image(message, image_url)

@spec image(t(), String.t()) :: t()

Sets the image URL for rich notifications.

new()

@spec new() :: t()

Creates a new empty message.

Examples

iex> PushX.Message.new()
%PushX.Message{title: nil, body: nil, data: %{}, priority: :high}

new(title, body)

@spec new(String.t(), String.t()) :: t()

Creates a new message with title and body.

Examples

iex> PushX.Message.new("Hello", "World")
%PushX.Message{title: "Hello", body: "World", data: %{}, priority: :high}

priority(message, priority)

@spec priority(t(), :high | :normal) :: t()

Sets the priority (:high or :normal).

put_data(message, key, value)

@spec put_data(t(), atom() | String.t(), any()) :: t()

Adds a key-value pair to the data payload.

sound(message, sound)

@spec sound(t(), String.t()) :: t()

Sets the notification sound.

thread_id(message, thread_id)

@spec thread_id(t(), String.t()) :: t()

Sets the thread ID for notification grouping (iOS).

title(message, title)

@spec title(t(), String.t()) :: t()

Sets the title of the message.

to_apns_payload(message)

@spec to_apns_payload(t()) :: map()

Converts the message to an APNS payload map.

to_fcm_payload(message)

@spec to_fcm_payload(t()) :: map()

Converts the message to an FCM payload map.

ttl(message, ttl)

@spec ttl(t(), non_neg_integer()) :: t()

Sets the TTL (time to live) in seconds.