This is an oVice fork of the original ExponentServerSdk project which is heavily outdated and does not support newer Elixir versions
The fork is just for making the library usable and adding the access token feature, we might need to maintain this library even further by improving code quality, adding proper tests/mocks, use Tesla instead of Poison or abandon it and write a from scratch module in ex-api
.
Some tests may fail because the library doesn't mock API calls but executes them with incorrect tokens instead
Use to send push notifications to Exponent Experiences from an Elixir/Phoenix server.
ExponentServerSdk is currently able to push single and multiple messages to the Expo Server and retrieve message delivery statuses from a list of IDs.
All HTTPoison Post Request body are automatically GZIP compressed.
You can install from Github:
def deps do
[{:exponent_server_sdk, git: "https://github.com/oviceinc/exponent-server-sdk-elixir.git"}]
end
and run mix deps.get
.
Now, list the :exponent_server_sdk
application as your application dependency:
def application do
[extra_applications: [:exponent_server_sdk]]
end
This fork supports setting up an access token to be used as bearer token when communication with Expo's APIs. More in here.
It's done by setting up a similar module config:
config :exponent_server_sdk,
:access_token,
System.get_env("EXPO_ACCESS_TOKEN", "MY_ACCESS_TOKEN")
The ExponentServerSdk.PushNotification
is responsible for sending the messages and hits the latest version of the api.
# Create a single message map
message = %{
to: "ExponentPushToken[XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX]",
title: "Pushed!",
body: "You got your first message"
}
# Send it to Expo
{:ok, response} = ExponentServerSdk.PushNotification.push(message)
# Example Response
{:ok, %{"status" => "ok", "id" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"}}
# Create a list of message maps (auto chunks list into lists of 100)
message_list = [
%{
to: "ExponentPushToken[XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX]",
title: "Pushed!",
body: "You got your first message"
},
%{
to: "ExponentPushToken[YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY]",
title: "Pushed Again!",
body: "You got your second message"
}
]
# Send it to Expo
{:ok, response} = ExponentServerSdk.PushNotification.push_list(messages)
# Example Response
{:ok,[ %{"status" => "ok", "id" => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"}, %{"status" => "ok", "id" => "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"} ]}
# Create a list of message ids
ids = ["XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY"]
# Send it to Expo
{:ok, response} = ExponentServerSdk.PushNotification.get_receipts(ids)
# Example Response
{:ok,[ %{ "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX": %{ "status": "ok" }, "YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY": %{ "status": "ok" } } ]}
The complete format of the messages can be found here.
See the CONTRIBUTING.md file for contribution guidelines.
ExponentServerSdk is licensed under the MIT license. For more details, see the LICENSE
file at the root of the repository. It depends on Elixir, which is under the
Apache 2 license.