View Source ADM (Amazon Android)
Usage
Set your environment variables.
config :pigeon, :adm, client_id: "your_oauth2_client_id_here", client_secret: "your_oauth2_client_secret_here"
Create a notification packet.
msg = %{ "body" => "your message" } n = Pigeon.ADM.Notification.new("your device registration ID", msg)
Send the packet.
Pigeon.ADM.push(n)
Handling Push Responses
Pass an optional anonymous function as your second parameter.
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)
Responses return a notification with an updated
:response
key. You could handle responses like so: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)
Error Responses
Taken from Amazon Device Messaging docs
Reason | Description |
---|---|
:invalid_registration_id | Invalid Registration Token |
:invalid_data | Bad format JSON data |
:invalid_consolidation_key | Invalid Consolidation Key |
:invalid_expiration | Invalid expiresAfter value |
:invalid_checksum | Invalid md5 value |
:invalid_type | Invalid Type header |
:unregistered | App instance no longer available |
:access_token_expired | Expired OAuth access token |
:message_too_large | Data size exceeds 6 KB |
:max_rate_exceeded | See Retry-After response header |
:unknown_error | Unknown Error |