I'm developing an application in Expo(React-native) that sends notifications to users each time there is a new article in the database. I use expo-notification for this. But after reading the documentation, I realized that the token created is unique. It therefore belongs to a single device. How can I send notifications to several devices at the same time?
I used the documentation to manage notification sending from the back-end. Here's the code.
defmodule PhoenixApi.NotificationsExpo do
alias HTTPoison
@url "https://exp.host/--/api/v2/push/send"
@token "ExponentPushToken[XXXXXXXXXXXXXXXXXXXXX]"
def send_to_expo(messages) when is_list(messages) do
headers = [{"content-type", "application/json"}]
body = Jason.encode!(messages |> add_token_to_messages())
case HTTPoison.post(@url, body, headers) do
{:ok, %HTTPoison.Response{body: body}} ->
{:ok, Jason.decode!(body)}
{:error, %HTTPoison.Error{reason: reason}} ->
{:error, reason}
end
end
defp add_token_to_messages(messages) do
Enum.map(messages, fn message ->
Map.put(message, "to", @token)
end)
end
end
Thanks for your answer.