Code Monkey home page Code Monkey logo

exponent-server-sdk-elixir's Introduction

ExponentServerSdk

Hex.pm Build Status Inline docs

Use to send push notifications to Exponent Experiences from an Elixir/Phoenix server.

Installation

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 it from Hex:

def deps do
  [{:exponent_server_sdk, "~> 0.2.0"}]
end

Or from Github:

def deps do
  [{:exponent_server_sdk, github: "rdrop/exponent-server-sdk-elixir"}]
end

and run mix deps.get.

Now, list the :exponent_server_sdk application as your application dependency:

def application do
  [applications: [:exponent_server_sdk]]
end

Usage

Notifications

The ExponentServerSdk.PushNotification is responsible for sending the messages and hits the latest version of the api.

Single Message:

# 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"}}

Multiple Messages:

# 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"} ]}

Get Messages Delivery Statuses:

# 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.

Contributing

See the CONTRIBUTING.md file for contribution guidelines.

License

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.

Inspiration

ex_twilio

exponent-server-sdk-elixir's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

exponent-server-sdk-elixir's Issues

Timeout error when send Multiple Messages to expo backend

%HTTPoison.Error{id: nil, reason: :timeout} ////////////////////////////////////////////////////////////////////////// 03:38:07.879 [error] Process #PID<0.11794.0> on node :"pancake_v2@web-app-7" raised an exception ** (HTTPoison.Error) :timeout (exponent_server_sdk) lib/exponent_server_sdk/push_notification.ex:19: ExponentServerSdk.PushNotification.request!/5 (exponent_server_sdk) lib/exponent_server_sdk/push_notification.ex:46: ExponentServerSdk.PushNotification.push_list/1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.