Trying to setup pigeon for push notification

Hi, I’m trying to use pigeon notification and setting up locally using this library Pigeon

I’m trying to use fcm config. FCM is used for android basically to setup this we have to follow this setup


config :pigeon, :fcm,
  fcm_default: %{
    key: "your_fcm_key_here"
  }

I have to add this in config. Key is something you can use when you’re using firebase. There you can create a project which will have the key for detail information follow it here

Now the next setup is to define your workers in config like this

config :pigeon, workers: [
  {YourApp.Pigeon, :apns_config},
  {YourApp.Pigeon, :fcm_config}
]

But to run this you have to check application.ex file

defmodule PushNotification.Application do
  # See https://hexdocs.pm/elixir/Application.html
  # for more information on OTP Applications
  @moduledoc false

  use Application

  def start(_type, _args) do
    children = [
      # Start the Ecto repository
      PushNotification.Repo,
      # Start the Telemetry supervisor
      PushNotificationWeb.Telemetry,
      # Start the PubSub system
      {Phoenix.PubSub, name: PushNotification.PubSub},
      # Start the Endpoint (http/https)
      PushNotificationWeb.Endpoint
      # Start a worker by calling: PushNotification.Worker.start_link(arg)
      # {PushNotification.Worker, arg}
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: PushNotification.Supervisor]
    with {:ok, sup} <- Supervisor.start_link(children, opts),
        {:ok, _} <- Application.ensure_all_started(:pigeon, :permanent) do
      {:ok, sup}
    end
  end

  # Tell Phoenix to update the endpoint configuration
  # whenever the application is updated.
  def config_change(changed, _new, removed) do
    PushNotificationWeb.Endpoint.config_change(changed, removed)
    :ok
  end
end

Basically I have to add this and it will start after the repo module

  with {:ok, sup} <- Supervisor.start_link(children, opts),
      {:ok, _} <- Application.ensure_all_started(:pigeon, :permanent) do
    {:ok, sup}
  end

So if you can see above I have two workers module. One for ios and other for android. If I’m only using ios its working fine. But if I have added one more worker module there its leading me to this error

** (Mix) Could not start application pigeon: Pigeon.start(:normal, []) returned an error: bad child specification, more than one child specification has the id: nil.
If using maps as child specifications, make sure the :id keys are unique.
If using a module or {module, arg} as child, use Supervisor.child_spec/2 to change the :id, for example:

    children = [
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_1),
      Supervisor.child_spec({MyWorker, arg}, id: :my_worker_2)
    ]

Let me know if you need more information

1 Like