### Add Pigeon Dispatcher to Elixir Supervision Tree Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This Elixir code demonstrates how to add the `YourApp.APNS` dispatcher to the application's supervision tree, ensuring it starts and is managed by the supervisor. This is the standard way to start workers in Pigeon v2.0. ```Elixir defmodule YourApp.Application do @moduledoc false use Application @doc false def start(_type, _args) do children = [ YourApp.APNS ] opts = [strategy: :one_for_one, name: YourApp.Supervisor] Supervisor.start_link(children, opts) end end ``` -------------------------------- ### Install Pigeon Elixir Dependency Source: https://github.com/codedge-llc/pigeon/blob/main/README.md Add the Pigeon library as a dependency in your Elixir project's mix.exs file to enable push notification capabilities. ```Elixir def deps do [ {:pigeon, "~> 2.0"} ] end ``` -------------------------------- ### Manually Start APNS Connection and Push by PID Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Demonstrates how to manually start an APNS connection and then push notifications to it using its process ID (PID). This allows for dynamic connection management outside of the application configuration. ```Elixir iex> {:ok, pid} = Pigeon.APNS.start_connection(cert: "cert.pem", ...> key: "key.pem", mode: :dev) iex> Pigeon.APNS.push(notif, to: pid) ``` -------------------------------- ### Manually Start Named APNS Connection and Push Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Shows how to manually start a named APNS connection using the `name` option in `Pigeon.APNS.start_connection`. Notifications can then be pushed to this connection by its assigned name. ```Elixir iex> Pigeon.APNS.start_connection(cert: "cert.pem", key: "key.pem", ...> mode: :dev, name: :custom) iex> Pigeon.APNS.push(notif, to: :custom) ``` -------------------------------- ### Define New Pigeon Dispatcher Module for APNS Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This Elixir code defines a new module, `YourApp.APNS`, which uses `Pigeon.Dispatcher` to manage push notifications. This module will be started under the application's supervision tree instead of being managed by Pigeon directly. ```Elixir # lib/your_app/apns.ex defmodule YourApp.APNS do use Pigeon.Dispatcher, otp_app: :your_app end ``` -------------------------------- ### Handle various Amazon Device Messaging (ADM) push responses in Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/ADM Amazon Android.md This snippet provides a comprehensive example of handling different ADM push response types using a 'case' statement on the ':response' key of the returned notification. It covers success, registration ID updates, invalid IDs, unregistered devices, and other errors, allowing for specific actions based on the outcome. ```Elixir on_response_handler = fn(x) -> case x.response do :success -> # Push successful :ok :update -> new_reg_id = x.updated_registration_id # Update the registration ID in the database :invalid_registration_id -> # Remove the bad ID from the database :unregistered -> # Remove the bad ID from the database error -> # Handle other errors end end data = %{ message: "your message" } n = Pigeon.ADM.Notification.new("your registration id", data) Pigeon.ADM.push(n, on_response: on_response_handler) ``` -------------------------------- ### Handle FCM Push Responses with Named Function and Case Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Provides a more structured example of handling FCM push responses using a named function (on_response) that pattern matches on the notification's status to manage different outcomes like success, unauthorized, or other errors. ```Elixir on_response = fn(n) -> case n.status do :success -> bad_regids = FCM.Notification.remove?(n) to_retry = FCM.Notification.retry?(n) # Handle updated regids, remove bad ones, etc :unauthorized -> # Bad FCM key error -> # Some other error end end data = %{message: "your message"} n = Pigeon.FCM.Notification.new("your device token", data) Pigeon.FCM.push(n, on_response: on_response) ``` -------------------------------- ### APNS Configuration Breaking Changes in Pigeon v2.0 Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md In Pigeon v2.0, the `:certfile` and `:keyfile` options for APNS configurations are no longer valid. Users must now read the certificate and key files into binary data using `File.read!` and pass them via the `cert` and `key` options directly. ```APIDOC APNS Configuration Options (Pigeon v2.0): - cert: binary (Required) Description: Binary content of the APNS certificate file. Example: File.read!("cert.pem") Replaces: :certfile - key: binary (Required) Description: Binary content of the APNS key file. Example: File.read!("key_unencrypted.pem") Replaces: :keyfile ``` -------------------------------- ### Configure New Pigeon Dispatcher in config.exs Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This Elixir configuration snippet shows how to configure the newly defined `YourApp.APNS` dispatcher in `config.exs`, specifying the adapter, certificate, key, and mode. This replaces the old global configuration. ```Elixir # config.exs config :your_app, YourApp.APNS, adapter: Pigeon.APNS, cert: File.read!("cert.pem"), key: File.read!("key_unencrypted.pem"), mode: :dev ``` -------------------------------- ### API Configuration Function Renames Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating to v1-1-0.md Across multiple services, the configuration function `config/1` has been consistently renamed to `new/1` for improved clarity and consistency. ```APNS APNS.Config.config/1 -> APNS.Config.new/1 ``` ```ADM ADM.Config.config/1 -> ADM.Config.new/1 ``` -------------------------------- ### Add Pigeon Dispatcher to Elixir Supervision Tree with Options Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This Elixir code shows an alternative way to add the `YourApp.APNS` dispatcher to the supervision tree, passing configuration options directly to the child specification using a private helper function. ```Elixir defmodule YourApp.Application do @moduledoc false use Application @doc false def start(_type, _args) do children = [ {YourApp.APNS, apns_opts()} ] opts = [strategy: :one_for_one, name: YourApp.Supervisor] Supervisor.start_link(children, opts) end defp apns_opts do [ adapter: Pigeon.APNS, cert: File.read!("cert.pem"), key: File.read!("key_unencrypted.pem"), mode: :dev ] end end ``` -------------------------------- ### API Push Function Signature Update Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating to v1-1-0.md The `push/3` function has been removed across APNS, FCM, and ADM services. All push operations should now use `push/2` by passing options as the second argument, streamlining the API. ```APNS Old: push(notification, config, options) New: push(notification, options) ``` ```FCM Old: push(notification, config, options) New: push(notification, options) ``` ```ADM Old: push(notification, config, options) New: push(notification, options) ``` -------------------------------- ### APNS Synchronous Push Response Format Change Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating to v1-1-0.md Synchronous APNS pushes now return a list of `APNS.Notification` structs directly, replacing the previous map-based response structure. ```APNS Old: %{ok: [...], error: [...]} New: [%APNS.Notification{}, ...] ``` -------------------------------- ### Update Pigeon Elixir Dependencies for v2.0 Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This snippet shows how to update the `mix.exs` file to use Pigeon v2.0 and remove the `kadadbra` dependency, which is no longer required. ```Elixir [ {:pigeon, "~> 2.0"} # Change this {:kadadbra, ~> 0.6.0} # Remove this ] ``` -------------------------------- ### Add Pigeon Legacy FCM Adapter Dependency Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This Elixir snippet shows how to add the `pigeon_legacy_fcm` dependency to `mix.exs` for projects that need to continue using FCM's decommissioned legacy API after upgrading Pigeon to v2.0. ```Elixir def deps do [ {:pigeon_legacy_fcm, "~> 0.2.0"} ] end ``` -------------------------------- ### Configure APNS with Token-based Authentication Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Alternatively, configure APNS using token-based authentication. This requires a `.p8` key file, a 10-character key identifier, and your 10-character Team ID, all obtained from your Apple developer account. The key can be a file path, file contents string, or a tuple. ```Elixir config :pigeon, :apns, apns_default: %{ key: "AuthKey.p8", key_identifier: "ABC1234567", team_id: "DEF8901234", mode: :dev } ``` -------------------------------- ### APNS Port Configuration Update Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating to v1-1-0.md The `:use_2197` configuration option has been deprecated and replaced by a more general `:port` option. While APNS servers primarily use ports 443 and 2197, the `:port` option allows for greater flexibility, especially for test environments. ```APNS Old config: :use_2197 New config: :port (accepts 443, 2197, or other for testing) ``` -------------------------------- ### FCM Notification Response Structure Update Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating to v1-1-0.md The `FCM.NotificationResponse` struct has been deprecated. Response information is now directly available on `FCM.Notification` structs, with helper functions `success?/1`, `remove?/1`, `update?/1`, and `retry?/1` replacing the old `:ok`, `:remove`, `:update`, and `:retry` keys. ```FCM Old: FCM.NotificationResponse (keys: :ok, :remove, :update, :retry) New: FCM.Notification (helper functions: success?/1, remove?/1, update?/1, retry?/1) ``` -------------------------------- ### APNS Reconnect Default Change Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating to v1-1-0.md The default behavior for `:reconnect` in APNS configurations has been changed to `false`. ```APNS APNS Config: :reconnect (default: false) ``` -------------------------------- ### Configure Pigeon FCM Environment Variables Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md This snippet shows how to configure the FCM key for Pigeon in Elixir, typically done in a configuration file. ```Elixir config :pigeon, :fcm, fcm_default: %{ key: "your_fcm_key_here" } ``` -------------------------------- ### Configure APNS with Certificate-based Authentication Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md This configuration block sets up a default APNS socket connection using a certificate and key. It supports static file paths, full-text strings, or paths relative to the application's `priv` folder for certificate and key files. The `mode` can be `:dev` or `:prod`. ```Elixir config :pigeon, :apns, apns_default: %{ cert: "cert.pem", key: "key_unencrypted.pem", mode: :dev } ``` -------------------------------- ### Create FCM Notification with Custom Data (Constructor) Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Illustrates how to create an FCM notification with both notification and data keys in its JSON payload by passing them directly to the Pigeon.FCM.Notification.new/3 constructor. ```Elixir notification = %{"body" => "your message"} data = %{"key" => "value"} Pigeon.FCM.Notification.new("registration ID", notification, data) ``` -------------------------------- ### Old Pigeon APNS Default Push Worker Configuration (v1.6) Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md This snippet illustrates the previous configuration method for a default APNS push worker in Pigeon v1.6, which is now deprecated. Workers are no longer configured globally under `:pigeon`. ```Elixir config :pigeon, :apns, apns_default: %{ cert: "cert.pem", key: "key_unencrypted.pem", mode: :dev } ``` -------------------------------- ### Create FCM Notification for Multiple Devices Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Shows how to create an FCM notification packet targeting multiple device registration IDs by passing a list of IDs to Pigeon.FCM.Notification.new/2. ```Elixir msg = %{"body" => "your message"} n = Pigeon.FCM.Notification.new(["first ID", "second ID"], msg) ``` -------------------------------- ### APNS Provider API Error Reasons and Descriptions Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md This section provides a comprehensive list of error reasons returned by the APNS Provider API, along with their detailed descriptions. Understanding these errors is crucial for debugging push notification delivery failures. ```APIDOC APNS Provider API Error Responses: :bad_collapse_id: Description: The collapse identifier exceeds the maximum allowed size :bad_device_token: Description: The specified device token was bad. Verify that the request contains a valid token and that the token matches the environment. :bad_expiration_date: Description: The apns-expiration value is bad. :bad_message_id: Description: The apns-id value is bad. :bad_priority: Description: The apns-priority value is bad. :bad_topic: Description: The apns-topic was invalid. :device_token_not_for_topic: Description: The device token does not match the specified topic. :duplicate_headers: Description: One or more headers were repeated. :idle_timeout: Description: Idle time out. :missing_device_token: Description: The device token is not specified in the request :path. Verify that the :path header contains the device token. :missing_topic: Description: The apns-topic header of the request was not specified and was required. The apns-topic header is mandatory when the client is connected using a certificate that supports multiple topics. :payload_empty: Description: The message payload was empty. :topic_disallowed: Description: Pushing to this topic is not allowed. :bad_certificate: Description: The certificate was bad. :bad_certificate_environment: Description: The client certificate was for the wrong environment. :expired_provider_token: Description: The provider token is stale and a new token should be generated. :forbidden: Description: The specified action is not allowed. :invalid_provider_token: Description: The provider token is not valid or the token signature could not be verified. ``` -------------------------------- ### FCM Legacy API Class Renaming in Pigeon v2.0 Source: https://github.com/codedge-llc/pigeon/blob/main/docs/Migrating-to-v2-0-0.md When migrating to Pigeon v2.0 and using the `pigeon_legacy_fcm` adapter, all instances of `Pigeon.FCM` must be renamed to `Pigeon.LegacyFCM` throughout the project to ensure compatibility with the decommissioned legacy API. ```APIDOC FCM Legacy API Renaming: - Old Class Name: Pigeon.FCM - New Class Name: Pigeon.LegacyFCM - Example Transformation: - Pigeon.FCM.Notification -> Pigeon.LegacyFCM.Notification ``` -------------------------------- ### Handling APNS push responses in Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Illustrates how to define a dedicated handler function to process the response from an asynchronous APNS push, using pattern matching on the notification's `:response` key to differentiate between success and various error states. ```Elixir handler = fn(%Pigeon.APNS.Notification{response: response}) -> case response do :success -> Logger.debug "Push successful!" :bad_device_token -> Logger.error "Bad device token!" _error -> Logger.error "Some other error happened." end end n = Pigeon.APNS.Notification.new("message", "device token", "push topic") Pigeon.APNS.push(n, on_response: handler) ``` -------------------------------- ### Create a Single FCM Notification Packet Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Illustrates how to create a new FCM notification struct with a message body and a single device registration ID using Pigeon.FCM.Notification.new/2. ```Elixir msg = %{"body" => "your message"} n = Pigeon.FCM.Notification.new("your device registration ID", msg) ``` -------------------------------- ### Handle FCM Push Responses with Anonymous Function Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Demonstrates how to pass an optional anonymous function as a second parameter to Pigeon.FCM.push/2 to handle the response of a push operation immediately after it completes. ```Elixir data = %{message: "your message"} n = Pigeon.FCM.Notification.new(data, "device registration ID") Pigeon.FCM.push(n, fn(x) -> IO.inspect(x) end) {:ok, %Pigeon.FCM.Notification{...}} ``` -------------------------------- ### FCM Server Error Response Codes Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Lists common error codes returned by the FCM server, along with their descriptions, providing insight into possible reasons for push failures. ```APIDOC | Reason | Description | | ------------------------------- | ---------------------------- | | ":missing_registration" | Missing Registration Token | | ":invalid_registration" | Invalid Registration Token | | ":not_registered" | Unregistered Device | | ":invalid_package_name" | Invalid Package Name | | ":authentication_error" | Authentication Error | | ":mismatch_sender_id" | Mismatched Sender | | ":invalid_json" | Invalid JSON | | ":message_too_big" | Message Too Big | | ":invalid_data_key" | Invalid Data Key | | ":invalid_ttl" | Invalid Time to Live | | ":unavailable" | Timeout | | ":internal_server_error" | Internal Server Error | | ":device_message_rate_exceeded" | Message Rate Exceeded | | ":topics_message_rate_exceeded" | Topics Message Rate Exceeded | | ":unknown_error" | Unknown Error | ``` -------------------------------- ### Pushing APNS notifications asynchronously with Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Demonstrates how to send an APNS notification asynchronously using `Pigeon.APNS.push` by providing an `on_response` anonymous function to handle the push result. ```Elixir n = Pigeon.APNS.Notification.new("message", "device token", "push topic") Pigeon.APNS.push(n, on_response: fn(x) -> IO.inspect(x) end) ``` -------------------------------- ### Create an Amazon Device Messaging (ADM) notification packet in Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/ADM Amazon Android.md This snippet demonstrates how to construct a new ADM notification packet using Pigeon.ADM.Notification.new/2. It requires a device registration ID and the message payload. ```Elixir msg = %{ "body" => "your message" } n = Pigeon.ADM.Notification.new("your device registration ID", msg) ``` -------------------------------- ### Create FCM Notification with Custom Data (Piping) Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Shows an alternative way to add notification and data keys to an FCM notification using Elixir's pipe operator with put_notification/2 and put_data/2 functions. ```Elixir Pigeon.FCM.Notification.new("registration ID") |> put_notification(%{"body" => "your message"}) |> put_data(%{"key" => "value"}) ``` -------------------------------- ### Configure Pigeon for Amazon Device Messaging (ADM) in Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/ADM Amazon Android.md This snippet shows how to set up the client ID and client secret for Amazon Device Messaging (ADM) within your Elixir application's configuration. These credentials are required for authentication with the ADM service. ```Elixir config :pigeon, :adm, client_id: "your_oauth2_client_id_here", client_secret: "your_oauth2_client_secret_here" ``` -------------------------------- ### Convert Private Key to PEM Format Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Convert the exported `key.p12` file to `key.pem` using `openssl`. This command extracts the private key from the PKCS#12 archive without the certificates. A PEM pass phrase must be set during this step. ```Shell openssl pkcs12 -nocerts -out key.pem -in key.p12 ``` -------------------------------- ### Create a New APNS Notification Packet Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Instantiate a new APNS notification packet using `Pigeon.APNS.Notification.new`. This function requires the message content, the target device token, and an optional push topic (typically the app's bundle identifier). ```Elixir n = Pigeon.APNS.Notification.new("your message", "your device token", "your push topic (optional)") ``` -------------------------------- ### Send an FCM Notification Packet Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Demonstrates how to send a previously created FCM notification packet synchronously using Pigeon.FCM.push/1. The function returns the notification with updated status and response. ```Elixir Pigeon.FCM.push(n) ``` -------------------------------- ### Amazon Device Messaging (ADM) Error Response Codes Source: https://github.com/codedge-llc/pigeon/blob/main/docs/ADM Amazon Android.md This table lists common error reasons returned by the Amazon Device Messaging service, along with their descriptions. These codes help in diagnosing issues when a push notification fails. ```APIDOC Reason: :invalid_registration_id Description: Invalid Registration Token Reason: :invalid_data Description: Bad format JSON data Reason: :invalid_consolidation_key Description: Invalid Consolidation Key Reason: :invalid_expiration Description: Invalid expiresAfter value Reason: :invalid_checksum Description: Invalid md5 value Reason: :invalid_type Description: Invalid Type header Reason: :unregistered Description: App instance no longer available Reason: :access_token_expired Description: Expired OAuth access token Reason: :message_too_large Description: Data size exceeds 6 KB Reason: :max_rate_exceeded Description: See Retry-After response header Reason: :unknown_error Description: Unknown Error ``` -------------------------------- ### Convert Certificate to PEM Format Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Convert the exported `cert.p12` file to `cert.pem` using `openssl`. This command extracts the client certificate from the PKCS#12 archive without the private key. ```Shell openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12 ``` -------------------------------- ### Send Amazon Device Messaging (ADM) notification with inline response handling in Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/ADM Amazon Android.md This snippet illustrates how to send an ADM notification and provide an anonymous function as a second parameter to Pigeon.ADM.push/2 to handle the push response immediately. The response object 'x' contains details about the push outcome. ```Elixir data = %{ message: "your message" } n = Pigeon.ADM.Notification.new("device registration ID", data) Pigeon.ADM.push(n, on_response: fn(x) -> IO.inspect(x) end) ``` -------------------------------- ### Configure Multiple APNS Worker Connections Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Configure multiple named APNS worker connections simultaneously within `config.exs`. This is useful for managing pushes to different applications or environments, each with its own certificate and key. ```Elixir config :pigeon, :apns, default: %{ cert: "cert.pem", key: "key_unencrypted.pem", mode: :dev }, custom_worker: %{ cert: "another_cert.pem", key: "another_key_unencrypted.pem", mode: :prod } ``` -------------------------------- ### Pigeon FCM Notification Struct Definition Source: https://github.com/codedge-llc/pigeon/blob/main/docs/FCM Android.md Defines the structure of the %Pigeon.FCM.Notification{} struct, detailing its fields, their types, and possible values. This struct represents an FCM notification payload. ```APIDOC %Pigeon.FCM.Notification{ collapse_key: nil | String.t(), dry_run: boolean, message_id: nil | String.t(), payload: %{...}, priority: :normal | :high, registration_id: String.t() | [String.t(), ...], response: [] | [{atom, String.t()}, ...], | atom, restricted_package_name: nil | String.t(), status: atom | nil, time_to_live: non_neg_integer } ``` -------------------------------- ### APNs Error Codes and Descriptions Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md A comprehensive list of error codes returned by the Apple Push Notification service (APNs) and their corresponding descriptions, indicating the reason for notification delivery failures or API request issues. ```APIDOC Error Code: :invalid_push_type Description: The apns-push-type value is invalid. Error Code: :missing_provider_token Description: No provider certificate was used to connect to APNs and Authorization header was missing or no provider token was specified. Error Code: :bad_path Description: The request contained a bad :path value. Error Code: :method_not_allowed Description: The specified :method was not POST. Error Code: :expired_token Description: The device token has expired. Error Code: :unregistered Description: The device token is inactive for the specified topic. Error Code: :payload_too_large Description: The message payload was too large. The maximum payload size is 4096 bytes. Error Code: :too_many_provider_token_updates Description: The provider token is being updated too often. Error Code: :too_many_requests Description: Too many requests were made consecutively to the same device token. Error Code: :internal_server_error Description: An internal server error occurred. Error Code: :service_unavailable Description: The service is unavailable. Error Code: :shutdown Description: The server is shutting down. ``` -------------------------------- ### Remove Passphrase from Private Key Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Remove the PEM pass phrase from the `key.pem` file, creating an unencrypted `key_unencrypted.pem`. This unencrypted key can then be used directly in your `config.exs`. ```Shell openssl rsa -in key.pem -out key_unencrypted.pem ``` -------------------------------- ### Send an Amazon Device Messaging (ADM) notification in Elixir Source: https://github.com/codedge-llc/pigeon/blob/main/docs/ADM Amazon Android.md This snippet shows how to send a previously created ADM notification packet using Pigeon.ADM.push/1. The function handles the actual push operation to the Amazon Device Messaging service. ```Elixir Pigeon.ADM.push(n) ``` -------------------------------- ### Add Custom Data and Properties to APNS Notification Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Demonstrates how to add various custom properties to an APNS notification using chained `put_` functions from `Pigeon.APNS.Notification`. This includes setting badge counts, sounds, content availability, mutable content, category, and interruption level. ```Elixir import Pigeon.APNS.Notification n = Pigeon.APNS.Notification.new("message", "device token", "push topic") |> put_badge(5) |> put_sound("default") |> put_content_available |> put_mutable_content |> put_category("category") |> put_interruption_level("time-sensitive") ``` -------------------------------- ### APNS Notification Struct Definition Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md This defines the structure of the `Pigeon.APNS.Notification` struct. The `payload` field contains data received on the iOS device, with string keys. `expiration` is a UNIX epoch date in seconds (UTC); `0` means immediate expiration. ```Elixir %Pigeon.APNS.Notification{ collapse_id: String.t() | nil, device_token: String.t() | nil, expiration: non_neg_integer | nil, id: String.t() | nil, payload: %{String.t() => String.t()}, response: atom, topic: String.t() | nil } ``` -------------------------------- ### Set Complex Alert Dictionary in APNS Notification Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Illustrates how to set a more complex `alert` dictionary within the notification payload, allowing for structured titles and bodies. ```Elixir n |> put_alert(%{ "title" => "alert title", "body" => "alert body" }) ``` -------------------------------- ### Send an APNS Notification Packet Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Send the created notification packet synchronously using `Pigeon.APNS.push`. The function returns the notification with an updated `:response` key, indicating the push result. ```Elixir Pigeon.APNS.push(n) ``` -------------------------------- ### Send APNS Notification to a Specific Named Worker Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Send a notification using a specific named worker connection by passing the `to: :worker_name` option to `Pigeon.APNS.push`. This directs the push through the pre-configured connection. ```Elixir n = Pigeon.APNS.Notification.new("message", "device token", "push topic") Pigeon.APNS.push(n, to: :custom_worker) ``` -------------------------------- ### Define Custom Payload Data in APNS Notification Source: https://github.com/codedge-llc/pigeon/blob/main/docs/APNS Apple iOS.md Shows how to add arbitrary custom data to the notification's payload using `put_custom`, allowing for nested maps to be sent to the device. ```Elixir n |> put_custom(%{"your-custom-key" => %{ "custom-value" => 500 }}) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.